Repository navigation
Fix #834: Extraction hardening for powershell - #903
Merged
Merged
Conversation
Hardens all four extraction gauntlets (func_start, args, class_start,
_dependency_capture) for powershell per
tests/extraction/how_to_harden_extraction.md. A fresh sweep surfaced
four real bugs:
- args/func_start shared the flat `\([^)]*\)` Rule-11 paren-list
step-over, breaking on default-value expressions containing their
own parens (`param($Tag = @('Slow', 'Feature'))`, a realistic
idiom). Widened to the established one-level-nesting idiom.
- PS class constructors (`Foo([string]$name) { ... }`, no `function`
keyword, no return-type bracket) were entirely invisible to
args/func_start. Added as a new alternative anchored to a trailing
`{` -- which in turn collided with PowerShell's own control-flow
statement shape (`if/while/switch/for/foreach (cond) { body }`)
until a negative-lookahead keyword exclusion was added.
- PowerShell scope-qualified function names (`function global:Foo
{}`, also script:/local:/private:) caused the name capture to
silently return the scope keyword itself instead of the real name
-- confidently wrong output, not just a non-match.
- _dependency_capture's optional-quote-pair idiom (`['"]?...['"]?`
around a whitespace-excluding class) truncated any quoted import
path containing a space -- the common Windows
`'C:\Program Files\...'` shape. Replaced with real per-quote-style
alternatives.
crucible_check.py showed a real diff, confirmed severity via the real
PowerShell Core corpus (one function's detected parameter count
jumped 3 -> 9) and confirmed the diff confined entirely to
powershell/core plus its own aggregate rollups -- no cross-repo
ripple this time, unlike scala's #825 _dependency_capture fix (this
language's fixes didn't materially change the shared dependency
graph's topology). Golden master fixtures re-blessed.
Checked test_language_standards_strict.py for intentional powershell
behavior before finalizing -- no conflicts; existing regression tests
pass unmodified. Migrated powershell's cases out of the four
monolithic dict files into tests/extraction/languages/test_powershell.py
(68 tests; test_class_extraction_strict.py had no prior powershell
entry at all -- class_start had zero test coverage before this).
Two known limitations documented: func_start's Mode-B
string-shielding gap reproduces via here-strings (a tenth language);
_dependency_capture reproduces the same here-string vector
independently, while confirmed structurally immune to the
comment-lookalike variant (second language with this negative result,
after c).
Epic #813 and the methodology doc updated with recurring bug classes
36-40.
Co-Authored-By: Claude Sonnet 5 <[email protected]>
Contributor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Part of the extraction-hardening epic (#813). Closes #834.
Hardens all four extraction gauntlets (
func_start,args,class_start,_dependency_capture) for powershell pertests/extraction/how_to_harden_extraction.md. This was a fresh sweep (no pre-flagged known bug) and surfaced four real bugs:args/func_startshared a flat\([^)]*\)Rule-11 paren-list step-over, breaking on default-value expressions containing their own parens (param($Tag = @('Slow', 'Feature')), a realistic idiom). Widened to the established one-level-nesting idiom.args/func_startnever recognized PS class constructors (Foo([string]$name) { ... }— nofunctionkeyword, no return-type bracket) at all. Added as a new alternative anchored to a trailing{— which, while testing the fix's own "invalid" case, turned out to collide with PowerShell's own control-flow statement shape (if/while/switch/for/foreach (cond) { body }, textually identical to a bare constructor call). Fixed with a negative-lookahead keyword exclusion before shipping.args/func_startmishandled PowerShell's scope-qualified function names (function global:Foo {}, alsoscript:/local:/private:) — the identifier class didn't include:, so the capture silently returned the scope keyword itself ("global") as the function name instead of failing to match. Confidently wrong output, not a safe non-match._dependency_capture's optional-quote-pair idiom (['"]?...['"]?around a whitespace-excluding class) truncated any quoted import path containing a space — the extremely common Windows'C:\Program Files\MyModule\MyModule.psd1'shape. Replaced with real per-quote-style alternatives (quoted branches permit the space; the bare/unquoted branch still excludes it, since an unquoted PS path genuinely can't contain one).Differential Scan
crucible_check.pyshowed a real diff, confined entirely topowershell/coreplus its own aggregate rollups — no cross-repo ripple this time, unlike scala's #825_dependency_capturefix (that language's fix materially changed the shared cross-repo dependency graph's topology; this one's fixes didn't).Invoke-LinuxTestsCore's detected parameter count jumped 3 → 9 (itsparam(...)block has a@('Slow', 'Feature', 'Scenario')array-subexpression default value — exactly the nested-paren shape the Rule-11 fix targets), andTest-MsiSignaturejumped 2 → 4 for the same reason in a different file.tests/golden_master_audit.json,tests/golden_master_zero_dep_audit.json) re-blessed viacrucible_check.py --update --yes; both modes now PASS cleanly.Checked
test_language_standards_strict.pyfor intentional powershell behavior before finalizing (per c's #822 lesson) — no conflicts; existing regression tests pass unmodified.Also documents two known, unfixed limitations:
func_start's Mode-B string-shielding gap reproduces via here-strings (@"..."@, now confirmed on a tenth language);_dependency_captureindependently reproduces the same here-string vector, while being confirmed structurally immune to the comment-lookalike variant (a second language with this specific negative result, after c's #822 finding) — PowerShell's#comment marker isn't whitespace, so it blocks the rule's own^[ \t]*anchor.Test plan
pytest tests/extraction/languages/test_powershell.py(68 tests) — run via barepytestfrom an unrelated CWD to reproduce CI's invocation style.test_class_extraction_strict.pyhad no prior powershell entry at all —class_starthad zero test coverage before this.python -m pytest tests/— 4054 passed, 1 deselected, 1 xfailed (pre-existing, unrelated)python tests/tools/audit_check.py— clean (ruff/mypy/dead-key baselines unchanged)python tests/tools/crucible_check.py— PASS on both venvs after re-blessing (see Differential Scan above)tests/extraction/languages/test_powershell.pyProcess note
Used the new self-scan DB tool (#901, merged just before this PR) for initial file-level orientation (sizes, existing test-file inventory) instead of grep/an Explore subagent — the actual regex/dict-internal work still required grep + Read as usual, since the DB doesn't parse
LANGUAGE_DEFINITIONS' dict-literal internals. Details on what that saved (and didn't) to follow separately.🤖 Generated with Claude Code