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.
This commit is contained in:
DhanushSantosh
2026-01-08 00:04:52 +05:30
parent 24ea10e818
commit 48a4fa5c6c
2 changed files with 10 additions and 6 deletions

View File

@@ -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,

View File

@@ -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 () => {