Skip to content

Fix #595: Strict parsing tests for m4 structural signatures - #766

Merged
squid-protocol merged 1 commit into
mainfrom
fix/595-m4-strict-parsing
Jul 30, 2026
Merged

squid-protocol merged 1 commit into
mainfrom
fix/595-m4-strict-parsing

Conversation

@squid-protocol

Copy link
Copy Markdown
Owner

Summary

Part of #518, closes #595.

Adds strict positive/negative, ambiguity-sweep, and ReDoS regression coverage in
tests/core_engine/test_language_standards_strict.py for all 31 non-None m4
structural signatures (41 tests). Found and fixed 1 real bug (Engine Rule 12:
Comment-Style Completeness), affecting 3 rules.

Real bug found and fixed

dead_code, doc, and ownership were all anchored ONLY on dnl, but GNU M4's
actual default lexer-level comment delimiter is #-to-newline -- confirmed in the
shared line_exclusive family table in gitgalaxy_config.py ({"delimiters": ["#", "<#", "#>", "=begin", "=end", ";", "dnl", "%", "#|", "|#"]}), which prism.py uses to
carve the comment stream for every line_exclusive language. dnl is a separate,
macro-level discard-to-newline mechanism, distinct from the lexer-level # comment.

Verified against the real language-crucible corpus (curl/gnucobol configure.ac):
# comments are as common as, or more common than, dnl ones in real Autoconf files
(88-106 # lines vs 128-265 dnl lines per file), including realistic
# FIXME:/# Copyright lines actually present in the corpus. Checking only dnl
silently missed the dominant real-world style. Widened all three rules to accept both
dnl[ \t]+ and #[ \t]* prefixes.

Also covered

  • The issue's known ambiguity pattern (func_start vs macros) -- confirmed no false
    collision: m4's macro-definition keywords (m4_define/define/AC_DEFUN/...) are
    structurally distinct from its C-preprocessor-hook-configuration keywords
    (AC_DEFINE/...). Also a ReDoS check on func_start against a long macro-shaped run.
  • 5 intentional double-classifications found via a systematic token-overlap sweep
    across all rule pairs (not just the known cross-language ones): api/macros on
    AC_DEFINE, cleanup/state_mutation on popdef, cleanup/test on
    AT_CLEANUP, dependency_injection/structural_boundaries on AC_REQUIRE, and
    doc/ownership on AC_COPYRIGHT.
  • A lexical-family check confirming no block-comment-family confusion (m4 is
    line_exclusive, no native block syntax -- a stray /* */-shaped sequence, which can
    legitimately appear as literal embedded C output, doesn't trigger dead_code/doc).
  • func_start's structural exclusion of dnl/#-commented lines (its own ^[ \t]*
    anchor can't tolerate either prefix, a stronger guarantee than relying on prism.py's
    stream separation alone).
  • A ReDoS scaling sweep (n=2000/4000/8000/16000/32000) across every rule with an
    unbounded-looking quantifier -- all showed ~2x time per doubling (linear), not the
    ~4x signature of catastrophic backtracking.

Verification

  • Strict test file: 41 new tests pass, 2020 total across the full suite (up from 1989
    pre-PR, includes test_prism.py)
  • ruff format --check clean; python tests/ruff_audit.py --ci -- no new findings
    beyond baseline
  • mypy audit's 2 new-looking findings are in guidestar_lens.py, untouched by this PR
    (pre-existing drift, confirmed via git status scope)
  • Differential Scan: ran python tests/tools/crucible_check.py against the local
    language-crucible corpus -- real diff found in both venvs, confined entirely to
    m4/curl and m4/gnucobol corpus entries (verified programmatically: no other
    repo's parsed-files section changed). The "Commented-out Code (Dead Logic)" count
    increase in both (curl: 0->4, gnucobol: 0->1) is the expected direct effect of the
    dead_code fix now detecting previously-invisible #-prefixed commented macros.
    Fixtures regenerated via crucible_check.py --update and re-verified clean (PASS)
    in both venvs.

🤖 Generated with Claude Code

Adds strict positive/negative, ambiguity-sweep, and ReDoS regression
coverage in tests/core_engine/test_language_standards_strict.py for all
31 non-None m4 structural signatures (41 tests). Found and fixed 1 real
bug (Engine Rule 12: Comment-Style Completeness), affecting 3 rules.

Real bug found and fixed:

dead_code, doc, and ownership were all anchored ONLY on `dnl`, but GNU
M4's actual default lexer-level comment delimiter is `#`-to-newline
(confirmed in the shared line_exclusive family table in
gitgalaxy_config.py, which prism.py uses to carve the comment stream for
every line_exclusive language -- `dnl` is a separate, macro-level
discard-to-newline mechanism, distinct from the lexer-level `#` comment).
Verified against the real language-crucible corpus (curl/gnucobol
configure.ac): `#` comments are as common as, or more common than, `dnl`
ones in real Autoconf files, including realistic `# FIXME:`/`# Copyright`
lines. Checking only `dnl` silently missed the dominant real-world style.
Widened all three rules to accept both `dnl[ \t]+` and `#[ \t]*` prefixes.

Also covers the issue's known ambiguity pattern (func_start vs macros --
confirmed no false collision, m4's macro-*definition* keywords are
structurally distinct from its C-preprocessor-hook-configuration keywords)
plus 5 intentional double-classifications found via a systematic
token-overlap sweep across all rule pairs (api/macros on AC_DEFINE,
cleanup/state_mutation on popdef, cleanup/test on AT_CLEANUP,
dependency_injection/structural_boundaries on AC_REQUIRE, doc/ownership on
AC_COPYRIGHT), a lexical-family check confirming no block-comment-family
confusion (m4 is line_exclusive), and a ReDoS scaling sweep (2000-32000,
all ~2x per doubling, confirming no catastrophic backtracking).

Golden master fixtures regenerated via tests/tools/crucible_check.py
--update; diff confirmed confined entirely to m4/curl and m4/gnucobol
corpus entries (verified programmatically -- no other repo's parsed-file
section changed), and the "Commented-out Code" count increase in both is
the expected direct effect of the dead_code fix now detecting previously-
invisible #-prefixed commented macros.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@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 8f9be10 into main Jul 30, 2026
38 of 39 checks passed
@squid-protocol
squid-protocol deleted the fix/595-m4-strict-parsing branch July 30, 2026 00:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Strict parsing tests: m4 structural signatures

1 participant