You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug]: PowerShell dot-source (. file.ps1) creates no imports edge, and script-scope calls are dropped #4356
Version: graphifyy 0.9.63 · Microsoft Windows 11 Home Single Language · Python 3.11.9
Summary
In PowerShell files, two common cross-file patterns produce no edges:
Dot-sourcing another script (. "$PSScriptRoot\lib.ps1") creates no imports edge from the caller file to the sourced file. Dot-sourcing is PowerShell's equivalent of an import, so the file-level dependency is lost.
Calls made at script scope (outside any function) are dropped. Only calls inside a function body get an edge.
Calls inside functions do resolve across files (as INFERRED), so the gap is limited to these two cases. They are the usual shape of PowerShell entry-point scripts: dot-source a library at the top, then call its functions at script scope.
frompathlibimportPathfromgraphify.extractimportextractd=Path(r"<folder with the two files>")
r=extract([d/"main.ps1", d/"lib.ps1"], cache_root=d)
print([n["id"] forninr["nodes"]])
foreinr["edges"]:
print(e["source"], e["relation"], e["target"], e.get("confidence"))
main imports lib (EXTRACTED), from the dot-source line.
main calls main_invoke_main, from the script-scope call on line 3 (with the file node as the caller).
Impact
In a real repo (a few PowerShell build/flash scripts that dot-source a shared toolchain.ps1 and a helper module), the graph showed the scripts as unconnected. Every --update that re-extracted those files dropped any hand-added edges, so they had to be re-added after each run.
Related, but different: #3992 and #4158 (PowerShell method-call resolution).
Root cause and a fix for this, checked against v8 at a5ba60d (0.9.86). Fix with regression tests: #4369.
Root cause (graphify/extractors/powershell.py)
Dot-source (around L264-L280). The path is read only from a command_name child of command_name_expr. tree-sitter-powershell parses the common forms differently:
Script-scope calls (L415-L416).walk_calls runs only over function_bodies, so commands in a script's main body never become calls edges or raw_calls. Calls inside functions do resolve across files, which is why this looked partial.
frompathlibimportPathfromgraphify.extractors.powershellimportextract_powershellr=extract_powershell(Path("repro/main.ps1"))
print([eforeinr["edges"] ife["relation"] =="imports_from"]) # [] on 0.9.86print(r["raw_calls"]) # [] on 0.9.86, Helper is missing
Accept command_name, path_command_name and string_literal and strip surrounding quotes. The existing basename logic does the rest.
Also call walk_calls(root, file_nid, None). walk_calls already stops at function_statement/class_statement, so function bodies are not walked twice; a control test covers this.
_AST_CACHE_SCHEMA 8 -> 9, so cached results for unchanged .ps1 files are refreshed.
The new tests fail on v8 (4 of 5; the 5th is the no-duplication control) and pass with the fix. Full suite and lint results are in the PR description. Prepared with Claude Code on my behalf.
Activity
github-actions commentedon Oct 12, 2026
Thanks for opening this issue, @FabioRueda. A maintainer will take a look soon.
If you would like to discuss it in real time, come say hi on our Discord server. For longer-form questions and ideas there is also GitHub Discussions.
To help us triage, please make sure the report includes what you expected, what actually happened, and the steps (and a small sample) to reproduce it.
FabioRueda commentedon Oct 12, 2026
Root cause and a fix for this, checked against
v8at a5ba60d (0.9.86). Fix with regression tests: #4369.Root cause (
graphify/extractors/powershell.py)command_namechild ofcommand_name_expr. tree-sitter-powershell parses the common forms differently:. ./lib.ps1,. .\lib.ps1->command_name(handled). "$PSScriptRoot\lib.ps1",. '.\lib.ps1'->string_literal(skipped). $PSScriptRoot\lib.ps1->path_command_name(skipped). (Join-Path $PSScriptRoot "lib.ps1")->parenthesized_expression(runtime-only path)walk_callsruns only overfunction_bodies, so commands in a script's main body never becomecallsedges orraw_calls. Calls inside functions do resolve across files, which is why this looked partial.Minimal repro
Variant results on 0.9.86 / with #4369:
. ./lib.ps1,. .\lib.ps1. "$PSScriptRoot\lib.ps1". $PSScriptRoot\lib.ps1. '.\lib.ps1'. (Join-Path $PSScriptRoot "lib.ps1")The fix in #4369
command_name,path_command_nameandstring_literaland strip surrounding quotes. The existing basename logic does the rest.walk_calls(root, file_nid, None).walk_callsalready stops atfunction_statement/class_statement, so function bodies are not walked twice; a control test covers this._AST_CACHE_SCHEMA8 -> 9, so cached results for unchanged.ps1files are refreshed.The new tests fail on
v8(4 of 5; the 5th is the no-duplication control) and pass with the fix. Full suite and lint results are in the PR description. Prepared with Claude Code on my behalf.fix(extract): resolve quoted dot-source and script-scope calls in Pow…
fix(powershell): dot-source quoted/$PSScriptRoot paths and script-sco…
safishamsi commentedon Oct 12, 2026
Fixed in v0.9.88 (
graphifyy 0.9.88on PyPI) via #4369.