Repository navigation
fix(powershell): dot-source quoted/$PSScriptRoot paths and script-scope calls (#4356) - #4369
FabioRueda wants to merge 1 commit into
Conversation
…pe calls (#4356) Two gaps in the PowerShell extractor dropped edges from real-world scripts: - Dot-source only read the path when tree-sitter parsed it as command_name. `. "$PSScriptRoot\lib.ps1"` and `. '.\lib.ps1'` parse as string_literal, and unquoted `. $PSScriptRoot\lib.ps1` as path_command_name, so no imports_from edge was emitted. Accept all three and strip surrounding quotes; the existing basename logic already handles the rest. - Calls were collected only from function/method bodies, so commands at script scope (the main body of most .ps1 scripts) produced no calls edge or raw_call. Walk the file root too, with the file node as the caller. walk_calls stops at function_statement/class_statement, so function bodies are not walked twice (covered by a control test). `. (Join-Path $PSScriptRoot 'lib.ps1')` stays unresolved: the path is only known at runtime. AST cache schema 8 -> 9 so cached results for unchanged .ps1 files are re-extracted. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_013LcXGsdFdpLjYVHemLogkE
|
Thanks for the pull request, @FabioRueda. 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. |
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_013LcXGsdFdpLjYVHemLogkE
|
Ran the full suite on Python 3.10 and 3.13 as requested (Windows 11, separate venvs per Python version and per tree), this branch vs unpatched
The +5 are the new tests. The 13 failures are the same on both trees and both versions, and are Windows-specific: 11 in |
Python property-accessor decorators and `Self` (#4385, #4386), Swift `Self` (#4387), Go generic type params (#4388), the Python forward type-hint file-node fix (#4343), PowerShell dot-source paths (#4369), and the C# verbatim-interpolated-string recovery (#3612) all change AST extraction output, so warm caches must re-extract. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
Shipped in v0.9.88, just released to PyPI as |
What does this PR do?
Fixes #4356. Two gaps in
graphify/extractors/powershell.pydropped edges from ordinary PowerShell scripts:$PSScriptRootpath. The handler only read the path when tree-sitter parsed it ascommand_name.. "$PSScriptRoot\lib.ps1"and. '.\lib.ps1'parse asstring_literal, and unquoted. $PSScriptRoot\lib.ps1aspath_command_name, so noimports_fromedge was emitted. The fix accepts all three node types and strips surrounding quotes; the existing basename logic handles the rest.walk_callsran only over function/method bodies, so commands in a script's main body produced nocallsedge and noraw_call. The fix also walks the file root with the file node as the caller.walk_callsalready stops atfunction_statement/class_statement, so function bodies are not walked twice.Also bumps
_AST_CACHE_SCHEMA8 -> 9 so cached results for unchanged.ps1files are re-extracted (same approach as c68d167).. ./lib.ps1,. .\lib.ps1. "$PSScriptRoot\lib.ps1". $PSScriptRoot\lib.ps1. '.\lib.ps1'. (Join-Path $PSScriptRoot "lib.ps1")Type of change
Verification & Invariants
Invariant: a
.ps1file that dot-sources another file gets animports_fromedge for every statically known path, and every command it invokes, in a function or at script scope, appears exactly once as acallsedge orraw_callattributed to the right caller. Calls inside a function must stay attributed to that function, not to the file; the control testtest_powershell_script_scope_walk_does_not_duplicate_function_callscovers this.Persisted state: AST cache entries written by schema 8 are invalidated by the schema bump.
How was this tested?
Windows 11, Python via
uv sync --all-extras, branch offv8at a5ba60d (0.9.86).Full suite on Python 3.10.21 and 3.13.15 (separate venvs per Python and per tree,
uv run --frozen --all-extras --python X pytest tests -q), this branch vs unpatchedv8:+5 passed = the new tests; the 13 failures are identical on both trees (Windows-specific, listed below).
Graphify-specific checklist
uv run python -m tools.skillgen --bless) when changing their source fragments. (n/a: no skill sources touched)Limitations
. (Join-Path $PSScriptRoot "lib.ps1")and other dot-sources that build the path at runtime stay unresolved.Found while mapping a small PowerShell toolchain repo (FabioRueda/pic-baremetal), where
build.ps1/flash.ps1dot-sourcetoolchain.ps1via$PSScriptRootand callFormat-HexConfigat script scope. The analysis, fix, tests and this description were prepared with Claude Code (agent acting on my behalf).🤖 Generated with Claude Code
https://claude.ai/code/session_013LcXGsdFdpLjYVHemLogkE