Repository navigation
Fix prism.py's comment-family taxonomy -- comment/code separation was broken for all 58 languages (#386) - #389
Merged
Conversation
… completely broken for all 58 languages (#386) Root cause (see #386 for the full empirical investigation): split_streams() special-cased exactly three family names ("recursive_c_style", "column_sensitive", "single_line_only") for dedicated stripping logic, and fell back to a REGEX_MATRIX built from comment_definitions.get( "mechanical_families", {}) for everything else -- a key nothing ever wrote (#378's original dead-key finding). But even fixing that key name alone wouldn't have been enough: none of the three special-cased names, nor the matrix-building fam_keys ("c_style_comment", "single_line_only", "embedded_syntax", "multi_style_dash"), matched the REAL per-language "lexical_family" taxonomy actually used across language_standards.py (standard_block: 29 languages, line_exclusive: 21, recursive_block: 3, positional_anchored: 3, block_exclusive: 1, non_lexical: 1). So every single language fell through to the always-empty generic stripper -- verified empirically: `Prism(...).split_streams("x = 1 # comment", "python")` returned the comment still embedded in code_stream, comment_ stream empty, even for Python. This went undetected because test_prism.py's entire suite ran against a hand-built mock config (MOCK_COMMENT_DEFS/MOCK_LANG_DEFS) using a fictional, internally-consistent taxonomy that matched split_streams()'s special cases but never matched the real config -- every test passed without ever exercising real data. Fix: renamed prism.py's three special-cased family checks and _compile_regex_matrix()'s fam_key checks to the real taxonomy (recursive_c_style -> recursive_block, column_sensitive -> positional_anchored, single_line_only -> line_exclusive, c_style_comment -> standard_block), plus the default "lexical_family" fallback. Verified empirically post-fix: C, Python, Rust, and COBOL (one language per previously-broken family) now correctly separate comments from code. Contained entirely to prism.py -- no changes to gitgalaxy_config.py or any of the 58 language definitions, per the scoped plan in #386. KNOWN LIMITATIONS, tracked but not fixed here (per the approved scope -- see #386): - "standard_block"'s real delimiter list has 9 entries (C-style, SQL/ Lua-style --/--[[/]], Haskell-style {-/-}, and a trailing #), but the regex-building branch only uses the first 3 (// and /* */). The ~24 C-style languages in this family (c, cpp, java, javascript, go, etc.) are fully fixed; the 5 that don't use C-style delimiters at all (sqlite, lua, haskell, powershell, perl) are unchanged from before -- not a regression, since nothing was stripped for them either way. - "block_exclusive" (xml, 1 language) has its own separately malformed delimiter data (["", "--!>"]) and isn't covered by this fix. - golden_master.json is not regenerated here. This fix will very likely shift LOC/signal counts across most of the corpus now that comments actually stop leaking into code -- per #330's philosophy, that's a deliberate, reviewable update someone should make on purpose, not a side effect of this PR. The golden-crucible CI check isn't currently wired to golden_diff.py (#328), so this won't silently break a gate, but the fixture itself is now stale relative to correct behavior. Tests: test_prism.py's mock config renamed to match the real taxonomy (same fictional-but-now-consistent structure, so no coverage lost); new test_prism_strips_comments_against_the_real_config() wires up the REAL LANGUAGE_DEFINITIONS/LEXICAL_FAMILY_HEURISTICS directly (not the mock) and proves comment stripping now works for one real language per family -- exactly the test category that would have caught this bug originally. tests/dead_key_audit_baseline.json: "mechanical_families" removed now that it's fixed. Full suite: 862 passed, 1 pre-existing xfail. Co-Authored-By: Claude Sonnet 5 <[email protected]>
squid-protocol
force-pushed
the
fix/386-prism-comment-family-taxonomy
branch
from
July 24, 2026 17:49
6778a9c to
057d0e3
Compare
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
Closes #386, closes #378. Comment/code separation was completely broken for every one of the 58 supported languages, verified empirically --
Prism(REAL_CONFIG).split_streams("x = 1 # comment", "python")returned the comment still embedded incode_stream,comment_streamempty, even for Python.Root cause
split_streams()special-cased exactly three family names ("recursive_c_style","column_sensitive","single_line_only") for dedicated stripping logic, and fell back to aREGEX_MATRIXbuilt fromcomment_definitions.get("mechanical_families", {})for everything else -- a key nothing ever wrote (#378's original dead-key finding). But fixing that key name alone wouldn't have been enough: none of the three special-cased names, nor the matrix-buildingfam_keys ("c_style_comment","single_line_only","embedded_syntax","multi_style_dash"), matched the real per-language"lexical_family"taxonomy actually used acrosslanguage_standards.py(standard_block: 29 languages,line_exclusive: 21,recursive_block: 3,positional_anchored: 3,block_exclusive: 1,non_lexical: 1). So every single language fell through to the always-empty generic stripper.This went undetected because
test_prism.py's entire suite ran against a hand-built mock config (MOCK_COMMENT_DEFS/MOCK_LANG_DEFS) using a fictional, internally-consistent taxonomy that matchedsplit_streams()'s special cases but never matched the real config -- every test passed without ever exercising real data.Fix
Renamed
prism.py's three special-cased family checks and_compile_regex_matrix()'sfam_keychecks to the real taxonomy (recursive_c_style->recursive_block,column_sensitive->positional_anchored,single_line_only->line_exclusive,c_style_comment->standard_block), plus the default"lexical_family"fallback. Verified empirically post-fix: C, Python, Rust, and COBOL (one language per previously-broken family) now correctly separate comments from code. Contained entirely toprism.py-- no changes togitgalaxy_config.pyor any of the 58 language definitions, per the scoped plan discussed in #386.Known limitations, tracked but not fixed here (approved scope)
"standard_block"'s real delimiter list has 9 entries (C-style, SQL/Lua-style--/--[[/]], Haskell-style{-/-}, and a trailing#), but the regex-building branch only uses the first 3 (//and/* */). The ~24 C-style languages in this family (c, cpp, java, javascript, go, etc.) are fully fixed; the 5 that don't use C-style delimiters at all (sqlite, lua, haskell, powershell, perl) are unchanged from before -- not a regression, since nothing was stripped for them either way."block_exclusive"(xml, 1 language) has its own separately malformed delimiter data (["", "--!>"]) and isn't covered by this fix.golden_master.jsonis not regenerated here. This fix will very likely shift LOC/signal counts across most of the corpus now that comments actually stop leaking into code -- per Require deliberate, reviewable updates to the golden_master.json fixture instead of silent overwrite #330's philosophy, that's a deliberate, reviewable update someone should make on purpose, not a side effect of this PR. The golden-crucible CI check isn't currently wired togolden_diff.py(golden-crucible.yml never invokes golden_diff.py -- wire in the missing comparison step #328), so this won't silently break a gate, but the fixture itself is now stale relative to correct behavior.Test plan
test_prism.py's mock config renamed to match the real taxonomy (same fictional-but-now-consistent structure, so no coverage lost).test_prism_strips_comments_against_the_real_config()wires up the REALLANGUAGE_DEFINITIONS/LEXICAL_FAMILY_HEURISTICSdirectly (not the mock) and proves comment stripping now works for one real language per family -- exactly the test category that would have caught this bug originally.tests/dead_key_audit_baseline.json:"mechanical_families"removed now that it's fixed.python -m pytest tests/ -q-- full suite, 862 passed, 1 pre-existing xfail.flake8 . --count --select=E9,F63,F7,F82-- 0.🤖 Generated with Claude Code