zcode: test the system shape zcode.z.ai lets through (plugins#348)
XinOrigin's matrix on plugins#348 (11-04) says zcode.z.ai serves a Start Plan request only when its system is an array of two or three text blocks, ZCode's first byte for byte and its second as ZCode's begins; a string, no system, the first block alone, the first with a block of the caller's, or a fourth block answers 405/3012. The new test sends Claude Code's shape (billing-header block, prompt, CLAUDE.md block, with thinking adaptive, context_management and output_config), Codex's string instructions, no system, and ZCode's first block alone, and checks each goes out as the passing row: three text blocks, ZCode's first two unchanged, the agent's text after ZCode's own sections in the third, the top-level fields kept. No code change: 0.1.51 already sends this shape (0.1.21 for #343, 0.1.48 for the 3.17.2 texts). Live, on the owner's ZCode account (11-06 15:48 UTC, a GLM Coding Plan account with no Start Plan gift), one request each to zcode.z.ai/api/v1/zcode-plan/anthropic/v1/messages with 0.1.51's startHeaders and dress: - Claude Code-style system: 200 {"code":1005,"msg":"exceed quota limit"} - the same with a 30KB agent system: 200, 1005 - Codex-style string system: 200, 1005 - Claude Code's top-level fields and a tool: 200, 1005 - control, ZCode's first block alone, not dressed: 405 code 3012 (logid 20261106154826f91ddad38c8bfdefae1d) So the system check runs before the quota check, and 0.1.51's dressing gets past it. Not tried: a request on an account with a live gift (the owner's has none), and a burst of requests. Run on mote: bun test in packages/zcode, 201 pass, 0 fail, 12 runs in a row; one earlier run had 5 reds in userid.test.mjs (expect(got.length) .toBe(1)), not seen again in those 12 runs. bun scripts/check.mjs zcode ok. Broken by hand: dress sending the agent's text as a fourth block and more turns the new test red (Expected 3, Received 6); restored, green.
This commit is contained in:
@@ -177,6 +177,41 @@ test("a Start Plan request's system is ZCode's three blocks, the agent's text at
|
||||
expect(JSON.parse(r.body).system).toEqual(zcodeSystem("zai-api/GLM-5.3"))
|
||||
})
|
||||
|
||||
// plugins#348 (XinOrigin, 11-04): zcode.z.ai lets a Start Plan request
|
||||
// through only when its system is an array of two or three text blocks,
|
||||
// ZCode's first byte for byte and its second as ZCode's begins; a string,
|
||||
// no system, the first alone, the first with a block of the caller's, or a
|
||||
// fourth block answers 405/3012. Claude Code's billing-header block and
|
||||
// Codex's string instructions, the two shapes a magpie agent sends, each
|
||||
// go out as the passing row: ZCode's three, the agent's text after
|
||||
// ZCode's own sections in the third. On 11-06 both, and Claude Code's
|
||||
// thinking, context_management and output_config, got past the check
|
||||
// live (1005 for an account with no gift) where ZCode's first block alone
|
||||
// got 3012.
|
||||
test("an agent's system goes out as the shape zcode.z.ai lets through (plugins#348)", async () => {
|
||||
const claude = [
|
||||
{ type: "text", text: "x-anthropic-billing-header: cc_version=2.1.310; cc_entrypoint=cli;" },
|
||||
{ type: "text", text: "You are an interactive agent that helps users with software engineering tasks.", cache_control: eph },
|
||||
{ type: "text", text: "# CLAUDE.md\nproject rules", cache_control: eph },
|
||||
]
|
||||
const codex = "You are Codex, a coding agent. You and the user share the same workspace."
|
||||
const extra = { thinking: { type: "adaptive" }, context_management: { edits: [{ type: "clear_thinking_20251015", keep: "all" }] }, output_config: { effort: "high" } }
|
||||
for (const system of [claude, codex, undefined, [{ type: "text", text: PROMPT.cliPrefix }]]) {
|
||||
got.length = 0
|
||||
const r = await send(start("zai"), JSON.stringify({ model: "GLM-5.3-Flash", max_tokens: 8, system, ...extra, messages: [{ role: "user", content: "hi" }] }))
|
||||
const b = JSON.parse(r.body)
|
||||
expect(Array.isArray(b.system)).toBe(true)
|
||||
expect(b.system.length).toBe(3)
|
||||
expect(b.system.every((x) => x.type === "text")).toBe(true)
|
||||
expect(b.system[0].text).toBe(PROMPT.cliPrefix)
|
||||
expect(b.system[1].text).toBe(PROMPT.stableSections.join("\n\n"))
|
||||
expect(b.system[2].text.startsWith("\n\n" + PROMPT.dynamicBehavior)).toBe(true)
|
||||
const own = system === undefined ? [] : typeof system === "string" ? [system] : system.map((x) => x.text)
|
||||
expect(b.system[2].text.endsWith(PROMPT.contextManagement + (own.length ? "\n\n" + own.join("\n\n") : ""))).toBe(true)
|
||||
for (const k of Object.keys(extra)) expect(b[k]).toEqual(extra[k])
|
||||
}
|
||||
})
|
||||
|
||||
test("the prompt texts are the plugin's, byte for byte", () => {
|
||||
expect(sha(PROMPT.cliPrefix)).toBe("7779642ea44a4696")
|
||||
expect(PROMPT.cliPrefix).toBe("You are ZCode, an interactive agent")
|
||||
|
||||
Reference in New Issue
Block a user