The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 04:45 UTC
| 1 | import { |
| 2 | nextThreadAnnouncement, |
| 3 | type ThreadAnnouncementMemory, |
| 4 | } from "@t3tools/client-runtime/state/thread-activity-announcement"; |
| 5 | import { RunId } from "@t3tools/contracts"; |
| 6 | import { describe, expect, it } from "vite-plus/test"; |
| 7 | |
| 8 | import { |
| 9 | nextThreadActivitySnapshot, |
| 10 | type ThreadActivityInput, |
| 11 | type ThreadActivityMemory, |
| 12 | } from "./threadStatusAnnouncement"; |
| 13 | |
| 14 | const run = RunId.make("run-1"); |
| 15 | |
| 16 | /** A frame of a working turn: what the question card shows and what the shell holds. */ |
| 17 | function frame(card: string | null, shell: string | null): ThreadActivityInput { |
| 18 | return { |
| 19 | approvalRequestId: null, |
| 20 | userInputRequestId: card, |
| 21 | shellRequestId: shell, |
| 22 | shellPendingUserInput: shell !== null, |
| 23 | working: true, |
| 24 | run: { runId: run, status: "running" }, |
| 25 | }; |
| 26 | } |
| 27 | |
| 28 | const idle: ThreadActivityInput = { ...frame(null, null), working: false, run: null }; |
| 29 | const done: ThreadActivityInput = { |
| 30 | ...frame(null, null), |
| 31 | working: false, |
| 32 | run: { runId: run, status: "completed" }, |
| 33 | }; |
| 34 | |
| 35 | function announcements(frames: ReadonlyArray<ThreadActivityInput>): ReadonlyArray<string | null> { |
| 36 | let activity: ThreadActivityMemory | null = null; |
| 37 | let memory: ThreadAnnouncementMemory | null = null; |
| 38 | return frames.map((input) => { |
| 39 | activity = nextThreadActivitySnapshot(activity, input); |
| 40 | const next = nextThreadAnnouncement(memory, activity.snapshot); |
| 41 | memory = next.memory; |
| 42 | return next.announcement; |
| 43 | }); |
| 44 | } |
| 45 | |
| 46 | describe("nextThreadActivitySnapshot", () => { |
| 47 | it("says each question once while the card and the shell catch up at different times", () => { |
| 48 | expect( |
| 49 | announcements([ |
| 50 | idle, |
| 51 | frame(null, null), |
| 52 | // The card shows question A before the shell has it. |
| 53 | frame("a", null), |
| 54 | frame("a", "a"), |
| 55 | // Answered: the card hides A at once, the shell still holds it. |
| 56 | frame(null, "a"), |
| 57 | // Question B reaches the card while the shell still holds A, and is answered before the shell has B. |
| 58 | frame("b", "a"), |
| 59 | frame(null, "a"), |
| 60 | frame(null, "b"), |
| 61 | frame(null, null), |
| 62 | // A secret request shows only in the shell. |
| 63 | frame(null, "secret"), |
| 64 | frame(null, null), |
| 65 | done, |
| 66 | ]), |
| 67 | ).toEqual([ |
| 68 | null, |
| 69 | "Working", |
| 70 | "Needs your input", |
| 71 | null, |
| 72 | null, |
| 73 | "Needs your input", |
| 74 | null, |
| 75 | null, |
| 76 | null, |
| 77 | "Needs your input", |
| 78 | null, |
| 79 | "Done", |
| 80 | ]); |
| 81 | }); |
| 82 | }); |