The best way to control Claude Code, Codex and more from any computer or phone

main
ts 34 lines 1.28 KB
Raw
1 import { EnvironmentId, ThreadId } from "@t3tools/contracts";
2 import { expect, it } from "vite-plus/test";
3
4 import { closingTerminalIds, holdTerminalIdWhileClosing } from "./closingTerminals";
5
6 function deferred() {
7 let resolve!: () => void;
8 let reject!: (error: Error) => void;
9 const promise = new Promise<void>((onResolve, onReject) => {
10 resolve = onResolve;
11 reject = onReject;
12 });
13 return { promise, resolve, reject };
14 }
15
16 it("keeps a closing terminal's ID out of reach until its last close settles", async () => {
17 const thread = { environmentId: EnvironmentId.make("env"), threadId: ThreadId.make("thread") };
18 const otherThread = { ...thread, threadId: ThreadId.make("other") };
19 const first = deferred();
20 const second = deferred();
21
22 const firstClose = holdTerminalIdWhileClosing(thread, "term-1", () => first.promise);
23 const secondClose = holdTerminalIdWhileClosing(thread, "term-1", () => second.promise);
24 expect(closingTerminalIds(thread)).toEqual(["term-1"]);
25 expect(closingTerminalIds(otherThread)).toEqual([]);
26
27 first.reject(new Error("close failed"));
28 await expect(firstClose).rejects.toThrow("close failed");
29 expect(closingTerminalIds(thread)).toEqual(["term-1"]);
30
31 second.resolve();
32 await secondClose;
33 expect(closingTerminalIds(thread)).toEqual([]);
34 });