Repository navigation
fix(network): import-graph precision for Go, Zig, C/C++, JS/TS and Python - #3589
Merged
Merged
Conversation
…thon Every remaining error import_graph_accuracy.py measured traced to one of: - Go: `_dependency_capture` made `import` optional, so any line starting with a quoted string was an import (test tables, call args). Junk tokens (`--help`, `apple`, `env`, `closure`) linked to a workflow .yml, .lua files and more, and fed the firewall/typosquat checks. An import spec is now an `import` line, a one-line block, or a spec line of an `import ( )` block. - Zig: `try @import("x.zig").f()` (an expression) was missed; `@import` may now follow any code or complete string literal on its line (not a comment, not a `\\` multiline-string line). - C/C++/ObjC: an extensionless include (`<chrono>`, `<list>`) names an extensionless file, never fmt's chrono.h or a same-stem file in another language (`include_names_file_literally`). - JS/TS: a bare specifier (`ejs`, `zod/mini`, `node:fs`) is a package; it resolves only when, less an `@/` `~/` `#` alias prefix, it is the tail of a real file path (`bare_import_names_package`). - Python: `from . import cli` is recorded as `.cli` (the submodule), not `.`; a name that is not a submodule falls back to the package __init__ (`relative_import_groups`). A `.`-led Python token is local, so the typosquat tally no longer reads `.Options` as a package. The capture loop moves into galaxyscope.extract_raw_imports (unit tested), which also carries #3554's `local_module_capture_group`. import_graph_accuracy (precision / recall), baseline regenerated: typescript 91.4/100 -> 99.6/100, javascript 90.5/100 -> 100/100, cpp 95.7/100 -> 99.3/100, go 83.3/90.9 -> 90.9/90.9, zig 100/94.1 -> 100/100, python 98.9/97.9 -> 99.1/98.9; others unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01YAtpBfGGyBGGovitSVaM5Q
…e prism call above does) Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01YAtpBfGGyBGGovitSVaM5Q
Contributor
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
This clears the remaining import-graph errors that
tests/tools/import_graph_accuracy.pymeasures against tree-sitter ground truth on the 16 pinned repos. Each fix comes from a root-caused false or missed edge._dependency_capturemadeimportoptional, so any line that started with a quoted string was an import: test tables ("--help",), call arguments, map keys. The junk tokens (--help,apple,env,closure) linked to.github/workflows/test.yml,env.lua,closure.lua,action.yml, and fed the firewall and typosquat checks.import [alias] "p"line; a one-lineimport ("p"); or a spec line inside animport ( … )block, meaning nothing after the path but a comment, and only specs, blank lines or comments down to the block's)line. The lookahead is bounded.try @import("features/goto.zig").handler(…)is an expression, and the capture only accepted@importat line start. That's how zls'sServer.zigreaches most feature files.@importmay follow any code or complete string literal on its line. A comment, an unclosed string, or a\\multiline-string line still rejects it.<chrono>,<ostream>,<list>,<map>resolved to fmt'schrono.h/ostream.h, and even to LiveCode'slist.lcb/map.lcband Ada'sfunctional.ads.include_names_file_literally: an extensionless include names a literally extensionless file.require('ejs')→test/acceptance/ejs.js,redis→examples/session/redis.js,zod/mini→ amini.tsfixture,zod/v4/core→core.ts.bare_import_names_package: a bare specifier is a package. It resolves only when, after stripping an@//~//#alias prefix, it is the tail of a real file path (@/components/Buttonstill resolves). Trade-off: a single-segmentbaseUrlimport (import "config") no longer links.from . import clicaptured only., so the edge went to__init__.pyandcli.pywas missed.relative_import_groups: each imported name is recorded as.cli. A name that isn't a submodule falls back to the package__init__, matching Python's own lookup order. A.-led Python token is also local now, so the typosquat tally no longer reads cython's.Optionsas a package mimickingOption.The capture loop moves into
galaxyscope.extract_raw_imports, which is unit-tested and also carries #3554'slocal_module_capture_group.Measured:
import_graph_accuracy.py(precision / recall)The baseline is regenerated. What's left, out of scope:
__init__.pyfiles from the scan (flask's package root vanishes) #3583: the Packed Payload Guard drops flask's re-export__init__.py.Type of change
gitgalaxy/core/detector.py,language_standards.py,prism.py, or a per-language rule)CI checklist
python -m pytest tests/passes: 11,124 passed, withtest_security_auditor.pyskipped locally for lack of numpy.crucible_check.py --update --yes: both fixtures reblessed on current main (after fix(spans): TS/JS/PHP functions start on their declaration line (#3543, #3555) #3585). Scope is below.import_graph_accuracy.py --cipasses, andspan_anchor_audit.py --cipasses.tree_sitter_accuracy_audit.py: left to CI. This change touches import capture and resolution, not function extraction.Golden-master scope
Zero-dependency fixture: 260 differences. 53 are coordinate or composition-fit ripple. The other 207:
go/anddockerfile/mobyGo files):Extracted Dependenciesloses the junk tokens, and the edges and exposures that follow..pyx/.pxdand NVDA's.pyundercpp/):.nametokens replace., adding edges to submodules.@importedges added.arm64.yml/action.ymland luaenv.lua/closure.lua: the removed Go tokensarm64,action,env,closure.list/map/iterator.lcband adafunctional.ads: C++ standard headers.ecosystem_audits.firewall.imports_unknown: 11269 → 11179, i.e. 90 junk Go "packages" gone.network_macroand directory-group averages follow the edge changes.typosquat_hits: 26 → 27. The new hit isperl/exiftool/ExifTool.pm"warningmimicswarnings". Perl's capture readsno warninginside a comment. That's an existing bug, which a Go junk token used to mask:warningappeared in two files, so it wasn't a one-off token. With the junk gone, it surfaces. I can fix it in a follow-up if wanted.Verification
🤖 Generated with Claude Code
https://claude.ai/code/session_01YAtpBfGGyBGGovitSVaM5Q
Generated by Claude Code