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

userMessage.test.ts

88 lines2.9 KB

1import { describe, expect, it } from "vite-plus/test";
2​
3import { GuestMessageId } from "@t3tools/contracts";
4import { ATTACHMENT_ONLY_BOOTSTRAP_PROMPT } from "@t3tools/shared/composerContextReferences";
5​
6import { resolveUserMessagePresentation } from "./userMessage.ts";
7​
8describe("resolveUserMessagePresentation", () => {
9 const legacyText = "[Triggered by schedule task: Daily audit]\n\nCheck for crashes.\n";
10​
11 it("preserves user-written and assistant-quoted schedule headers", () => {
12 for (const message of [
13 { role: "user", createdBy: "user" as const },
14 { role: "user" },
15 { role: "assistant", createdBy: "agent" as const },
16 ]) {
17 expect(resolveUserMessagePresentation({ ...message, text: legacyText })).toEqual({
18 text: legacyText,
19 attribution: null,
20 scheduledTaskId: undefined,
21 });
22 }
23 });
24​
25 it("hides the prompt that stands in for an attachment-only message", () => {
26 for (const text of [
27 ATTACHMENT_ONLY_BOOTSTRAP_PROMPT,
28 `Ultrathink:\n${ATTACHMENT_ONLY_BOOTSTRAP_PROMPT}`,
29 ]) {
30 expect(resolveUserMessagePresentation({ role: "user", text })).toEqual({
31 text: "",
32 attribution: null,
33 scheduledTaskId: undefined,
34 });
35 }
36 });
37​
38 it("shows a guest's own words and name, not the attributed text the agent reads", () => {
39 expect(
40 resolveUserMessagePresentation({
41 role: "user",
42 createdBy: "user",
43 text: "Message from guest Sam, sent by the owner:\n\nWhy?",
44 context: {
45 guest: {
46 guestMessageId: GuestMessageId.make("guest-message:one"),
47 name: "Sam",
48 text: "Why?",
49 },
50 },
51 }),
52 ).toEqual({ text: "Why?", attribution: "guest", scheduledTaskId: undefined, guestName: "Sam" });
53 });
54​
55 it("attributes older server-sent restart continuations to T3 Code, not another agent", () => {
56 const text = "Note: the T3 server restarted.";
57 expect(
58 resolveUserMessagePresentation({
59 role: "user",
60 createdBy: "agent",
61 creationSource: "server",
62 text,
63 }),
64 ).toMatchObject({ attribution: "t3code" });
65 for (const creationSource of ["mcp", "provider"] as const) {
66 expect(
67 resolveUserMessagePresentation({ role: "user", createdBy: "agent", creationSource, text }),
68 ).toMatchObject({ attribution: "agent" });
69 }
70 });
71​
72 it("recovers the triggering automation from older scheduler message ids", () => {
73 for (const trigger of ["scheduled", "manual"]) {
74 expect(
75 resolveUserMessagePresentation({
76 id: `scheduled-task-message:task:daily-audit:1788661140000:${trigger}`,
77 role: "user",
78 createdBy: "user",
79 text: legacyText,
80 }),
81 ).toEqual({
82 text: "Check for crashes.\n",
83 attribution: "automation",
84 scheduledTaskId: "task:daily-audit",
85 });
86 }
87 });
88});