| 1 | import assert from "node:assert/strict"; |
| 2 | import { executeClearSession } 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 ports = { |
| 9 | clearSession: async () => { calls.push("local"); }, |
| 10 | clearRemoteSession: async (tabId: string) => { calls.push(`remote:${tabId}`); }, |
| 11 | retryRemoteHydration: async () => { calls.push("hydrate"); }, |
| 12 | }; |
| 13 | |
| 14 | await executeClearSession(target, { remote: false }, ports, authority); |
| 15 | assert.deepEqual(calls, ["local"]); |
| 16 | calls.length = 0; |
| 17 | await executeClearSession(target, { remote: true }, ports, authority); |
| 18 | assert.deepEqual(calls, ["remote:A", "hydrate"]); |
| 19 | calls.length = 0; |
| 20 | owned = false; |
| 21 | await assert.rejects(executeClearSession(target, { remote: false }, ports, authority), /stale/); |
| 22 | assert.deepEqual(calls, [], "stale source cannot clear a replacement session"); |
| 23 | console.log("session clear owner: source/UI ownership and local/remote paths passed"); |
| 24 |