-
Notifications
You must be signed in to change notification settings - Fork 10
fix(native): purge stale rows when WASM-only files are deleted #1122
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+302
−9
Merged
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
f26abee
fix(native): purge stale rows when WASM-only files are deleted
carlos-alm 8af09cc
refactor(builder): drop redundant classify pass and harden DB path ma…
carlos-alm c8fabe1
Merge branch 'main' into fix/1073-wasm-stale-purge
carlos-alm b7de480
Merge branch 'main' into fix/1073-wasm-stale-purge
carlos-alm 17bf7fd
fix: resolve merge conflicts with main
carlos-alm 4c22410
fix(stale-purge): preserve raw path so DELETE matches DB row (#1122)
carlos-alm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,132 @@ | ||
| /** | ||
| * Unit tests for `computeWasmOnlyStaleFiles` (#1073). | ||
| * | ||
| * The Rust orchestrator's `detect_removed_files` filter (#1070) skips files | ||
| * outside its supported extensions, so deletions of WASM-only languages don't | ||
| * reach the native purge path. The JS-side backfill only inserts rows, so | ||
| * without this helper a deleted WASM-only file would leak `nodes`/`file_hashes` | ||
| * rows until the next full rebuild. | ||
| * | ||
| * These tests pass the extension sets as parameters so they remain meaningful | ||
| * even when every currently-registered language is natively supported | ||
| * (i.e. `installedExts == nativeSupported`). The bug surface re-opens any time | ||
| * a new WASM-only language enters the registry before its Rust extractor. | ||
| */ | ||
| import { describe, expect, it } from 'vitest'; | ||
| import { computeWasmOnlyStaleFiles } from '../../src/domain/graph/builder/pipeline.js'; | ||
|
|
||
| const NATIVE = new Set(['.ts', '.js', '.r']); | ||
| const INSTALLED = new Set(['.ts', '.js', '.r', '.gleam', '.foo']); | ||
|
|
||
| describe('computeWasmOnlyStaleFiles', () => { | ||
| it('returns WASM-only files present in DB but missing from disk', () => { | ||
| const stale = computeWasmOnlyStaleFiles({ | ||
| existingNodes: new Set(['src/a.gleam', 'src/b.ts']), | ||
| existingHashes: new Set(['src/a.gleam', 'src/b.ts']), | ||
| expected: new Set(['src/b.ts']), | ||
| installedExts: INSTALLED, | ||
| nativeSupported: NATIVE, | ||
| }); | ||
| expect(stale).toEqual(['src/a.gleam']); | ||
| }); | ||
|
|
||
| it('skips natively-supported extensions — Rust owns their deletion path', () => { | ||
| const stale = computeWasmOnlyStaleFiles({ | ||
| existingNodes: new Set(['src/old.ts', 'src/old.r']), | ||
| existingHashes: new Set(['src/old.ts', 'src/old.r']), | ||
| expected: new Set(), | ||
| installedExts: INSTALLED, | ||
| nativeSupported: NATIVE, | ||
| }); | ||
| expect(stale).toEqual([]); | ||
| }); | ||
|
|
||
| it('skips extensions with no installed WASM grammar', () => { | ||
| // .bar is not in installedExts — neither engine can parse it, so DB rows | ||
| // for it can't have been written by this codepath. Leave them alone. | ||
| const stale = computeWasmOnlyStaleFiles({ | ||
| existingNodes: new Set(['src/x.bar']), | ||
| existingHashes: new Set(['src/x.bar']), | ||
| expected: new Set(), | ||
| installedExts: INSTALLED, | ||
| nativeSupported: NATIVE, | ||
| }); | ||
| expect(stale).toEqual([]); | ||
| }); | ||
|
|
||
| it('catches files that exist only in file_hashes (nodes missing)', () => { | ||
| // Legacy DB shape where file_hashes was written but `nodes` was not — the | ||
| // backfill should still recognise the file_hashes row as stale. | ||
| const stale = computeWasmOnlyStaleFiles({ | ||
| existingNodes: new Set(), | ||
| existingHashes: new Set(['src/leftover.gleam']), | ||
| expected: new Set(), | ||
| installedExts: INSTALLED, | ||
| nativeSupported: NATIVE, | ||
| }); | ||
| expect(stale).toEqual(['src/leftover.gleam']); | ||
| }); | ||
|
|
||
| it('catches files that exist only in nodes (file_hashes missing)', () => { | ||
| const stale = computeWasmOnlyStaleFiles({ | ||
| existingNodes: new Set(['src/leftover.gleam']), | ||
| existingHashes: new Set(), | ||
| expected: new Set(), | ||
| installedExts: INSTALLED, | ||
| nativeSupported: NATIVE, | ||
| }); | ||
| expect(stale).toEqual(['src/leftover.gleam']); | ||
| }); | ||
|
|
||
| it('deduplicates files appearing in both nodes and file_hashes', () => { | ||
| const stale = computeWasmOnlyStaleFiles({ | ||
| existingNodes: new Set(['src/dup.gleam']), | ||
| existingHashes: new Set(['src/dup.gleam']), | ||
| expected: new Set(), | ||
| installedExts: INSTALLED, | ||
| nativeSupported: NATIVE, | ||
| }); | ||
| expect(stale).toEqual(['src/dup.gleam']); | ||
| }); | ||
|
|
||
| it('lowercases extensions to match registry/Rust normalisation', () => { | ||
| // R is conventionally written `.R` on disk. The registry and the Rust | ||
| // `LanguageKind::from_extension` accept both cases; `installedExts` and | ||
| // `nativeSupported` carry the lowercase canonical form. | ||
| const stale = computeWasmOnlyStaleFiles({ | ||
| existingNodes: new Set(['src/Plot.R']), | ||
| existingHashes: new Set(['src/Plot.R']), | ||
| expected: new Set(), | ||
| installedExts: INSTALLED, | ||
| nativeSupported: NATIVE, | ||
| }); | ||
| // .R lowercases to .r which IS native-supported, so it should be skipped. | ||
| expect(stale).toEqual([]); | ||
| }); | ||
|
|
||
| it('returns empty when DB and disk agree', () => { | ||
| const stale = computeWasmOnlyStaleFiles({ | ||
| existingNodes: new Set(['src/a.gleam', 'src/b.ts']), | ||
| existingHashes: new Set(['src/a.gleam', 'src/b.ts']), | ||
| expected: new Set(['src/a.gleam', 'src/b.ts']), | ||
| installedExts: INSTALLED, | ||
| nativeSupported: NATIVE, | ||
| }); | ||
| expect(stale).toEqual([]); | ||
| }); | ||
|
|
||
| it('normalises DB paths with back-slashes against forward-slash expected set', () => { | ||
| // Defends against false-positive purges on Windows where a stale DB row | ||
| // (written by older code) could carry back-slashes while `expected` is | ||
| // always normalised. Without `normalizePath` inside `consider`, the file | ||
| // would look stale and be purged even though it exists on disk. | ||
| const stale = computeWasmOnlyStaleFiles({ | ||
| existingNodes: new Set(['src\\live.gleam']), | ||
| existingHashes: new Set(['src\\live.gleam']), | ||
| expected: new Set(['src/live.gleam']), | ||
| installedExts: INSTALLED, | ||
| nativeSupported: NATIVE, | ||
| }); | ||
| expect(stale).toEqual([]); | ||
| }); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
stale.push(rel)stores the forward-slash-normalised path, butpurgeFilesDataexecutesDELETE FROM nodes WHERE file = ?with that value. If the DB row was stored with back-slashes (the Windows-migration case the comment describes), the SQL predicate won't match and the DELETE hits 0 rows — the stale row silently persists, which is exactly the regression this PR is trying to fix.The dedup key should remain the normalised form (so
src/a.gleamandsrc\a.gleamare still treated as one file), but the value pushed intostalemust be the originalrawRelso the laterWHERE file = ?matches the actual stored path. The existing back-slash test only covers the "file still on disk" path; adding a counterpart with an emptyexpectedset would catch this.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 4c22410.
consider()now pushesrawRel(not the normalisedrel) into the stale list, sopurgeFilesData'sDELETE FROM nodes WHERE file = ?is byte-identical to the stored row. The dedupseenset still uses the normalised form so a path written once with\and once with/is treated as one entry. Added the counterpart regression test (preserves back-slash form so DELETE matches the actual DB row) covering a stale back-slash row with an emptyexpectedset.