@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, 04:45 UTC

main
ts 44 lines 1.66 KB
Raw
1 import { ThreadId } from "@t3tools/contracts";
2 import { describe, expect, it } from "vite-plus/test";
3 import { collectComposerContextReferences } from "@t3tools/shared/composerContextReferences";
4 import { terminalContextRecord } from "./composerContextRecords";
5
6 import {
7 formatTerminalContextReference,
8 INLINE_TERMINAL_CONTEXT_PLACEHOLDER,
9 migrateLegacyTerminalContextPlaceholders,
10 type TerminalContextDraft,
11 } from "./terminalContext";
12
13 function makeContext(overrides?: Partial<TerminalContextDraft>): TerminalContextDraft {
14 return {
15 id: "context-1",
16 threadId: ThreadId.make("thread-1"),
17 terminalId: "default",
18 terminalLabel: "Terminal 1",
19 lineStart: 12,
20 lineEnd: 13,
21 text: "git status\nOn branch main",
22 createdAt: "2026-03-13T12:00:00.000Z",
23 ...overrides,
24 };
25 }
26
27 describe("terminalContext", () => {
28 it("folds legacy producer ids consistently in records and references", () => {
29 const context = makeContext({ id: "old terminal:one" });
30 const reference = collectComposerContextReferences(formatTerminalContextReference(context))[0];
31 expect(reference).toBeDefined();
32 expect(reference?.contextId).toBe(terminalContextRecord(context).contextId);
33 });
34
35 it("migrates legacy placeholders to references in order and drops extras", () => {
36 const placeholder = INLINE_TERMINAL_CONTEXT_PLACEHOLDER;
37 const first = formatTerminalContextReference(makeContext());
38 const contexts = [makeContext()];
39 expect(
40 migrateLegacyTerminalContextPlaceholders(`a ${placeholder} b ${placeholder}`, contexts),
41 ).toBe(`a ${first} b `);
42 expect(migrateLegacyTerminalContextPlaceholders("plain", contexts)).toBe("plain");
43 });
44 });