Skip to content

fix(powershell): strip the extension from a using module or assembly name - #4847

Closed
ayushcodes10 wants to merge 2 commits into
Graphify-Labs:v8from
ayushcodes10:fix-powershell-using-module-assembly-extension
Closed

ayushcodes10 wants to merge 2 commits into
Graphify-Labs:v8from
ayushcodes10:fix-powershell-using-module-assembly-extension

Conversation

@ayushcodes10

Copy link
Copy Markdown
Contributor

Bug

PowerShell's using statement 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 for namespace (a dotted hierarchy where the last segment is the piece wanted), but wrong for module/assembly, whose value is a file or library name with an extension, not a namespace path. using module Helpers.psm1 resolved the import edge to psm1 (the extension) instead of helpers, and using assembly System.Data.dll resolved to dll.

No existing issue or PR covers this; found via self-audit of graphify/extractors/powershell.py (objc.py had no genuine bug after a full read). Searched gh pr list/gh issue list for "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 for module/assembly, matching the convention already used elsewhere in this file for Import-Module and dot-sourcing.

Tests

Added to tests/test_languages.py:

  • test_powershell_using_module_with_extension_resolves_to_stem
  • test_powershell_using_assembly_with_extension_resolves_to_stem
  • test_powershell_using_namespace_keeps_last_segment (control, confirms namespace behavior is unchanged)

Verification

  • Confirmed the bug pre-fix: using module Helpers.psm1 resolved to psm1, using assembly System.Data.dll resolved to dll.
  • Full suite: 2 failed, 8893 passed, 81 skipped, 1 xfailed — the 2 failures are the pre-existing flakes in test_erlang_extractor.py and the skill backtick test, unrelated to this change.
  • python3 -m tools.skillgen --check: check OK: 134 artifact(s) match committed output and expected/.

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

Copy link
Copy Markdown

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.

@github-actions github-actions Bot added the contributor Pull request from a returning community contributor label Oct 28, 2026

@graphify-labs graphify-labs Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

safishamsi added a commit that referenced this pull request Oct 30, 2026
…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]>
@safishamsi

Copy link
Copy Markdown
Member

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.

@safishamsi safishamsi closed this Oct 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contributor Pull request from a returning community contributor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants