Skip to content
Source
Sign inSign up
Open History to see the last commit

terminalContext.test.ts

44 lines1.7 KB

1import { ThreadId } from "@t3tools/contracts";
2import { describe, expect, it } from "vite-plus/test";
3import { collectComposerContextReferences } from "@t3tools/shared/composerContextReferences";
4import { terminalContextRecord } from "./composerContextRecords";
5​
6import {
7 formatTerminalContextReference,
8 INLINE_TERMINAL_CONTEXT_PLACEHOLDER,
9 migrateLegacyTerminalContextPlaceholders,
10 type TerminalContextDraft,
11} from "./terminalContext";
12​
13function 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 };
26​
27describe("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});