Files
pipelines/web/test/runIntent.test.mjs
T

23 lines
1.3 KiB
JavaScript

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);
});