Skip to content

Commit d4a539f

Browse files
committed
fix(doctor): narrow noninteractive restart guard
1 parent 6da9dc4 commit d4a539f

2 files changed

Lines changed: 23 additions & 4 deletions

File tree

src/commands/doctor-gateway-daemon-flow.test.ts

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -245,16 +245,16 @@ describe("maybeRepairGatewayDaemon", () => {
245245
});
246246
}
247247

248-
async function runAutoRepair() {
248+
async function runAutoRepair(options: { repair?: boolean; yes?: boolean } = { repair: true }) {
249249
const runtime = { log: vi.fn(), error: vi.fn(), exit: vi.fn() };
250250
await maybeRepairGatewayDaemon({
251251
cfg: { gateway: {} },
252252
runtime,
253253
prompter: createDoctorPrompter({
254254
runtime,
255-
options: { repair: true },
255+
options,
256256
}),
257-
options: { deep: false, repair: true },
257+
options: { deep: false, ...options },
258258
gatewayDetailsMessage: "details",
259259
healthOk: false,
260260
});
@@ -559,6 +559,22 @@ describe("maybeRepairGatewayDaemon", () => {
559559
expect(service.restart).toHaveBeenCalledTimes(1);
560560
});
561561

562+
it("restarts running service when repair is explicitly approved", async () => {
563+
setPlatform("linux");
564+
565+
await runAutoRepair();
566+
567+
expect(service.restart).toHaveBeenCalledTimes(1);
568+
});
569+
570+
it("restarts running service when --yes explicitly approves repairs", async () => {
571+
setPlatform("linux");
572+
573+
await runAutoRepair({ yes: true });
574+
575+
expect(service.restart).toHaveBeenCalledTimes(1);
576+
});
577+
562578
it("skips gateway service install when service repair policy is external", async () => {
563579
setPlatform("linux");
564580
service.isLoaded.mockResolvedValue(false);

src/commands/doctor-gateway-daemon-flow.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -459,13 +459,16 @@ export async function maybeRepairGatewayDaemon(params: {
459459
// Health probe failed — fall through to the restart prompt below.
460460
}
461461
}
462+
if (params.options.nonInteractive === true) {
463+
// --fix auto-approves runtime repairs; do not let a headless doctor kill its live gateway.
464+
return;
465+
}
462466

463467
const restart = await confirmDoctorServiceRepair(
464468
params.prompter,
465469
{
466470
message: "Restart gateway service now?",
467471
initialValue: false,
468-
requiresInteractiveConfirmation: true,
469472
},
470473
serviceRepairPolicy,
471474
);

0 commit comments

Comments
 (0)