| 1 | import type { |
| 2 | EnvironmentProject, |
| 3 | EnvironmentThreadShell, |
| 4 | } from "@t3tools/client-runtime/state/shell"; |
| 5 | import { EnvironmentId, ProjectId, ThreadId } from "@t3tools/contracts"; |
| 6 | import { assert, it } from "@effect/vitest"; |
| 7 | |
| 8 | import { |
| 9 | buildShowcaseAgentActivity, |
| 10 | SHOWCASE_AGENT_ACTIVITY_ROWS, |
| 11 | showcaseAndroidActivityData, |
| 12 | } from "./showcaseAgentActivity"; |
| 13 | |
| 14 | const NOW = Date.parse("2026-07-16T09:00:00.000Z"); |
| 15 | |
| 16 | const project = (environmentId: string, id: string, title: string) => |
| 17 | ({ |
| 18 | environmentId: EnvironmentId.make(environmentId), |
| 19 | id: ProjectId.make(id), |
| 20 | title, |
| 21 | }) as EnvironmentProject; |
| 22 | |
| 23 | const thread = (environmentId: string, id: string, projectId: string, title: string) => |
| 24 | ({ |
| 25 | environmentId: EnvironmentId.make(environmentId), |
| 26 | id: ThreadId.make(id), |
| 27 | projectId: ProjectId.make(projectId), |
| 28 | title, |
| 29 | }) as EnvironmentThreadShell; |
| 30 | |
| 31 | const projects = [ |
| 32 | project("moonbase-terminal", "t3code", "T3 Code"), |
| 33 | project("suspense-station", "react", "React"), |
| 34 | project("kernel-cabin", "linux", "Linux"), |
| 35 | ]; |
| 36 | |
| 37 | const threads = [ |
| 38 | thread("moonbase-terminal", "remote-command-center", "t3code", "Make remote coding feel local"), |
| 39 | thread( |
| 40 | "moonbase-terminal", |
| 41 | "pocket-command-center", |
| 42 | "t3code", |
| 43 | "Put the command center in your pocket", |
| 44 | ), |
| 45 | thread("suspense-station", "buttery-suspense", "react", "Make Suspense transitions buttery"), |
| 46 | thread("kernel-cabin", "beautiful-boot", "linux", "Make boot logs oddly beautiful"), |
| 47 | ]; |
| 48 | |
| 49 | it("waits until every staged thread and its project have loaded", () => { |
| 50 | assert.isNull(buildShowcaseAgentActivity(threads.slice(1), projects, NOW)); |
| 51 | assert.isNull(buildShowcaseAgentActivity(threads, projects.slice(0, 2), NOW)); |
| 52 | }); |
| 53 | |
| 54 | it("stages relay-shaped rows against the seeded threads", () => { |
| 55 | const activity = buildShowcaseAgentActivity(threads, projects, NOW); |
| 56 | assert.isNotNull(activity); |
| 57 | if (!activity) return; |
| 58 | |
| 59 | assert.strictEqual(activity.activeCount, 3); |
| 60 | assert.deepStrictEqual( |
| 61 | activity.activities.map((row) => [row.threadId, row.status, row.projectTitle, row.updatedAt]), |
| 62 | [ |
| 63 | ["pocket-command-center", "Approval", "T3 Code", "2026-07-16T08:59:00.000Z"], |
| 64 | ["beautiful-boot", "Input", "Linux", "2026-07-16T08:56:00.000Z"], |
| 65 | ["buttery-suspense", "Working", "React", "2026-07-16T08:58:00.000Z"], |
| 66 | ["remote-command-center", "Done", "T3 Code", "2026-07-16T08:57:00.000Z"], |
| 67 | ], |
| 68 | ); |
| 69 | assert.strictEqual( |
| 70 | activity.activities[0]?.deepLink, |
| 71 | "/threads/moonbase-terminal/pocket-command-center", |
| 72 | ); |
| 73 | assert.strictEqual(activity.activities.length, SHOWCASE_AGENT_ACTIVITY_ROWS.length); |
| 74 | }); |
| 75 | |
| 76 | it("encodes the Android Live Update and its alert like a relay push", () => { |
| 77 | const activity = buildShowcaseAgentActivity(threads, projects, NOW); |
| 78 | assert.isNotNull(activity); |
| 79 | if (!activity) return; |
| 80 | const data = showcaseAndroidActivityData(activity, NOW); |
| 81 | |
| 82 | assert.strictEqual(data.active, "true"); |
| 83 | assert.strictEqual(data.activity_chip, "Review"); |
| 84 | assert.strictEqual(data.activity_title, "3 active agents · 2 need attention"); |
| 85 | assert.strictEqual( |
| 86 | data.activity_line_0, |
| 87 | "Approval\tPut the command center in your pocket\tT3 Code", |
| 88 | ); |
| 89 | assert.strictEqual(data.activity_line_3, "Done\tMake remote coding feel local\tT3 Code"); |
| 90 | assert.strictEqual(data.alert_title, "Put the command center in your pocket"); |
| 91 | assert.strictEqual(data.alert_body, "Approval: T3 Code"); |
| 92 | assert.strictEqual(data.alert_path, "/threads/moonbase-terminal/pocket-command-center"); |
| 93 | }); |