S3 ask-once-ts: the TypeScript stdio asks once; the kind stopping goes
Builds: design 47 H2 H-A-570 (2) (3) (4)
This commit is contained in:
Vendored
+16
@@ -0,0 +1,16 @@
|
||||
// A launched bundle whose one tool asks a seat's verb through the runtime, and says how the ask ended: its answer, or the
|
||||
// words of its fault (design 47 H2 H-A-570 (2), (4)).
|
||||
import { broker } from "../../dist/messaging/index.js";
|
||||
import { registerModuleTools } from "../../dist/tools/index.js";
|
||||
import { serveRegisteredOverStdio } from "../../dist/stdio/index.js";
|
||||
|
||||
registerModuleTools("builder", () => [
|
||||
{ name: "publish", description: "asks the registry", input: {}, run: async () => {
|
||||
try {
|
||||
return { answer: await broker().request("seat:go-package-registry.publish", {}) };
|
||||
} catch (err) {
|
||||
return { words: err.message };
|
||||
}
|
||||
} },
|
||||
]);
|
||||
await serveRegisteredOverStdio();
|
||||
Vendored
-24
@@ -1,24 +0,0 @@
|
||||
// A launched bundle whose one tool asks a seat's verb through the runtime, and says how the ask ended: its answer, or
|
||||
// whether its fault was the typed fault stopping, and the pauses between its asks (design 47 H2 H-A-542, H-A-544,
|
||||
// H-A-549). Its pause moves a clock instead of sleeping.
|
||||
import { broker } from "../../dist/messaging/index.js";
|
||||
import { registerModuleTools } from "../../dist/tools/index.js";
|
||||
import { serveRegisteredOverStdio, isStopping, askPacing } from "../../dist/stdio/index.js";
|
||||
|
||||
let clock = 0;
|
||||
let paused = [];
|
||||
askPacing.now = () => clock;
|
||||
askPacing.pause = async (ms) => { paused.push(ms); clock += ms; };
|
||||
|
||||
registerModuleTools("builder", () => [
|
||||
{ name: "publish", description: "asks the registry", input: {}, run: async () => {
|
||||
clock = 0;
|
||||
paused = [];
|
||||
try {
|
||||
return { answer: await broker().request("seat:go-package-registry.publish", {}), paused };
|
||||
} catch (err) {
|
||||
return { stopping: isStopping(err), words: err.message, paused };
|
||||
}
|
||||
} },
|
||||
]);
|
||||
await serveRegisteredOverStdio();
|
||||
+12
-12
@@ -379,10 +379,10 @@ async function aBundlesFindingWriter(): Promise<void> {
|
||||
}
|
||||
}
|
||||
|
||||
test("a call a stopping tool runner did not take is asked again after a pause until the new runner answers or the bound ends; a plain refusal and a bare timeout are not (design 47 H2 H-A-542, H-A-544, H-A-549)", async () => {
|
||||
const child = spawn(process.execPath, [fileURLToPath(new URL("./fixtures/stdio-stopping.mjs", import.meta.url))],
|
||||
test("a call is made once: no responders is returned after one ask, a reply of the withdrawn kind stopping is a refusal, and at the bound the fault is no answer within <bound> (design 47 H2 H-A-570 (2), (4))", async () => {
|
||||
const child = spawn(process.execPath, [fileURLToPath(new URL("./fixtures/stdio-ask.mjs", import.meta.url))],
|
||||
{ stdio: ["pipe", "pipe", "pipe"], env: { ...process.env, MESH_SERVED_MODULE: "builder",
|
||||
MESH_CONFIG_KEPT_CALL_PACE_FIRST: "2s", MESH_CONFIG_KEPT_CALL_PACE_MAX: "4s", MESH_CONFIG_ASK_BOUND: "10s" } });
|
||||
MESH_CONFIG_ASK_BOUND: "50ms" } });
|
||||
const seen: any[] = [];
|
||||
let buffered = "";
|
||||
let said = "";
|
||||
@@ -404,16 +404,16 @@ test("a call a stopping tool runner did not take is asked again after a pause un
|
||||
try {
|
||||
send({ jsonrpc: "2.0", id: 1, method: "initialize", params: { protocolVersion: "2025-03-26", capabilities: {} } });
|
||||
await until((m) => m.id === 1);
|
||||
const noResponders = { code: -32000, message: "nats: no responders available for request" };
|
||||
for (const row of [
|
||||
// The pace and the bound are the settings (2 s doubling to 4 s, a bound of 10 s, H-A-549); the pause moves a clock.
|
||||
{ id: 2, answers: [{ error: stopping }, { error: stopping }, { result: { published: true } }],
|
||||
want: { answer: { published: true }, paused: [2000, 4000] } },
|
||||
{ id: 3, answers: [{ error: stopping }, { error: stopping }, { error: stopping }],
|
||||
want: { stopping: true, words: `seat:go-package-registry.publish: the tool runner was stopping, asked again until the bound of 10000ms: ${stopping.message}`, paused: [2000, 4000] } },
|
||||
{ id: 4, answers: [{ error: { code: -32000, message: "refused" } }], want: { stopping: false, words: "refused", paused: [] } },
|
||||
{ id: 5, answers: [{ error: { code: -32000, message: "timeout" } }], want: { stopping: false, words: "timeout", paused: [] } },
|
||||
{ id: 2, answers: [{ result: { published: true } }], want: { answer: { published: true } } },
|
||||
{ id: 3, answers: [{ error: noResponders }], want: { words: noResponders.message } },
|
||||
{ id: 4, answers: [{ error: stopping }], want: { words: stopping.message } },
|
||||
{ id: 5, answers: [{ error: { code: -32000, message: "refused" } }], want: { words: "refused" } },
|
||||
{ id: 6, answers: [], want: { words: "no answer within 50ms" } },
|
||||
]) {
|
||||
send({ jsonrpc: "2.0", id: row.id, method: "tools/call", params: { name: "publish", arguments: {} } });
|
||||
if (row.answers.length === 0) await until((m) => m.method === "mesh/ask" && !m.answered).then((m) => { m.answered = true; });
|
||||
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})`);
|
||||
@@ -422,9 +422,9 @@ test("a call a stopping tool runner did not take is asked again after a pause un
|
||||
}
|
||||
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.equal(seen.filter((m) => m.method === "mesh/ask" && !m.answered).length, 0, `asked more than ${Math.max(row.answers.length, 1)} times`);
|
||||
}
|
||||
assert.match(said, /the tool runner is stopping/);
|
||||
assert.doesNotMatch(said, /asked again/);
|
||||
} finally {
|
||||
child.kill();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user