Files
dev/third_party/pi/packages/coding-agent/test/interactive-mode-assistant-diagnostics.test.ts
alexion 4def357d09 chore(vendor): import pi 0.85.1
Imported as a linear vendor commit so forge rebases do not replay the upstream root tree.

git-subtree-dir: third_party/pi

git-subtree-split: d981de1229ef899957bbe968bc8dcda02a21f477
2026-09-14 10:48:47 -04:00

68 lines
2.0 KiB
TypeScript

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);
});
});