runs: reconcile uncertain browser launches with a persistent intent key

This commit is contained in:
2026-10-20 15:40:43 +01:00
parent f06281db08
commit 44834e91f0
8 changed files with 146 additions and 9 deletions
+14
View File
@@ -332,6 +332,20 @@ test("a run action throws when the reply has no run detail", async () => {
// ---- The composer's own commands (C8/C9) ----------------------------------
test("run retries preserve one admission key and can reconcile without execution", async () => {
const { repo, ws } = connected();
ws.reply = (frame) => ({ id: frame.id, type: "run", run_detail: { id: 42 } });
const intent = { pipelineId: 7, version: 1, prompt: "task", workspace: "/work", requestKey: "same-intent" };
await repo.runPipeline(intent);
await repo.runPipeline(intent);
assert.deepEqual(ws.sent.map((frame) => frame.request_key), ["same-intent", "same-intent"]);
assert.equal((await repo.runByRequestKey("same-intent")).id, 42);
assert.equal(lastFrame(ws).type, "get_run");
assert.equal(lastFrame(ws).request_key, "same-intent");
ws.reply = (frame) => ({ id: frame.id, type: "run" });
assert.equal(await repo.runByRequestKey("not-admitted"), null);
});
test("chatPrompt trims the text, sends the operation and native message ids, and omits files when empty", async () => {
const { repo, ws } = connected();
ws.reply = (frame) => ({ id: frame.id, type: "chat_prompt" });
+22
View File
@@ -0,0 +1,22 @@
import { test } from "node:test";
import assert from "node:assert/strict";
import { createRunIntent, saveRunIntent, pendingRun, clearRunIntent } from "../src/runIntent.js";
test("pending launch identity and payload survive reload and stay endpoint-scoped", () => {
const values = new Map();
const storage = { getItem: (key) => values.get(key), setItem: (key, value) => values.set(key, value), removeItem: (key) => values.delete(key) };
const payload = { pipelineId: 7, version: 3, prompt: "report", workspace: "/work", notifyMode: "off" };
const intent = createRunIntent(payload);
assert.ok(intent.requestKey);
saveRunIntent(storage, "ws://server/connect", intent);
assert.deepEqual(pendingRun(storage, "ws://server/connect", 7, 3), intent);
assert.equal(pendingRun(storage, "ws://other/connect", 7, 3), null);
assert.equal(pendingRun(storage, "ws://server/connect", 7, 4), null);
clearRunIntent(storage, "ws://server/connect", intent);
assert.equal(pendingRun(storage, "ws://server/connect", 7, 3), null);
});
test("malformed or unavailable pending-run storage never invents an intent", () => {
assert.equal(pendingRun({ getItem: () => "not json" }, "ws://s", 1, 1), null);
assert.equal(pendingRun({ getItem: () => { throw Error("disabled"); } }, "ws://s", 1, 1), null);
});