Repository navigation
Description
Summary
tests/tools/tree_sitter_accuracy_audit.py --lang powershell measures func_start recall at only
69.1% (76/110 real functions found). Root cause confirmed via direct pipeline tracing: this is
NOT a func_start regex gap (the regex correctly matches every real function name at its correct
line) -- it's a downstream slicing bug where a script-level param(...) block gets misidentified
as a function definition and its body-span calculation swallows the rest of the file, causing
every subsequent real function in that file to be silently dropped.
Repro
language-crucible/data/powershell/core/Install-PowerShellRemoting.ps1: confirmed via direct
func_start.finditer() that the regex correctly matches all 3 real functions in this file
(Register-WinRmPlugin at line 36, New-PluginConfigFile at line 89, Install-PluginEndpoint
at line 113) at their correct positions -- alongside 3 spurious matches on the bare word param
(lines 20, 91, 114), each preceded by a [CmdletBinding(...)] attribute:
[CmdletBinding(DefaultParameterSetName = "NotByPath")]
param
(
[parameter(Mandatory = $true, ParameterSetName = "ByPath")]
[switch]$Force,
[string]
$PowerShellHome
)
Set-StrictMode -Version 3.0
... (more script-level code) ...
function Register-WinRmPlugin
{
...But a full galaxyscope scan of just this one file finds exactly ONE function total:
param, with an LOC of 212 -- i.e. its body span (via Mode B's _slice_by_braces) is
mis-calculated to extend across virtually the ENTIRE REST OF THE FILE, absorbing all 3 real
functions into its own (bogus) body and causing them to be skipped as already-covered.
Suggested fix shape
This is a variant of the "Invocation Shield" bug class already fixed for 7 other languages via
#1221 -- func_start's third alternative (the brace-anchored constructor/call shape,
([A-Za-z_]\w*)\s*\((?:[^()]|\([^()]*\))*\)\s*[ \t\n]*\{) matches param + its parameter-list
parens, then searches forward through an UNBOUNDED [ \t\n]* gap for the next { -- but a
top-level param(...) block is followed by ordinary script statements (not immediately a {),
so the match likely succeeds by reaching across many lines to the first { of some unrelated
later construct (an if block, or the next real function ... {), then Mode B's own brace-depth
counting compounds the error by treating THAT as param's own body open. Needs its own
root-cause trace into _slice_by_braces's brace-matching for this specific match (this issue
only traces it as far as confirming the regex match positions and the resulting DB output; the
exact point where the oversized span gets computed -- likely in _slice_by_braces or
_find_balanced_end -- needs a closer look). Consider either: excluding param as a reserved
non-function name for this alternative (PowerShell's param block is a language keyword, not a
user-definable function name), or tightening the alternative's trailing lookahead the same way
csharp's zero-prefix branch was tightened in #1418 (require the { to follow with only the
param-list's own closing paren in between, not an unbounded gap).
Scope note
This only affects func_start/args/class_start name-extraction accuracy (the extraction-
gauntlet pillar from epic #813), not GitGalaxy's risk-scoring rules, which are unaffected.
Activity
fix(powershell): exclude 'param' from func_start + use powershell-cor…