Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,10 @@ describe("OAuth error parsing", () => {
});

describe("Claude assistant prefill stripping", () => {
const maxStepsPrefill = `CRITICAL - MAXIMUM STEPS REACHED

The maximum number of steps allowed for this task has been reached. Tools are disabled until next user input. Respond with text only.`;

it("strips the synthetic continue prefill so Anthropic requests end with a user message", () => {
const out = stripAssistantPrefillForClaude([
{ role: "user", content: [{ type: "text", text: "hello" }] },
Expand All @@ -167,13 +171,44 @@ describe("Claude assistant prefill stripping", () => {
]);
});

it("converts opencode max-steps assistant prefill into a user message", () => {
const out = stripAssistantPrefillForClaude([
{ role: "user", content: [{ type: "text", text: "hello" }] },
{ role: "assistant", content: maxStepsPrefill },
]);
assert.deepEqual(out, [
{ role: "user", content: [{ type: "text", text: "hello" }] },
{ role: "user", content: maxStepsPrefill },
]);
});

it("converts text-block max-steps assistant prefill into a user message", () => {
const content = [{ type: "text", text: maxStepsPrefill }];
const out = stripAssistantPrefillForClaude([
{ role: "user", content: [{ type: "text", text: "hello" }] },
{ role: "assistant", content },
]);
assert.deepEqual(out, [
{ role: "user", content: [{ type: "text", text: "hello" }] },
{ role: "user", content },
]);
});

it("keeps non-synthetic assistant messages intact", () => {
const input = [
{ role: "user", content: [{ type: "text", text: "hello" }] },
{ role: "assistant", content: "Real assistant content" },
];
assert.deepEqual(stripAssistantPrefillForClaude(input), input);
});

it("keeps assistant tool-use messages intact", () => {
const input = [
{ role: "user", content: [{ type: "text", text: "hello" }] },
{ role: "assistant", content: [{ type: "tool_use", id: "toolu_1", name: "Read", input: {} }] },
];
assert.deepEqual(stripAssistantPrefillForClaude(input), input);
});
});

describe("system cache control", () => {
Expand Down