Skip to content

Commit 40a9db1

Browse files
committed
test(codex): cover feature invocation without injected toggle
1 parent e618338 commit 40a9db1

1 file changed

Lines changed: 26 additions & 1 deletion

File tree

‎tests/codex-integration/codex-cli-update-parent-async.test.ts‎

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ function featureToggleFixture(signal?: AbortSignal) {
258258
headers: { "content-type": "application/json" }, body: JSON.stringify({ enabled: true }) });
259259
return { path, original, req, url };
260260
}
261-
function callFeatureToggle(f: ReturnType<typeof featureToggleFixture>, toggle: NonNullable<ManagementContext["deps"]["toggleDefaultModeRequestUserInput"]>) {
261+
function callFeatureToggle(f: ReturnType<typeof featureToggleFixture>, toggle?: NonNullable<ManagementContext["deps"]["toggleDefaultModeRequestUserInput"]>) {
262262
return handleAgentSettingsRoutes({ req: f.req, url: f.url, config: { providers: [] } as unknown as OcxConfig,
263263
deps: { toggleDefaultModeRequestUserInput: toggle }, version: "test", trustedLoopbackIngress: true,
264264
guiSessionIssuance: null, convergeCodexCatalog: async () => { throw new Error("unexpected catalog convergence"); },
@@ -279,6 +279,31 @@ test("single feature toggle refuses a held update gate before any child runs", a
279279
} finally { worker.exit(); }
280280
});
281281

282+
test("no-toggle feature request resolves its runtime inside parent admission commit", async () => {
283+
const f = featureToggleFixture();
284+
spies.push(spyOn(recovery, "codexCliUpdateRecoveryBlocksAdmissionAsync").mockResolvedValue(false));
285+
spies.push(spyOn(recovery, "codexCliUpdateRecoveryBlocksAdmission").mockReturnValue(false));
286+
const lock = spyOn(configWriteLock, "acquireConfigWriteLock"); spies.push(lock);
287+
const worker = gate.createWorkerCommitWindow({ gate: gate.codexCliUpdateSelectionGate(), fence: gate.createCodexCliUpdateFence() });
288+
let resolutions = 0, state = "", workerEntered = false, nestedEntered = false;
289+
spies.push(spyOn(runtime, "resolveAndPersistCodexRuntime").mockImplementation(() => {
290+
resolutions++; state = gate.codexCliSelectionGateState();
291+
workerEntered = worker.tryEnter(); if (workerEntered) worker.exit();
292+
const nested = gate.beginCodexCliSelectionParentWrite();
293+
nestedEntered = nested.entered; if (nestedEntered) nested.exit();
294+
return { runtime: { command: "codex", source: "fallback", version: null }, failures: [] };
295+
}));
296+
try {
297+
const response = await callFeatureToggle(f);
298+
expect(resolutions).toBe(1); expect(state).toBe("parent_write");
299+
expect(workerEntered).toBe(false); expect(nestedEntered).toBe(true);
300+
expect(response?.status).toBe(502);
301+
expect(await response!.json()).toMatchObject({ error: "default_mode_request_user_input toggle failed: spawn codex ENOENT" });
302+
expect(lock).not.toHaveBeenCalled(); expect(readFileSync(f.path, "utf8")).toBe(f.original);
303+
expect(free()).toBe(true);
304+
} finally { worker.exit(); }
305+
});
306+
282307
for (const outcome of ["success", "child-failure", "cancel", "lock-failure"] as const) {
283308
test(`single feature toggle holds selection across config-lock wait and releases after ${outcome}`, async () => {
284309
const controller = new AbortController(); const f = featureToggleFixture(controller.signal);

0 commit comments

Comments
 (0)