Skip to content

Commit e3a6da0

Browse files
committed
test: tighten doctor update progress coverage
1 parent 8ec1c06 commit e3a6da0

2 files changed

Lines changed: 45 additions & 1 deletion

File tree

src/commands/doctor-update.test.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
44
import { maybeOfferUpdateBeforeDoctor } from "./doctor-update.js";
55

66
const originalStdinIsTtyDescriptor = Object.getOwnPropertyDescriptor(process.stdin, "isTTY");
7+
const originalStdoutIsTtyDescriptor = Object.getOwnPropertyDescriptor(process.stdout, "isTTY");
78

89
const mocks = vi.hoisted(() => ({
910
createUpdateProgress: vi.fn(),
@@ -52,6 +53,10 @@ beforeEach(async () => {
5253
configurable: true,
5354
value: true,
5455
});
56+
Object.defineProperty(process.stdout, "isTTY", {
57+
configurable: true,
58+
value: true,
59+
});
5560
});
5661

5762
afterEach(() => {
@@ -61,6 +66,11 @@ afterEach(() => {
6166
} else {
6267
delete (process.stdin as Partial<typeof process.stdin>).isTTY;
6368
}
69+
if (originalStdoutIsTtyDescriptor) {
70+
Object.defineProperty(process.stdout, "isTTY", originalStdoutIsTtyDescriptor);
71+
} else {
72+
delete (process.stdout as Partial<typeof process.stdout>).isTTY;
73+
}
6474
});
6575

6676
describe("maybeOfferUpdateBeforeDoctor", () => {
@@ -115,9 +125,42 @@ describe("maybeOfferUpdateBeforeDoctor", () => {
115125
await expect(runOffer({ root: "/repo/link", confirm })).rejects.toThrow("update exploded");
116126

117127
expect(mocks.runGatewayUpdate).toHaveBeenCalledWith(expect.objectContaining({ progress }));
128+
expect(mocks.createUpdateProgress).toHaveBeenCalledWith(true);
118129
expect(stop).toHaveBeenCalledTimes(1);
119130
});
120131

132+
it("disables update progress when stdout is not a TTY", async () => {
133+
Object.defineProperty(process.stdout, "isTTY", {
134+
configurable: true,
135+
value: false,
136+
});
137+
vi.spyOn(fs, "realpath").mockImplementation(async (candidate) => String(candidate));
138+
mocks.runCommandWithTimeout.mockResolvedValue({
139+
stdout: "/repo/link\n",
140+
stderr: "",
141+
code: 0,
142+
killed: false,
143+
signal: null,
144+
termination: "exit",
145+
noOutputTimedOut: false,
146+
});
147+
mocks.runGatewayUpdate.mockResolvedValue({
148+
status: "skipped",
149+
mode: "git",
150+
root: "/repo/link",
151+
steps: [],
152+
durationMs: 0,
153+
});
154+
155+
const confirm = vi.fn().mockResolvedValue(true);
156+
await expect(runOffer({ root: "/repo/link", confirm })).resolves.toEqual({
157+
updated: true,
158+
handled: false,
159+
});
160+
161+
expect(mocks.createUpdateProgress).toHaveBeenCalledWith(false);
162+
});
163+
121164
it("keeps package-manager guidance when git reports a different checkout", async () => {
122165
const confirm = vi.fn();
123166
vi.spyOn(fs, "realpath").mockImplementation(async (candidate) => String(candidate));

src/commands/doctor-update.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { formatCliCommand } from "../cli/command-format.js";
77
import { createUpdateProgress } from "../cli/update-cli/progress.js";
88
import { isTruthyEnvValue } from "../infra/env.js";
99
import { runGatewayUpdate } from "../infra/update-runner.js";
10+
import type { UpdateRunResult } from "../infra/update-runner.js";
1011
import { runCommandWithTimeout } from "../process/exec.js";
1112
import type { RuntimeEnv } from "../runtime.js";
1213
import type { DoctorOptions } from "./doctor-prompter.js";
@@ -66,7 +67,7 @@ export async function maybeOfferUpdateBeforeDoctor(params: {
6667
}
6768
note("Running update…", "Update");
6869
const { progress, stop } = createUpdateProgress(process.stdout.isTTY);
69-
let result;
70+
let result: UpdateRunResult;
7071
try {
7172
result = await runGatewayUpdate({
7273
cwd: params.root,

0 commit comments

Comments
 (0)