Skip to content

test(guardrails): wait for the gate's log row, and skip the file mode check on Windows - #82

Open
zereight wants to merge 1 commit into
mainfrom
fix/guardrail-log-record-before-reply
Open

zereight wants to merge 1 commit into
mainfrom
fix/guardrail-log-record-before-reply

Conversation

@zereight

@zereight zereight commented Dec 2, 2026

Copy link
Copy Markdown
Owner

What changed

Two test lines from #80, which fail on the CI runners:

  • server/mcp-gate.test.ts:445 now waits for the second log row with expect.poll instead of reading the file once.
  • server/tool-guardrail-log.test.ts:28 checks the 0o600 file mode only off Windows, like the other tests that check a mode (server/attachments.test.ts:171, server/admin-activity.test.ts:192).

No product code changes. The branch name says "record before reply"; that was the first idea, and it was dropped (see Why).

Why

Since #79/#80 were merged, main run 46787163030 (b5b7b4b) fails two files that passed before:

test runners error
mcp-gate.test.ts › lets a log-mode rule's call through … ubuntu shard 3, windows shard 2 expected [ { …(6) } ] to match object [ { blockedBy: null }, …(1) ]: one row where two were expected
tool-guardrail-log.test.ts › appends one row per observed rule … windows shard 2 expected 438 to be 384: the file reads 0o666 on Windows

mcp-gate. For a blocked call, the gate answers first and writes the row after (server/mcp-gate.ts:360-362). That order is deliberate (#80: "The deny is printed before any row is written"): the row is built outside the write's try (server/tool-guardrail-log.ts:52-66, including the secret masking), so a throw there must never stop the deny. The test read the file as soon as the answer arrived. The gate is another process, so on a slow runner the test can read before the row is written. The product behaves as designed; the test assumed an order the gate does not promise. Writing the row first would make the test pass by weakening that guarantee, so the test waits for the row instead.

tool-guardrail-log. Windows has no POSIX modes; mode: 0o600 cannot hold there.

How it was verified

Branch from main 8c67e9d, macOS, Node 24.22.1 (the CI version).

To make the CI race happen every time locally without touching source, a preload delays only writes to paths containing guardrail-log by 200 ms (fs.appendFileSync wrapped, then syncBuiltinESMExports()), passed as NODE_OPTIONS=--import=<preload>. The gate child inherits process.env (server/mcp-gate.test.ts:91), so the delay applies inside the gate.

Before shows the CI assertion with the delayed write; after shows the test passing with the same delay.

check Before (main 8c67e9d) After (this branch)
vitest run server/mcp-gate.test.ts -t "log-mode" passes (the race does not happen on this Mac) passes
same, with the 200 ms write delay FAIL … expected [ { …(6) } ] to match object [ { blockedBy: null }, …(1) ], the CI error Tests 1 passed
vitest run server/mcp-gate.test.ts server/tool-guardrail-log.test.ts, with and without the delay Test Files 2 passed (2), Tests 49 passed (49) both ways

oxlint on both files exits 0.

Not covered

Checklist

  • pnpm typecheck and pnpm test pass locally: not run in full; the two touched test files pass.
  • Server behavior changes come with tests: no server change
  • No dist-server/ edits
  • macOS-only code is platform-gated: none added
  • No secrets in logs, responses, events, or argv

… check on Windows

The MCP gate answers a blocked call before it writes the log row, on purpose (#80): the row is built outside the
write's try, so a throw there must not stop the deny. The test read the file as soon as the answer arrived and, on
the CI runners, read it before the row was written. It now polls for the row.

Windows has no POSIX file modes: the log file reads 0o666 there, so the 0o600 check runs only off Windows, as in the
other tests that check a mode.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant