@devries-cameron20 / t3code Mirror · read-only
Fork 0

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

main
tsx 52 lines 2.03 KB
Raw
1 import type { ChildThreadApproval } from "@t3tools/client-runtime/state/thread-requests";
2 import { EnvironmentId, RuntimeRequestId, ThreadId } from "@t3tools/contracts";
3 import * as Cause from "effect/Cause";
4 import { AsyncResult, Atom } from "effect/reactivity";
5 import { expect, it, vi } from "vite-plus/test";
6
7 import { render } from "../../../test/render";
8
9 const state = vi.hoisted(() => ({ respond: vi.fn(), approvalsAtom: null as unknown }));
10
11 vi.mock("../../state/session", () => ({ useEnvironmentScope: () => true }));
12 vi.mock("../../state/use-atom-command", () => ({ useAtomCommand: () => state.respond }));
13 vi.mock("../../state/threads", () => ({
14 childThreadApprovalsAtom: () => state.approvalsAtom,
15 threadEnvironment: { respondToApproval: {} },
16 }));
17
18 import { ChildThreadApprovals } from "./ChildThreadApprovals";
19
20 function setup() {
21 state.respond.mockReset();
22 state.respond
23 .mockResolvedValueOnce(AsyncResult.failure(Cause.fail(new Error("Child environment offline"))))
24 .mockResolvedValueOnce(AsyncResult.success(undefined));
25 const thread = {
26 environmentId: EnvironmentId.make("child-env"),
27 threadId: ThreadId.make("child"),
28 };
29 state.approvalsAtom = Atom.make<ReadonlyArray<ChildThreadApproval>>([
30 {
31 thread,
32 title: "Compile task",
33 approval: {
34 requestId: RuntimeRequestId.make("approval"),
35 requestKind: "command",
36 detail: "Run compiler",
37 createdAt: "2026-11-01T00:00:00.000Z",
38 responseCapability: "live",
39 },
40 },
41 ]);
42 return thread;
43 }
44
45 it("shows a failed decision and clears the error when the user retries", async () => {
46 const thread = setup();
47 await using screen = await render(<ChildThreadApprovals threadRef={thread} />);
48 await screen.getByRole("button", { name: "Approve", exact: true }).click();
49 await expect.element(screen.getByRole("alert")).toHaveTextContent("Child environment offline");
50 await screen.getByRole("button", { name: "Approve", exact: true }).click();
51 await expect.element(screen.getByRole("alert")).not.toBeInTheDocument();
52 });