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

userMessage.test.ts

55 lines1.8 KB

1import { describe, expect, it } from "vite-plus/test";
2​
3import { resolveUserMessagePresentation } from "./userMessage.ts";
4​
5describe("resolveUserMessagePresentation", () => {
6 const legacyText = "[Triggered by schedule task: Daily audit]\n\nCheck for crashes.\n";
7​
8 it("preserves user-written and assistant-quoted schedule headers", () => {
9 for (const message of [
10 { role: "user", createdBy: "user" as const },
11 { role: "user" },
12 { role: "assistant", createdBy: "agent" as const },
13 ]) {
14 expect(resolveUserMessagePresentation({ ...message, text: legacyText })).toEqual({
15 text: legacyText,
16 attribution: null,
17 scheduledTaskId: undefined,
18 });
19 }
20 });
21​
22 it("attributes older server-sent restart continuations to T3 Code, not another agent", () => {
23 const text = "Note: the T3 server restarted.";
24 expect(
25 resolveUserMessagePresentation({
26 role: "user",
27 createdBy: "agent",
28 creationSource: "server",
29 text,
30 }),
31 ).toMatchObject({ attribution: "t3code" });
32 for (const creationSource of ["mcp", "provider"] as const) {
33 expect(
34 resolveUserMessagePresentation({ role: "user", createdBy: "agent", creationSource, text }),
35 ).toMatchObject({ attribution: "agent" });
36 }
37 });
38​
39 it("recovers the triggering automation from older scheduler message ids", () => {
40 for (const trigger of ["scheduled", "manual"]) {
41 expect(
42 resolveUserMessagePresentation({
43 id: `scheduled-task-message:task:daily-audit:1788661140000:${trigger}`,
44 role: "user",
45 createdBy: "user",
46 text: legacyText,
47 }),
48 ).toEqual({
49 text: "Check for crashes.\n",
50 attribution: "automation",
51 scheduledTaskId: "task:daily-audit",
52 });
53 }
54 });
55});