Skip to content

fix(core): metadata source walk skips cache dirs and vanished files - #928

Merged
Aymericr merged 2 commits into
mainfrom
fidelity/a-02-scan-race
Sep 25, 2026
Merged

Aymericr merged 2 commits into
mainfrom
fidelity/a-02-scan-race

Conversation

@Aymericr

@Aymericr Aymericr commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?

This fixes the quality failure that #923 introduced on main at a9c1d4561. The failure also reproduced on a rerun.

Cause: reference-inventory.test.ts walks every editor source file to find the metadata keys it uses. At the same time, history.test.ts creates and deletes .turbo/history-*/probe.ts. When a file the walk has already listed is deleted before it is stat'ed or read, the walk throws ENOENT.

Changes:

  • Walk extracted. The walk now lives in contracts/metadata-scan.ts as scanMetadataSources. It takes an injectable fs so a test can reproduce the race. This file stays test and tooling only, excluded from the package build.
  • Build and cache dirs skipped. The walk now skips node_modules, dist, build, out, coverage, __fixtures__ and every dot-directory (.turbo, .next, …).
  • Deleted files tolerated. An ENOENT from readdir, stat or read is treated as a file that vanished mid-walk and is skipped. Any other error still throws.

Commits:

  1. 79909befa adds the reproducing test. It deletes a listed file between readdir and stat, and plants a .turbo/history-1/probe.ts. On that commit the test fails with ENOENT: … stat …/vanishing.ts.
  2. The second commit is the fix; the same test now passes.

How to test

  1. bun run --cwd packages/core test: 2955 pass, 0 fail.
  2. bun run --cwd packages/core check-types: clean.
  3. bun run check: clean.

Screenshots / screen recording

Not applicable: tests only.

Checklist

  • I've tested this locally (core tests; no bun dev surface)
  • My code follows the existing code style (run bun check to verify)
  • I've updated relevant documentation (if applicable)
  • This PR targets the main branch

🤖 Generated with Claude Code


Note

Low Risk
Changes are limited to contract/test tooling in metadata-scan.ts and inventory tests; no runtime editor or package build surface.

Overview
Fixes flaky quality failures when reference-inventory.test.ts walks editor sources while other suites delete files under .turbo.

The inline source-tree walk is replaced by scanMetadataSources in metadata-scan.ts, which maps metadata keys to the first source file that uses them. The walk now ignores build/cache/dependency paths (dist, build, out, coverage, etc.) and all dot-directories (e.g. .turbo), and treats ENOENT on readdir/stat/read as a file that disappeared mid-scan instead of throwing. Filesystem access is injectable via ScanFs so tests can simulate the race.

reference-inventory.test.ts uses the shared scanner for METADATA_KEYS and adds a test that deletes a listed file between readdir and stat while ensuring keys under .turbo are not picked up.

Reviewed by Cursor Bugbot for commit 3e13c78. Bugbot is set up for automated code reviews on this repo. Configure here.

Aymericr and others added 2 commits September 25, 2026 04:08
The walk over editor sources stats and reads files that concurrent suites
(history.test.ts) create and delete under .turbo, failing quality on main
with ENOENT. Extract the walk with an injectable fs and add a failing
case that deletes a listed file mid-scan and plants a .turbo probe.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…walk

Skip build, dependency, cache and dot directories (.turbo, .next,
node_modules, dist, …) and treat ENOENT on readdir, stat or read as a file
that vanished mid-walk, so concurrent suites can no longer fail quality.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@pascal

pascal Bot commented Sep 25, 2026

Copy link
Copy Markdown

I hit an error while handling your request (Model unavailable on AI Gateway free tier: Free tier users do not have access to this model. Upgrade to paid credits at https://vercel.com/d?to=%2F%5Bteam%5D%2F%7E%2Fai%3Fmodal%3Dtop-up for unrestricted…).

Please try again, rephrase, or reach out if it keeps failing.

Error id: daf35de7-e1eb-4dc3-9bdc-d90943e94c50

@Aymericr
Aymericr merged commit f643905 into main Sep 25, 2026
4 checks passed
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