Repository navigation
fix(network): resolve imports by each language's own rule (#3544 #3545 #3552 #3553, #3554 in part) - #3562
Merged
Conversation
…#3552 #3553 #3554) _resolve_target only ever searched by path, file name or stem: - #3553/#3552: a relative token (./x, ../x) and every C/C++/Obj-C/Ruby/Zig import now resolve against the importing file's directory first, so a name that repeats elsewhere (libuv's internal.h, express's ./db) still links; an extensionless token takes the same extension-less path or its index file, and an ESM ./x.js takes x.ts. A token with any other extension names exactly that file (<poll.h> is never poll.c). - #3545/#3544 (python): package_init_file languages resolve by Python's rule: a.b is a/b.py or a/b/__init__.py under a source root (a non-package dir), so from fastapi import X binds fastapi/__init__.py and import types is not fastapi/types.py; leading dots are relative; several matches draw no edge (#261 unchanged). - #3544 (lua/perl/java): a dotted token must end in its package path even when it is the only candidate (starlette.requests is not the local requests.py). - #3554: perl :: is the path separator; java retries the enclosing class for static-member and nested-class imports. Per-language behaviour is declared by new top-level DEFINITION flags. import_graph_accuracy.py: a nested Java class resolves to its outer class file (the audit scored those imports as unresolvable). Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01YAtpBfGGyBGGovitSVaM5Q
Callers that already hold a file (tests' `src/lib.py`, `f1.py`) pass path-shaped tokens; only a dotted module name (`a.b`, `.a`) takes Python's module rule. Fixes test_edge_data and the graph-metric tests. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01YAtpBfGGyBGGovitSVaM5Q
…atch
A token that matched as a whole file name (lua `dofile("nextvar.lua")`)
already names its file; only a match made through a dotted token's last
segment has to end in the token's package path. Restores cosmopolitan's
20 dofile edges.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01YAtpBfGGyBGGovitSVaM5Q
…t import-graph baseline Golden masters (both fixtures identical in scope): 2443 differences, 2311 of them the corpus-wide Composition Fit z-score (network metrics feed it); 132 direct: Dependency Blast Radius / Popularity Rank and the network summary. Crucible edge diff main -> branch: +229 (220 python __init__ / module edges, 5 zig and 3 typescript relative imports, 1 markdown link), -128 (69 cross-language basename matches such as python `import os` -> bootos/os.asm, 44 python #3544 wrong targets, 13 micropython and 2 java edges to paths the corpus flattened). import_graph_accuracy baseline: python 89.5/58.1 -> 98.9/97.9, typescript 1.9/0.2 -> 91.4/100, javascript 82.9/47.6 -> 90.5/100, java 98.0/98.2 -> 100/100, c recall 91.1 -> 100, zig recall 79.0 -> 94.1, ruby recall 96.2 -> 99.6, perl recall 4.1 -> 100 (precision 100 -> 97.9: the one edge comes from a `use` inside POD). Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01YAtpBfGGyBGGovitSVaM5Q
Contributor
This was referenced Sep 25, 2026
Closed
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
Fixes #3544, #3545, #3552 and #3553; fixes #3554 except its Rust
mod x;part (below).NetworkRiskSensor._resolve_targetresolved every import token by searching the whole repo for its path, file name or stem. It never used the importing file's location or the language's module rule. The new graph-accuracy gate (#3547) measured the cost on 16 pinned real repos. This PR adds the language rules, each declared per language with a new top-level DEFINITION flag, like the existingcase_insensitive_imports/imports_are_source_members..//../token (any language), and every import of a language that searches the importer's directory first, resolves atdirname(importer)/tokenbefore the name search. A token without an extension also takes the same extension-less path or itsindexfile../x.jsalso takesx.ts. A token with any other extension names exactly that file, so<poll.h>is neverpoll.c.imports_resolve_from_importer_dir)a.bisa/b.pyora/b/__init__.pyunder a source root, a directory that isn't itself a package. Sofrom fastapi import Xbindsfastapi/__init__.py, which a stem search could never find, andimport typesisn'tfastapi/types.py. Leading dots are relative to the importing package. Several matches still draw no edge (#261 unchanged). Path-shaped tokens keep the name search.package_init_file)starlette.requestsis not the only localrequests.py. A token that matched as a whole file name (dofile("x.lua")) is exempt.import_path_mirrors_module_path)::is the path separator. Java retries the enclosing class forimport static a.b.C.memberand nesteda.b.Outer.Inner.import_path_separator), java (imports_may_name_member)C#, Kotlin and Scala are deliberately left out of the mirror check, because their namespaces don't mirror files. JS/TS bare specifiers are unchanged.
Measured:
tests/tools/import_graph_accuracy.py(baseline ratcheted in this PR)use HTTP::Request;inside POD documentation inHTTP/Config.pm: the import capture reads the raw file....TestTypes.BagOfPrimitives) lives in the outer class's file; the audit used to score those as unresolvable.Where the remaining gaps are:
"zod/v4/core") matched by basename.@importforms the capture regex doesn't match.mod x;is still not captured. That is the rest of Import forms never resolved: Rustmod x;, Perluse A::B, Java static imports #3554, left for a follow-up because it needs a_dependency_capturechange under the import-count contract.Crucible edge diff (main → this branch, one full-corpus scan each)
+229 edges:
__init__edges;−128 edges:
import os→assembly/bootos/os.asm,import io→scheme/racket/io.ss,import datetime→livecode/.../datetime.livecodescript, and Javaimport java.util.Collection→php/laravel_core/Collection.php.starlette.types→fastapi/types.py.import lib.loggingtargetslib/logging.py, which the corpus stores aslogging.py. Springboot'sBinder.javalost its package directories. No edge is right there.Golden masters
Both fixtures were re-blessed with
crucible_check.py --update --yesand have identical scope: 2,443 differences.fastapi/__init__.pyblast radius goes 0 → 200 andnumpy/__init__.py0 → 7 (Python package imports (from pkg import X) never draw an edge topkg/__init__.py#3545).fastapi/types.pygoes 25 → 16,bootos/os.asm49 → 28 andracket/io.ss24 → 18 (Import resolver links a dotted import to any lone same-named file, ignoring its package path (false dependency edges) #3544).Type of change
network_risk_sensor.py, per-language DEFINITION flags)CI checklist
python tests/tools/audit_check.py: ruff OK, dead-key OK, ast-accuracy OK. mypy reports only the 3 local "stubs not installed for yaml" findings that main has too (none in the touched files).python -m pytest tests/: 11,086 passed. The only error istest_security_auditor.py, because numpy isn't installed locally.crucible_check.py --update --yes: both fixtures, scoped as above.import_graph_accuracy.py(regenerated, the gains above),call_graph_accuracy.py --ciOK,call_graph_resolution.py python --ciOK.Verification
The COBOL
COPYresolution (Stage 3) is untouched;mainframe-ground-truth.ymlchecks it on this PR.🤖 Generated with Claude Code
https://claude.ai/code/session_01YAtpBfGGyBGGovitSVaM5Q