| 1 | import assert from "node:assert/strict"; |
| 2 | import { executeCancelRuntimeJob } from "../app-runtime/sessionRuntimeOwner"; |
| 3 | |
| 4 | const target = { tabId: "A", sessionKey: "A:1" }; |
| 5 | let owned = true; |
| 6 | const authority = { checkpoint() { if (!owned) throw new Error("stale"); }, ownsUI: () => owned }; |
| 7 | const calls: string[] = []; |
| 8 | const result = await executeCancelRuntimeJob(target, "job-1", { |
| 9 | cancelForTab: async (tabId, jobId) => { calls.push(`cancel:${tabId}:${jobId}`); return true; }, |
| 10 | refresh: async () => { calls.push("refresh"); }, |
| 11 | }, authority); |
| 12 | assert.equal(result, true); |
| 13 | assert.deepEqual(calls, ["cancel:A:job-1", "refresh"]); |
| 14 | calls.length = 0; |
| 15 | owned = false; |
| 16 | await assert.rejects(executeCancelRuntimeJob(target, "job-2", { |
| 17 | cancelForTab: async () => { calls.push("cancel"); return true; }, |
| 18 | refresh: async () => { calls.push("refresh"); }, |
| 19 | }, authority), /stale/); |
| 20 | assert.deepEqual(calls, [], "stale source cannot cancel a replacement session"); |
| 21 | console.log("runtime job owner: source/UI ownership passed"); |
| 22 |