Skip to content

Fix #834: Extraction hardening for powershell - #903

Merged
squid-protocol merged 1 commit into
mainfrom
feature/834-extraction-hardening-powershell
Jul 31, 2026
Merged

squid-protocol merged 1 commit into
mainfrom
feature/834-extraction-hardening-powershell

Conversation

@squid-protocol

Copy link
Copy Markdown
Owner

Summary

Part of the extraction-hardening epic (#813). Closes #834.

Hardens all four extraction gauntlets (func_start, args, class_start, _dependency_capture) for powershell per tests/extraction/how_to_harden_extraction.md. This was a fresh sweep (no pre-flagged known bug) and surfaced four real bugs:

  • args/func_start shared 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_start never recognized PS class constructors (Foo([string]$name) { ... } — no function keyword, 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_start mishandled PowerShell's scope-qualified function names (function global:Foo {}, also script:/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.py showed a real diff, confined entirely to powershell/core plus its own aggregate rollups — no cross-repo ripple this time, unlike scala's #825 _dependency_capture fix (that language's fix materially changed the shared cross-repo dependency graph's topology; this one's fixes didn't).

  • Confirmed severity directly in the real PowerShell Core corpus: Invoke-LinuxTestsCore's detected parameter count jumped 3 → 9 (its param(...) block has a @('Slow', 'Feature', 'Scenario') array-subexpression default value — exactly the nested-paren shape the Rule-11 fix targets), and Test-MsiSignature jumped 2 → 4 for the same reason in a different file.
  • Golden master fixtures (tests/golden_master_audit.json, tests/golden_master_zero_dep_audit.json) re-blessed via crucible_check.py --update --yes; both modes now PASS cleanly.

Checked test_language_standards_strict.py for 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_capture independently 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 bare pytest from an unrelated CWD to reproduce CI's invocation style. test_class_extraction_strict.py had no prior powershell entry at all — class_start had 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)
  • Migrated powershell's cases out of the four monolithic dict files into tests/extraction/languages/test_powershell.py
  • Epic Epic: Harden the four extraction gauntlets (function/args/class/dependency) per language #813 and the methodology doc updated with new recurring bug classes 36-40
  • ReDoS scaling sweeps (n=2000→32000/100000, linear) for all four regex changes

Process 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

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

Copy link
Copy Markdown
Contributor

🐦‍⬛ Muninn Security Scan

✅ No security issues found.

🐦‍⬛ Powered by Muninn · Skald Lab

@squid-protocol
squid-protocol merged commit c6d3d47 into main Jul 31, 2026
28 checks passed
@squid-protocol
squid-protocol deleted the feature/834-extraction-hardening-powershell branch July 31, 2026 16:21
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.

Extraction hardening: powershell

1 participant