The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import { describe, expect, it } from "vite-plus/test"; |
| 2 | import { nextThreadFindAnnouncement, type ThreadFindAnnouncement } from "./threadFind"; |
| 3 | |
| 4 | type Step = Omit<ThreadFindAnnouncement, "provisional"> & { readonly provisional?: boolean }; |
| 5 | |
| 6 | function replay(steps: readonly Step[]) { |
| 7 | let current: ThreadFindAnnouncement | null = null; |
| 8 | const spoken: string[] = []; |
| 9 | for (const step of steps) { |
| 10 | const next = nextThreadFindAnnouncement(current, { provisional: false, ...step }); |
| 11 | if (next.text !== (current?.text ?? "")) spoken.push(next.text); |
| 12 | current = next; |
| 13 | } |
| 14 | return spoken; |
| 15 | } |
| 16 | |
| 17 | describe("nextThreadFindAnnouncement", () => { |
| 18 | it("speaks each settled search or step once and stays silent through streamed refreshes", () => { |
| 19 | expect( |
| 20 | replay([ |
| 21 | { navigationId: 1, text: "Searching…", settled: true, provisional: true }, |
| 22 | { navigationId: 1, text: "1/…", settled: false }, |
| 23 | { navigationId: 1, text: "1/3", settled: true }, |
| 24 | { navigationId: 1, text: "1/…", settled: false }, |
| 25 | { navigationId: 1, text: "1/4", settled: true }, |
| 26 | { navigationId: 2, text: "1/4", settled: false }, |
| 27 | { navigationId: 2, text: "2/4", settled: true }, |
| 28 | { navigationId: 2, text: "2/5", settled: true }, |
| 29 | ]), |
| 30 | ).toEqual(["Searching…", "1/3", "2/4"]); |
| 31 | }); |
| 32 | |
| 33 | it("speaks a failure and the result of retrying it", () => { |
| 34 | expect( |
| 35 | replay([ |
| 36 | { navigationId: 1, text: "Search failed", settled: true, provisional: true }, |
| 37 | { navigationId: 1, text: "1/3", settled: true }, |
| 38 | { navigationId: 1, text: "1/4", settled: true }, |
| 39 | ]), |
| 40 | ).toEqual(["Search failed", "1/3"]); |
| 41 | }); |
| 42 | |
| 43 | it("speaks a new search that ends on the same count as the last one", () => { |
| 44 | expect( |
| 45 | replay([ |
| 46 | { navigationId: 1, text: "Searching…", settled: true, provisional: true }, |
| 47 | { navigationId: 1, text: "0/0", settled: true }, |
| 48 | { navigationId: 2, text: "Searching…", settled: true, provisional: true }, |
| 49 | { navigationId: 2, text: "0/0", settled: true }, |
| 50 | ]), |
| 51 | ).toEqual(["Searching…", "0/0", "Searching…", "0/0"]); |
| 52 | }); |
| 53 | }); |