Repository navigation
fix(powershell): strip the extension from a using module or assembly name - #4847
ayushcodes10 wants to merge 2 commits into
Conversation
The using statement handler took the last dotted segment of the value for all three forms: namespace, module and assembly. That is correct for namespace, a dotted hierarchy where the last segment is the piece wanted, but wrong for module and assembly, whose value is a file or library name with an extension rather than a namespace path. using module Helpers.psm1 resolved the import edge to psm1 instead of helpers, and using assembly System.Data.dll resolved to dll. Branch on the leading keyword: keep last segment splitting for namespace, but strip the trailing extension for module and assembly, matching the convention already used elsewhere in this file for Import Module and dot sourcing.
Covers using module Helpers.psm1 and using assembly System.Data.dll resolving to the library name rather than its extension, plus a control confirming using namespace keeps its existing last segment behavior.
|
Thanks for the pull request, @ayushcodes10. A maintainer will review it soon. Want to talk it through while it is in review? Come join us on our Discord server. For longer-form discussion there is also GitHub Discussions. A couple of things that speed up review: make sure the test suite passes on Python 3.10 and 3.13, and that the change keeps extraction deterministic. |
There was a problem hiding this comment.
Graphify reviewed this change.
Worth a look — the grounded gate found no coupling regressions or blocking issues, but 2 advisory finding(s) below merit a look before merge.
Not checked: tests were not run; formal verification proved 0 of 1 changed function(s) (1 sampled, not proven).
Formal verification. PR-changed functions: 1/1 verified (0 proven, 1 may-equivalent, 0 distinguished) · 0 not verified.
Graphify review — findings
Fixes PowerShell using module and using assembly statements so the import edge targets the module or library name (Helpers, System.Data) instead of the trailing extension (psm1, dll). using namespace still takes the last dotted segment, since there the dot is a real namespace separator. The module/assembly branch strips a trailing .ext and then any directory prefix, so a dotted name with no extension or a dotted relative path can lose or mangle its final segment.
Worth a look
- Dotted module names without extension lose their final segment —
graphify/extractors/powershell.py:308· Escalate · medium- NOT verified (no proof, no reproducing execution) — needs human review
- Extension regex applied before path split mangles relative/dotted paths —
graphify/extractors/powershell.py:308· Escalate · medium- NOT verified (no proof, no reproducing execution) — needs human review
Analysis details — impact, health, verification
Impact & health
Graphify review
Impact — 736 functions depend on the 736 functions this change touches.
Health — this change adds coupling hotspots:
- worse:
extract_powershell()— 31 callers, 7 callees
Verification — 736 functions in the blast radius were not formally verified this run (proofs are advisory here).
Gate & verification
graphify gate
PASS — objectively clean (no health regressions, tests not run — proofs not run this pass (advisory)). Grounded, not self-assessed.
Advisory (not blocking):
- verification_scope: 736 function(s) in the blast radius were not formally verified this run
Test selection
Test selection
1 of 469 test file(s) selected (0%) via static blast radius.
tests/test_languages.py— impact, changed-test
Selection is safe under the controlled-regression assumption; always-run tests + a periodic full run are the backstops. Advisory — it never changes the check verdict.
Formal verification
No difference found (not proven): No behavior difference found in extract\_powershell (not a proof).
The verifier ran both versions of extract\_powershell on many inputs and saw identical behavior every time. Strong evidence the change is safe, but evidence, not a proof.
Guarantee: Empirical: differential testing (both versions run on many generated inputs). A divergence on an untested input remains possible, so this is 'no counterexample found', not 'proven equivalent'.
Note: An input the sampler did not try could still differ.
· 1 more finding(s) on lines outside this diff (see the check run).
…using name Follow-up to #4847. Its fix stripped any trailing dotted segment, so a dotted module name with no file extension (using module Az.Accounts) resolved to 'az' (dropping .Accounts). Restrict the strip to real module/assembly suffixes (.psm1/.psd1/.ps1/.dll/.exe) so file names like Helpers.psm1 still resolve to 'helpers' while Az.Accounts keeps its full name. Adds a regression test. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
Landed in v0.9.98, now on PyPI (pip install graphifyy==0.9.98). using module/assembly drops a real file extension but keeps a dotted module name intact. Thanks for the fix, @ayushcodes10. |
Bug
PowerShell's
usingstatement handler (extract_powershell) took the last dotted segment of the value for all three forms:using namespace X.Y,using module X,using assembly X. That's correct fornamespace(a dotted hierarchy where the last segment is the piece wanted), but wrong formodule/assembly, whose value is a file or library name with an extension, not a namespace path.using module Helpers.psm1resolved the import edge topsm1(the extension) instead ofhelpers, andusing assembly System.Data.dllresolved todll.No existing issue or PR covers this; found via self-audit of
graphify/extractors/powershell.py(objc.pyhad no genuine bug after a full read). Searchedgh pr list/gh issue listfor "using module"/"using namespace"/"module_tokens" — nothing claims this.Fix
Branch on the leading keyword: keep last-segment splitting for
namespace, but strip the trailing extension formodule/assembly, matching the convention already used elsewhere in this file forImport-Moduleand dot-sourcing.Tests
Added to
tests/test_languages.py:test_powershell_using_module_with_extension_resolves_to_stemtest_powershell_using_assembly_with_extension_resolves_to_stemtest_powershell_using_namespace_keeps_last_segment(control, confirmsnamespacebehavior is unchanged)Verification
using module Helpers.psm1resolved topsm1,using assembly System.Data.dllresolved todll.2 failed, 8893 passed, 81 skipped, 1 xfailed— the 2 failures are the pre-existing flakes intest_erlang_extractor.pyand the skill backtick test, unrelated to this change.python3 -m tools.skillgen --check:check OK: 134 artifact(s) match committed output and expected/.