Skip to content

fix(gate): fail the unit gate closed, and cache only what it can prove (#150) - #179

Merged
nplez1 merged 2 commits into
nplez1/mainfrom
nplez1/gate-unit-verdict
Oct 24, 2026
Merged

nplez1 merged 2 commits into
nplez1/mainfrom
nplez1/gate-unit-verdict

Conversation

@nplez1

@nplez1 nplez1 commented Oct 24, 2026

Copy link
Copy Markdown
Owner

Summary

Gate 1 of this fork's PR process is node local/gate-unit.mjs: one full unit run, each unallowlisted
failure re-run in isolation, exit 0 only when nothing outside local/unit-known-red.json fails.
local/open-pr.mjs refuses a PR without a cached PASS from it. Issue #150 listed five ways that
verdict could be wrong; three of them had already landed by the time this branch was cut (#160 fixed
the linked-worktree cache directory, #177 the dirty-verdict refusal and the shared cache module, #178
the judgment module, its tests and the missing closeSync import). This branch closes the rest, and it
is rebased onto 204984546d so it builds on that shape instead of against it.

Vitest's exit status is read. runSuite returned it and evaluate only ever consumed elapsedMs,
so a non-zero exit that the report did not explain was green. The rule is now the CI twin's
(check-unit-shard-verdict.mjs): a non-zero exit fails the gate only when neither the report nor the
log explains it. With it, the declared-vs-read unhandled count is !== rather than > (a log yielding
more headlines than Vitest declared is a moved log shape too), and a step that could not be spawned
names the step instead of reading as failed.

What is recorded, and what is reused, is a decision with a reason. The cached verdict records
gateInputs — a fingerprint over GATE_INPUT_PATHS (this gate, its coupling module, the shared cache
module, the shard-verdict parser, config/.bun-version) plus the installed node and bun — and both
readers compare it, because the machine-bound sqlite-binding and host-toolchain classes move with a
bun upgrade that HEAD never sees. --no-cache forces a re-run and still records it (the only way a
stale environmental FAIL can be replaced) without parsing the cache, so it stays the way out of a
damaged file; --allow-dirty neither reads the cache nor records, because both would answer about the
tree rather than HEAD; forwarded selectors record nothing. Before writing, HEAD and the tree are
re-read — the suite takes twenty minutes, and a commit made in that window would otherwise be recorded
as a verdict on the revision it replaced.

A forwarded selector cannot be quoted as gate 1. -- <vitest args> still runs, but the shared
summary line carries partial: -- <args> and NOT a gate-1 verdict: forwarded selectors ran a subset of the suite.

A flaky pass is waived only when nothing coupled to the test changed. #178 made the isolated re-run
per test, but the waiver still asked only whether the test file was in the diff, so a branch that
changed src/x.ts and broke x.test.ts one run in ten waived it as "not ours". The new
local/gate-flake-coupling.mjs couples a test to itself, its sibling module, its imports (one level,
relative or @renderer//@), and the whole harness: SHARED_TEST_INPUTS plus whatever
config/vitest.config.ts and config/scripts/run-vitest.mjs import, including the two inputs a parser
cannot see (config/dark-build-switches.cjs, loaded through createRequire(…), and
src/packages/process-host/, the runner's bare workspace import). A per-test row that passes in
isolation and is still refused says why in the summary instead of reading as a plain UNEXPECTED
failure.

local/gate-flake-coupling.mjs is new (the coupling rule moved out of gate-unit.mjs to stay under
oxlint's 600-line budget, and two helpers each moved to gate-verdict-cache.mjs and
unit-gate-judgement.mjs for the same reason). tests/tools/gate-unit.test.mjs is new;
tests/tools/open-pr.test.mjs gains the gate-inputs refusal and a cross-reader fingerprint check.

Fixes #150

Verification

Gate Command Result
Focused suites node config/scripts/run-vitest.mjs run --config config/vitest.config.ts tests/tools/gate-unit.test.mjs tests/tools/open-pr.test.mjs tests/tools/unit-gate.test.mjs PASS — 3 files, 65 tests (24 new in gate-unit.test.mjs, 2 new in open-pr.test.mjs; #178's unit-gate.test.mjs still green)
Changed-code quality pnpm run check:code-quality:changed since 204984546d PASS — 0 new findings across 7 changed code files (oxlint, type-aware, casting, React Doctor, design system, SAFETY)
Typecheck ORCA_QUEUE_LOCKED=1 orca-queue -- /opt/homebrew/bin/pnpm tc PASS on 3c0ad4e858 — no type errors in 18,074 + 3,231 + 34 + 16,084 files. Not re-run on the final revision: the queued re-run sat behind other worktrees' full gate-unit runs for 70+ minutes and never started (see below). Every file this diff touches is .mjs under local/ or tests/tools/, outside every tsconfig include, so the typechecked surface of the branch is exactly the base's; the re-run is confirmation, not a different verdict.
Full unit suite (gate 1) not run — waived, see below —

Why gate 1 is waived here. The full suite has a known runtime trap on this machine, and the shared
orca-queue lock was held by other worktrees' full gate-unit runs for essentially the whole
verification window (a 34-minute run was still going when this PR opened, with three jobs ahead of
mine). Recorded as not-run rather than claimed. Every changed file is local/ tooling or its tests;
nothing touches product code, the allowlist or the red set. Run orca-queue node local/gate-unit.mjs
on 4b7c756dcf before merging if you want gate 1's own PASS on record.

Two environment problems found while verifying, worth fixing separately. One orphaned
post-sync.mjs held the queue lock for 32 minutes at 0.85 s of CPU. And orca-queue does not export
ORCA_QUEUE_LOCKED to the command it runs, so the pnpm shim re-queues inside a run that already
holds the lock and deadlocks against its own parent — reproduced four times, by me and by other
worktrees. Passing ORCA_QUEUE_LOCKED=1 makes the shim exec real pnpm while the outer queue still
serialises, which is how pnpm tc ran. The focused suites were run directly through
config/scripts/run-vitest.mjs — the same runner pnpm test uses — because a queued pnpm test
waited 25 minutes for the lock and hit the tool deadline.

Review

Reviewed by Opus 5.5, high (claude/opus, tool-enabled), R1–R4 over the branch's own diff: every round's blocking findings fixed, round 4's SHOULD-FIX fixed and pinned by a test, no fifth round (AGENTS.md caps the review at three rounds without your approval).

What each round changed:

  • R1 — the waiver ignored the harness every test runs under. A branch could change the pool, a
    timeout or a setup file and still waive its own load-only flake. sharedHarnessPaths() now derives
    the harness from config/vitest.config.ts and run-vitest.mjs, plus the two inputs a parser cannot
    see.
  • R1 — the docs overstated item 2. A run that writes no report already failed on the base. Corrected
    to what was actually unread (the exit status), with the residual limit stated: a partial report with
    failures still explains a non-zero exit.
  • R1/R2 — a non-complete FAIL could be cached, and --no-cache could not replace it. Now an
    incomplete run is never recorded and --no-cache records its result.
  • R2 — --allow-dirty could reuse a clean cached verdict, answering about a tree the cache never
    saw. The cache is not read in that mode at all.
  • R2/R3 — HEAD was not re-read after the run, so a mid-run commit could be recorded as the previous
    revision's verdict. HEAD and the tree are re-checked before writing.
  • R4 (after the test(unit-gate): name every known red and run what upstream's unit lane runs #178 rebase) — a refused flake was reported with no reason, and the matched field
    was dead on the rows that kept it. The refusal now travels with the failure and prints as
    FLAKY in isolation, but <file> is in this branch diff.
  • R4 MINORs: the record refusal duplicated the blocked: line verbatim, and nothing tested that
    open-pr and gate-unit fingerprint the same bytes — now a test that reads the inputs from the
    commit, the same shape as the allowlist-symmetry test fix(fork): make the process surface report what it reads #177 recorded the bug for.
  • R1 NITs addressed: the inputs fingerprint covers the coupling module, the toolchain versions are
    read from node and bun on PATH, the descriptor test cleans up its temp dir, and the cache-dir
    probe became an assertion instead of writing into the real gitdir.

Note for review

#150)

Vitest's exit status was returned by runSuite and never read, so a non-zero exit that the
report did not explain was green. The rule is now the CI twin's (check-unit-shard-verdict):
a non-zero exit fails the gate only when neither the report nor the log explains it. The
declared-vs-read unhandled count drops '>' for '!==' for the same reason, and a step that
could not be spawned names the step instead of reading as failed.

A cached verdict now records the gate inputs it was computed against — GATE_INPUT_PATHS
plus the installed node and bun — and both readers compare them, because the machine-bound
sqlite-binding and host-toolchain classes move with a bun upgrade that HEAD never sees.
What may be reused or recorded is a decision with a reason: --no-cache forces a re-run and
still records it, --allow-dirty neither reuses nor records, forwarded selectors record
nothing, and HEAD and the tree are re-read before writing so a mid-run commit cannot become
the previous revision's verdict.

A forwarded selector's summary line now says it is not a gate-1 verdict, because it printed
the same shape as one.

The flake waiver asked only whether the test file was in the diff, so a branch that changed
src/x.ts and broke x.test.ts one run in ten waived it as 'not ours'. local/gate-flake-coupling.mjs
couples a test to itself, its sibling module, its one level of imports and the harness
sharedHarnessPaths derives from the config and the runner; a per-test row that passes in
isolation but is still refused says why.
#150)

LOCAL-PATCHES keeps the evidence for the release-tooling patch series and the known-red
sets, so the gate repairs need an entry there: which of the issue's five items had already
landed (#160's linked-worktree cache directory, #177's dirty-verdict refusal and shared
cache module, #178's judgement module and its tests), what the new fail-closed and cache
rules are, why the verdict records its gate inputs, and the coupling rule's limits.

BRANCHES gets the branch entry: why it exists, its shape, its target, and its verification
state.
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.

[Infra]: gate-unit.mjs can report a PASS it never earned, and cannot run at all in a linked worktree

1 participant