Repository navigation
test(rules): list overlaps between allow prefixes and forbidden regexes with Z3 - #108
Conversation
…es with Z3 Add the P2 check of #73. A POSIX ERE to Z3 converter covers the dialect the forbidden rules use and refuses anything else; it is compared with the system grep on every forbidden pattern, with and without case folding, on random text and on edited Z3 witnesses. The overlap finder names one line that an allow prefix lets through and a forbidden rule would deny, skipping matches that begin only in the free tail after the prefix words. The 20 overlaps found are listed as reviewed; a new or vanished one fails the test. Refs #73 Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
The z3-solver wheel links libstdc++, which a Nix Python on Linux does not find by itself, so every test that imports z3 failed to load libz3 in CI. Point LD_LIBRARY_PATH at the compiler runtime library in the dev shell on Linux only. Refs #73 Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Address review of the P2 check. - Key each reviewed overlap by the complete forbidden pattern, so a new pattern that shares its first characters with a reviewed one no longer collapses into it. - Move the line sentinels to the two highest code points so U+0001 and U+0002 are ordinary text characters, as in a shell argument. - Refuse a backslash inside a bracket expression, where the grep dialects differ, instead of widening the set. - Refuse a prefix word that is empty or holds whitespace, which joining with spaces would merge into several arguments. - Pin that a leading hyphen in a bracket expression is a literal. Refs #73 Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…e converter Refuse the grep anchor escapes \< \> \` and \' instead of reading them as plain characters, and refuse the alpha, alnum, upper, and lower classes, whose members grow with a UTF-8 locale. The space and digit classes stay, read as ASCII. Refs #73 Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
… converter A cased non-ASCII letter folds by locale in grep, so a scoped rule with one is refused instead of folded as ASCII only. State in the module docstring that the converter models the C locale and where [[:space:]] differs under UTF-8. Refs #73 Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
[=a=] and [.a.] depend on the locale and were read as ordinary bracket members, which silently widened or shifted the set. Refuse them. Refs #73 Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
grep reads each line of a pattern as a separate pattern, which the converter would otherwise treat as one literal newline. Refuse it. Refs #73 Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
main widened the forbidden patterns for abbreviated --no-verify and for python options before -m. The reviewed overlaps keep the same prefixes against the same rule families; only the pattern text in the reviewed list changes. Refs #73 Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
|
@codex review |
レビュー結果ブロッキングな指摘(P0/P1)はありません.インラインコメントもありません. 確認した点:
🤖 Generated with Claude Code |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1ce78b409f
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| shifted = [(low + CASE_OFFSET, high + CASE_OFFSET) for low, high in intersect(intervals, (UPPERCASE,))] | ||
| shifted += [(low - CASE_OFFSET, high - CASE_OFFSET) for low, high in intersect(intervals, (LOWERCASE,))] | ||
| return normalize(intervals + tuple(shifted)) |
There was a problem hiding this comment.
Model UTF-8 case equivalents when folding ASCII
When the guard inherits a UTF-8 locale, grep's case-insensitive matching is broader than adding only the opposite ASCII case: for example, under the inspected C.UTF-8 environment, grep -qiE '^s$' accepts ſ, while this language rejects it. Consequently, a scoped forbidden rule containing s can overlap an allow prefix containing such a Unicode equivalent without find_overlaps reporting it. Either force the guard and tests to use the C locale or model/refuse these locale-dependent equivalents.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
This is a real gap in the converter, but it is out of scope for #108. The converter models grep in the C locale (stated in the module docstring), and the case-insensitive fold covers ASCII only. It is tracked in #107 with this thread linked; the fix is either to pin the guard and the tests to the C locale or to widen the model.
|
@codex review |
|
Codex Review: Didn't find any major issues. 👍 Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
概要
#73 の P2(allow prefix と禁止正規表現の重なりの列挙)を Z3 で追加する.
Refs #73.#102 の引き継ぎ.#100 のマージで base ブランチが削除され,#102 が自動で close されたあと,force push 済みのため reopen できなかった.レビューの経緯(スレッドと返信)は #102 に残っている.#100 は main にマージ済みで,この PR の base は main.#104 がこの PR の上に積まれている.tests/ere_to_z3.py: POSIX ERE から Z3 正規表現への変換器.規則が使う文法(^ $ . [] [:class:] () | * + ? {m,n}とエスケープ)だけを扱い,後方参照・先読み・\wなどはUnsupportedPatternで拒否する.tests/rule_overlap.py: allow prefix の語列(と,その後ろに空白と任意の文字列が続く形)と,禁止規則(例外を除く)の共通部分を Z3 で解き,witness を 1 行返す.tests/test_forbidden_overlap.py: 現行規則の 20 件を「確認済み」として固定する.増えた重なりも,規則の削除で消えた重なりも赤になる.grep -Eと比較\w,括弧の不整合などを拒否a^bなどは witness なし判断
(^|[[:space:]])git add)は,どの prefix の後ろの自由な tail にも現れるため,全 278 prefix と重なり 1405 件のノイズになった.マッチが prefix の語の範囲内から始まるものだけを数える定義に絞り,20 件になった.agent-browserのfile:など,引数に現れる禁止形は tail から始まるため P2 の対象外.これらは P4 の変形検査と既存テストで見る.git addとgit add .,uv run ... mutmut applyなど).自動修正はしない.REVIEWEDリスト(禁止形 7 種と,それに重なる allow prefix)は,2026-11-09 にユーザーが確認し,すべて意図どおりであることを確認済み..hypothesis/を ls-lint の ignore に追加した(ローカルで Hypothesis を動かすと pre-commit の ls-lint が落ちるため.P4 のコミット時点では未生成で気づかなかった).検証
壊したルールの検査:allow prefix を広げる(
gitを追加),deny 規則を消すと,確認済みリストと一致せず赤になる 2 件pytest 224 件 pass(関連テスト選択),ruff check / format,ty
実行時間:20 件の列挙に約 5 秒
flake.nix:Linux の devShell でlibstdc++が見つからずlibz3.soを読めなかったため,LD_LIBRARY_PATHを追加した(CI のtestが落ちた原因).変換器は C ロケールの grep を模す.ロケール依存の構文(文字クラス,等価クラス,非 ASCII の大小畳み込みなど)は拒否する.
[[:space:]]だけは ASCII の空白として扱う限界を docstring に記載した.計画:#73 (comment)
未対応のレビュー指摘(
xargsなど wrapper の内側コマンドの重なり):#107🤖 Generated with Claude Code