Skip to content

Commit 7dbf9b0

Browse files
committed
fix(wrapper): make windows shell guards opt-in
1 parent b9c9273 commit 7dbf9b0

2 files changed

Lines changed: 57 additions & 2 deletions

File tree

scripts/codex.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ const POWERSHELL_PROFILE_MARKER_END = "# <<< codex-multi-auth shell guard <<<";
197197

198198
function shouldInstallWindowsBatchShimGuard() {
199199
if (process.platform !== "win32") return false;
200-
const override = (process.env.CODEX_MULTI_AUTH_WINDOWS_BATCH_SHIM_GUARD ?? "1").trim();
200+
const override = (process.env.CODEX_MULTI_AUTH_WINDOWS_BATCH_SHIM_GUARD ?? "0").trim();
201201
return override !== "0";
202202
}
203203

@@ -370,7 +370,7 @@ function ensureWindowsShellShim(filePath, desiredContent, options = {}) {
370370

371371
function shouldInstallPowerShellProfileGuard() {
372372
if (process.platform !== "win32") return false;
373-
const override = (process.env.CODEX_MULTI_AUTH_PWSH_PROFILE_GUARD ?? "1").trim();
373+
const override = (process.env.CODEX_MULTI_AUTH_PWSH_PROFILE_GUARD ?? "0").trim();
374374
return override !== "0";
375375
}
376376

test/codex-bin-wrapper.test.ts

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,7 @@ describe("codex bin wrapper", () => {
296296
const result = runWrapper(fixtureRoot, ["--version"], {
297297
CODEX_MULTI_AUTH_REAL_CODEX_BIN: fakeBin,
298298
CODEX_MULTI_AUTH_WINDOWS_BATCH_SHIM_GUARD: "1",
299+
CODEX_MULTI_AUTH_PWSH_PROFILE_GUARD: "1",
299300
PATH: `${shimDir}${delimiter}${process.env.PATH ?? ""}`,
300301
USERPROFILE: fixtureRoot,
301302
HOME: fixtureRoot,
@@ -335,6 +336,59 @@ describe("codex bin wrapper", () => {
335336
},
336337
);
337338

339+
it.skipIf(process.platform !== "win32")(
340+
"does not install Windows shell guards unless explicitly enabled",
341+
() => {
342+
const fixtureRoot = createWrapperFixture();
343+
const fakeBin = createFakeCodexBin(fixtureRoot);
344+
const shimDir = join(fixtureRoot, "shim-bin");
345+
mkdirSync(shimDir, { recursive: true });
346+
writeFileSync(
347+
join(shimDir, "codex-multi-auth.cmd"),
348+
"@ECHO OFF\r\nREM fixture codex-multi-auth shim\r\n",
349+
"utf8",
350+
);
351+
writeFileSync(
352+
join(shimDir, "codex.cmd"),
353+
'@ECHO OFF\r\necho "%dp0%\\node_modules\\@openai\\codex\\bin\\codex.js"\r\n',
354+
"utf8",
355+
);
356+
writeFileSync(
357+
join(shimDir, "codex.ps1"),
358+
'Write-Output "$basedir/node_modules/@openai/codex/bin/codex.js"' +
359+
"\r\n",
360+
"utf8",
361+
);
362+
363+
const result = runWrapper(fixtureRoot, ["--version"], {
364+
CODEX_MULTI_AUTH_REAL_CODEX_BIN: fakeBin,
365+
PATH: `${shimDir}${delimiter}${process.env.PATH ?? ""}`,
366+
USERPROFILE: fixtureRoot,
367+
HOME: fixtureRoot,
368+
});
369+
expect(result.status).toBe(0);
370+
371+
expect(() => readFileSync(join(shimDir, "codex.bat"), "utf8")).toThrow();
372+
expect(readFileSync(join(shimDir, "codex.cmd"), "utf8")).toContain(
373+
"node_modules\\@openai\\codex\\bin\\codex.js",
374+
);
375+
expect(readFileSync(join(shimDir, "codex.ps1"), "utf8")).toContain(
376+
"node_modules/@openai/codex/bin/codex.js",
377+
);
378+
expect(() =>
379+
readFileSync(
380+
join(
381+
fixtureRoot,
382+
"Documents",
383+
"PowerShell",
384+
"Microsoft.PowerShell_profile.ps1",
385+
),
386+
"utf8",
387+
),
388+
).toThrow();
389+
},
390+
);
391+
338392
it.skipIf(process.platform !== "win32")(
339393
"prefers invocation-derived shim directory over PATH-decoy shim entries",
340394
() => {
@@ -374,6 +428,7 @@ describe("codex bin wrapper", () => {
374428
const scriptPath = join(scriptDir, "codex.js");
375429
const result = runWrapperScript(scriptPath, ["--version"], {
376430
CODEX_MULTI_AUTH_REAL_CODEX_BIN: fakeBin,
431+
CODEX_MULTI_AUTH_WINDOWS_BATCH_SHIM_GUARD: "1",
377432
PATH: `${decoyShimDir}${delimiter}${globalShimDir}${delimiter}${process.env.PATH ?? ""}`,
378433
USERPROFILE: fixtureRoot,
379434
HOME: fixtureRoot,

0 commit comments

Comments
 (0)