From b0a8b3bebb5260dd7a87a4db756937cf6b6af7b6 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Sun, 22 Feb 2026 14:14:03 +0000 Subject: [PATCH] test: share fast-path mocks for targeted doctor suites --- src/commands/doctor.fast-path-mocks.ts | 49 ++++++++++++++++++ ...owfrom-channels-whatsapp-allowfrom.test.ts | 51 +------------------ ...agent-sandbox-docker-browser-prune.test.ts | 3 ++ ...r.warns-state-directory-is-missing.test.ts | 5 +- 4 files changed, 58 insertions(+), 50 deletions(-) create mode 100644 src/commands/doctor.fast-path-mocks.ts diff --git a/src/commands/doctor.fast-path-mocks.ts b/src/commands/doctor.fast-path-mocks.ts new file mode 100644 index 000000000..329ba61e6 --- /dev/null +++ b/src/commands/doctor.fast-path-mocks.ts @@ -0,0 +1,49 @@ +import { vi } from "vitest"; + +vi.mock("./doctor-completion.js", () => ({ + doctorShellCompletion: vi.fn().mockResolvedValue(undefined), +})); + +vi.mock("./doctor-gateway-daemon-flow.js", () => ({ + maybeRepairGatewayDaemon: vi.fn().mockResolvedValue(undefined), +})); + +vi.mock("./doctor-gateway-health.js", () => ({ + checkGatewayHealth: vi.fn().mockResolvedValue({ healthOk: false }), +})); + +vi.mock("./doctor-memory-search.js", () => ({ + noteMemorySearchHealth: vi.fn().mockResolvedValue(undefined), +})); + +vi.mock("./doctor-platform-notes.js", () => ({ + noteDeprecatedLegacyEnvVars: vi.fn(), + noteMacLaunchAgentOverrides: vi.fn().mockResolvedValue(undefined), + noteMacLaunchctlGatewayEnvOverrides: vi.fn().mockResolvedValue(undefined), +})); + +vi.mock("./doctor-sandbox.js", () => ({ + maybeRepairSandboxImages: vi.fn(async (cfg: unknown) => cfg), + noteSandboxScopeWarnings: vi.fn(), +})); + +vi.mock("./doctor-security.js", () => ({ + noteSecurityWarnings: vi.fn().mockResolvedValue(undefined), +})); + +vi.mock("./doctor-session-locks.js", () => ({ + noteSessionLockHealth: vi.fn().mockResolvedValue(undefined), +})); + +vi.mock("./doctor-state-integrity.js", () => ({ + noteStateIntegrity: vi.fn().mockResolvedValue(undefined), + noteWorkspaceBackupTip: vi.fn(), +})); + +vi.mock("./doctor-ui.js", () => ({ + maybeRepairUiProtocolFreshness: vi.fn().mockResolvedValue(undefined), +})); + +vi.mock("./doctor-workspace-status.js", () => ({ + noteWorkspaceStatus: vi.fn(), +})); diff --git a/src/commands/doctor.migrates-routing-allowfrom-channels-whatsapp-allowfrom.test.ts b/src/commands/doctor.migrates-routing-allowfrom-channels-whatsapp-allowfrom.test.ts index ce83587a3..6f1067814 100644 --- a/src/commands/doctor.migrates-routing-allowfrom-channels-whatsapp-allowfrom.test.ts +++ b/src/commands/doctor.migrates-routing-allowfrom-channels-whatsapp-allowfrom.test.ts @@ -1,4 +1,4 @@ -import { describe, expect, it, vi } from "vitest"; +import { describe, expect, it } from "vitest"; import { createDoctorRuntime, findLegacyGatewayServices, @@ -14,57 +14,10 @@ import { uninstallLegacyGatewayServices, writeConfigFile, } from "./doctor.e2e-harness.js"; +import "./doctor.fast-path-mocks.js"; const DOCTOR_MIGRATION_TIMEOUT_MS = 20_000; -vi.mock("./doctor-completion.js", () => ({ - doctorShellCompletion: vi.fn().mockResolvedValue(undefined), -})); - -vi.mock("./doctor-gateway-daemon-flow.js", () => ({ - maybeRepairGatewayDaemon: vi.fn().mockResolvedValue(undefined), -})); - -vi.mock("./doctor-gateway-health.js", () => ({ - checkGatewayHealth: vi.fn().mockResolvedValue({ healthOk: false }), -})); - -vi.mock("./doctor-memory-search.js", () => ({ - noteMemorySearchHealth: vi.fn().mockResolvedValue(undefined), -})); - -vi.mock("./doctor-platform-notes.js", () => ({ - noteDeprecatedLegacyEnvVars: vi.fn(), - noteMacLaunchAgentOverrides: vi.fn().mockResolvedValue(undefined), - noteMacLaunchctlGatewayEnvOverrides: vi.fn().mockResolvedValue(undefined), -})); - -vi.mock("./doctor-sandbox.js", () => ({ - maybeRepairSandboxImages: vi.fn(async (cfg: unknown) => cfg), - noteSandboxScopeWarnings: vi.fn(), -})); - -vi.mock("./doctor-security.js", () => ({ - noteSecurityWarnings: vi.fn().mockResolvedValue(undefined), -})); - -vi.mock("./doctor-session-locks.js", () => ({ - noteSessionLockHealth: vi.fn().mockResolvedValue(undefined), -})); - -vi.mock("./doctor-state-integrity.js", () => ({ - noteStateIntegrity: vi.fn().mockResolvedValue(undefined), - noteWorkspaceBackupTip: vi.fn(), -})); - -vi.mock("./doctor-ui.js", () => ({ - maybeRepairUiProtocolFreshness: vi.fn().mockResolvedValue(undefined), -})); - -vi.mock("./doctor-workspace-status.js", () => ({ - noteWorkspaceStatus: vi.fn(), -})); - describe("doctor command", () => { it("does not add a new gateway auth token while fixing legacy issues on invalid config", async () => { mockDoctorConfigSnapshot({ diff --git a/src/commands/doctor.warns-per-agent-sandbox-docker-browser-prune.test.ts b/src/commands/doctor.warns-per-agent-sandbox-docker-browser-prune.test.ts index 2fbe02bdf..954c1905f 100644 --- a/src/commands/doctor.warns-per-agent-sandbox-docker-browser-prune.test.ts +++ b/src/commands/doctor.warns-per-agent-sandbox-docker-browser-prune.test.ts @@ -3,6 +3,9 @@ import os from "node:os"; import path from "node:path"; import { beforeAll, describe, expect, it, vi } from "vitest"; import { createDoctorRuntime, mockDoctorConfigSnapshot, note } from "./doctor.e2e-harness.js"; +import "./doctor.fast-path-mocks.js"; + +vi.doUnmock("./doctor-sandbox.js"); let doctorCommand: typeof import("./doctor.js").doctorCommand; diff --git a/src/commands/doctor.warns-state-directory-is-missing.test.ts b/src/commands/doctor.warns-state-directory-is-missing.test.ts index 89de182f7..aabab0403 100644 --- a/src/commands/doctor.warns-state-directory-is-missing.test.ts +++ b/src/commands/doctor.warns-state-directory-is-missing.test.ts @@ -1,8 +1,11 @@ import fs from "node:fs"; import os from "node:os"; import path from "node:path"; -import { beforeAll, describe, expect, it } from "vitest"; +import { beforeAll, describe, expect, it, vi } from "vitest"; import { createDoctorRuntime, mockDoctorConfigSnapshot, note } from "./doctor.e2e-harness.js"; +import "./doctor.fast-path-mocks.js"; + +vi.doUnmock("./doctor-state-integrity.js"); let doctorCommand: typeof import("./doctor.js").doctorCommand;