fix(acc-scanner): skip @acc: matches inside string literals#2
Open
jhetchan wants to merge 1 commit into
Open
Conversation
Replace line-based regex scan for .py files with tokenize-based scan that only matches COMMENT tokens. String literals (single, double, and triple-quoted) are now immune to false-positive @acc: matches, even when the literal content starts with '# @acc:' at the beginning of a source line. Non-Python files (.ts, .js, etc.) continue to use the existing line-regex path since their comment syntax differs. tokenize.TokenError is caught and treated as an empty result so syntactically broken files do not crash the scanner. Adds TestAccScannerStringLiteralImmunity with 5 cases covering: string literals, real comments, mixed sources, TokenizeError, and non-Python file preservation. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> https://claude.ai/code/session_012d1U3o5ej6rQ9Gm447LjiL
❌ ExoProtocol Health ReportVerdict: FAIL · Drift: |
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
The
@acc:scanner inexo/stdlib/requirements.pypreviously used a plain regex over each line of text to find acceptance-criteria annotations in test files. This approach failed for Python test files whose fixtures quote the marker as string-literal data — e.g.write_text("# @acc: ACC-001\n…")or triple-quoted blocks where# @acc:appears at the start of a source line inside the literal. Those occurrences were being matched and reported asacc_orphanerrors, causingexo trace-reqs --check-tests(and the session-finish verify gate) to fail spuriously. The fix usestokenize.generate_tokensfor.pyfiles and matches@acc:only insideCOMMENTtokens, making string literals invisible to the scanner. Non-Python files (.ts,.js,.rb, etc.) continue using the existing line-regex path because their comment syntax does not produce the same false-positive collision.Repro
Before (plain regex —
.pyfile string literals matched):With a
requirements.yamlthat defines ACC IDs, runningexo trace-reqs --check-testsagainst the repo would produce ~23acc_orphanerrors, all pointing at lines insidetests/test_requirements.pythat quote the@acc:marker inside Python string literals (e.g. test fixture data written to temp files). None of those occurrences were real test annotations.After (tokenize — only COMMENT tokens matched):
Test plan
TestAccScannerStringLiteralImmunity::test_string_literal_yields_no_refs— Python source withf = "# @acc: ACC-001"yields zero refsTestAccScannerStringLiteralImmunity::test_real_comment_yields_one_ref— Python source with# @acc: ACC-002comment yields exactly one ref atACC-002TestAccScannerStringLiteralImmunity::test_mixed_source_yields_only_comment_ref— source mixing both yields exactly one ref (the comment)TestAccScannerStringLiteralImmunity::test_tokenize_error_returns_empty— syntactically broken Python ("""unterminated) does not raise; returns empty listTestAccScannerStringLiteralImmunity::test_non_python_file_line_regex_preserved—.tsfile with// @acc: ACC-003still yields one ref (non-Python path preserved)python3 -m pytest tests/test_requirements.py -v— 97/97 pass including new testsruff check exo/ tests/andruff format --check exo/ tests/— cleanpython3 -m pytest— 1583 passing; 62 pre-existing failures on main unchangedGoverned by ExoProtocol · ticket
TKT-20260502-093139-P9I2· intentINT-20260502-093114-N3NRhttps://claude.ai/code/session_012d1U3o5ej6rQ9Gm447LjiL
Generated by Claude Code