Skip to content

Commit 5b7b1c4

Browse files
committed
test(guardrails): WindowsのACL起動経路を診断
PR #367の実WindowsでACL fixture7件が5秒で終了しない。ACL判定を変える前に、同じ固定source scriptをBun既定stdin・Bun stdin無効・本番と同じNodeで比較する。検査対象は一時dummy fileのみで、実鍵や環境変数は出力しない。診断回収後にこの一時stepを撤去する。 Follow-up: 4a953b1 (#367) Refs: #366 Agent-Lane: codex
1 parent 67c914c commit 5b7b1c4

2 files changed

Lines changed: 85 additions & 0 deletions

File tree

‎.github/workflows/test.yml‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,9 @@ 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 Windows ACL subprocess transport
114+
if: runner.os == 'Windows'
115+
run: bun packages/guardrails/bin/windows-acl-diagnostic.mjs
113116

114117
- name: Test Effect simplification rules
115118
if: runner.os == 'Linux'
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
// Temporary, key-free CI diagnosis for Cor-Incorporated/opencode#366. No production settings are changed.
2+
import { spawnSync } from "node:child_process"
3+
import { mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs"
4+
import { tmpdir } from "node:os"
5+
import path from "node:path"
6+
import { fileURLToPath } from "node:url"
7+
import { privateWindowsKeyAcl } from "./cor-local-env.js"
8+
9+
if (process.platform !== "win32") {
10+
console.log("windows-acl-diagnostic: Windows runner required")
11+
process.exit(0)
12+
}
13+
14+
const here = path.dirname(fileURLToPath(import.meta.url))
15+
const fixture = readFileSync(path.join(here, "../profile/src/cor-local-bin-defaults.test.ts"), "utf8").match(
16+
/const script = `([\s\S]*?)`/,
17+
)?.[1]
18+
const probe = readFileSync(path.join(here, "cor-local-env.js"), "utf8").match(
19+
/const WINDOWS_KEY_ACL = `([\s\S]*?)`/,
20+
)?.[1]
21+
if (!fixture || !probe) throw new Error("ACL source script not found")
22+
const powershell = path.join(process.env.SystemRoot || "C:\\Windows", "System32/WindowsPowerShell/v1.0/powershell.exe")
23+
24+
function diagnose(label, ignoreStdin) {
25+
const directory = mkdtempSync(path.join(tmpdir(), "opencode-acl-diagnostic-"))
26+
const file = path.join(directory, "fixture [key]'s.key")
27+
writeFileSync(file, "diagnostic-placeholder\n")
28+
const env = {
29+
...process.env,
30+
OPENCODE_COR_LOCAL_TEST_PATH: file,
31+
OPENCODE_COR_LOCAL_TEST_PUBLIC: "0",
32+
OPENCODE_COR_LOCAL_ACL_PATH: file,
33+
}
34+
const run = (stage, script) => {
35+
const started = performance.now()
36+
const result = spawnSync(powershell, ["-NoLogo", "-NoProfile", "-NonInteractive", "-Command", script], {
37+
env,
38+
encoding: "utf8",
39+
timeout: 5_000,
40+
maxBuffer: 65_536,
41+
windowsHide: true,
42+
shell: false,
43+
...(ignoreStdin ? { stdio: ["ignore", "pipe", "pipe"] } : {}),
44+
})
45+
console.log(
46+
JSON.stringify({
47+
label,
48+
runtime: process.versions.bun ? `Bun ${process.versions.bun}` : `Node ${process.versions.node}`,
49+
stage,
50+
status: result.status,
51+
signal: result.signal,
52+
error: result.error?.code,
53+
elapsed: Math.round(performance.now() - started),
54+
stdout: result.stdout?.slice(0, 512),
55+
stderr: result.stderr?.slice(0, 512),
56+
...(stage === "Get-Acl" ? { privateAcl: privateWindowsKeyAcl(result) } : {}),
57+
}),
58+
)
59+
return result.status === 0 && !result.error
60+
}
61+
try {
62+
run("exit 0", "exit 0")
63+
if (run("Set-Acl", fixture)) run("Get-Acl", probe)
64+
} finally {
65+
rmSync(directory, { recursive: true, force: true })
66+
}
67+
}
68+
69+
if (process.argv[2] === "node") {
70+
diagnose("Node stdin ignore", true)
71+
process.exit(0)
72+
}
73+
diagnose("Bun stdin default", false)
74+
diagnose("Bun stdin ignore", true)
75+
const node = spawnSync("node", [fileURLToPath(import.meta.url), "node"], {
76+
encoding: "utf8",
77+
stdio: ["ignore", "pipe", "pipe"],
78+
timeout: 20_000,
79+
})
80+
process.stdout.write(node.stdout || "")
81+
process.stderr.write(node.stderr || "")
82+
if (node.error || node.status !== 0) throw new Error(`Node ACL diagnostic failed: ${node.error?.code || node.status}`)

0 commit comments

Comments
 (0)