Skip to content

Commit dae6f09

Browse files
feat: centralized CLAWSWEEPER_CODEX_LOGIN_METHOD with validation
Centralize forced_login_method override into a shared helper in codex-env.ts with validation (only 'api' and 'chatgpt' accepted, invalid values fall back to 'api'). Applied to all 4 Codex spawn sites: - clawsweeper.ts runCodex() - clawsweeper.ts runCodexAssist() - commit-sweeper.ts - pr-close-coverage-proof.ts Tests: default api, chatgpt override, invalid rejection, config string format.
1 parent 74f63a0 commit dae6f09

5 files changed

Lines changed: 72 additions & 8 deletions

File tree

‎src/clawsweeper.ts‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import {
2424
repositoryProfileForSlug,
2525
type RepositoryProfile,
2626
} from "./repository-profiles.js";
27-
import { codexEnv } from "./codex-env.js";
27+
import { codexEnv, codexLoginMethodConfig } from "./codex-env.js";
2828
import {
2929
ghRetryKind,
3030
ghRetryWaitMs,
@@ -66,7 +66,7 @@ import {
6666
} from "./clawsweeper-args.js";
6767
import { escapeRegExp, safeOutputTail, trimMiddle, truncateText } from "./clawsweeper-text.js";
6868

69-
export { codexEnv } from "./codex-env.js";
69+
export { codexEnv, resolveCodexLoginMethod, codexLoginMethodConfig } from "./codex-env.js";
7070
export { parseGhJson, parseGhJsonLines } from "./github-json.js";
7171
export { itemNumbersArg } from "./clawsweeper-args.js";
7272
export { safeOutputTail } from "./clawsweeper-text.js";
@@ -6174,7 +6174,7 @@ function runCodex(options: {
61746174
}
61756175
const codexConfig = [
61766176
`model_reasoning_effort="${options.reasoningEffort}"`,
6177-
'forced_login_method="api"',
6177+
codexLoginMethodConfig(),
61786178
'approval_policy="never"',
61796179
];
61806180
if (options.serviceTier) codexConfig.splice(1, 0, `service_tier="${options.serviceTier}"`);
@@ -6434,7 +6434,7 @@ function runCodexAssist(options: {
64346434
writeFileSync(promptPath, prompt, "utf8");
64356435
const codexConfig = [
64366436
`model_reasoning_effort="${options.reasoningEffort}"`,
6437-
'forced_login_method="api"',
6437+
codexLoginMethodConfig(),
64386438
'approval_policy="never"',
64396439
];
64406440
const result = spawnSync(

‎src/codex-env.ts‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
const VALID_LOGIN_METHODS = new Set(["api", "chatgpt"]);
2+
3+
export function resolveCodexLoginMethod(): string {
4+
const value = process.env.CLAWSWEEPER_CODEX_LOGIN_METHOD?.trim().toLowerCase();
5+
if (value && VALID_LOGIN_METHODS.has(value)) {
6+
return value;
7+
}
8+
return "api";
9+
}
10+
11+
export function codexLoginMethodConfig(): string {
12+
return `forced_login_method="${resolveCodexLoginMethod()}"`;
13+
}
14+
115
export type CodexEnvOptions = {
216
ghToken?: string | undefined;
317
};

‎src/commit-sweeper.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
import { publishCheckFromReport, splitFrontMatter } from "./commit-checks.js";
1212
import { argBool, argNumber, argString, parseArgs, type Args } from "./clawsweeper-args.js";
1313
import { safeOutputTail } from "./clawsweeper-text.js";
14-
import { codexEnv } from "./codex-env.js";
14+
import { codexEnv, codexLoginMethodConfig } from "./codex-env.js";
1515
import { runText } from "./command.js";
1616
import { ghRetryKind, ghRetryWaitMs } from "./github-retry.js";
1717
import { DEFAULT_TARGET_REPO, repositoryProfileFor } from "./repository-profiles.js";
@@ -296,7 +296,7 @@ function runCodex(options: {
296296
);
297297
const codexConfig = [
298298
`model_reasoning_effort="${options.reasoningEffort}"`,
299-
'forced_login_method="api"',
299+
codexLoginMethodConfig(),
300300
'approval_policy="never"',
301301
];
302302
if (options.serviceTier) codexConfig.splice(1, 0, `service_tier="${options.serviceTier}"`);

‎src/pr-close-coverage-proof.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { spawnSync } from "node:child_process";
22
import { existsSync, mkdirSync, readFileSync, unlinkSync, writeFileSync } from "node:fs";
33
import { join } from "node:path";
4-
import { codexEnv } from "./codex-env.js";
4+
import { codexEnv, codexLoginMethodConfig } from "./codex-env.js";
55
import { safeOutputTail, truncateText } from "./clawsweeper-text.js";
66

77
export type PrCloseCoverageProofModelDecision = "covered" | "keep_open";
@@ -252,7 +252,7 @@ export function runPrCloseCoverageProofModel(options: {
252252
if (existsSync(outputPath)) unlinkSync(outputPath);
253253
const codexConfig = [
254254
`model_reasoning_effort="${options.runtime.reasoningEffort}"`,
255-
'forced_login_method="api"',
255+
codexLoginMethodConfig(),
256256
'approval_policy="never"',
257257
];
258258
if (options.runtime.serviceTier) {

‎test/clawsweeper.test.ts‎

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ import {
3434
referencingMergedPullRequestsForIssueForTest,
3535
configSurfaceChangeFromPullFilesForTest,
3636
codexEnv,
37+
resolveCodexLoginMethod,
38+
codexLoginMethodConfig,
3739
dashboardClosedAt,
3840
extractLatestClawSweeperReviewForTest,
3941
filterReviewContextCommentsForTest,
@@ -16727,6 +16729,54 @@ test("codex subprocess env can expose an explicit read-only GitHub token", () =>
1672716729
}
1672816730
});
1672916731

16732+
test("resolveCodexLoginMethod defaults to api", () => {
16733+
const original = process.env.CLAWSWEEPER_CODEX_LOGIN_METHOD;
16734+
try {
16735+
delete process.env.CLAWSWEEPER_CODEX_LOGIN_METHOD;
16736+
assert.equal(resolveCodexLoginMethod(), "api");
16737+
} finally {
16738+
if (original === undefined) delete process.env.CLAWSWEEPER_CODEX_LOGIN_METHOD;
16739+
else process.env.CLAWSWEEPER_CODEX_LOGIN_METHOD = original;
16740+
}
16741+
});
16742+
16743+
test("resolveCodexLoginMethod accepts chatgpt", () => {
16744+
const original = process.env.CLAWSWEEPER_CODEX_LOGIN_METHOD;
16745+
try {
16746+
process.env.CLAWSWEEPER_CODEX_LOGIN_METHOD = "chatgpt";
16747+
assert.equal(resolveCodexLoginMethod(), "chatgpt");
16748+
} finally {
16749+
if (original === undefined) delete process.env.CLAWSWEEPER_CODEX_LOGIN_METHOD;
16750+
else process.env.CLAWSWEEPER_CODEX_LOGIN_METHOD = original;
16751+
}
16752+
});
16753+
16754+
test("resolveCodexLoginMethod rejects invalid values", () => {
16755+
const original = process.env.CLAWSWEEPER_CODEX_LOGIN_METHOD;
16756+
try {
16757+
process.env.CLAWSWEEPER_CODEX_LOGIN_METHOD = "oauth-browser";
16758+
assert.equal(resolveCodexLoginMethod(), "api");
16759+
process.env.CLAWSWEEPER_CODEX_LOGIN_METHOD = "";
16760+
assert.equal(resolveCodexLoginMethod(), "api");
16761+
} finally {
16762+
if (original === undefined) delete process.env.CLAWSWEEPER_CODEX_LOGIN_METHOD;
16763+
else process.env.CLAWSWEEPER_CODEX_LOGIN_METHOD = original;
16764+
}
16765+
});
16766+
16767+
test("codexLoginMethodConfig produces valid Codex config string", () => {
16768+
const original = process.env.CLAWSWEEPER_CODEX_LOGIN_METHOD;
16769+
try {
16770+
delete process.env.CLAWSWEEPER_CODEX_LOGIN_METHOD;
16771+
assert.equal(codexLoginMethodConfig(), 'forced_login_method="api"');
16772+
process.env.CLAWSWEEPER_CODEX_LOGIN_METHOD = "chatgpt";
16773+
assert.equal(codexLoginMethodConfig(), 'forced_login_method="chatgpt"');
16774+
} finally {
16775+
if (original === undefined) delete process.env.CLAWSWEEPER_CODEX_LOGIN_METHOD;
16776+
else process.env.CLAWSWEEPER_CODEX_LOGIN_METHOD = original;
16777+
}
16778+
});
16779+
1673016780
test("related title search terms keep issue-specific words", () => {
1673116781
assert.deepEqual(
1673216782
relatedTitleSearchTerms(

0 commit comments

Comments
 (0)