|
| 1 | +import { MessageId } from "@t3tools/contracts"; |
| 2 | +import { ATTACHMENT_ONLY_BOOTSTRAP_PROMPT } from "@t3tools/shared/composerContextReferences"; |
| 3 | +import { applyClaudePromptEffortPrefix } from "@t3tools/shared/model"; |
| 4 | +import { describe, expect, it } from "vite-plus/test"; |
| 5 | + |
| 6 | +import type { MessagesTimelineRow } from "./MessagesTimeline.logic"; |
| 7 | +import { deriveTimelineMinimapItems, resolveTimelineMinimapPreview } from "./timelineMinimapItems"; |
| 8 | + |
| 9 | +function messageRow( |
| 10 | + role: "user" | "assistant", |
| 11 | + text: string, |
| 12 | +): Extract<MessagesTimelineRow, { kind: "message" }> { |
| 13 | + const createdAt = "2026-01-01T00:00:00.000Z"; |
| 14 | + return { |
| 15 | + kind: "message", |
| 16 | + id: role, |
| 17 | + createdAt, |
| 18 | + message: { |
| 19 | + id: MessageId.make(role), |
| 20 | + role, |
| 21 | + text, |
| 22 | + runId: null, |
| 23 | + createdAt, |
| 24 | + updatedAt: createdAt, |
| 25 | + streaming: false, |
| 26 | + }, |
| 27 | + durationStart: createdAt, |
| 28 | + showAssistantMeta: false, |
| 29 | + showAssistantCopyButton: false, |
| 30 | + assistantCopyStreaming: false, |
| 31 | + }; |
| 32 | +} |
| 33 | + |
| 34 | +describe("deriveTimelineMinimapItems", () => { |
| 35 | + it.each([ |
| 36 | + ATTACHMENT_ONLY_BOOTSTRAP_PROMPT, |
| 37 | + applyClaudePromptEffortPrefix(ATTACHMENT_ONLY_BOOTSTRAP_PROMPT, "ultrathink"), |
| 38 | + ])("hides attachment-only text from minimap previews: %s", (text) => { |
| 39 | + const rows = [messageRow("user", text), messageRow("assistant", "Image received.")]; |
| 40 | + const items = deriveTimelineMinimapItems(rows); |
| 41 | + |
| 42 | + expect(items).toEqual([ |
| 43 | + { id: "user", rowIndex: 0, userText: "", assistantText: "Image received." }, |
| 44 | + ]); |
| 45 | + expect(resolveTimelineMinimapPreview(items[0] ?? null)).toEqual({ |
| 46 | + id: "user", |
| 47 | + rowIndex: 0, |
| 48 | + userText: null, |
| 49 | + assistantText: "Image received.", |
| 50 | + }); |
| 51 | + expect(rows[0]?.message.text).toBe(text); |
| 52 | + }); |
| 53 | + |
| 54 | + it("preserves typed text and assistant text", () => { |
| 55 | + const text = "Ultrathink:\n Check this image.\n"; |
| 56 | + const items = deriveTimelineMinimapItems([ |
| 57 | + messageRow("user", text), |
| 58 | + messageRow("assistant", ATTACHMENT_ONLY_BOOTSTRAP_PROMPT), |
| 59 | + ]); |
| 60 | + |
| 61 | + expect(items).toEqual([ |
| 62 | + { id: "user", rowIndex: 0, userText: text, assistantText: ATTACHMENT_ONLY_BOOTSTRAP_PROMPT }, |
| 63 | + ]); |
| 64 | + }); |
| 65 | +}); |
0 commit comments