Skip to content

Close #606: strict tests for python, fix a real comprehensions bug found along the way - #633

Merged
squid-protocol merged 1 commit into
mainfrom
test-python-strict-parsing
Jul 26, 2026
Merged

squid-protocol merged 1 commit into
mainfrom
test-python-strict-parsing

Conversation

@squid-protocol

Copy link
Copy Markdown
Owner

Summary

Full positive/negative/ambiguity/ReDoS test coverage for all 44 checklisted structural signatures python defines (per epic #518's per-language scaffold), plus a systematic literal-keyword ambiguity sweep and a generic ReDoS sweep across every non-None pattern in the language (both came back clean beyond what's already tested).

Bug found and fixed

comprehensions was matching JavaScript's idiom, not Python's

"comprehensions": re.compile(r"\.(?:map|filter|reduce|flatMap|some|every|find|forEach|groupBy)\s*\("),

That's JavaScript's Array-method chain (.map(, .filter(, etc.) -- copy-pasted in by mistake. Python has no builtin .map(/.filter( list methods; it has comprehension syntax ([x for x in y], {k: v for k, v in items}, generator expressions). The old pattern never matched a single real Python comprehension and only fired incidentally on unrelated methods that happen to share a name (e.g. a Django queryset's .filter(active=True)).

Confirmed via the golden-crucible corpus: real comprehension detection went from a flat 0 to 1-9 per file across the python corpus (previously always zero, now correctly nonzero).

Before touching anything, I checked whether javascript/typescript share this exact pattern text too (they do) -- confirmed those two are correct as-is (.map(/.filter( really is their idiom), so only python's copy needed fixing. Fixed using the same pattern shape as embedded_python's already-correct (and already ReDoS-bounded, from an earlier fix this session) comprehensions rule.

Sweeps run (both clean)

  • Ambiguity sweep: literal-keyword overlap check across every pair of python's signatures. All overlaps found were the expected/intentional kind (multiple import-based sensors sharing "import"/"from"/"require" by design). Manually verified the two closest-looking candidates (high_risk_execution/reflection_metaprogramming sharing "call", exfiltration_camouflage/telemetry sharing "log") don't actually cross-fire.
  • ReDoS sweep: every non-None compiled pattern in python against generic pathological payload shapes, up to N=10,000. Clean.

Golden master fixtures

Updated both fixtures via the sanctioned tests/tools/update_golden_master.py, reviewed before blessing: all ~856 diffs confined to python files (confirmed by checking every mismatch path), zero signal-count collapse anywhere.

Test plan

  • pytest tests/ -- 1025 passed
  • python tests/ruff_audit.py --ci -- clean
  • python tests/mypy_audit.py --ci -- clean
  • pytest -m golden_crucible -- passes in both full-precision and zero-dependency modes after fixture regeneration

Closes #606.

🤖 Generated with Claude Code

…und along the way

Full positive/negative/ambiguity/ReDoS coverage for all 44 checklisted
structural signatures python defines (per epic #518's per-language
scaffold), plus a systematic ambiguity sweep and ReDoS sweep across every
non-None pattern in the language (both clean beyond what's already tested).

One real, currently-shipping bug surfaced while writing the tests:

`comprehensions` was `\.(?:map|filter|reduce|flatMap|...)\s*\(` --
JavaScript's Array-method idiom, copy-pasted in by mistake. Python has no
builtin `.map(`/`.filter(` list methods; it has comprehension syntax
(`[x for x in y]`, `{k: v for k, v in items}`, generator expressions). The
old pattern never matched a single real Python comprehension and only
fired incidentally on unrelated methods sharing a name (e.g. a Django
queryset's `.filter(active=True)`). Confirmed via the golden-crucible
corpus: real comprehension detection went from a flat 0 to 1-9 per file
across the python corpus (previously always zero, now correctly nonzero).
javascript/typescript's own copies of this pattern are correct as-is --
only python's was wrong -- confirmed by checking all 3 languages sharing
the exact pattern text before touching anything.

Fixed using the same (already ReDoS-bounded, from an earlier fix this
session) pattern shape as `embedded_python`'s correct comprehensions rule.

Golden master fixtures (both full-precision and zero-dependency) updated
via the sanctioned tests/tools/update_golden_master.py and reviewed before
blessing: all drift confined to python files, zero signal-count collapse.

Full suite (1025 tests), ruff audit, mypy audit, and both golden-crucible
modes pass.

Closes #606.

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 256d100 into main Jul 26, 2026
27 checks passed
@squid-protocol
squid-protocol deleted the test-python-strict-parsing branch July 26, 2026 17: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: python structural signatures

1 participant