Repository navigation
test(rules): verify generated provider rules decide like the source - #104
Conversation
|
@codex review |
レビュー結果ブロッキングな指摘はありません(P0/P1: 0 件,P2/P3: 0 件). 確認した点:
補足(指摘ではない):guard は scope 付き規則の判定前にタブと改行を取り除くが,Z3 モデルはこれを扱っていない.同じ scope 同士を比べる限り結果は変わらない. 🤖 Generated with Claude Code |
a3b3d2d to
0552679
Compare
8652bb8 to
05453d6
Compare
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8652bb82b4
ℹ️ 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".
| pytest.param(2, marks=DROPS_FIELDS), | ||
| pytest.param(3, marks=DROPS_FIELDS), | ||
| pytest.param(4, marks=DROPS_FIELDS), | ||
| pytest.param(5, marks=DROPS_FIELDS), |
There was a problem hiding this comment.
Constrain the xfails to the known dropped fields
For rules 2–5, these unconditional xfail marks accept any assertion failure, not only the known loss of exceptions or programs. If a later agent-harness build also drops a pattern, changes a regex, or adds an unrelated denial while still exhibiting the known field-loss bug, the integration suite continues to pass with the same expected failures and the new regression is hidden. Assert the expected field-stripped rule shape or the specific known semantic difference before marking the remaining mismatch expected.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
修正しました(01f3951).生成された規則が「元の規則から exceptions と programs だけを除いたもの」と完全に一致することを全規則について検査する形を追加しました.これで xfail は既知の欠落だけを覆い,パターンの欠落や正規表現の変更など他の変化は形の検査で赤になります.xfail の印は,exceptions か programs を持つ元の規則から自動で付けるようにしました.
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. |
|
|
||
|
|
||
| def codex_rules(text: str) -> list[Rule]: | ||
| rules = [] |
There was a problem hiding this comment.
P2 codex_rules silently skips any prefix_rule(...) block that doesn't match CODEX_RULE exactly. That covers different whitespace, decision written before pattern, and a nested alternatives list such as ["git", ["status", "log"]], where [^\]]* stops at the inner ].
If the source rules are dropped, the integration test still catches it, because they show up as gaps. But if the generated file has an extra rule in one of those shapes, for example a widening allow, it never gets parsed, so decision_gaps reports nothing and the test passes. That goes against the "refused instead of skipped" promise the Claude and Devin parsers keep, and the unit test for that promise doesn't cover Codex at all.
Suggested fix: count the prefix_rule( occurrences in text and raise ValueError when the count differs from len(rules). Also add a Codex case to test_an_entry_in_an_unknown_shape_is_refused_instead_of_skipped.
There was a problem hiding this comment.
修正しました(01f3951).prefix_rule( の出現数と解釈できた規則の数が違えば ValueError にします.入れ子のパターン,decision が先に来る形,空のパターン,未知の decision を,単体テストで拒否することを確認しています.
|
Review summary (read-only) Findings: 1 × P2, no blocking findings.
What checked out:
🤖 Generated with Claude Code |
05453d6 to
ecec094
Compare
|
@codex review |
|
|
||
| def codex_rules(text: str) -> list[Rule]: | ||
| rules = [] | ||
| for match in CODEX_RULE.finditer(text): |
There was a problem hiding this comment.
P3 — codex_rules doesn't raise on rules it can't parse, even though the PR says unknown shapes raise ValueError. finditer only sees prefix_rule( blocks that match CODEX_RULE exactly. That means pattern has to come first, with = spacing, and decision has to come right after it. Any other block is dropped without an error.
Most of the time this still fails loudly, because a dropped generated rule shows up as a gap against the source. One case gets through: if the generated file has an extra, stricter rule in a different layout (say, decision before pattern, or an extra key in between), that rule is ignored and the test passes. Claude and Devin don't have this problem.
Suggested fix: count the prefix_rule( occurrences in text, raise if the count differs from len(rules), and add a unit test for it next to test_an_entry_in_an_unknown_shape_is_refused_instead_of_skipped.
There was a problem hiding this comment.
修正しました(01f3951).同じ指摘への対応です.出現数が合わない場合は ValueError,レイアウト違いの Codex 規則を拒否する単体テストを追加しました.
Review summaryNo blocking findings (P0/P1: 0). What I checked:
Inline:
🤖 Generated with Claude Code |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ecec094b4e
ℹ️ 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".
| def test_a_generated_forbidden_rule_denies_the_lines_its_source_rule_denies( | ||
| index: int, generated_forbidden: list[dict] | ||
| ) -> None: | ||
| assert find_denial_difference([FORBIDDEN[index]], [generated_forbidden[index]]) is None |
There was a problem hiding this comment.
Compare forbidden rule sets without relying on order
When a future agent-harness version merely reorders or regroups the generated rules, this index-by-index comparison reports semantic regressions even though find_denial_difference is explicitly designed—and tested above—to treat ordering and grouping as irrelevant. Compare the complete source and generated rule sets (while separately accounting for the known dropped fields) so an equivalent generator output does not fail CI.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
修正しました(01f3951).生成規則は元の規則と patterns の集合で対にし,順序と並びは比較しません.対になる規則がない,または複数ある場合は明示的に失敗します.
ecec094 to
a7db443
Compare
|
@codex review |
1 similar comment
|
@codex review |
| # that keeps both fields; the shape test then needs the same update. | ||
| DROPPED_FIELDS = frozenset({"exceptions", "programs"}) | ||
| DROPS_FIELDS = pytest.mark.xfail( | ||
| strict=True, reason="agent-harness 0.9.9 generate-forbidden-commands drops exceptions and programs" |
There was a problem hiding this comment.
P3: this xfail has no raises=, so any exception counts as the expected failure. That includes the TimeoutError that find_line raises when Z3 hits its 30 s limit. The PR notes that rule 5's case-insensitive comparison already takes most of the ~20 s runtime, so on a slower CI runner these 4 tests could stay "xfailed" because Z3 timed out, not because it found the known gap. If that happens, the test isn't checking anything. Pinning the exception keeps a timeout reported as an error:
| strict=True, reason="agent-harness 0.9.9 generate-forbidden-commands drops exceptions and programs" | |
| strict=True, | |
| raises=AssertionError, | |
| reason="agent-harness 0.9.9 generate-forbidden-commands drops exceptions and programs", |
レビュー結果ブロッキングな指摘はありません(P0: 0,P1: 0,P2: 0,P3: 1). P3: 確認したこと:
補足:PR 本文には「規則を位置で対にした」とありますが,実装( 🤖 Generated with Claude Code |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 01f3951847
ℹ️ 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".
| def claude_rules(permissions: Mapping[str, Sequence[str]]) -> list[Rule]: | ||
| """The Bash prefix entries of a Claude permissions object, with every other tool entry left out.""" | ||
| return [ | ||
| Rule(tuple(match["prefix"].split(" ")), decision) |
There was a problem hiding this comment.
Model Claude's wrapper handling
For Claude commands containing a recognized wrapper, converting Bash(...) entries into word tuples does not reproduce the provider's decisions. For example, the source model leaves timeout 30 cargo test undecided, while Claude strips timeout 30 before matching and therefore applies the generated Bash(cargo test:*) allow rule; the current probes never exercise that difference, so the integration test reports equality despite broader real behavior. Claude's documented matcher explicitly strips wrappers including timeout, time, and nohup before applying rules (Claude Code wrapper semantics), so this comparison should model those transformations or exercise Claude's actual evaluator.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
反映せず,根拠を残します.このテストが比べるのは,provider の評価結果ではなく,生成された規則集合が元の規則集合と同じ prefix と判定を持つかどうかです.Claude が timeout 30 などの wrapper を外してから規則を当てる処理は,元の規則に対しても生成された規則に対しても同じように働くため,2 つの規則集合が同じなら,どの wrapper 付きコマンドでも判定は一致します.wrapper を外した後の判定を実際に検査するのは #100(P4)で,guard が wrapper の内側の ask と deny を見落とさないことを,10 種の wrapper とシェル経由の組み合わせで確認しています.Claude の評価器を直接動かす検査は,provider の CLI が必要になるためこの範囲に含めていません.
|
@codex review |
8b7d48e to
d4a3f73
Compare
|
@codex review |
|
Automated review: no findings. Checked:
One note, not a finding: the test comment says the problem is tracked in furedea/agent-harness#203, but the PR description says no agent-harness issue has been filed yet. I couldn't confirm whether #203 exists. Please make sure the reference is real. 🤖 Generated with Claude Code |
|
Codex Review: Didn't find any major issues. Can't wait for the next one! 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". |
2d92152 to
a3e58bd
Compare
d4a3f73 to
fb4f0db
Compare
|
@codex review |
| Rule(tuple(match["prefix"].split(" ")), decision) | ||
| for decision in ("allow", "ask", "deny") | ||
| for entry in permissions.get(decision, ()) | ||
| if entry.startswith("Bash(") and entry not in CLAUDE_NON_PREFIX |
There was a problem hiding this comment.
P3: entry.startswith("Bash(") silently drops a bare "Bash" entry. If the generator ever emitted "allow": ["Bash"] (allow every shell command), claude_rules would skip it, and test_the_generated_claude_rules_decide_like_the_source would still pass even though Claude would then allow everything. That doesn't match the "refuse, don't skip" approach the Codex and Devin parsers follow. Consider raising ValueError on entry == "Bash" too (or on any entry whose tool name is Bash), and adding a case for it to test_an_entry_in_an_unknown_shape_is_refused_instead_of_skipped.
|
@codex review |
レビュー結果指摘なし(P0/P1/P2/P3 いずれもなし). 確認した点:
🤖 Generated with Claude Code |
|
Codex Review: Didn't find any major issues. Hooray! 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". |
|
@codex review |
Review summaryNo P0–P3 findings. What I checked:
🤖 Generated with Claude Code |
|
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". |
…ns (#100) ## 概要 #73 の P4(guard が対応を謳う変形で禁止が効くこと)を Hypothesis で追加する.`Refs #73`.#98(P1)のマージ後に main へ付け替えた.#102・#104 がこの PR の上に積まれている(マージ順は #100 → #102 → #104). - 実ポリシーの deny prefix 130 件が,変形後も `forbidden` で deny になることを検査する(shell 系 5 件は `bash -c true` のように script を付けた代表形). - ask prefix は wrapper や script の内側で `allowed` が ask になり,直接なら allow(provider の判定)のままであることを検査する. - 変形は,クォート(単・二重・なし),`/usr/bin/` 付きパス,wrapper 10 種,`bash`・`sh`・`zsh` の `-c`,シェル組み込みの実行,先頭の `!` を最大 3 層まで組み合わせる. - `hypothesis` と `z3-solver` を test グループに追加した(`z3-solver` は P2・P3 用). | 検査 | 内容 | | ------------ | --------------------------------------------------------------------------- | | deny 性質 | 全変形で deny | | ask 性質 | 層があれば ask,なければ allow | | 壊したルール | deny / ask prefix を全部消したポリシーで各性質が赤になることを確認する 2 件 | ## 検証 - [x] `tests/hooks/test_guard_transformations.py` 183 件 pass(deny 125 件・ask 48 件を個別に,1 prefix あたり 12 例,`derandomize=True` で再現可能.prefix を 1 件だけ消したポリシーで赤になるテスト 10 件を含む) - [x] 関連テスト選択への登録と期待値の更新 - [x] ruff check / format,ty ## 発見と判断 - `bash -c`,`bash -lc`,`sh -c`,`zsh -c`,`zsh -lc` は deny prefix だが,script がない素の形では guard が先に ask を返す.deny にはならないが,安全側で止まる.script を付けた代表形で検査している. - 5 件以外に,素の形・変形のどちらでも #87 の抜け道によって落ちるものは見つからなかったため,`xfail` は使っていない.guard 本体は変更していない. - 依存は `uv add` が `>=` で入れた.repo の他の test 依存は `==` 固定のため,`==` に揃えるなら `uv lock` の再実行が必要(ユーザー作業). 計画:#73 (comment) 未対応のレビュー指摘(`sudo` と shell 層で deny 性質が自明に通る件):#107 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: furedea <[email protected]> Co-authored-by: Claude Sonnet 5.5 <[email protected]>
e0b52cb to
1ce78b4
Compare
|
@codex review |
|
Codex Review: Didn't find any major issues. What shall we delve into next? 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". |
…es with Z3 (#108) ## 概要 #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 件を「確認済み」として固定する.増えた重なりも,規則の削除で消えた重なりも赤になる. | 変換器の検査 | 内容 | | ------------- | ----------------------------------------------------------------------------------------------------------------------------- | | 文法ごとの例 | 受理 / 拒否する文字列 26 組 | | grep との差分 | 全 forbidden パターン × 大小文字の区別あり / なし で,ランダム文字列と,Z3 の witness を少し編集した文字列を `grep -E` と比較 | | 範囲外の文法 | 後方参照,`\w`,括弧の不整合などを拒否 | | witness | Z3 の witness を grep が受理する.充足不能な `a^b` などは witness なし | ## 判断 - 未アンカーのパターン(`(^|[[:space:]])git add`)は,どの prefix の後ろの自由な tail にも現れるため,全 278 prefix と重なり 1405 件のノイズになった.マッチが prefix の語の範囲内から始まるものだけを数える定義に絞り,20 件になった. - `agent-browser` の `file:` など,引数に現れる禁止形は tail から始まるため P2 の対象外.これらは P4 の変形検査と既存テストで見る. - 20 件はいずれも「provider は prefix を許可し,hook が狭い形を deny する」意図どおりの構成で,修正は不要と判断した(`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 のコミット時点では未生成で気づかなかった). ## 検証 - [x] 壊したルールの検査:allow prefix を広げる(`git` を追加),deny 規則を消すと,確認済みリストと一致せず赤になる 2 件 - [x] 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](https://claude.com/claude-code) --------- Co-authored-by: furedea <[email protected]> Co-authored-by: Claude Sonnet 5.5 <[email protected]>
Add the P3 check of #73. The Claude, Codex, and Devin prefix rules generated by agent-harness are read back and compared with the shared prefixes on every prefix, shorter form, and longer form, under the strictest-wins model. Z3 compares each generated forbidden-command regex rule with its source rule. agent-harness 0.9.9 writes generate-forbidden-commands without the `exceptions` and `programs` fields, so four of the six generated rules deny lines the source allows or reads case-sensitively. Those four comparisons are strict xfail until a locked agent-harness keeps both fields. Refs #73 Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Address review of the P3 check. - Refuse a Codex prefix_rule that is not in the pattern, decision layout instead of skipping it, which would hide a widening rule. - Pin the generated forbidden rule shape: each equals its source rule without `exceptions` and `programs`, so the strict xfail covers only that known loss and any other change to a generated rule fails. - Pair generated and source rules by their patterns, so a reordered or regrouped generator output is not reported as a regression. Refs #73 Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
The generate-forbidden-commands gap is tracked in furedea/agent-harness#203. Refs #73 Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
The generated Claude, Codex, Devin, and forbidden-command rules come from the agent-harness locked in flake.lock, so a pin change must run the tests that read them. Refs #73 Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
29a5f34 to
81595e5
Compare
|
@codex review |
|
Review summary (read-only) I found no P0–P3 issues to report. Checked:
🤖 Generated with Claude Code |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 81595e5e5d
ℹ️ 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".
| "tests/test_command_permission_sync.py", | ||
| "tests/test_prefix_rules.py", | ||
| "tests/test_forbidden_overlap.py", | ||
| "tests/test_generated_rules.py", |
There was a problem hiding this comment.
Run the Claude equivalence test for settings changes
test_the_generated_claude_rules_decide_like_the_source consumes the full permissions object produced from agents/claude/settings.json, but that source's related-test mapping does not select tests/test_generated_rules.py. Consequently, a settings-only change that adds or changes a Bash(...) allow, ask, or deny prefix can skip the new semantic comparison in the related-test workflow; add this test alongside the existing targets for agents/claude/settings.json.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
The finding is correct: the related-test mapping for agents/claude/settings.json lacks tests/test_generated_rules.py. Per the decision to stop iterating on Codex findings for #104, it is not fixed here; it is tracked in #107 with this thread linked, and the change is one line in related_test_extensions.json.
概要
#73 の P3(生成された Claude / Codex / Devin のルールが元と同じ判定をすること)を追加する.
Refs #73.#102(P2)に積んだ PR で,base はtest/73-forbidden-overlap(#102 のマージ後に main へ付け替える).マージ順は #100 → #102 → #104.Bash(prefix:*),Codexprefix_rule,DevinExec(prefix)generate-forbidden-commandsの正規表現規則発見:
generate-forbidden-commandsがexceptionsとprogramsを落とす固定している agent-harness 0.9.9 の出力では,次の差が出る.guard は両フィールドを読むため,この出力を
~/.claude/hooks/rules/forbidden_commands.jsonに置くと判定が変わる(agent-harness の README にその置き場所の記載がある).herdr agent start ... --)herdr agent start a --timeout 0 -- --model sonnet --effort mediumuv ruN MUTMUT APPLYfile:)agent-browser filE:agent-desktop warPxfail(strict=True)にして,agent-harness が両フィールドを保持するようになったらマーカーを外す.判断
Bash(dangerouslyDisableSandbox:true)は prefix ではないため比較から外した.検証
ValueError計画:#73 (comment)
未対応のレビュー指摘(xfail の
raises=,裸のBashエントリの拒否):#107🤖 Generated with Claude Code