Skip to content

Commit 67c914c

Browse files
committed
fix(guardrails): CJS大文字拡張子の自己参照を防止
JS shimの選択は大文字小文字を区別しない一方、自己参照用環境変数の除去だけが小文字限定だった。判定を揃え、実entrypointで.CJSへ環境変数が継承されないことを確認する。 Follow-up: 4a953b1 (#367) Refs: #366 Agent-Lane: codex
1 parent 4a953b1 commit 67c914c

2 files changed

Lines changed: 3 additions & 3 deletions

File tree

‎packages/guardrails/bin/opencode-guardrails‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ extraPlugins()
129129
const target = bin()
130130
const childEnv = { ...process.env }
131131
// the @opencode/cli `opencode.cjs` shim reads OPENCODE_BIN_PATH as *its* target; handing it its own path loops forever
132-
if (target.endsWith(".cjs")) delete childEnv.OPENCODE_BIN_PATH
132+
if (/\.cjs$/i.test(target)) delete childEnv.OPENCODE_BIN_PATH
133133

134134
const [command, ...args] = cliCommand(
135135
target,

‎packages/guardrails/profile/src/launcher-bin.test.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const bin = fileURLToPath(new URL("../../bin/opencode-guardrails", import.meta.u
99
test("explicit JavaScript CLI paths run through Node without executable permission", () => {
1010
const dir = mkdtempSync(path.join(tmpdir(), "guardrails-launcher-"))
1111
try {
12-
for (const extension of ["js", "mjs", "cjs"]) {
12+
for (const extension of ["js", "mjs", "cjs", "CJS"]) {
1313
const target = path.join(dir, `cli.${extension}`)
1414
writeFileSync(
1515
target,
@@ -23,7 +23,7 @@ test("explicit JavaScript CLI paths run through Node without executable permissi
2323
expect(run.exitCode, new TextDecoder().decode(run.stderr)).toBe(0)
2424
expect(JSON.parse(new TextDecoder().decode(run.stdout))).toEqual({
2525
args: ["models", "--standalone"],
26-
...(extension === "cjs" ? {} : { binary: target }),
26+
...(extension.toLowerCase() === "cjs" ? {} : { binary: target }),
2727
})
2828
}
2929
} finally {

0 commit comments

Comments
 (0)