From aa262c244dbe1250356f36fc08d25cfa6c2d15ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20=C3=81ngel?= Date: Sun, 22 Nov 2026 11:53:42 +0000 Subject: [PATCH] test(cli): the doctor output test no longer runs every machine check (#8497) * test(cli): the doctor output test prints rows without running every machine check * test(cli): call the row printer directly in the doctor output test --- .../cli/src/commands/doctor.output.test.ts | 34 ++++--------- packages/cli/src/commands/doctor.ts | 51 ++++++++++--------- 2 files changed, 37 insertions(+), 48 deletions(-) diff --git a/packages/cli/src/commands/doctor.output.test.ts b/packages/cli/src/commands/doctor.output.test.ts index fd69a7cd99..fc331d7bc1 100644 --- a/packages/cli/src/commands/doctor.output.test.ts +++ b/packages/cli/src/commands/doctor.output.test.ts @@ -1,43 +1,29 @@ import { afterEach, describe, expect, it, vi } from "vitest"; -import { consumeCommandResult } from "../utils/commandResult.js"; +import { printDoctorOutcomes } from "./doctor.js"; const ESC = String.fromCharCode(27); const ODD = `od${ESC}[2Jd\x07`; const SHOWN = "od\\x1b[2Jd\\x07"; -vi.mock("../browser/preflight.js", async (importOriginal) => ({ - ...(await importOriginal()), - runEnvironmentChecks: async () => ({ - outcomes: [ - { - name: `Tool ${ODD}`, - ok: false, - level: "error", - detail: `not found at ${ODD}\nsecond line`, - hint: `install ${ODD}`, - }, - ], - }), -})); - -const { default: doctorCommand } = await import("./doctor.js"); - afterEach(() => { - consumeCommandResult(); vi.restoreAllMocks(); }); describe("doctor output", () => { // fails without the fix: a check's name, detail and hint are printed as the check returned them. - it("shows control characters in a check row as text", async () => { + it("shows control characters in a check row as text", () => { const said: string[] = []; vi.spyOn(console, "log").mockImplementation((...args: unknown[]) => { said.push(args.join(" ")); }); - vi.spyOn(console, "error").mockImplementation(() => {}); - await Promise.resolve( - doctorCommand.run?.({ args: { json: false }, rawArgs: [], cmd: doctorCommand } as never), - ).catch(() => undefined); + printDoctorOutcomes([ + { + name: `Tool ${ODD}`, + ok: false, + detail: `not found at ${ODD}\nsecond line`, + hint: `install ${ODD}`, + }, + ]); const text = said.join("\n").replace(new RegExp(`${ESC}\\[[0-9;]*m`, "g"), ""); expect(text).toContain(`Tool ${SHOWN}`); expect(text).toContain(`not found at ${SHOWN}\nsecond line`); diff --git a/packages/cli/src/commands/doctor.ts b/packages/cli/src/commands/doctor.ts index 9c301f0d7b..23e7f8c355 100644 --- a/packages/cli/src/commands/doctor.ts +++ b/packages/cli/src/commands/doctor.ts @@ -403,6 +403,32 @@ export function buildDoctorReport(outcomes: CheckOutcome[], options: { redact?: }); } +export function printDoctorOutcomes(outcomes: CheckOutcome[]): void { + const allOk = outcomes.every((o) => o.ok); + console.log(); + console.log(c.bold("hyperframes doctor")); + console.log(); + + for (const outcome of outcomes) { + const icon = outcome.ok ? c.success("\u2713") : c.error("\u2717"); + const name = terminalText(outcome.name).padEnd(16); + console.log( + ` ${icon} ${c.bold(name)} ${outcome.ok ? c.dim(terminalLines(outcome.detail)) : c.error(terminalLines(outcome.detail))}`, + ); + if (!outcome.ok && outcome.hint) { + console.log(` ${" ".repeat(19)}${c.accent(terminalLines(outcome.hint))}`); + } + } + + console.log(); + if (allOk) { + console.log(` ${c.success("\u25C7")} ${c.success("All checks passed")}`); + } else { + console.log(` ${c.warn("\u25C7")} ${c.warn("Some checks failed \u2014 see hints above")}`); + } + console.log(); +} + export default defineCommand({ meta: { name: "doctor", description: "Check system dependencies and environment" }, args: { @@ -466,8 +492,6 @@ export default defineCommand({ ...(result.hint ? { hint: result.hint } : {}), }); } - const allOk = outcomes.every((o) => o.ok); - if (args.json) { // Exit code intentionally reflects command success, not environment // health — `checkVersion` returns ok:false when an npm update is @@ -479,27 +503,6 @@ export default defineCommand({ return; } - console.log(); - console.log(c.bold("hyperframes doctor")); - console.log(); - - for (const outcome of outcomes) { - const icon = outcome.ok ? c.success("\u2713") : c.error("\u2717"); - const name = terminalText(outcome.name).padEnd(16); - console.log( - ` ${icon} ${c.bold(name)} ${outcome.ok ? c.dim(terminalLines(outcome.detail)) : c.error(terminalLines(outcome.detail))}`, - ); - if (!outcome.ok && outcome.hint) { - console.log(` ${" ".repeat(19)}${c.accent(terminalLines(outcome.hint))}`); - } - } - - console.log(); - if (allOk) { - console.log(` ${c.success("\u25C7")} ${c.success("All checks passed")}`); - } else { - console.log(` ${c.warn("\u25C7")} ${c.warn("Some checks failed \u2014 see hints above")}`); - } - console.log(); + printDoctorOutcomes(outcomes); }, });