From 48a4fa5c6c49ad80ab8bd104c420ce1ed95dc7ee Mon Sep 17 00:00:00 2001 From: DhanushSantosh Date: Thu, 8 Jan 2026 00:04:52 +0530 Subject: [PATCH] refactor: streamline argument handling in CodexProvider - Reorganized argument construction in CodexProvider to separate pre-execution arguments from global flags, improving clarity and maintainability. - Updated unit tests to reflect changes in argument order, ensuring correct validation of approval and search indices. These changes enhance the structure of the CodexProvider's command execution process and improve test reliability. --- apps/server/src/providers/codex-provider.ts | 12 ++++++++---- .../tests/unit/providers/codex-provider.test.ts | 4 ++-- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/apps/server/src/providers/codex-provider.ts b/apps/server/src/providers/codex-provider.ts index 615d0db7..db237424 100644 --- a/apps/server/src/providers/codex-provider.ts +++ b/apps/server/src/providers/codex-provider.ts @@ -744,21 +744,25 @@ export class CodexProvider extends BaseProvider { } const configOverrides = buildConfigOverrides(overrides); - const globalArgs = [CODEX_SKIP_GIT_REPO_CHECK_FLAG, CODEX_APPROVAL_FLAG, approvalPolicy]; + const preExecArgs: string[] = []; + if (searchEnabled) { - globalArgs.push(CODEX_SEARCH_FLAG); + preExecArgs.push(CODEX_SEARCH_FLAG); } // Add additional directories with write access if (codexSettings.additionalDirs && codexSettings.additionalDirs.length > 0) { for (const dir of codexSettings.additionalDirs) { - globalArgs.push(CODEX_ADD_DIR_FLAG, dir); + preExecArgs.push(CODEX_ADD_DIR_FLAG, dir); } } const args = [ - ...globalArgs, CODEX_EXEC_SUBCOMMAND, + CODEX_SKIP_GIT_REPO_CHECK_FLAG, + CODEX_APPROVAL_FLAG, + approvalPolicy, + ...preExecArgs, CODEX_MODEL_FLAG, options.model, CODEX_JSON_FLAG, diff --git a/apps/server/tests/unit/providers/codex-provider.test.ts b/apps/server/tests/unit/providers/codex-provider.test.ts index 19f4d674..fd981458 100644 --- a/apps/server/tests/unit/providers/codex-provider.test.ts +++ b/apps/server/tests/unit/providers/codex-provider.test.ts @@ -193,9 +193,9 @@ describe('codex-provider.ts', () => { expect(call.args[approvalIndex + 1]).toBe('never'); expect(approvalIndex).toBeGreaterThan(-1); expect(execIndex).toBeGreaterThan(-1); - expect(approvalIndex).toBeLessThan(execIndex); + expect(approvalIndex).toBeGreaterThan(execIndex); expect(searchIndex).toBeGreaterThan(-1); - expect(searchIndex).toBeLessThan(execIndex); + expect(searchIndex).toBeGreaterThan(execIndex); }); it('injects user and project instructions when auto-load is enabled', async () => {