Skip to content

Commit a801770

Browse files
committed
test(guardrails): ACL起動を同一条件で比較する
単独診断と実テストの差を切り分けるため、同じPowerShell入力を直接のBun testとTurbo経由で比較する。各入力はBun直接とNode24子プロセスでも実行し、既知の環境変数は存在有無だけを記録する。 productionと既存の検証条件は変更しない。全起動は5秒で制限し、一時診断を撤去して根因の回帰検査へ置き換えるまでマージしない。 Refs: #366 Agent-Lane: codex
1 parent fc34e8f commit a801770

3 files changed

Lines changed: 129 additions & 0 deletions

File tree

‎.github/workflows/test.yml‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,17 @@ jobs:
110110
- name: Verify search tool prerequisites
111111
working-directory: packages/core
112112
run: bun run script/test.ts test/ripgrep.test.ts test/tool-search.test.ts
113+
- name: Diagnose ACL transport directly
114+
if: runner.os == 'Windows'
115+
continue-on-error: true
116+
working-directory: packages/guardrails
117+
run: bun test profile/src/windows-acl-transport.test.ts
118+
119+
- name: Diagnose ACL transport under Turbo
120+
if: runner.os == 'Windows'
121+
continue-on-error: true
122+
run: GITHUB_ACTIONS=false bun turbo test --filter=@opencode-ai/guardrails -- --test-name-pattern 'Windows ACL transport'
123+
113124
- name: Test Effect simplification rules
114125
if: runner.os == 'Linux'
115126
run: bun run test:effect-simplification-rules
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
// Temporary, key-free diagnosis for #366; never used by the production launcher.
2+
import { spawnSync } from "node:child_process"
3+
import { createHash } from "node:crypto"
4+
import { mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs"
5+
import { tmpdir } from "node:os"
6+
import path from "node:path"
7+
import { fileURLToPath } from "node:url"
8+
9+
const here = path.dirname(fileURLToPath(import.meta.url))
10+
const sources = {
11+
"exit 0": "exit 0",
12+
"Set-Acl": readFileSync(path.join(here, "../profile/src/cor-local-bin-defaults.test.ts"), "utf8").match(
13+
/const script = `([\s\S]*?)`/,
14+
)?.[1],
15+
"Get-Acl": readFileSync(path.join(here, "cor-local-env.js"), "utf8").match(
16+
/const WINDOWS_KEY_ACL = `([\s\S]*?)`/,
17+
)?.[1],
18+
}
19+
20+
function presence() {
21+
const names = new Set(Object.keys(process.env).map((key) => key.toUpperCase()))
22+
return {
23+
...Object.fromEntries(
24+
["SYSTEMROOT", "WINDIR", "PSMODULEPATH", "USERPROFILE", "TEMP", "TMP", "PATH", "LOCALAPPDATA", "COMSPEC"].map(
25+
(key) => [key, names.has(key)],
26+
),
27+
),
28+
SystemRootLookup: Boolean(process.env.SystemRoot),
29+
SYSTEMROOTLookup: Boolean(process.env.SYSTEMROOT),
30+
}
31+
}
32+
33+
function probe(stage) {
34+
const script = sources[stage]
35+
if (!script) throw new Error("Unknown ACL diagnostic stage")
36+
const dir = mkdtempSync(path.join(tmpdir(), "opencode-acl-transport-"))
37+
const file = path.join(dir, "fixture [key]'s.key")
38+
writeFileSync(file, "diagnostic-placeholder\n")
39+
const started = performance.now()
40+
try {
41+
const result = spawnSync(
42+
path.join(process.env.SystemRoot || "C:\\\\Windows", "System32", "WindowsPowerShell", "v1.0", "powershell.exe"),
43+
["-NoLogo", "-NoProfile", "-NonInteractive", "-Command", script],
44+
{
45+
env: {
46+
...process.env,
47+
OPENCODE_COR_LOCAL_TEST_PATH: file,
48+
OPENCODE_COR_LOCAL_TEST_PUBLIC: "0",
49+
OPENCODE_COR_LOCAL_ACL_PATH: file,
50+
},
51+
encoding: "utf8",
52+
stdio: ["ignore", "pipe", "pipe"],
53+
timeout: 5_000,
54+
maxBuffer: 65_536,
55+
windowsHide: true,
56+
shell: false,
57+
},
58+
)
59+
return {
60+
stage,
61+
runtime: process.versions.bun ? `Bun ${process.versions.bun}` : `Node ${process.versions.node}`,
62+
envPresence: presence(),
63+
scriptSha256: createHash("sha256").update(script).digest("hex"),
64+
status: result.status,
65+
signal: result.signal,
66+
errorCode: result.error?.code,
67+
elapsed: Math.round(performance.now() - started),
68+
stdoutBytes: result.stdout?.length || 0,
69+
stderrBytes: result.stderr?.length || 0,
70+
}
71+
} finally {
72+
rmSync(dir, { recursive: true, force: true })
73+
}
74+
}
75+
76+
export function diagnose(stage, transport) {
77+
if (transport === "bun") return probe(stage)
78+
const result = spawnSync("node", [fileURLToPath(import.meta.url), stage], {
79+
env: process.env,
80+
encoding: "utf8",
81+
stdio: ["ignore", "pipe", "pipe"],
82+
timeout: 5_000,
83+
maxBuffer: 65_536,
84+
windowsHide: true,
85+
shell: false,
86+
})
87+
if (result.status === 0 && !result.error) return JSON.parse(result.stdout)
88+
return {
89+
stage,
90+
runtime: "Node child did not report",
91+
envPresence: presence(),
92+
status: result.status,
93+
signal: result.signal,
94+
errorCode: result.error?.code,
95+
stdoutBytes: result.stdout?.length || 0,
96+
stderrBytes: result.stderr?.length || 0,
97+
}
98+
}
99+
100+
if (process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
101+
if (process.platform !== "win32" || process.versions.node.split(".")[0] !== "24")
102+
throw new Error("ACL diagnostic child requires Windows Node 24")
103+
console.log(JSON.stringify(probe(process.argv[2])))
104+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Temporary Windows-only transport diagnosis for #366; the real ACL tests remain unchanged.
2+
import { expect, test } from "bun:test"
3+
import { diagnose } from "../../bin/windows-acl-transport.mjs"
4+
5+
for (const transport of ["bun", "node24"]) {
6+
for (const stage of ["exit 0", "Set-Acl", "Get-Acl"]) {
7+
test.skipIf(process.platform !== "win32")(`Windows ACL transport ${transport} ${stage}`, () => {
8+
const result = diagnose(stage, transport)
9+
console.log(`ACL_TRANSPORT ${JSON.stringify({ transport, ...result })}`)
10+
expect(result.errorCode).toBeUndefined()
11+
expect(result.status).toBe(0)
12+
})
13+
}
14+
}

0 commit comments

Comments
 (0)