Skip to content

Commit 7cc7d1b

Browse files
committed
test(guardrails): ACL環境の欠落要因を分離する
Turbo strictでのみACL cmdletが停止するため、loose対照とPSModulePath・LOCALAPPDATA各単独/両方の復元を比較する。既知2変数の値はowner-onlyの一時ファイル経由で渡し、ログは存在有無と結果だけに限定して診断後に削除する。 productionと既存full unitのstrict設定・5秒上限・ACL制約は変更しない。診断結果を回収した後は一時コードを撤去する。 Refs: #366 Agent-Lane: codex
1 parent a801770 commit 7cc7d1b

3 files changed

Lines changed: 87 additions & 11 deletions

File tree

‎.github/workflows/test.yml‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,29 @@ 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: Prepare private ACL diagnostic snapshot
114+
id: acl-snapshot
115+
if: runner.os == 'Windows'
116+
continue-on-error: true
117+
shell: pwsh
118+
run: |
119+
$ErrorActionPreference = 'Stop'
120+
$path = Join-Path $env:RUNNER_TEMP 'opencode-acl-environment.json'
121+
New-Item -ItemType File -Path $path -Force | Out-Null
122+
$user = [System.Security.Principal.WindowsIdentity]::GetCurrent().User
123+
$acl = [System.Security.AccessControl.FileSecurity]::new()
124+
$acl.SetOwner($user)
125+
$acl.SetAccessRuleProtection($true, $false)
126+
$acl.AddAccessRule([System.Security.AccessControl.FileSystemAccessRule]::new($user, [System.Security.AccessControl.FileSystemRights]::FullControl, [System.Security.AccessControl.AccessControlType]::Allow))
127+
Set-Acl -LiteralPath $path -AclObject $acl
128+
129+
- name: Capture ACL diagnostic environment
130+
id: acl-environment
131+
if: runner.os == 'Windows' && steps.acl-snapshot.outcome == 'success'
132+
continue-on-error: true
133+
run: |
134+
node -e 'require("node:fs").writeFileSync(require("node:path").join(process.env.RUNNER_TEMP, "opencode-acl-environment.json"), JSON.stringify({PSModulePath: process.env.PSModulePath, LOCALAPPDATA: process.env.LOCALAPPDATA}), {flag:"r+"})'
135+
113136
- name: Diagnose ACL transport directly
114137
if: runner.os == 'Windows'
115138
continue-on-error: true
@@ -121,6 +144,21 @@ jobs:
121144
continue-on-error: true
122145
run: GITHUB_ACTIONS=false bun turbo test --filter=@opencode-ai/guardrails -- --test-name-pattern 'Windows ACL transport'
123146

147+
- name: Diagnose ACL transport with loose environment
148+
if: runner.os == 'Windows'
149+
continue-on-error: true
150+
run: GITHUB_ACTIONS=false bun turbo test --env-mode=loose --filter=@opencode-ai/guardrails -- --test-name-pattern 'Windows ACL transport'
151+
152+
- name: Diagnose ACL environment factors under strict mode
153+
if: runner.os == 'Windows' && steps.acl-environment.outcome == 'success'
154+
continue-on-error: true
155+
run: GITHUB_ACTIONS=false bun turbo test --filter=@opencode-ai/guardrails -- bin/windows-acl-environment.test.ts --test-name-pattern 'Windows ACL environment factor'
156+
157+
- name: Remove private ACL diagnostic snapshot
158+
if: always() && runner.os == 'Windows'
159+
shell: pwsh
160+
run: Remove-Item -LiteralPath (Join-Path $env:RUNNER_TEMP 'opencode-acl-environment.json') -Force -ErrorAction SilentlyContinue
161+
124162
- name: Test Effect simplification rules
125163
if: runner.os == 'Linux'
126164
run: bun run test:effect-simplification-rules
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Temporary factor experiment, outside the normal production test directories.
2+
import { expect, test } from "bun:test"
3+
import { diagnose } from "./windows-acl-transport.mjs"
4+
5+
for (const restore of ["PSModulePath", "LOCALAPPDATA", "both"]) {
6+
for (const transport of ["bun", "node24"]) {
7+
for (const stage of ["Set-Acl", "Get-Acl"]) {
8+
test.skipIf(process.platform !== "win32")(
9+
"Windows ACL environment factor " + restore + " " + transport + " " + stage,
10+
() => {
11+
const result = diagnose(stage, transport, restore)
12+
console.log("ACL_ENVIRONMENT " + JSON.stringify({ transport, ...result }))
13+
expect(result.errorCode).toBeUndefined()
14+
expect(result.status).toBe(0)
15+
},
16+
)
17+
}
18+
}
19+
}

‎packages/guardrails/bin/windows-acl-transport.mjs‎

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,39 @@ const sources = {
1717
)?.[1],
1818
}
1919

20-
function presence() {
21-
const names = new Set(Object.keys(process.env).map((key) => key.toUpperCase()))
20+
function presence(env = process.env) {
21+
const names = new Set(Object.keys(env).map((key) => key.toUpperCase()))
2222
return {
2323
...Object.fromEntries(
2424
["SYSTEMROOT", "WINDIR", "PSMODULEPATH", "USERPROFILE", "TEMP", "TMP", "PATH", "LOCALAPPDATA", "COMSPEC"].map(
2525
(key) => [key, names.has(key)],
2626
),
2727
),
28-
SystemRootLookup: Boolean(process.env.SystemRoot),
29-
SYSTEMROOTLookup: Boolean(process.env.SYSTEMROOT),
28+
SystemRootLookup: Boolean(env.SystemRoot),
29+
SYSTEMROOTLookup: Boolean(env.SYSTEMROOT),
3030
}
3131
}
3232

33-
function probe(stage) {
33+
function probe(stage, restore = "none") {
3434
const script = sources[stage]
3535
if (!script) throw new Error("Unknown ACL diagnostic stage")
36+
const choices = {
37+
none: [],
38+
PSModulePath: ["PSModulePath"],
39+
LOCALAPPDATA: ["LOCALAPPDATA"],
40+
both: ["PSModulePath", "LOCALAPPDATA"],
41+
}
42+
if (!Object.hasOwn(choices, restore)) throw new Error("Unknown ACL environment factor")
43+
const env = { ...process.env }
44+
if (restore !== "none") {
45+
const snapshot = JSON.parse(
46+
readFileSync(path.join(process.env.RUNNER_TEMP, "opencode-acl-environment.json"), "utf8"),
47+
)
48+
for (const key of choices[restore]) {
49+
if (typeof snapshot[key] !== "string" || !snapshot[key]) throw new Error("ACL environment factor unavailable")
50+
env[key] = snapshot[key]
51+
}
52+
}
3653
const dir = mkdtempSync(path.join(tmpdir(), "opencode-acl-transport-"))
3754
const file = path.join(dir, "fixture [key]'s.key")
3855
writeFileSync(file, "diagnostic-placeholder\n")
@@ -43,7 +60,7 @@ function probe(stage) {
4360
["-NoLogo", "-NoProfile", "-NonInteractive", "-Command", script],
4461
{
4562
env: {
46-
...process.env,
63+
...env,
4764
OPENCODE_COR_LOCAL_TEST_PATH: file,
4865
OPENCODE_COR_LOCAL_TEST_PUBLIC: "0",
4966
OPENCODE_COR_LOCAL_ACL_PATH: file,
@@ -59,7 +76,8 @@ function probe(stage) {
5976
return {
6077
stage,
6178
runtime: process.versions.bun ? `Bun ${process.versions.bun}` : `Node ${process.versions.node}`,
62-
envPresence: presence(),
79+
restore,
80+
envPresence: presence(env),
6381
scriptSha256: createHash("sha256").update(script).digest("hex"),
6482
status: result.status,
6583
signal: result.signal,
@@ -73,9 +91,9 @@ function probe(stage) {
7391
}
7492
}
7593

76-
export function diagnose(stage, transport) {
77-
if (transport === "bun") return probe(stage)
78-
const result = spawnSync("node", [fileURLToPath(import.meta.url), stage], {
94+
export function diagnose(stage, transport, restore = "none") {
95+
if (transport === "bun") return probe(stage, restore)
96+
const result = spawnSync("node", [fileURLToPath(import.meta.url), stage, restore], {
7997
env: process.env,
8098
encoding: "utf8",
8199
stdio: ["ignore", "pipe", "pipe"],
@@ -88,6 +106,7 @@ export function diagnose(stage, transport) {
88106
return {
89107
stage,
90108
runtime: "Node child did not report",
109+
restore,
91110
envPresence: presence(),
92111
status: result.status,
93112
signal: result.signal,
@@ -100,5 +119,5 @@ export function diagnose(stage, transport) {
100119
if (process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
101120
if (process.platform !== "win32" || process.versions.node.split(".")[0] !== "24")
102121
throw new Error("ACL diagnostic child requires Windows Node 24")
103-
console.log(JSON.stringify(probe(process.argv[2])))
122+
console.log(JSON.stringify(probe(process.argv[2], process.argv[3])))
104123
}

0 commit comments

Comments
 (0)