From 3cba0b7ed26fbde4484ea50746364fc4fb064742 Mon Sep 17 00:00:00 2001 From: Alex Southwell <4596216+saphid@users.noreply.github.com> Date: Tue, 3 Nov 2026 14:22:04 +1100 Subject: [PATCH] fix(web): device host checks show the error without a stack trace Co-Authored-By: Claude Opus 5.5 --- .../useHostConnectionChecks.browser.test.tsx | 64 +++++++++++++++++++ .../settings/useHostConnectionChecks.ts | 4 +- 2 files changed, 66 insertions(+), 2 deletions(-) create mode 100644 apps/web/src/components/settings/useHostConnectionChecks.browser.test.tsx diff --git a/apps/web/src/components/settings/useHostConnectionChecks.browser.test.tsx b/apps/web/src/components/settings/useHostConnectionChecks.browser.test.tsx new file mode 100644 index 0000000000000..93c2776034a4d --- /dev/null +++ b/apps/web/src/components/settings/useHostConnectionChecks.browser.test.tsx @@ -0,0 +1,64 @@ +import { DeviceHostUnavailableError, EnvironmentId } from "@t3tools/contracts"; +import * as Cause from "effect/Cause"; +import { AsyncResult } from "effect/reactivity"; +import { describe, expect, it, vi } from "vite-plus/test"; + +import { act, render } from "../../../test/render"; + +const state = vi.hoisted(() => ({ test: vi.fn() })); +function setup() { + state.test.mockReset(); +} + +vi.mock(import("../../state/use-atom-command"), async (original) => ({ + ...(await original()), + useAtomCommand: (() => state.test) as never, +})); +vi.mock(import("../../state/session"), async (original) => ({ + ...(await original()), + readEnvironmentScope: (() => true) as never, +})); + +import { useHostConnectionChecks } from "./useHostConnectionChecks"; + +const environmentId = EnvironmentId.make("environment-1"); +const targets = [{ environmentId, label: "This Mac", connected: true }]; + +function Harness({ + onReady, +}: { + onReady: (run: ReturnType) => void; +}) { + onReady(useHostConnectionChecks(targets)); + return null; +} + +describe("useHostConnectionChecks", () => { + it("reports a failed check by its message, without a stack trace", async () => { + setup(); + state.test.mockResolvedValue( + AsyncResult.failure( + Cause.fail( + new DeviceHostUnavailableError({ + hostId: "mac", + hostLabel: "Mac mini", + reason: "SSH connection refused.", + }), + ), + ), + ); + let checks!: ReturnType; + await using _screen = await render( (checks = next)} />, { + router: false, // the hook reads no route state + }); + + const results = await act(() => + checks.testConnection({ kind: "ssh", id: "mac", label: "Mac mini", target: "user@mac" }), + ); + + expect(results?.[environmentId]).toEqual({ + status: "failed", + error: "Mac mini is unavailable: SSH connection refused.", + }); + }); +}); diff --git a/apps/web/src/components/settings/useHostConnectionChecks.ts b/apps/web/src/components/settings/useHostConnectionChecks.ts index 4b2733cdfcf42..e96b992a149b8 100644 --- a/apps/web/src/components/settings/useHostConnectionChecks.ts +++ b/apps/web/src/components/settings/useHostConnectionChecks.ts @@ -1,7 +1,7 @@ import { AuthSettingsWriteScope } from "@t3tools/contracts"; import { readEnvironmentScope } from "../../state/session"; import { useRef, useState } from "react"; -import * as Cause from "effect/Cause"; +import { squashAtomCommandFailure } from "@t3tools/client-runtime/state/runtime"; import type { SshDeviceHostConfig } from "@t3tools/contracts"; import { deviceEnvironment } from "../../state/device"; import { useAtomCommand } from "../../state/use-atom-command"; @@ -30,7 +30,7 @@ export function useHostConnectionChecks(targets: ReadonlyArray {