Skip to content

fix(network): import-graph precision for Go, Zig, C/C++, JS/TS and Python - #3589

Merged
squid-protocol merged 2 commits into
mainfrom
claude/festive-fermat-kojuy7
Sep 25, 2026
Merged

squid-protocol merged 2 commits into
mainfrom
claude/festive-fermat-kojuy7

Conversation

@squid-protocol

Copy link
Copy Markdown
Owner

Summary

This clears the remaining import-graph errors that tests/tools/import_graph_accuracy.py measures against tree-sitter ground truth on the 16 pinned repos. Each fix comes from a root-caused false or missed edge.

# Language Bug Fix
1 Go _dependency_capture made import optional, 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. An import spec is now one of: an import [alias] "p" line; a one-line import ("p"); or a spec line inside an import ( … ) 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.
2 Zig try @import("features/goto.zig").handler(…) is an expression, and the capture only accepted @import at line start. That's how zls's Server.zig reaches most feature files. @import may follow any code or complete string literal on its line. A comment, an unclosed string, or a \\ multiline-string line still rejects it.
3 C / C++ / ObjC Standard headers <chrono>, <ostream>, <list>, <map> resolved to fmt's chrono.h/ostream.h, and even to LiveCode's list.lcb/map.lcb and Ada's functional.ads. New flag include_names_file_literally: an extensionless include names a literally extensionless file.
4 JS / TS Bare specifiers linked to same-named local files: require('ejs') → test/acceptance/ejs.js, redis → examples/session/redis.js, zod/mini → a mini.ts fixture, zod/v4/core → core.ts. New flag 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/Button still resolves). Trade-off: a single-segment baseUrl import (import "config") no longer links.
5 Python from . import cli captured only ., so the edge went to __init__.py and cli.py was missed. New top-level key 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 .Options as a package mimicking Option.

The capture loop moves into galaxyscope.extract_raw_imports, which is unit-tested and also carries #3554's local_module_capture_group.

Measured: import_graph_accuracy.py (precision / recall)

language before after
typescript (zod) 91.4 / 100 99.6 / 100
javascript (express) 90.5 / 100 100 / 100
cpp (fmt) 95.7 / 100 99.3 / 100
go (cobra) 83.3 / 90.9 90.9 / 90.9
zig (zls) 100 / 94.1 100 / 100
python (httpx, fastapi, flask) 98.9 / 97.9 99.1 / 98.9
c, java, lua, php, ruby, rust, perl — unchanged

The baseline is regenerated. What's left, out of scope:

Type of change

  • Bug fix
  • New feature / language support
  • Parsing or engine logic (gitgalaxy/core/detector.py, language_standards.py, prism.py, or a per-language rule)
  • Docs, tooling, or CI only
  • Other (describe above)

CI checklist

  • ruff-audit and dead-key are clean. Local format and mypy flags are the same on main (local tool versions).
  • python -m pytest tests/ passes: 11,124 passed, with test_security_auditor.py skipped 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 --ci passes, and span_anchor_audit.py --ci passes.
  • 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 (the go/ and dockerfile/moby Go files): Extracted Dependencies loses the junk tokens, and the edges and exposures that follow.
  • Python (incl. cython .pyx/.pxd and NVDA's .py under cpp/): .name tokens replace ., adding edges to submodules.
  • Zig: inline @import edges added.
  • YAML, Lua, LiveCode, Ada, shell, SQLite, Rust, Perl: only incoming-edge fields drop (popularity, direct and total downstream). These were targets of the false edges above.
    • Verified for yaml arm64.yml / action.yml and lua env.lua / closure.lua: the removed Go tokens arm64, action, env, closure.
    • Verified for livecode list / map / iterator.lcb and ada functional.ads: C++ standard headers.
  • Summary:
    • ecosystem_audits.firewall.imports_unknown: 11269 → 11179, i.e. 90 junk Go "packages" gone.
    • network_macro and directory-group averages follow the edge changes.
    • typosquat_hits: 26 → 27. The new hit is perl/exiftool/ExifTool.pm "warning mimics warnings". Perl's capture reads no warning inside a comment. That's an existing bug, which a Go junk token used to mask: warning appeared 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

$ pytest tests/security_auditing/test_import_resolution_by_language_rule.py tests/core_engine/test_extract_raw_imports.py \
         tests/extraction/languages/test_go.py tests/extraction/languages/test_zig.py -q        -- all pass
$ pytest tests/core_engine/test_galaxyscope.py -k relative_imports   -- fails without the tally fix, passes with it
$ IMPORT_GRAPH_CORPUS_PATH=../import-graph-corpus python tests/tools/import_graph_accuracy.py --ci
import_graph_accuracy: OK -- 13 language(s) measured
$ python -m pytest tests/ -n auto   -- 11124 passed

🤖 Generated with Claude Code

https://claude.ai/code/session_01YAtpBfGGyBGGovitSVaM5Q


Generated by Claude Code

…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
@github-actions

Copy link
Copy Markdown
Contributor

🐦‍⬛ Muninn Security Scan

✅ No security issues found.

🐦‍⬛ Powered by Muninn · Skald Lab

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.

2 participants