@devries-cameron20 / t3code Mirror · read-only
Fork 0

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

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 03:37 UTC

main
ts 53 lines 2.15 KB
Raw
1 import { describe, expect, it } from "vite-plus/test";
2
3 import { DEFAULT_TERMINAL_ID, TerminalOpenInput } from "@t3tools/contracts";
4 import * as Schema from "effect/Schema";
5 import { mFallback } from "gt-i18n";
6 import type { MFunctionType } from "gt-i18n/types";
7
8 import { getTerminalLabel, nextTerminalId } from "./terminalLabels.ts";
9 import { resolveTerminalSessionLabel } from "./terminalLabelsCopy.ts";
10
11 const decodeTerminalOpen = Schema.decodeUnknownSync(TerminalOpenInput);
12
13 const japanese: MFunctionType = (encodedMsg, options) => {
14 const english = mFallback(encodedMsg, options);
15 return (
16 typeof english === "string" ? english.replace("Terminal", "ターミナル") : english
17 ) as typeof english;
18 };
19
20 describe("resolveTerminalSessionLabel", () => {
21 it("translates the idle default and keeps process names", () => {
22 const resolve = (label: string, hasRunningSubprocess: boolean) =>
23 resolveTerminalSessionLabel("term-2", { label, hasRunningSubprocess }, japanese);
24 expect(resolve("Terminal 2", false)).toBe("ターミナル 2");
25 expect(resolve(" ", false)).toBe("ターミナル 2");
26 expect(resolve("sleep", true)).toBe("sleep");
27 expect(resolve("Terminal 2", true)).toBe("Terminal 2");
28 });
29 });
30
31 describe("nextTerminalId", () => {
32 it("skips over taken term-N slots", () => {
33 expect(nextTerminalId([DEFAULT_TERMINAL_ID, "term-2", "term-3"])).toBe("term-4");
34 expect(nextTerminalId([DEFAULT_TERMINAL_ID, "term-3"])).toBe("term-2");
35 expect(nextTerminalId(["term-2", "term-3"])).toBe("term-1");
36 });
37
38 it("avoids unseen sessions when metadata is unavailable and resumes normal numbering", () => {
39 const first = nextTerminalId([], "783c91cc-a413-47c7-8312-c2a5a1f05e40");
40 const second = nextTerminalId([first], "102315fc-ceef-45c4-b978-c4d4947d3c26");
41 expect(first).not.toBe(DEFAULT_TERMINAL_ID);
42 expect(second).not.toBe(first);
43 expect(getTerminalLabel(second)).toBe("Terminal 2");
44 expect(nextTerminalId([first, second])).toBe("term-3");
45 expect(
46 decodeTerminalOpen({
47 threadId: "thread",
48 terminalId: second,
49 cwd: "/workspace",
50 }),
51 ).toMatchObject({ terminalId: second });
52 });
53 });