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

threadTitleContext.test.ts

62 lines2.7 KB

1import { describe, expect, it } from "vite-plus/test";
2import { ChatAttachmentId } from "@t3tools/contracts";
3import { ATTACHMENT_ONLY_BOOTSTRAP_PROMPT } from "@t3tools/shared/composerContextReferences";
4import { formatThreadTitleContext, limitTitleMessage } from "./threadTitleContext.ts";
5​
6describe("thread title context", () => {
7 it.each(["", "Ultrathink:\n"])("keeps attachments without bootstrap text (%j)", (prefix) => {
8 const attachments = [
9 {
10 type: "image" as const,
11 id: ChatAttachmentId.make("diagram"),
12 name: "diagram.png",
13 mimeType: "image/png",
14 sizeBytes: 10,
15 },
16 ];
17 const text = prefix + ATTACHMENT_ONLY_BOOTSTRAP_PROMPT;
18 expect(formatThreadTitleContext([{ role: "user", text, attachments }])).toEqual({
19 message: "USER:\n[Attachments: diagram.png]",
20 attachments,
21 });
22 expect(formatThreadTitleContext([{ role: "user", text }])).toEqual({
23 message: "",
24 attachments: [],
25 });
26 });
27​
28 it("keeps a user's scope change despite long assistant output", () => {
29 const result = formatThreadTitleContext([
30 { role: "user", text: "Review QR sharing" },
31 { role: "assistant", text: "Old findings. ".repeat(2_000) },
32 { role: "user", text: "Focus on pairing expiry instead. Keep remote access working." },
33 { role: "assistant", text: "Implementation details. ".repeat(2_000) },
34 { role: "user", text: "Merge it when green." },
35 ]);
36 expect(result.message.length).toBeLessThanOrEqual(8_000);
37 expect(result.message).toContain("USER:\nReview QR sharing");
38 expect(result.message).toContain(
39 "USER:\nFocus on pairing expiry instead. Keep remote access working.",
40 );
41 expect(result.message).toContain("USER:\nMerge it when green.");
42 expect(result.message).toContain("ASSISTANT:\nImplementation details.");
43 });
44​
45 it("retains both ends and role labels in long user messages", () => {
46 const result = formatThreadTitleContext([
47 { role: "system", text: "System instructions" },
48 { role: "user", text: `Fix Android pairing. ${"logs ".repeat(3_000)}Keep iOS behavior.` },
49 { role: "assistant", text: "Found the cause." },
50 ]);
51 expect(result.message).toContain("USER:\nFix Android pairing.");
52 expect(result.message).toContain("Keep iOS behavior.");
53 expect(result.message).toContain("ASSISTANT:\nFound the cause.");
54 expect(result.message).not.toContain("System instructions");
55 expect(result.message.match(/USER:/g)).toHaveLength(1);
56 });
57​
58 it("cuts both ends of a long message without splitting an emoji", () => {
59 const result = limitTitleMessage(`${"a".repeat(9)}πŸš€${"b".repeat(20)}πŸš€${"c".repeat(9)}`, 41);
60 expect(result).toBe(`${"a".repeat(9)}\n[Content truncated]\n${"c".repeat(9)}`);
61 });
62});