feat(core): harden graph edge extraction (dotted Python imports, Ruby strings)#2
Merged
Merged
Conversation
…d Ruby strings Three scoped follow-ups to the relational code-graph extractor, all label-honest (edges stay import-resolved or name-only — never type-resolved). Dotted Python imports: `import a.b.c` now binds the full dotted module path instead of only the top-level segment, so `a.b.c.func()` resolves to `func` in `a/b/c.py` (import-resolved when the module exists on disk, name-only otherwise) and no longer emits bogus intermediate `b`/`c` edges. Single-segment imports and `import x as y` are unchanged. Ruby string masking: maskRubySyntaxLines now blanks `=begin`/`=end` block comments, heredoc bodies/terminators (`<<~`, `<<-`, quoted tags, and plain `<<IDENT` with an uppercase-led tag), and single-line `%w`/`%i`/`%W`/`%I` word arrays — so identifiers inside those constructs stop leaking out as bogus name-only call edges. The opener line keeps any code before the heredoc token, and `array << item` left-shift is not misread as a heredoc opener. Name-only test coverage: added persisted-edge + findCallers tests for Java, Ruby, and Rust (previously only Go and Python were covered), plus dotted-import and Ruby-masking regression tests. Verified on Node 22: pnpm build, pnpm typecheck, pnpm test — 11 files, 184 tests passing. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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
Three scoped hardening follow-ups to the relational code-graph edge extractor
(
packages/core/src/repo.ts), all label-honest: edges stayimport-resolvedorname-only— nevertype-resolved(there is no type checker).1. Dotted Python imports
import a.b.cnow binds the full dotted module path instead of only thetop-level segment. So
a.b.c.func()resolves tofuncina/b/c.py(
import-resolvedwhen the module exists on disk,name-onlyotherwise) and nolonger emits bogus intermediate
b/cedges. Single-segmentimport osandimport x as yare unchanged. Dottedfrom a.b.c import funccontinues toresolve to the dotted module file.
2. Ruby string masking
maskRubySyntaxLinesnow blanks:=begin/=endblock comments<<~,<<-,quoted tags (
<<'EOS',<<"HTML"), and plain<<IDENTonly foruppercase-led tags (so
array << itemleft-shift is not misread as aheredoc)
%w/%i/%W/%Iword arraysThe opener line keeps any real code before the
<<…token. Identifiers buriedinside these constructs no longer leak out as bogus
name-onlycall edges.3. Name-only test coverage
Added persisted-edge +
findCallerstests for Java, Ruby, and Rust(previously only Go and Python were covered), plus dotted-import and
Ruby-masking regression tests. The Ruby test asserts that
ghost_call/select/notifyburied in a block comment, a heredoc, and a%W[]literal producezero edges while the real call still resolves.
Verification
Run on Node 22 (
pnpm build,pnpm typecheck,pnpm test):(was 177 before this change — +7 tests, no regressions.)
🤖 Generated with Claude Code