zen-free: ZCode 3.17.2 workflow tool pairs go under other names (#694)
Reviewed every line at 4619beb34bdfc3a2d16ee067a12e10f064501e6c. Adds two REFUSED_TOGETHER pairs (CreateWorkflow+GetWorkflowRun, AmendWorkflow+FillWorkflowHole) for ZCode 3.17.2. The rename and the way back reuse the existing renameRefused / nameGuard paths unchanged, so tools, past calls and tool_choice are renamed and replies (streamed or not) come back under ZCode's names in chat, responses and messages. Run on mote at that head (node --test packages/zen-free/*.test.mjs, node 22): 212 of 216 pass. The 4 reds (3 "sends OpenCode's own headers" tests and keyless.test.mjs) fail the same on origin/main in a worktree (208 of 212; node 22 adds accept-language/sec-fetch-mode headers), so they are not from this PR. Broke it by hand: provider.mjs from origin/main with the PR's tests -> the 3 new per-protocol round-trip tests fail (index.test 55-57); the lone-name test passes both ways, as it should. Not tried: a real ZCode request against Zen (the reporter's bisection is taken from the PR). Version bump follows on main (0.1.25).
This commit is contained in:
@@ -1110,6 +1110,97 @@ for (const { protocol, path, model } of protocols) {
|
||||
});
|
||||
}
|
||||
|
||||
// Z.ai's ZCode 3.17.2 declares its dynamic-workflow tools, and Zen refuses
|
||||
// the whole request when two of them travel together: CreateWorkflow beside
|
||||
// GetWorkflowRun, and AmendWorkflow beside FillWorkflowHole. Either name
|
||||
// alone is served (a real 55-tool ZCode request bisected on 2026-11-04,
|
||||
// plugins#693). Its other workflow tools, ListWorkflowRuns included, keep
|
||||
// their names.
|
||||
for (const { protocol, path, model } of protocols) {
|
||||
test(`${protocol}: ZCode's workflow pairs go under other names and come back as ZCode's (#693)`, async (t) => {
|
||||
const { plugin, state, origin } = await fixture(t);
|
||||
await plugin.provider.models({ models: {} }, { auth: await publicAuth() });
|
||||
const loader = await plugin.auth.loader(publicAuth);
|
||||
const schema = { type: "object", properties: { run_id: { type: "string" } } };
|
||||
const names = ["CreateWorkflow", "GetWorkflowRun", "AmendWorkflow", "FillWorkflowHole", "ListWorkflowRuns"];
|
||||
const tools = names.map((name) => {
|
||||
const tool = { name, description: `ZCode ${name}` };
|
||||
if (protocol === "chat") return { type: "function", function: { ...tool, parameters: schema } };
|
||||
if (protocol === "anthropic") return { ...tool, input_schema: schema };
|
||||
return { type: "function", ...tool, parameters: schema };
|
||||
});
|
||||
const body = { model, stream: false, tools };
|
||||
if (protocol === "chat") {
|
||||
body.messages = [
|
||||
{ role: "user", content: "hi" },
|
||||
{ role: "assistant", content: [], tool_calls: [{ id: "c0", type: "function", function: { name: "GetWorkflowRun", arguments: "{}" } }] },
|
||||
{ role: "tool", tool_call_id: "c0", content: "ok" },
|
||||
];
|
||||
body.tool_choice = { type: "function", function: { name: "CreateWorkflow" } };
|
||||
} else if (protocol === "anthropic") {
|
||||
body.messages = [
|
||||
{ role: "user", content: "hi" },
|
||||
{ role: "assistant", content: [{ type: "tool_use", id: "c0", name: "GetWorkflowRun", input: {} }] },
|
||||
{ role: "user", content: [{ type: "tool_result", tool_use_id: "c0", content: "ok" }] },
|
||||
];
|
||||
body.tool_choice = { type: "tool", name: "CreateWorkflow" };
|
||||
} else {
|
||||
body.input = [
|
||||
{ role: "user", content: "hi" },
|
||||
{ type: "function_call", call_id: "c0", name: "GetWorkflowRun", arguments: "{}" },
|
||||
{ type: "function_call_output", call_id: "c0", output: "ok" },
|
||||
];
|
||||
body.tool_choice = { type: "function", name: "CreateWorkflow" };
|
||||
}
|
||||
const send = () => loader.fetch(`${origin}/v1/${path}`, { method: "POST", body: JSON.stringify(body) });
|
||||
for (const [upstream, expected] of [
|
||||
["workflow_inspect", "GetWorkflowRun"],
|
||||
["workflow_amend", "AmendWorkflow"],
|
||||
["ListWorkflowRuns", "ListWorkflowRuns"],
|
||||
]) {
|
||||
state.reply = toolReply(protocol, upstream, true);
|
||||
const response = await send();
|
||||
assert.equal(response.status, 200);
|
||||
const text = await response.text();
|
||||
assert.match(text, new RegExp(`"name"\\s*:\\s*"${expected}"`), upstream);
|
||||
}
|
||||
const sent = state.calls.at(-1).body;
|
||||
const sentNames = sent.tools.map((tool) => (protocol === "chat" ? tool.function.name : tool.name));
|
||||
assert.deepEqual(sentNames.slice(0, names.length), [
|
||||
"workflow_create",
|
||||
"workflow_inspect",
|
||||
"workflow_amend",
|
||||
"workflow_answer",
|
||||
"ListWorkflowRuns",
|
||||
]);
|
||||
const described = sent.tools.find((tool) => (tool.function?.name ?? tool.name) === "workflow_amend");
|
||||
assert.equal(described.function?.description ?? described.description, "ZCode AmendWorkflow");
|
||||
const past =
|
||||
protocol === "chat"
|
||||
? sent.messages.find((message) => message.tool_calls).tool_calls[0].function.name
|
||||
: protocol === "anthropic"
|
||||
? sent.messages[1].content[0].name
|
||||
: sent.input[1].name;
|
||||
assert.equal(past, "workflow_inspect");
|
||||
assert.equal(sent.tool_choice.function?.name ?? sent.tool_choice.name, "workflow_create");
|
||||
});
|
||||
}
|
||||
|
||||
test("a ZCode workflow tool alone goes as named (#693)", async (t) => {
|
||||
const { plugin, state, origin } = await fixture(t);
|
||||
await plugin.provider.models({ models: {} }, { auth: await publicAuth() });
|
||||
const loader = await plugin.auth.loader(publicAuth);
|
||||
for (const name of ["CreateWorkflow", "GetWorkflowRun", "AmendWorkflow", "FillWorkflowHole"]) {
|
||||
const tools = [...declaredTools("chat"), { type: "function", function: { name, parameters: { type: "object" } } }];
|
||||
const response = await loader.fetch(`${origin}/v1/chat/completions`, {
|
||||
method: "POST",
|
||||
body: JSON.stringify({ model: "chat-free", stream: false, tools }),
|
||||
});
|
||||
await response.text();
|
||||
assert.deepEqual(state.calls.at(-1).body.tools.slice(0, tools.length), tools, name);
|
||||
}
|
||||
});
|
||||
|
||||
test("read_image or working_directory alone goes as named (#632)", async (t) => {
|
||||
const { plugin, state, origin } = await fixture(t);
|
||||
await plugin.provider.models({ models: {} }, { auth: await publicAuth() });
|
||||
|
||||
@@ -279,7 +279,11 @@ function normalizeTools(body, protocol) {
|
||||
// request bisected on 2026-10-30 (Ebony-Vinyl/dsh-our-free-model#709),
|
||||
// served whole with only those two names changed, as jdld-ybd saw DSH
|
||||
// refused while other agents were served from the same address
|
||||
// (plugins#632).
|
||||
// (plugins#632);
|
||||
// - ZCode 3.17.2's CreateWorkflow offered beside GetWorkflowRun, and its
|
||||
// AmendWorkflow beside FillWorkflowHole (either alone was served): a
|
||||
// real 55-tool ZCode request bisected on 2026-11-04, served whole with
|
||||
// only those four names changed (plugins#693).
|
||||
//
|
||||
// Such a tool goes to Zen under another name (the ones those bisections
|
||||
// were served under), in the agent's past calls and tool_choice too, and a
|
||||
@@ -293,6 +297,14 @@ const REFUSED_TOGETHER = [
|
||||
},
|
||||
{ names: ["subagent_fork"], as: { subagent_fork: "conversation_delegate" } },
|
||||
{ names: ["read_image", "working_directory"], as: { working_directory: "workspace_directory" } },
|
||||
{
|
||||
names: ["CreateWorkflow", "GetWorkflowRun"],
|
||||
as: { CreateWorkflow: "workflow_create", GetWorkflowRun: "workflow_inspect" },
|
||||
},
|
||||
{
|
||||
names: ["AmendWorkflow", "FillWorkflowHole"],
|
||||
as: { AmendWorkflow: "workflow_amend", FillWorkflowHole: "workflow_answer" },
|
||||
},
|
||||
];
|
||||
const REFUSED_WORD = /terminal/i;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user