Skip to content

[stacked on #1649] fix(contract): refuse a backreference in a list pattern - #1667

Draft
napetrov wants to merge 5 commits into
intel:mainfrom
napetrov:arch/r15-1
Draft

napetrov wants to merge 5 commits into
intel:mainfrom
napetrov:arch/r15-1

Conversation

@napetrov

@napetrov napetrov commented Dec 6, 2026

Copy link
Copy Markdown
Contributor

Summary

A list-valued contract pattern is joined into one alternation, and group numbers shift when the elements are joined. An element (a)\1 placed after (x) then refers to (x), so the action misses a call it should match. This PR refuses \1-\99, (?P=name) and (?(1)...) inside a list element. A single-string pattern keeps them.

Stacked on #1649 (arch/r14-2); this PR's diff is the one commit.

Evidence

  • New tests in tests/test_context_consistency.py: red first (5 of the refused cases failed before the change, the single-string case passed), green after.
  • Context, change-review, shell and user-regex suites: 792 passed.
  • make ci-local: the test step passes (36273 passed). pip-audit fails for an environmental reason (platformdirs refuses the cache under /mnt/cached_oses, owned by another user), not this change.
  • Self-review: two passes on the commit tree, no confirmed blocking. Declined items are recorded in the review notes.

Merge danger

  • Behaviour change: a contract whose list element has a backreference now fails to load with "a backreference is refused in a list pattern". Single strings and lists without backreferences are unchanged.
  • Declined by the spec: a one-element list [(a)\1] and a backreference in the first element are refused too.
  • Stacked: merge fix(contract): refuse a list pattern whose element is not a regex #1649 first; this draft targets main and includes its commits until then.

🤖 Generated with Claude Code

re.compile raises OverflowError for a repeat count that does not fit
and RecursionError for groups nested too deep, not re.error. The
process_metrics and contract loaders caught only re.error, so such a
pattern crashed with a traceback instead of a refusal.

One compile_user_regex helper maps all three to ValueError. It is used
at the two loader compile sites, and at the branch-filter glob compile
(repos/l0/branches.py), which compiles user-derived text. The manifest
catches ValueError from parse_counter, so it refuses too without a
change of its own. The remaining re.compile in environment/instructions.py
compiles module-level literals only and is unchanged.

Signed-off-by: Nikolay Petrov <nikolay.a.petrov@intel.com>
A list-valued matcher key was joined with `|`, each element wrapped in
`(?:...)`, and only the joined pattern was compiled. `["a)|(?:b"]`
joins to two groups and was accepted, though the element is not a
regex. Each element is now compiled on its own and refused by name.
A list whose elements are each a regex compiles to the same pattern as
before. A list where one element refers to a group of another is
refused now, since that element is not a regex alone.

Signed-off-by: Nikolay Petrov <nikolay.a.petrov@intel.com>
Signed-off-by: Nikolay Petrov <nikolay.a.petrov@intel.com>

# Conflicts:
#	dokimi/tests/test_context_consistency.py
#	dokimi/tests/test_import_architecture.py
Thread: PRRT_kwDOVBg7g87AQkB0
Signed-off-by: Nikolay Petrov <nikolay.a.petrov@intel.com>
A list pattern is joined into one alternation, so a group number shifts
when the elements are joined: `(a)\1` after `(x)` refers to `(x)` and
the action misses a call it should match. Refuse `\1`-`\99`, `(?P=name)`
and `(?(1)...)` in a list element; a single string keeps them. A digit
in a character class or an escaped backslash is not a reference. The
run consistency doc describes the rule.

Signed-off-by: Nikolay Petrov <nikolay.a.petrov@intel.com>
@github-actions

github-actions Bot commented Dec 6, 2026

Copy link
Copy Markdown

Mutation of changed lines

⚠️ Not a clean result: some breaks or tests were left out

At b8abf83: 0 caught · 0 missed

This is not a clean result:

  • 27 changed lines were not mutated

Warning only: a missed break does not fail the job. Updated on every push; the full report is in the ci run summary.

@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 93.75000% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 96.43%. Comparing base (19e5222) to head (b8abf83).

Files with missing lines Patch % Lines
dokimi/dokimi/context/contract.py 93.75% 1 Missing and 1 partial ⚠️
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1667      +/-   ##
==========================================
- Coverage   96.44%   96.43%   -0.02%     
==========================================
  Files         585      585              
  Lines       76600    76631      +31     
  Branches    13175    13185      +10     
==========================================
+ Hits        73876    73898      +22     
- Misses       1671     1675       +4     
- Partials     1053     1058       +5     
Files with missing lines Coverage Δ
dokimi/dokimi/context/contract.py 98.00% <93.75%> (-0.82%) ⬇️

... and 6 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

This branch has not been deployed

No deployments
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.

2 participants