Repository navigation
Conversation
…ort no longer panics
A tsconfig/jsconfig `paths` key with text on both sides of its `*`, like
`@x/*/index`, splits into the prefix `@x/` and the suffix `/index`.
apply_aliases checked starts_with and ends_with separately, then sliced
import_path[prefix.len()..len - suffix.len()]. An import of `@x/index`
starts with the one and ends with the other only by counting its one `/`
twice, so the slice ended before it began and panicked ("byte range
starts at 3 but ends at 2"). `codegraph init` exited 101 and left the
index in phase=building, unreadable. In an indexed project, the sync that
picked up such an import panicked the same way, and so did every sync
after it.
A wildcard pattern now matches only an import at least as long as its
prefix and suffix together, TypeScript's own isPatternMatch rule. A
shorter import skips the pattern, and a less specific pattern may still
match it. An empty capture at exactly the prefix plus the suffix
(`@x//index`) still matches, as tsc allows. This ports upstream 77ee3484
(#2969); upstream's string slice did not throw there, and instead linked
the import to the file the empty capture named.
No extraction version move: a repository with this shape cannot finish
an index today, and every other graph is unchanged. All 32 golden
corpora check identical.
Evidence: the upstream audit reproduced the panic on the official
v0.56.0 binary, for both init and sync. The new applyAliases unit tests
mirror upstream's cases: the overlap, the fall-through to a less specific
pattern (in tsc's declaration order, and through the loader with a
shorter prefix), and the exact-length capture. The first three panic on
the unchanged code; the exact-length case passes on both. The new sync
convergence cases typescript_tsconfig_overlapping_wildcard_import_appears
and _disappears fail on the unchanged code (sync and init exit 101); with
the fix, each sync equals a fresh index.
Codecov Report✅ All modified and coverable lines are covered by tests. @@ Coverage Diff @@
## main #358 +/- ##
==========================================
- Coverage 96.40% 96.40% -0.01%
==========================================
Files 368 368
Lines 254628 254704 +76
==========================================
+ Hits 245468 245541 +73
- Misses 9160 9163 +3
... and 2 files with indirect coverage changes 🚀 New features to boost your workflow:
|
This branch has not been deployed
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
A tsconfig/jsconfig
pathskey with text on both sides of its*, such as"@x/*/index", madecodegraph initpanic on an import like@x/index:apply_aliasescheckedstarts_with(prefix)andends_with(suffix)separately and then slicedimport_path[prefix.len()..len - suffix.len()].@x/indexpasses both checks only by counting its one/twice, so the slice range is reversed. Init exits 101 and leaves the index inphase=building, unreadable. In an indexed project, the sync that picks up such an import panics, and so does every later sync.The fix applies TypeScript's
isPatternMatchlength rule: a wildcard pattern matches only an import at least as long as its prefix and suffix together. A shorter import skips the pattern, so a less specific pattern may still match it. An empty capture at exactly prefix + suffix (@x//index) still matches, as tsc allows.This ports upstream colbymchenry/codegraph 77ee3484 (#2969). Upstream's JS
slicereturned an empty string there and linked the import towidgets/index; this build panicked instead.Graph impact
No extraction version move. A repository with this shape cannot finish an index on v0.56.0, and every other repository's graph is unchanged:
scripts/regen-goldens.sh --checkreports all 32 corpora identical.Tests
crates/codegraph-resolve/src/path_aliases.rs: four unit tests mirroring upstream'sapplyAliasescases. They cover: the overlap does not match; the search falls through past an overlapping pattern (once with upstream's two@x/patterns in tsc's declaration order, once through the loader with a shorter prefix); the exact-length empty capture still matches. The first three panic onmainatpath_aliases.rs:453:24. The exact-length case passes on both, as upstream reports for its own suite.crates/codegraph-cli/tests/sync_convergence:typescript_tsconfig_overlapping_wildcard_import_appearsandtypescript_tsconfig_overlapping_wildcard_import_disappears, matrix cases beside the other tsconfigpathscases. Onmain, the sync (appears) and the init (disappears) exit 101. With the fix, each sync equals a fresh index, and the import links to neithersrc/widgets/index.tsnor itstrap.Validation
cargo test -p codegraph-resolve --locked path_aliascargo test -p codegraph-resolve --lockedcargo test -p codegraph-rs --locked --test sync_convergence overlapping_wildcardcargo test -p codegraph-rs --locked --test sync_convergence -- tsconfig jsconfig alias paths_cargo clippy -p codegraph-resolve -p codegraph-rs --all-targets --locked -- -D warningscargo fmt --all --checkpython3 scripts/docs-check.pyscripts/regen-goldens.sh --checkwith this branch's releasecodegraphandbenchAll cargo commands ran with
env -u RUSTUP_TOOLCHAIN(the pinned 1.98.0 toolchain).Not in this PR:
pathskey orderload_project_aliasesreadscompilerOptions.pathsinto aserde_json::Mapbuilt withoutpreserve_order, so the keys come out sorted. Among patterns whose prefixes have the same length, the stable specificity sort keeps that order, while tsc breaks such ties by declaration order. With{"@x/*/index": ["widgets/*/index"], "@x/*": ["lib/*"]}, tsc and upstream send@x/button/indextowidgets/button/index. This build sends it tolib/button/index, which does not exist, so the import stays unresolved andpresslinks by name only. Matching tsc's order changes the graph, so it is tracked separately with the other graph-changing work and is not part of this crash fix.The pre-push
make pre-cipassed on 0e16434. This is owner decision OD-C10: the crash was found by the v1.6.4 upstream audit and reproduced on the official v0.56.0 binary, and it is fixed in the v0.56.1 patch.