Files
plugins/packages/workbuddy/unflag.test.mjs
T
yetone 575f1e23e7 workbuddy 0.1.30: a refused line quoted back into an assistant message is reworded there too (#291)
tearslee measured on 0.1.29 that the "Web GUI whose URL the runtime
context names. When the user refers" line is refused as 11128 in an
assistant message, where the system-prompt move can't reach it, so a
long DeepSeek Harness chat stays refused for good. Its wording "...
names. The interface, when the user refers" went 400 -> 200 for them.
It joins FLAGGED, which unflag applies to every message, assistant
ones included. The README now says the move doesn't cover an assistant
message and that only a new chat clears words not in the list.

Run: bun test in packages/workbuddy (sandbox HOME), 112 pass; the new
test covers a string and a parts assistant message and a line break
between the sentences.
Not tried: the 400 itself. A short probe with the line through magpie
got 200, so the refusal needs more of the chat than I have; the 400 ->
200 is tearslee's measurement.
2026-10-23 09:31:24 +08:00

72 lines
4.1 KiB
JavaScript

// WorkBuddy refuses a chat holding words of Codex's or Claude Code's own
// prompts (magpie #182); withSystem puts words that pass in their place,
// in every message, as tried against both builds.
import { expect, test } from "bun:test"
import { _internal } from "./index.mjs"
const { withSystem, unflagged } = _internal
test("each flagged phrase is put in other words, whatever its case", () => {
expect(unflagged("You are Claude Code, Anthropic's official CLI for Claude.")).toBe("You are Claude Code, Anthropic's CLI for Claude.")
expect(unflagged("Main branch (you will usually use this for PRs): main")).toBe("Main branch (usually the base for PRs): main")
expect(unflagged("MAIN BRANCH (YOU WILL USUALLY USE THIS FOR PRS): main")).toBe("Main branch (usually the base for PRs): main")
const codex = "You are a coding agent running in the Codex CLI, a terminal-based coding assistant. Codex CLI is an open source project led by OpenAI. You are expected to be precise, safe, and helpful."
expect(unflagged(codex)).toBe(codex.replace("Codex CLI is an open", "The Codex CLI is an open"))
expect(unflagged(unflagged(codex))).toBe(unflagged(codex))
expect(unflagged("x-anthropic-billing-header: cc_version=2.1.280.31f; cc_entrypoint=sdk-cli;\nhello")).toBe("hello")
expect(unflagged("nothing to see")).toBe("nothing to see")
expect(unflagged("You are an AI agent powered by DeepSeek Harness. Be brief.")).toBe("You are an AI agent that helps the user with programming tasks. Be brief.")
expect(unflagged("YOU ARE AN AI AGENT POWERED BY DEEPSEEK HARNESS")).toBe("You are an AI agent that helps the user with programming tasks.")
})
test("Claude Code's request through magpie passes: header block gone, the rest rewritten", () => {
const body = JSON.stringify({
model: "glm-5.3",
messages: [
{ role: "system", content: [
{ type: "text", text: "x-anthropic-billing-header: cc_version=2.1.280.31f; cc_entrypoint=cli;" },
{ type: "text", text: "You are Claude Code, Anthropic's official CLI for Claude." },
] },
{ role: "user", content: [{ type: "text", text: "gitStatus\nMain branch (you will usually use this for PRs): main" }, { type: "image_url", image_url: { url: "data:," } }] },
],
})
const b = JSON.parse(withSystem(body))
expect(b.messages[0]).toEqual({ role: "system", content: [{ type: "text", text: "You are Claude Code, Anthropic's CLI for Claude." }] })
expect(b.messages[1].content[0].text).toBe("gitStatus\nMain branch (usually the base for PRs): main")
expect(b.messages[1].content[1]).toEqual({ type: "image_url", image_url: { url: "data:," } })
})
test("a system message of the header alone goes, and WorkBuddy's default takes its place", () => {
const body = JSON.stringify({ messages: [
{ role: "system", content: "x-anthropic-billing-header: cc_version=2.1.280; cc_entrypoint=cli;" },
{ role: "user", content: "hi" },
] })
expect(JSON.parse(withSystem(body)).messages).toEqual([
{ role: "system", content: "You are a helpful assistant." },
{ role: "user", content: "hi" },
])
})
test("a chat with nothing flagged is sent as it came", () => {
const body = JSON.stringify({ messages: [{ role: "system", content: "be brief" }, { role: "user", content: "hi" }] })
expect(withSystem(body)).toBe(body)
})
test("a refused line quoted back into an assistant message is reworded there too (#291)", () => {
const line = "There is a Web GUI whose URL the runtime context names. When the user refers to it, open it."
const fixed = "There is a Web GUI whose URL the runtime context names. The interface, when the user refers to it, open it."
expect(unflagged(line)).toBe(fixed)
expect(unflagged(line.replace(". When", ".\nWhen"))).toBe(fixed)
expect(unflagged(fixed)).toBe(fixed)
const body = JSON.stringify({ messages: [
{ role: "system", content: "be brief" },
{ role: "user", content: "hi" },
{ role: "assistant", content: line },
{ role: "assistant", content: [{ type: "text", text: line }] },
{ role: "user", content: "go on" },
] })
const b = JSON.parse(withSystem(body))
expect(b.messages[2].content).toBe(fixed)
expect(b.messages[3].content[0].text).toBe(fixed)
})