Repository navigation
Description
🛑 Problem Statement
Found while investigating #378 (part of #325's dead key audit). This is a much larger finding than #378 originally scoped, so it's filed separately and #378 stays focused on the narrower mechanical_families key itself.
prism.py's split_streams() never actually strips comments from the code stream, for any of the 58 supported languages, in production. Verified empirically, not just by reading code:
p = Prism(LEXICAL_FAMILY_HEURISTICS, LANGUAGE_DEFINITIONS) # the REAL config, not a test mock
result = p.split_streams("x = 1 # this is a comment\ny = 2\n", "python")
result["code_stream"] # 'x = 1 # this is a comment\ny = 2\n' -- comment NOT stripped
result["comment_stream"] # '' -- emptySame result for c, and (by construction) every other language.
Root cause
split_streams() special-cases exactly three family names for dedicated stripping logic:
if family == "recursive_c_style": ... # -> _strip_nested_comments
if family == "column_sensitive": ... # -> _strip_positional_comments
if family == "single_line_only": ... # -> _strip_single_line_commentsEverything else falls through to a "generic stripper" driven by self.REGEX_MATRIX, built from self._compile_regex_matrix(), which iterates self.lexical_families -- itself comment_definitions.get("mechanical_families", {}) (#378's dead key). Since that key never existed, self.lexical_families and self.REGEX_MATRIX are always empty, so the generic stripper always returns None for pattern and passes text through untouched.
But the deeper problem: none of the three special-cased family names match the real taxonomy either. The actual lexical_family values used across language_standards.py (confirmed via Counter over all 58 entries) are:
standard_block: 29 line_exclusive: 21 recursive_block: 3
positional_anchored: 3 block_exclusive: 1 non_lexical: 1
None of "recursive_c_style", "column_sensitive", "single_line_only" appear anywhere in that list. So every single language falls through to the always-empty generic stripper -- not just the 29 "standard_block" languages. The only comment/doc extraction that happens at all is Python/Ruby's docstring pre-pass and PHP's heredoc pre-pass, both of which run before the family dispatch and only catch triple-quoted/heredoc string literals, not #////block comments.
Why this went undetected
tests/core_engine/test_prism.py's entire suite runs against a hand-built mock config:
MOCK_COMMENT_DEFS = {
"mechanical_families": {
"c_style_comment": {...}, "single_line_only": {...},
"recursive_c_style": {...}, "column_sensitive": {...},
}
}
MOCK_LANG_DEFS = {"c": {"lexical_family": "c_style_comment"}, ...}This mock is internally consistent (its keys match its own lexical_family values, and match split_streams()'s special cases) but has never matched the real gitgalaxy_config.py/language_standards.py taxonomy. Every prism.py test passes; none of them exercise the real config.
🎯 Impact
For the entire codebase this engine scans, in every supported language:
- Comment text is never separated from code, so every regex-based structural/security signal (branch, io, secrets, high_risk_execution, TODO/FIXME, etc.) can be triggered by comment text, not just real code.
coding_loccounts include comment-only lines.- Doc-comment/docstring extraction never correctly separates from code, for any language except the narrow Python/Ruby/PHP string-literal cases.
🛠️ Scoping notes (not yet a proposed fix)
Two possible directions:
- Realign
prism.py's special-case names and_compile_regex_matrix()'s expectedfam_keys to the real taxonomy (standard_block,line_exclusive,recursive_block,block_exclusive,positional_anchored,non_lexical) -- contained toprism.py, smaller blast radius. - Rename the real taxonomy in
gitgalaxy_config.py/all 58language_standards.pyentries to match whatprism.pycurrently expects -- touches every language definition, much larger blast radius.
(1) is very likely the right direction given it's a single-file change vs. 58 call sites, but needs careful mapping of each real family's semantics/delimiter shape to the right _compile_regex_matrix() branch (e.g. standard_block's 29 languages need to land on whatever branch currently handles "c_style_comment"-shaped delimiter lists).
This will very likely shift golden_master.json (the CI-gated fixture #330 says needs "deliberate, reviewable updates... not silent overwrite") across a large fraction of the corpus, since LOC counts and every regex-based signal count will change once comments actually stop leaking into code. test_prism.py's mock config also needs to be replaced with (or cross-checked against) the real config so this class of bug can't recur silently.
✅ Acceptance Criteria
-
split_streams()correctly strips comments for a real file in each of the 6 real family categories, proven by a test against the REALLANGUAGE_DEFINITIONS/LEXICAL_FAMILY_HEURISTICS, not a mock. -
test_prism.py's mock config is replaced or reconciled with the real config so a future rename/refactor can't silently diverge again. -
golden_master.jsonis deliberately, reviewably updated to reflect the corrected LOC/signal counts (per Require deliberate, reviewable updates to the golden_master.json fixture instead of silent overwrite #330's philosophy), not silently regenerated.
Activity
Fix TYPOSQUAT_WHITELIST, typosquat_hits, and disqualifiers (#375, #376,
Fix TYPOSQUAT_WHITELIST, typosquat_hits, and disqualifiers (#375, #376,
Fix TYPOSQUAT_WHITELIST, typosquat_hits, and disqualifiers (#375, #376,
Fix prism.py's comment-family taxonomy -- comment/code separation was…
Fix prism.py's comment-family taxonomy -- comment/code separation was…
Fix a missed "recursive_c_style" reference in _strip_nested_comments (#…
Scope golden-crucible to language-crucible/data, pin the corpus, and …
Scope golden-crucible to language-crucible/data, pin the corpus, and …
Close #622: strict tests for prism's real per-family comment stripping (