Skip to content

Commit 305bbfb

Browse files
committed
fix: harden discussion codex repo checks
1 parent 1fd9f10 commit 305bbfb

5 files changed

Lines changed: 35 additions & 11 deletions

File tree

__tests__/unit/providers/codex-provider.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,16 @@ describe('CodexProvider', () => {
7373

7474
expect(args).toEqual(
7575
expect.arrayContaining([
76+
'--skip-git-repo-check',
7677
'--disable',
7778
'shell_tool',
7879
'unified_exec',
7980
'browser_use',
8081
'computer_use',
8182
'plugins',
82-
'--skip-git-repo-check',
8383
])
8484
);
85+
expect(args.indexOf('--skip-git-repo-check')).toBe(1);
8586
});
8687

8788
it('sanitizes spawned Codex environment', () => {

dist/index.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13296,6 +13296,9 @@ var CodexProvider = class extends Provider {
1329613296
"--output-last-message",
1329713297
options.outputLastMessageFile
1329813298
];
13299+
if (options.skipGitRepoCheck) {
13300+
args.splice(1, 0, "--skip-git-repo-check");
13301+
}
1329913302
if (options.disableTools) {
1330013303
args.push(
1330113304
"--disable",
@@ -13316,9 +13319,6 @@ var CodexProvider = class extends Provider {
1331613319
"plugins"
1331713320
);
1331813321
}
13319-
if (options.skipGitRepoCheck) {
13320-
args.push("--skip-git-repo-check");
13321-
}
1332213322
if (options.outputSchemaFile) {
1332313323
args.push("--output-schema", options.outputSchemaFile);
1332413324
}
@@ -27768,6 +27768,8 @@ function sanitizeError(error2) {
2776827768
var fs14 = __toESM(require("fs/promises"));
2776927769
var os6 = __toESM(require("os"));
2777027770
var path13 = __toESM(require("path"));
27771+
var import_child_process7 = require("child_process");
27772+
var import_util5 = require("util");
2777127773
var INTENTS = [
2777227774
"question",
2777327775
"disagreement",
@@ -27780,6 +27782,7 @@ var SUGGESTED_ACTIONS = [
2778027782
"suggest_rr_skip",
2778127783
"ask_for_details"
2778227784
];
27785+
var execFileAsync = (0, import_util5.promisify)(import_child_process7.execFile);
2778327786
var CodexDiscussionResponder = class {
2778427787
constructor(model, timeoutMs) {
2778527788
this.model = model;
@@ -27792,6 +27795,7 @@ var CodexDiscussionResponder = class {
2779227795
});
2779327796
const cwd = await fs14.mkdtemp(path13.join(os6.tmpdir(), "review-router-chat-"));
2779427797
try {
27798+
await initializeEmptyGitRepository(cwd);
2779527799
const content = await provider.runStructuredPrompt(
2779627800
this.buildPrompt(context),
2779727801
this.buildSchema(),
@@ -27931,6 +27935,12 @@ function redactSecrets(value) {
2793127935
function escapeAttr(value) {
2793227936
return value.replace(/&/g, "&").replace(/"/g, """);
2793327937
}
27938+
async function initializeEmptyGitRepository(cwd) {
27939+
try {
27940+
await execFileAsync("git", ["init", "-q"], { cwd, timeout: 5e3 });
27941+
} catch {
27942+
}
27943+
}
2793427944

2793527945
// src/main.ts
2793627946
function syncEnvFromInputs() {

dist/index.js.map

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/discussion/codex-responder.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import * as fs from 'fs/promises';
22
import * as os from 'os';
33
import * as path from 'path';
4+
import { execFile } from 'child_process';
5+
import { promisify } from 'util';
46
import { CodexProvider } from '../providers/codex';
57
import {
68
DiscussionIntent,
@@ -23,6 +25,7 @@ const SUGGESTED_ACTIONS: DiscussionSuggestedAction[] = [
2325
'suggest_rr_skip',
2426
'ask_for_details',
2527
];
28+
const execFileAsync = promisify(execFile);
2629

2730
export class CodexDiscussionResponder implements DiscussionResponder {
2831
constructor(
@@ -38,6 +41,7 @@ export class CodexDiscussionResponder implements DiscussionResponder {
3841
const cwd = await fs.mkdtemp(path.join(os.tmpdir(), 'review-router-chat-'));
3942

4043
try {
44+
await initializeEmptyGitRepository(cwd);
4145
const content = await provider.runStructuredPrompt(
4246
this.buildPrompt(context),
4347
this.buildSchema(),
@@ -212,3 +216,12 @@ function redactSecrets(value: string): string {
212216
function escapeAttr(value: string): string {
213217
return value.replace(/&/g, '&').replace(/"/g, '"');
214218
}
219+
220+
async function initializeEmptyGitRepository(cwd: string): Promise<void> {
221+
try {
222+
await execFileAsync('git', ['init', '-q'], { cwd, timeout: 5000 });
223+
} catch {
224+
// Codex also receives --skip-git-repo-check. The empty repo is a CI
225+
// compatibility layer, not a hard dependency for discussion replies.
226+
}
227+
}

src/providers/codex.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,10 @@ export class CodexProvider extends Provider {
220220
options.outputLastMessageFile,
221221
];
222222

223+
if (options.skipGitRepoCheck) {
224+
args.splice(1, 0, '--skip-git-repo-check');
225+
}
226+
223227
if (options.disableTools) {
224228
args.push(
225229
'--disable',
@@ -241,10 +245,6 @@ export class CodexProvider extends Provider {
241245
);
242246
}
243247

244-
if (options.skipGitRepoCheck) {
245-
args.push('--skip-git-repo-check');
246-
}
247-
248248
if (options.outputSchemaFile) {
249249
args.push('--output-schema', options.outputSchemaFile);
250250
}

0 commit comments

Comments
 (0)