stdio (TypeScript): a stopping tool runner's fault reaches the bundle as such and is asked again (H-A-544)
As in the Go stdio: the runtime's answer names its typed fault in the error's data error-kind, kept on the error as errorKind (isStopping); a broker request (mesh/ask) met by stopping is asked again after a pause at the kept-call pace (the settings kept-call-pace-first and -max, 1 s doubling to 30 s by default) until the new runner answers or 60 s end, then the fault is the caller's. A plain refusal is never asked again; a TypeScript bundle (the forge, the registries' holder) meets a restarting runner as a Go one does. Builds: design 47 H2 H-A-542, H-A-544
This commit is contained in:
@@ -378,3 +378,49 @@ async function aBundlesFindingWriter(): Promise<void> {
|
||||
child.kill();
|
||||
}
|
||||
}
|
||||
|
||||
test("a call a stopping tool runner did not take is asked again after a pause until the new runner answers; a plain refusal is not (design 47 H2 H-A-542, H-A-544)", async () => {
|
||||
const child = spawn(process.execPath, [fileURLToPath(new URL("./fixtures/stdio-stopping.mjs", import.meta.url))],
|
||||
{ stdio: ["pipe", "pipe", "pipe"], env: { ...process.env, MESH_SERVED_MODULE: "builder",
|
||||
MESH_CONFIG_KEPT_CALL_PACE_FIRST: "1ms", MESH_CONFIG_KEPT_CALL_PACE_MAX: "2ms" } });
|
||||
const seen: any[] = [];
|
||||
let buffered = "";
|
||||
let said = "";
|
||||
child.stderr.on("data", (d) => (said += d.toString()));
|
||||
child.stdout.on("data", (d) => {
|
||||
buffered += d.toString();
|
||||
let at: number;
|
||||
while ((at = buffered.indexOf("\n")) >= 0) {
|
||||
seen.push(JSON.parse(buffered.slice(0, at)));
|
||||
buffered = buffered.slice(at + 1);
|
||||
}
|
||||
});
|
||||
const until = async (match: (m: any) => boolean) => {
|
||||
for (let i = 0; i < 150 && !seen.some(match); i++) await new Promise((r) => setTimeout(r, 20));
|
||||
return seen.find(match);
|
||||
};
|
||||
const send = (m: unknown) => child.stdin.write(JSON.stringify(m) + "\n");
|
||||
const stopping = { code: -32000, message: "registry's publish was not taken: the tool runner is stopping", data: { "error-kind": "stopping" } };
|
||||
try {
|
||||
send({ jsonrpc: "2.0", id: 1, method: "initialize", params: { protocolVersion: "2025-03-26", capabilities: {} } });
|
||||
await until((m) => m.id === 1);
|
||||
for (const row of [
|
||||
{ id: 2, answers: [{ error: stopping }, { error: stopping }, { result: { published: true } }], want: { answer: { published: true } } },
|
||||
{ id: 3, answers: [{ error: { code: -32000, message: "refused" } }], want: { stopping: false, words: "refused" } },
|
||||
]) {
|
||||
send({ jsonrpc: "2.0", id: row.id, method: "tools/call", params: { name: "publish", arguments: {} } });
|
||||
for (const a of row.answers) {
|
||||
const asked = await until((m) => m.method === "mesh/ask" && !m.answered);
|
||||
assert.ok(asked, `the bundle did not ask again (row ${row.id})`);
|
||||
asked.answered = true;
|
||||
send({ jsonrpc: "2.0", id: asked.id, ...a });
|
||||
}
|
||||
const done = await until((m) => m.id === row.id);
|
||||
assert.deepEqual(JSON.parse(done.result.content[0].text), row.want);
|
||||
assert.equal(seen.filter((m) => m.method === "mesh/ask" && !m.answered).length, 0, `asked more than ${row.answers.length} times`);
|
||||
}
|
||||
assert.match(said, /the tool runner is stopping/);
|
||||
} finally {
|
||||
child.kill();
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user