Skip to content

Commit ea50ec3

Browse files
committed
fix: address review feedback — add safety comment, verify all 3 parallel branches in test
- Document Promise.all safety contract in repair-sequencing.ts - Assert repairStaleOAuthProfileShadows call args in OAuth migration test - Assert cleanupLegacyPluginDependencyState was called (all 3 branches) - Convert plugin-dependency-cleanup mock from anonymous fn to vi.fn() so it's assertable
1 parent a7e3679 commit ea50ec3

2 files changed

Lines changed: 20 additions & 4 deletions

File tree

‎src/commands/doctor/repair-sequencing.test.ts‎

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { runDoctorRepairSequence } from "./repair-sequencing.js";
44

55
const mocks = vi.hoisted(() => ({
66
applyPluginAutoEnable: vi.fn(),
7+
cleanupLegacyPluginDependencyState: vi.fn(),
78
ensureAuthProfileStore: vi.fn(),
89
evaluateStoredCredentialEligibility: vi.fn(),
910
getInstalledPluginRecord: vi.fn(),
@@ -183,10 +184,7 @@ vi.mock("./shared/exec-safe-bins.js", () => ({
183184
}));
184185

185186
vi.mock("./shared/plugin-dependency-cleanup.js", () => ({
186-
cleanupLegacyPluginDependencyState: async () => ({
187-
changes: [],
188-
warnings: [],
189-
}),
187+
cleanupLegacyPluginDependencyState: mocks.cleanupLegacyPluginDependencyState,
190188
}));
191189

192190
describe("doctor repair sequencing", () => {
@@ -221,6 +219,10 @@ describe("doctor repair sequencing", () => {
221219
config: cfg,
222220
changes: [],
223221
}));
222+
mocks.cleanupLegacyPluginDependencyState.mockResolvedValue({
223+
changes: [],
224+
warnings: [],
225+
});
224226
mocks.maybeRepairStaleManagedNpmBundledPlugins.mockReturnValue(false);
225227
mocks.repairMissingConfiguredPluginInstalls.mockResolvedValue({
226228
changes: [],
@@ -380,6 +382,14 @@ describe("doctor repair sequencing", () => {
380382
emitNotes: false,
381383
env: process.env,
382384
});
385+
expect(mocks.repairStaleOAuthProfileShadows).toHaveBeenCalledWith({
386+
cfg: {},
387+
env: process.env,
388+
});
389+
// Verify all 3 parallel branches were exercised
390+
expect(mocks.cleanupLegacyPluginDependencyState).toHaveBeenCalledWith({
391+
env: process.env,
392+
});
383393
expect(result.changeNotes).toEqual([
384394
"Migrated 1 sidecar-backed Codex OAuth profile.",
385395
"Removed stale OAuth auth profile shadow openai-codex.",

‎src/commands/doctor/repair-sequencing.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,12 @@ export async function runDoctorRepairSequence(params: {
128128
// Parallel I/O: dep cleanup and OAuth repairs are filesystem-only
129129
// operations independent of config state. Running them concurrently
130130
// reduces total wall-clock time from sum to max.
131+
//
132+
// Safety: each function catches I/O errors internally and returns a
133+
// structured {changes, warnings} result — none of them throw on expected
134+
// failure paths. Promise.all is safe here because every branch handles
135+
// its own errors. If a future change adds an uncaught throw path, it will
136+
// lose results from all 3 branches; add internal error handling instead.
131137
const [pluginDependencyCleanup, legacyOAuthSidecarRepair, staleOAuthShadowRepair] =
132138
await Promise.all([
133139
cleanupLegacyPluginDependencyState({ env }),

0 commit comments

Comments
 (0)