Skip to content

Fix prism.py's comment-family taxonomy -- comment/code separation was broken for all 58 languages (#386) - #389

Merged
squid-protocol merged 1 commit into
mainfrom
fix/386-prism-comment-family-taxonomy
Jul 24, 2026
Merged

squid-protocol merged 1 commit into
mainfrom
fix/386-prism-comment-family-taxonomy

Conversation

@squid-protocol

Copy link
Copy Markdown
Owner

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 in code_stream, comment_stream empty, 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 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 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.

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 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.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 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 to golden_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).
  • 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.
  • 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

… 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
squid-protocol force-pushed the fix/386-prism-comment-family-taxonomy branch from 6778a9c to 057d0e3 Compare July 24, 2026 17:49
@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 1a70f72 into main Jul 24, 2026
23 checks passed
@squid-protocol
squid-protocol deleted the fix/386-prism-comment-family-taxonomy branch July 24, 2026 17:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant