Repository navigation
Description
Summary
tests/tools/tree_sitter_accuracy_audit.py --lang csharp reports class_precision 73.3% (found_classes=22, extra_classes=8). All 8 "extra classes" are in a single corpus file, roslyn/LanguageParser.cs: LanguageParser, NameOptions, ParseTypeMode, Precedence, ResetPoint, ScanTypeArgumentListKind, ScanTypeFlags, VariableFlags -- every one a real, correctly-named C# class/enum/struct confirmed present in the corpus source (e.g. private enum NameOptions at line 5997, internal sealed partial class LanguageParser : SyntaxParser at line 20).
Root cause
This is the same ground-truth blind spot as #1427/#1567 (csharp extra_functions), just never extended to the class comparison. tree-sitter-c-sharp's installed grammar fails to parse a C# 11 list-pattern + property-pattern construct partway through LanguageParser.cs; the resulting ERROR node cascade is severe enough that tree.root_node.type itself becomes "ERROR" (confirmed directly) rather than the normal compilation_unit -- i.e. _find_trailing_error_cascade_start correctly detects a cascade for this file (trailing_error_start computed, non-None), but that detection is currently only applied to the function comparison (measure(), line ~1811-1812: unmatched_gg = [occ for occ in unmatched_gg if occ[0] < trailing_error_start]). The class comparison (line ~1793-1794: metrics["extra_classes"] += len(gg_classes - real_classes)) has no equivalent filtering at all, so every real GitGalaxy-found class whose defining node never survived the cascade (including the outer LanguageParser class itself, whose body span covers the entire corrupted region and so never resolves into a proper class_declaration node at all, even though it starts at line 20 -- well before the cascade's textual start) gets counted as a false "extra".
This is precision-only; csharp's class_recall (91.7%) is a separate, already-understood/accepted limitation (ground truth is genuinely blind past the cascade) and isn't being touched by this fix.
Suggested fix
Extend the existing trailing_error_start gate to the class comparison. Caveat: unlike function_data, class_data (gitgalaxy/recorders/record_keeper.py) has no start_line column, so the precise per-occurrence line-based filtering functions use (occ[0] < trailing_error_start) isn't directly available for classes. Recommend a coarser, file-level version instead of a schema change: when trailing_error_start is not None for a file, skip adding that file's gg_classes - real_classes to extra_classes entirely (rather than trying to determine which individual GG-found class names fall before/after the cascade point). This is a strict scope match for the evidence here -- trailing_error_start for LanguageParser.cs resolves to line 1 (the cascade swallows the root node itself), so a file-level exclusion produces the identical outcome an occurrence-level one would for this file, without adding a start_line column to a production DB table just to serve one audit tool.
Out of scope
- Adding
start_linetoclass_datafor finer-grained (occurrence-level, not file-level) future filtering -- real option if a future file needs the extra precision, but no evidence yet that this file-level version is too coarse for any real corpus file. - c's own class_start precision gap (78.2%) has a completely different, unrelated root cause (
Anonymous_Classsynthetic placeholder name) -- filed separately as c class_start: extra_classes measures the tool's own synthetic 'Anonymous_Class' placeholder against tree-sitter, understating class_precision #1641.
Scope note: this only affects the tree-sitter-accuracy measurement's class_precision number (epic #1261/#813's extraction-pillar naming accuracy), not GitGalaxy's actual risk-scoring output.
Activity
fix(testing): tree-sitter accuracy audit -- fix c/csharp class_start …