The best way to control Claude Code, Codex and more from any computer or phone

main
tsx 64 lines 1.92 KB
Raw
1 import { DeviceHostUnavailableError, EnvironmentId } from "@t3tools/contracts";
2 import * as Cause from "effect/Cause";
3 import { AsyncResult } from "effect/reactivity";
4 import { describe, expect, it, vi } from "vite-plus/test";
5
6 import { act, render } from "../../../test/render";
7
8 const state = vi.hoisted(() => ({ test: vi.fn() }));
9 function setup() {
10 state.test.mockReset();
11 }
12
13 vi.mock(import("../../state/use-atom-command"), async (original) => ({
14 ...(await original()),
15 useAtomCommand: (() => state.test) as never,
16 }));
17 vi.mock(import("../../state/session"), async (original) => ({
18 ...(await original()),
19 readEnvironmentScope: (() => true) as never,
20 }));
21
22 import { useHostConnectionChecks } from "./useHostConnectionChecks";
23
24 const environmentId = EnvironmentId.make("environment-1");
25 const targets = [{ environmentId, label: "This Mac", connected: true }];
26
27 function Harness({
28 onReady,
29 }: {
30 onReady: (run: ReturnType<typeof useHostConnectionChecks>) => void;
31 }) {
32 onReady(useHostConnectionChecks(targets));
33 return null;
34 }
35
36 describe("useHostConnectionChecks", () => {
37 it("reports a failed check by its message, without a stack trace", async () => {
38 setup();
39 state.test.mockResolvedValue(
40 AsyncResult.failure(
41 Cause.fail(
42 new DeviceHostUnavailableError({
43 hostId: "mac",
44 hostLabel: "Mac mini",
45 reason: "SSH connection refused.",
46 }),
47 ),
48 ),
49 );
50 let checks!: ReturnType<typeof useHostConnectionChecks>;
51 await using _screen = await render(<Harness onReady={(next) => (checks = next)} />, {
52 router: false, // the hook reads no route state
53 });
54
55 const results = await act(() =>
56 checks.testConnection({ kind: "ssh", id: "mac", label: "Mac mini", target: "user@mac" }),
57 );
58
59 expect(results?.[environmentId]).toEqual({
60 status: "failed",
61 error: "Mac mini is unavailable: SSH connection refused.",
62 });
63 });
64 });