Skip to content

fix(test): clear the allowlist rot and the two false red claims (#224) - #247

Merged
nplez1 merged 5 commits into
nplez1/mainfrom
nplez1/audit-224
Oct 29, 2026
Merged

nplez1 merged 5 commits into
nplez1/mainfrom
nplez1/audit-224

Conversation

@nplez1

@nplez1 nplez1 commented Oct 29, 2026

Copy link
Copy Markdown
Owner

Fixes #224.

Three findings from the 2026-10-29 audit, all in the fork's allowlists — the files that are themselves the assertion — plus the one test change the audit asked for so an allowlist can shrink.

T1 — seven Bun-masked SQLite tests, two of them still masked

The audit said all seven allowlisted tests ran under Bun because findSqliteRuntimeTests misses their indirect node:sqlite imports, and that session-search-indexer.test.ts imports it directly. Re-measured on 6d7cb785047, the split is two files still unrouted, three already green:

file before now
tests/e2e/helpers/persisted-profile-state.unit.test.ts 2 failed / 3 (Bun) 3/3 pass
src/main/ai-vault-search/session-search-indexer.test.ts 1 failed / 42 (Bun) 42/42 pass
editor-view-layout-apply, restored-editor-move-restart, sweep-terminal-placement already Node-routed 3/3, 1/1, 9/9

The three topology files were routed by upstream stablyai#33533 (a886dcd1fe9), merged with the 10-28 sync: it added terminal-topology-profile-fixture to the harness list the scan keys on, so those four entries were already stale. The other two are genuinely invisible to a per-file import scan — neither names node:sqlite or one of the scanned modules — so they are now in NODE_RUNTIME_INCLUDE with the reason, and vitest-node-runtime-boundary.test.ts pins the pair, because the only other evidence was the allowlist itself.

Acceptance: pnpm test tests/e2e/helpers/persisted-profile-state.unit.test.ts → 3 passed (was 2 failed); pnpm test src/main/ai-vault-search/session-search-indexer.test.ts → 42 passed (was 1 failed); pnpm test config/scripts/vitest-node-runtime-boundary.test.ts → 3 passed, including the new pin.

All seven entries are gone. The hazard the audit named is why: their match was Unable to read profile state database, exactly what a real profile-state open regression throws.

T3 — a dead entry the gate structurally cannot see, and a static check for the next one

Entry 9 named sync-database-portability.test.ts › SQLite runtime contract rejects explicit undefined bindings before modifying rows, which no longer exists anywhere — upstream stablyai#34661 (e5f1eef466) deleted it, because Node 26.10 binds an explicit undefined as NULL. local/gate-unit.mjs derives staleness only from an entry that matched a failure, so a dead entry sits in the file for ever: no run will ever derive it.

tests/tools/unit-gate.test.mjs now checks every entry's title against its own file, statically, at PR time. titleExistsInSource in local/unit-gate-judgement.mjs rebuilds the shape a Vitest full name has — the describe chain plus the case title, single-space joined — from the file's own title literals, treating an it.each substitution (%s, %$, $name) as a wildcard, following the *.spec modules a file imports its cases from, and reading it.skip/it.todo as absent.

Entries 7-8 were re-checked as the audit asked: entry 8 (cannot add rowid alias) is stale — stablyai#34661 rebuilt that case through CREATE TABLE instead of an ADD COLUMN alias, and it runs 16/16 green, so it is pruned; entry 7 and its five neighbours are still red (6 failed / 8 when run alone) and stay. LOCAL-PATCHES.md now records what actually happened instead of "the bundled SQLite's own binding behaviour differs".

Acceptance: pnpm test tests/tools/unit-gate.test.mjs → 31 passed. Before the prune the same test failed with exactly the dead entry named; the guard also reports the 31 prunedSince titles correctly (all resolve except that one, which is the proof it is dead rather than invisible).

T4 — two of the fork's own reds, fixed rather than allowlisted

local/lint-known-red.json carried two foreign-red entries for fork PR #198's own files. Both are now fixed where the ratchet asked for them:

  • check-details-cache.test.ts pins the clock with vi.useFakeTimers() + vi.setSystemTime(); the four Date.now() reads were the TTL cases asking how fast the machine ran them.
  • checks-list-expanded-details.test.tsx drives useDelayedFlag's 200 ms deferral with vi.advanceTimersByTimeAsync, and now proves the deferral instead of assuming it: absent at 199 ms, present at 250 ms. The case went from a real 250 ms sleep to milliseconds.

Both entries are deleted; entries is now []. The claim recorded beside them was false and is corrected: it said a match naming the rule and path means "a new finding in either file still fails the gate". The ratchet prints one line per rule and file — <rule>:<path>: N flaky-test finding(s), baseline allows M. — and the regex is anchored on the rule and path alone, so a fifth Date.now() in the same file was masked.

Acceptance: pnpm exec ast-grep scan --config config/sgconfig.yml --filter "^test-" <both files> → 0 findings (was 5); ORCA_CODE_QUALITY_BASE=origin/nplez1/main node config/scripts/ast-grep-gates.mjs → exit 0, with both files in the changed-file scope the ratchet evaluates; pnpm test on both files → 12 and 20 passed.

Verification

  • pnpm tc — exit 0 (node, cli, web), run on this revision.
  • pnpm check:code-quality:changed → 0 new finding(s) across 6 changed file(s).
  • ORCA_CODE_QUALITY_BASE=origin/nplez1/main node config/scripts/ast-grep-gates.mjs → exit 0. Note: the same command without that base resolves against upstream's main and reports pre-existing drift in five files this branch does not touch (session-summary-fold, vm-recipe-extend, three session-scanner-* parsers) — the whole 3,061-file fork delta is in scope that way.
  • Focused suites, all green: tests/tools/unit-gate.test.mjs 31, tests/tools/lint-gate.test.mjs 23, config/scripts/check-flaky-test-pattern-ratchet.test.mjs 4, config/scripts/vitest-node-runtime-boundary.test.ts 3, config/scripts/vitest-sqlite-runtime-boundary.test.ts 14, config/scripts/ci-shard-assignment.test.mjs 12, config/scripts/vitest-runtime-boundary.test.ts 5, session-search-indexer 42, persisted-profile-state.unit 3, the topology suites 3/1/9, check-details-cache 12, checks-list-expanded-details 20, profile-state-streaming-validation 16, process-host-dev-rebuild 6 failed / 2 passed (unchanged, still allowlisted).

Not run: the full unit suite. This box was running another worktree's local/gate-unit.mjs throughout, and the suite has a known runtime trap here; gate 1 is waived below rather than claimed. The nightly fork-main-tests.yml lane and the release gate are the backstop.

Review

Reviewed by claude/opus, high: R1 (no blockers; 2 should-fix, 5 minor, 4 nit — all fixed), delta clean on R2.

Round 1 found the new guard unsound in both directions: $name was not a wildcard, aliased case tables (itRunsUnixShell.each) and *.spec-imported titles were invisible, while it.skip/it.todo titles read as live. All three shapes exist in this repo. Round 2 found one regression from that fix — the widened substitution class dropped %% — fixed in 212caf4e7a2, with %% and %$ now pinned by tests.

Gate 1 waived: full unit suite not run: another worktree's local/gate-unit.mjs held the single orca-queue lock for this session, and the suite has a known runtime trap on this machine. The config/ change is two literals added to NODE_RUNTIME_INCLUDE, both measured green in the Node project; targeted suites, pnpm tc, check:code-quality:changed and the lint gate all pass, and the nightly fork-main-tests.yml lane plus the release gate are the backstop.

`lint:ast-grep-gates` carried a known-red entry for each of two files PR #198
merged: four `Date.now()` reads in `check-details-cache.test.ts` and a 250 ms
real-time wait in `checks-list-expanded-details.test.tsx`. Both are the fork's
own work, and `local/lint-known-red.json` had them down as `foreign-red`.

Both are now fixed where the ratchet asked for them:

- the cache suite pins the clock with `vi.useFakeTimers()` + `vi.setSystemTime()`,
  which is what the TTL cases needed — `checkDetailsNeedRefresh` compares a
  payload's `readAt` against the wall clock, so they were really asking how fast
  the machine ran them;
- the checks-list suite drives `useDelayedFlag`'s 200 ms deferral with
  `vi.advanceTimersByTimeAsync(250)` instead of sleeping 250 real milliseconds to
  catch a label a fast machine never shows.

The claim recorded alongside the entries — that each `match` naming the rule and
the path means "a new finding in either file still fails the gate" — was false:
the ratchet prints one line per rule and file, and the regex is anchored on the
rule and the path alone, so a fifth `Date.now()` in the same file was masked.
The section in LOCAL-PATCHES.md now says so.
`findSqliteRuntimeTests` classifies a test by the imports it names, and it
cannot follow an indirect one. Two suites reach `node:sqlite` through modules
it does not know — `tests/e2e/helpers/persisted-profile-state.unit.test.ts`
imports the profile-state modules directly, and
`src/main/ai-vault-search/session-search-indexer.test.ts` reaches the driver
through the indexer, the schema and its fixture — so both ran in the Bun
project. Bun's `node:sqlite` on macOS cannot open a WAL database read-only once
`close()` has removed `-wal`/`-shm`, so they failed 2/3 and 1/42 there and pass
3/3 and 42/42 here.

Both are now in `NODE_RUNTIME_INCLUDE`, with the reason, and
`vitest-node-runtime-boundary.test.ts` pins the pair: nothing else would notice
their removal, because the only other evidence was the known-red manifest.

That also retires the two `Unable to read profile state database` entries.
Their `match` string is what a genuine profile-state open regression throws, so
while they were allowlisted the gate could not have seen one.
`local/gate-unit.mjs` derives staleness only from an entry that *matched a
failure*, so an entry naming a test that no longer exists can never be reported:
it sits in the manifest for ever, and only a 25-minute full run could have said
anything about it — and that run derives nothing from an entry nothing matched.

One such entry was there. `src/main/sqlite/sync-database-portability.test.ts >
SQLite runtime contract rejects explicit undefined bindings before modifying
rows` names a case upstream stablyai#34661 (`e5f1eef466`) deleted, because Node 26.10
binds an explicit `undefined` as NULL. Its recorded cause — "the bundled SQLite's
own binding behaviour" — was wrong, and `LOCAL-PATCHES.md` now says what actually
happened.

So the title is now checked against its file, statically, at PR time.
`titleExistsInSource` in `local/unit-gate-judgement.mjs` rebuilds a Vitest full
name — the `describe` chain and the case title joined by single spaces — from the
file's own title literals, treating an `it.each` substitution as a wildcard, and
`tests/tools/unit-gate.test.mjs` asserts the real manifest has no dead entry.

Nine entries are pruned with it, every one re-measured today:

- the four topology cases run in the Node project already, since upstream stablyai#33533
  (`a886dcd1fe9`) seated their fixture in the import scan; 3/3, 1/1 and 9/9 pass;
- `profile-state-streaming-validation`'s rowid case was rebuilt by stablyai#34661 to use
  `CREATE TABLE` over `ALTER TABLE … ADD COLUMN`; 16/16 pass;
- the two re-routed suites from the previous commit, and the now-deleted case.

What remains is 8 entries, all `host-toolchain`; the `sqlite-binding` class is
empty. Each prune carries its reason and the revision that closed it in
`prunedSince`, which keeps `observedRun`'s arithmetic honest.
Adversarial review of the branch (Opus, high, over 6d7cb78..HEAD) found
nothing blocking and two should-fix gaps in the new guard, plus five MINOR and
four NIT. Each is addressed here.

Guard soundness — it reported live tests as dead in shapes this repo writes:

- `$name` off an `it.each` table row is a substitution like `%s`; the comment
  claimed it and the pattern did not have it. `%$` too.
- case tables are named `itRunsUnixShell.each(...)`, not `it.each(...)`, so the
  caller pattern now accepts any identifier starting with describe/it/test/suite.
  `src/main/cli/packaged-cli-assets.test.ts` is exactly that shape and would have
  reported its live title as dead.
- `src/main/runtime/orca-runtime.test.ts` imports every case from `*.spec`
  modules, so its titles are in files the entry does not name. `source` is now
  the file plus those modules, via `importedCaseSpecifiers`.

Guard precision — it called dead entries live:

- `it.skip` / `it.todo` never run, so a title behind one can never be a known
  red. Both now read as absent. A title surviving only in a comment still counts
  as present, and the doc comment says so.

Coverage for both directions (`tests/tools/unit-gate.test.mjs`, 29 → 31 tests):
nested describes, `$name`, an aliased table, a generic `.each`, an apostrophe in
a double-quoted title, a template-literal title, skip/todo, and a real
spec-imported title that must be found through the follow and not without it.

The deferred-label case also asserted only half of what its comment claims: it
now proves "Refreshing check details…" is absent at 199 ms and present at 250 ms,
which is the deferral `useDelayedFlag` exists for and costs milliseconds with the
clock faked.

Three LOCAL-PATCHES claims were wrong and are corrected: the prune split is seven
re-routed and two upstream-rebuilt (not six and three), the rowid diagnosis was
right about SQLite 3.54's `ADD COLUMN` refusal and wrong only about the cause
being fork-local, and the `local(lint)` entry count is now zero.
The delta re-check (Opus, high, over R1..R2) came back clean with one MINOR
regression from that round's own fix: the widened substitution class dropped
`%%`, which Vitest renders as a single `%`, so a title written `shows 50%% done`
would have looked dead at `shows 50% done`. `%` is back in the class, and the
test pins `%%` and `%$` so neither can be dropped again.

The doc comment also claimed the comment-only shape was the *one* thing the
check cannot tell apart. It is not: a title behind `(cond ? it : it.skip)('t')`
is unresolved callee, not a skip, so it reads as present too. Both are stated.
@nplez1
nplez1 merged commit 28ff99b into nplez1/main Oct 29, 2026
2 checks passed
@nplez1
nplez1 deleted the nplez1/audit-224 branch October 29, 2026 16:01
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.

Audit 2026-10-29 · Allowlist rot, and one untested security refusal

1 participant