Squashed 'third_party/pi/' content from commit d981de122
git-subtree-dir: third_party/pi git-subtree-split: d981de1229ef899957bbe968bc8dcda02a21f477
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
import type { AssistantMessage } from "@earendil-works/pi-ai";
|
||||
import { Container } from "@earendil-works/pi-tui";
|
||||
import { describe, expect, test } from "vitest";
|
||||
import { InteractiveMode } from "../src/modes/interactive/interactive-mode.ts";
|
||||
import { initTheme } from "../src/modes/interactive/theme/theme.ts";
|
||||
import { stripAnsi } from "../src/utils/ansi.ts";
|
||||
|
||||
const message: AssistantMessage = {
|
||||
role: "assistant",
|
||||
content: [{ type: "text", text: "survived" }],
|
||||
api: "anthropic-messages",
|
||||
provider: "anthropic",
|
||||
model: "claude-fable-5-1",
|
||||
usage: {
|
||||
input: 1,
|
||||
output: 1,
|
||||
cacheRead: 0,
|
||||
cacheWrite: 0,
|
||||
totalTokens: 2,
|
||||
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 },
|
||||
},
|
||||
stopReason: "stop",
|
||||
timestamp: 1,
|
||||
diagnostics: [
|
||||
{
|
||||
type: "anthropic_input_transformations",
|
||||
timestamp: 1,
|
||||
details: {
|
||||
transformations: [
|
||||
{
|
||||
type: "thinking_dropped",
|
||||
path: "messages.2.content.0",
|
||||
reason: "prefix_binding_mismatch",
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
describe("InteractiveMode assistant diagnostics", () => {
|
||||
test("shows Anthropic thinking drops when cache miss notices are enabled", () => {
|
||||
const maybeShowAssistantDiagnostics = Reflect.get(InteractiveMode.prototype, "maybeShowAssistantDiagnostics") as (
|
||||
this: {
|
||||
chatContainer: Container;
|
||||
settingsManager: { getShowCacheMissNotices(): boolean };
|
||||
},
|
||||
message: AssistantMessage,
|
||||
) => void;
|
||||
|
||||
initTheme("dark");
|
||||
const enabled = {
|
||||
chatContainer: new Container(),
|
||||
settingsManager: { getShowCacheMissNotices: () => true },
|
||||
};
|
||||
maybeShowAssistantDiagnostics.call(enabled, message);
|
||||
const output = stripAnsi(enabled.chatContainer.render(120).join("\n"));
|
||||
expect(output).toContain("Anthropic dropped thinking block: prefix_binding_mismatch at messages.2.content.0");
|
||||
|
||||
const disabled = {
|
||||
chatContainer: new Container(),
|
||||
settingsManager: { getShowCacheMissNotices: () => false },
|
||||
};
|
||||
maybeShowAssistantDiagnostics.call(disabled, message);
|
||||
expect(disabled.chatContainer.children).toHaveLength(0);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user