Skip to content

fix(parser): extract PowerShell functions, classes, methods and command calls - #1079

Open
azizur100389 wants to merge 5 commits into
tirth8205:stagingfrom
azizur100389:codex/fix-powershell-extraction
Open

azizur100389 wants to merge 5 commits into
tirth8205:stagingfrom
azizur100389:codex/fix-powershell-extraction

Conversation

@azizur100389

@azizur100389 azizur100389 commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Linked issue

Closes #1067.

What & why

PowerShell declarations were discarded because their grammar names are function_name/simple_name, and the configured call node did not exist. Read those names, index class_method_definition, and extract command calls. Treat the approved Test-* verb as production code outside test files. Regression coverage includes .ps1/.psm1 declarations, method scope, internal and top-level calls, test-file classification, and Python/Bash compatibility.

How it was tested

Following the same staged regression/baseline methodology used in my earlier PRs (#274, #276, #279, #353 and #354), against the current contribution target staging at 6b12d11625cbec3b6773e076cb3d136464fa90e5.

  • New regression tests: 7/7 passed on Windows, Python 3.13.14. The reported bug reproduces on unchanged staging before the fix.
  • Initial affected-module run: 629 passed, 13 baseline failures. Every failure also reproduces on unchanged staging (compared by JUnit test identity). The final expanded regression module passed separately; no new affected-module failures.
  • ruff check code_review_graph tests/test_powershell_extraction.py: clean.
  • bandit -r code_review_graph/ -c pyproject.toml: zero findings.
  • mypy code_review_graph/ --ignore-missing-imports --no-strict-optional: the same three existing Windows fcntl.LOCK_EX/LOCK_NB/flock errors in daemon.py as unchanged staging; no new errors.
  • Schema remains version 13 on both Python and VS Code sides.
  • GitHub CI: 17 checks passed on the final commit. Python 3.10–3.13, browser tests, Windows native tests, and the Linux/macOS/Windows MCP client checks are green. Python 3.13 full-suite result: 4275 passed, 804 skipped, 46 deselected, 2 xfailed, 2 xpassed; 85.86% coverage (65% required). The manual upgrade job is skipped by design.

Exact test commands (using a local virtual environment with .[dev], as uv is not installed):

python -m pytest tests/test_powershell_extraction.py -q --tb=short
python -m pytest tests/test_powershell_extraction.py tests/test_parser.py tests/test_multilang.py -q --tb=short
$env:GIT_CEILING_DIRECTORIES = $env:TEMP.Replace('\', '/')
python -m pytest --tb=short -q -m 'not browser and not upgrade' --cov=code_review_graph --cov-report=term --cov-fail-under=65

Full local Windows suite completed: 4,149 passed, 111 failed, 819 skipped, 46 deselected, 2 xfailed, 2 xpassed; 86% coverage. Unchanged staging: 4,143 passed, 110 failed, with identical skip/xfail/xpass counts. All 110 staging failures also occur here. The one additional failure was TestRealObserver::test_deleting_a_watched_directory_does_not_kill_the_watcher with RuntimeError('Failed joining thread'); it passed 3/3 isolated reruns on this branch and 3/3 on unchanged staging, indicating an intermittent Windows observer thread failure. No reproducible new failure was found. The Git ceiling isolates temporary test repositories from an unrelated enclosing home-directory Git repository; PATH/PYTHONPATH point to each checkout under test. Browser tests passed in CI; browser and opt-in upgrade suites were excluded locally.

@github-actions

github-actions Bot commented Oct 1, 2026 •

Copy link
Copy Markdown

code-review-graph review

Overall risk: 0.40 (MEDIUM) — 12 changed function(s)/class(es), 0 affected flow(s), 3 test gap(s)

Risk-scored changes

Risk Level Symbol Location Tested
0.40 medium code_review_graph/parser.py::CodeParser._get_name code_review_graph/parser.py:17027 no
0.40 medium code_review_graph/parser.py::CodeParser._get_call_name code_review_graph/parser.py:18499 no
0.15 low code_review_graph/parser.py::CodeParser code_review_graph/parser.py:2955 yes
0.10 low code_review_graph/parser.py::CodeParser._extract_functions code_review_graph/parser.py:11825 no
0.05 low tests/test_powershell_extraction.py::test_extracts_declarations_and_method_scope tests/test_powershell_extraction.py:24 (test)
0.05 low tests/test_powershell_extraction.py::test_extracts_internal_and_top_level_calls tests/test_powershell_extraction.py:33 (test)
0.05 low tests/test_powershell_extraction.py::test_approved_test_verb_is_production_code tests/test_powershell_extraction.py:42 (test)
0.05 low tests/test_powershell_extraction.py::test_approved_test_verb_in_test_file_is_still_test_code tests/test_powershell_extraction.py:49 (test)
0.05 low tests/test_powershell_extraction.py::test_numeric_ranges_are_not_command_calls tests/test_powershell_extraction.py:71 (test)
0.05 low tests/test_powershell_extraction.py::test_range_like_command_names_remain_calls tests/test_powershell_extraction.py:81 (test)

Test gaps

  • code_review_graph/parser.py::CodeParser._extract_functions (code_review_graph/parser.py:11825)
  • code_review_graph/parser.py::CodeParser._get_name (code_review_graph/parser.py:17027)
  • code_review_graph/parser.py::CodeParser._get_call_name (code_review_graph/parser.py:18499)

Token savings: this graph-backed report used ~193,007 fewer tokens (~99%) than reading every changed file in full (estimated, chars/4 approximation).


Powered by code-review-graph — local-first analysis; no code leaves the CI runner.

@tirth8205

Copy link
Copy Markdown
Owner

Thank you for this PR.
I built graphs from PowerShell scripts and ran the parser tests.
Before I can merge it, please fix these:

  1. Number ranges become fake calls. The range is read as a command name. Where: code_review_graph/parser.py:18579. Example: function Get-Many { foreach ($i in 1..3) { Get-Leaf } } gives a call to "1..3". 1..10 | Measure-Object does the same.
  2. A method named Test() is stored as a test. Every DSC class resource has one. The functions it calls then look tested. Where: code_review_graph/parser.py:11874. Example: class R { [bool] Test() { return Get-State } } in a .psm1 file outside tests/. Using the test-path check for every PowerShell name fixes it.

After you push the fix, I will test it again.

@azizur100389

Copy link
Copy Markdown
Contributor Author

Hi @tirth8205, the review issues have been fixed and pushed, with regression tests covering the reported cases.

Numeric ranges no longer produce fake calls, including decimal, hexadecimal, binary, and suffixed literals. PowerShell test classification now uses the file path, so production DSC Test() methods are not marked as tests.

I rechecked CI today: all 17 checks are passing, with the upgrade-path check intentionally skipped. The branch is also up to date with staging and has no merge conflicts.

Could you please retest the updated PR when you have a chance? Thank you!

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PowerShell: no functions, classes or calls are extracted (function_name and simple_name never read; command_expression is not a node kind)

2 participants