返回 DeepSeek-Reasonix
terminal-output-owner.test.ts
根目录 / desktop / frontend / src / __tests__ / terminal-output-owner.test.ts
1 import assert from "node:assert/strict";
2 import { executeTerminalOutputInsertion } 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 inserted = await executeTerminalOutputInsertion(target, "term-1", {
9 read: async (tabId, sessionId) => { calls.push(`read:${tabId}:${sessionId}`); return "output"; },
10 apply: (text) => calls.push(`apply:${text}`),
11 }, (value) => value.toUpperCase(), authority);
12 assert.equal(inserted, true);
13 assert.deepEqual(calls, ["read:A:term-1", "apply:OUTPUT"]);
14 calls.length = 0;
15 owned = false;
16 await assert.rejects(executeTerminalOutputInsertion(target, "term-2", {
17 read: async () => "stale-output",
18 apply: () => calls.push("apply"),
19 }, value => value, authority), /stale/);
20 assert.deepEqual(calls, [], "stale source cannot insert terminal output");
21 console.log("terminal output owner: source/UI ownership passed");
22
22 lines TYPESCRIPT