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 { ThreadId, type WorktreeSetupSnapshot } from "@t3tools/contracts"; |
| 2 | import { resolveVisibleWorktreeSetup } from "@t3tools/client-runtime/worktree-setup"; |
| 3 | import { describe, expect, it } from "vite-plus/test"; |
| 4 | import * as DateTime from "effect/DateTime"; |
| 5 | import { resolveWorktreeSetupSnapshot } from "./worktree-setup-state"; |
| 6 | |
| 7 | const threadId = ThreadId.make("setup-thread"); |
| 8 | const running: WorktreeSetupSnapshot = { |
| 9 | threadId, |
| 10 | sequence: 1, |
| 11 | phase: "running", |
| 12 | startedAt: "2026-09-17T00:00:00.000Z", |
| 13 | endedAt: null, |
| 14 | branch: "feature", |
| 15 | baseRef: "main", |
| 16 | worktreePath: null, |
| 17 | setupScript: null, |
| 18 | stages: [], |
| 19 | error: null, |
| 20 | }; |
| 21 | |
| 22 | describe("mobile worktree setup handoff", () => { |
| 23 | it("keeps the setup identity after its card retires so the working header can take over", () => { |
| 24 | const done = { ...running, phase: "done" as const, sequence: 2 }; |
| 25 | const held = resolveWorktreeSetupSnapshot(threadId, done, running); |
| 26 | expect(held).toBe(done); |
| 27 | expect( |
| 28 | resolveVisibleWorktreeSetup({ |
| 29 | live: held, |
| 30 | recorded: null, |
| 31 | runs: [], |
| 32 | followUpSent: false, |
| 33 | }), |
| 34 | ).toBe(done); |
| 35 | expect( |
| 36 | resolveVisibleWorktreeSetup({ |
| 37 | live: held, |
| 38 | recorded: null, |
| 39 | runs: [{ startedAt: DateTime.makeUnsafe(running.startedAt) }], |
| 40 | followUpSent: false, |
| 41 | }), |
| 42 | ).toBeNull(); |
| 43 | const afterFirstMessageEdit = { |
| 44 | live: held, |
| 45 | recorded: null, |
| 46 | followUpSent: false, |
| 47 | runs: [{ startedAt: DateTime.makeUnsafe(running.startedAt) }, { startedAt: null }], |
| 48 | }; |
| 49 | expect(resolveVisibleWorktreeSetup(afterFirstMessageEdit)).toBeNull(); |
| 50 | expect(resolveWorktreeSetupSnapshot(threadId, undefined, held)).toBe(done); |
| 51 | }); |
| 52 | |
| 53 | it.each(["failed", "cancelled"] as const)( |
| 54 | "retains %s details after the stream closes", |
| 55 | (phase) => { |
| 56 | const settled = { ...running, phase, sequence: 3 }; |
| 57 | const held = resolveWorktreeSetupSnapshot(threadId, settled, running); |
| 58 | expect(resolveWorktreeSetupSnapshot(threadId, null, held)).toBe(settled); |
| 59 | expect(resolveWorktreeSetupSnapshot(threadId, running, held)).toBe(settled); |
| 60 | expect( |
| 61 | resolveVisibleWorktreeSetup({ |
| 62 | live: held, |
| 63 | recorded: null, |
| 64 | runs: [], |
| 65 | followUpSent: false, |
| 66 | }), |
| 67 | ).toBe(settled); |
| 68 | expect( |
| 69 | resolveVisibleWorktreeSetup({ |
| 70 | live: held, |
| 71 | recorded: null, |
| 72 | runs: [], |
| 73 | followUpSent: true, |
| 74 | }), |
| 75 | ).toBeNull(); |
| 76 | }, |
| 77 | ); |
| 78 | |
| 79 | it("does not carry a previous thread's progress across navigation", () => { |
| 80 | const otherId = ThreadId.make("other-thread"); |
| 81 | expect(resolveWorktreeSetupSnapshot(otherId, running, running)).toBeNull(); |
| 82 | const other = { ...running, threadId: otherId }; |
| 83 | expect(resolveWorktreeSetupSnapshot(otherId, other, running)).toBe(other); |
| 84 | }); |
| 85 | }); |