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

timelineMinimapItems.test.ts

94 lines3.2 KB

1import { describe, expect, it } from "vite-plus/test";
2import { EnvironmentId, MessageId, ThreadId } from "@t3tools/contracts";
3import { serializeAssistantCitation } from "@t3tools/shared/assistantCitations";
4import {
5 ATTACHMENT_ONLY_BOOTSTRAP_PROMPT,
6 formatComposerContextReference,
7 toComposerContextId,
8} from "@t3tools/shared/composerContextReferences";
9​
10import { deriveTimelineMinimapItems, resolveTimelineMinimapPreview } from "./timelineMinimapItems";
11​
12describe("deriveTimelineMinimapItems", () => {
13 it.each(["", "Ultrathink:\n"])(
14 "omits bootstrap text from the minimap label and tooltip (%j)",
15 (prefix) => {
16 const at = "2026-10-01T00:00:00Z";
17 const items = deriveTimelineMinimapItems([
18 {
19 kind: "message",
20 id: "image-only",
21 createdAt: at,
22 showAssistantMeta: false,
23 showAssistantCopyButton: false,
24 assistantCopyStreaming: false,
25 message: {
26 id: MessageId.make("image-only"),
27 role: "user",
28 text: prefix + ATTACHMENT_ONLY_BOOTSTRAP_PROMPT,
29 runId: null,
30 streaming: false,
31 createdAt: at,
32 updatedAt: at,
33 },
34 },
35 ]);
36 expect(items).toEqual([{ id: "image-only", rowIndex: 0, userText: "", assistantText: null }]);
37 expect(resolveTimelineMinimapPreview(items[0]!)?.userText).toBeNull();
38 },
39 );
40});
41​
42describe("resolveTimelineMinimapPreview", () => {
43 it("previews a thread autolink as prose, not its URL", () => {
44 const preview = resolveTimelineMinimapPreview({
45 id: "turn-1",
46 rowIndex: 0,
47 userText: null,
48 assistantText:
49 "Started <t3-thread://v2/env-1/thread-1> and [Fix CI](t3-thread://v2/env-1/t2).",
50 });
51 expect(preview?.assistantText).toBe("Started a thread and Fix CI.");
52 });
53​
54 it("previews a quote, a context chip and a file link in the user's message as their text", () => {
55 const quote = serializeAssistantCitation({
56 version: 1,
57 environmentId: EnvironmentId.make("env-1"),
58 threadId: ThreadId.make("thread-1"),
59 messageId: MessageId.make("assistant-1"),
60 text: "The cache misses on a cold start.",
61 start: 0,
62 end: 33,
63 prefix: "",
64 suffix: "",
65 });
66 const file = formatComposerContextReference({
67 kind: "file",
68 contextId: toComposerContextId("readme"),
69 label: "README.md",
70 });
71 const preview = resolveTimelineMinimapPreview({
72 id: "turn-1",
73 rowIndex: 0,
74 userText: `${quote}\nWhere do ${file} and [math.ts](src/math.ts) cover this?`,
75 assistantText: null,
76 });
77 expect(preview?.userText).toBe(
78 "The cache misses on a cold start. Where do README.md and math.ts cover this?",
79 );
80 });
81​
82 it("does not split a surrogate pair at the preview slice boundary", () => {
83 const linkStart = "[Build log](https://example.com/builds/1042/log?sig=";
84 const linkEnd = ") ";
85 const pad = "a".repeat(1_499 - linkStart.length - linkEnd.length);
86 const preview = resolveTimelineMinimapPreview({
87 id: "turn-1",
88 rowIndex: 0,
89 userText: `${linkStart}${pad}${linkEnd}🎉 the release build passed`,
90 assistantText: null,
91 });
92 expect(preview?.userText).toBe("Build log");
93 });
94});