Skip to content

test(rules): verify generated provider rules decide like the source - #104

Merged
furedea merged 4 commits into
mainfrom
test/73-generated-rules
Nov 9, 2026
Merged

furedea merged 4 commits into
mainfrom
test/73-generated-rules

Conversation

@furedea-agent

@furedea-agent furedea-agent Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

概要

#73 の P3(生成された Claude / Codex / Devin のルールが元と同じ判定をすること)を追加する.Refs #73.#102(P2)に積んだ PR で,base は test/73-forbidden-overlap(#102 のマージ後に main へ付け替える).マージ順は #100 → #102 → #104.

対象 手段 結果
Claude Bash(prefix:*),Codex prefix_rule,Devin Exec(prefix) 全 prefix・短い形・長い形・未登録コマンドを列挙し,最も厳しい判定が勝つモデルで元と比較 3 つとも差なし
generate-forbidden-commands の正規表現規則 規則を位置で対にして,Z3 で「片方だけが deny する行」を探す 6 規則中 4 規則で差あり(下記)

発見:generate-forbidden-commands が exceptions と programs を落とす

固定している agent-harness 0.9.9 の出力では,次の差が出る.guard は両フィールドを読むため,この出力を ~/.claude/hooks/rules/forbidden_commands.json に置くと判定が変わる(agent-harness の README にその置き場所の記載がある).

規則 Z3 の witness 差
2(herdr agent start ... --) herdr agent start a --timeout 0 -- --model sonnet --effort medium 例外で許可される形まで deny する
3(cargo / pnpm / uv の in-place) uv ruN MUTMUT APPLY scope と大小文字の無視が消え,元が deny する行を allow する
4(agent-browser の file:) agent-browser filE: 同上
5(agent-desktop のアプリ名) agent-desktop warP 同上

判断

  • Devin の判定意味は未確認のため,最も厳しい判定が勝つと仮定して比較している.仮定はテストの docstring に書いた.
  • 規則全体の補集合を使う Z3 の問いは 13 パターンでは 30 秒で解けなかったため,生成規則と元規則を位置で対にした.generator は順序を保つ.規則の数が同じであることも検査する.
  • Claude の Bash(dangerouslyDisableSandbox:true) は prefix ではないため比較から外した.

検証

  • 壊した生成規則(allow の追加,deny の欠落,判定の書き換え,長い形だけの欠落)で gap が出る単体テスト
  • 未知の形の項目は読み飛ばさず ValueError
  • pytest 37 件(33 pass,4 xfail),ruff check / format,ty
  • 実行時間:Z3 の比較で約 20 秒(規則 5 の大文字小文字を無視する比較が支配的)

計画:#73 (comment)
未対応のレビュー指摘(xfail の raises=,裸の Bash エントリの拒否):#107

🤖 Generated with Claude Code

@furedea

furedea commented Nov 9, 2026

Copy link
Copy Markdown
Owner

@codex review

@github-actions

github-actions Bot commented Nov 9, 2026

Copy link
Copy Markdown

レビュー結果

ブロッキングな指摘はありません(P0/P1: 0 件,P2/P3: 0 件).

確認した点:

  • decision_gaps の probe(各 prefix の短い形・長い形・未登録コマンド)は,prefix 一致のみで決まる判定空間を網羅している.どのコマンドも,規則の prefix の切り詰めのうち最長のものと同じ規則集合に一致するため,取りこぼしはない.
  • codex_rules は形の違う prefix_rule を finditer で読み飛ばしうるが,読み飛ばしが判定を変える場合は gap として必ず失敗するため,差を隠すことはない.
  • rule_language の scope 付き規則(プログラム名は大小文字を区別し,pattern と exceptions は区別しない)は,command_policy.argument_reason と一致している.
  • generated_forbidden は module scope だが,agent_harness は session scope なので scope の不一致はない.
  • xfail(strict=True) の 4 件は,現在の forbidden_commands.json の規則 2〜5(exceptions / programs を持つもの)と対応している.

補足(指摘ではない):guard は scope 付き規則の判定前にタブと改行を取り除くが,Z3 モデルはこれを扱っていない.同じ scope 同士を比べる限り結果は変わらない.

🤖 Generated with Claude Code

@furedea-agent
furedea-agent Bot force-pushed the test/73-forbidden-overlap branch from a3b3d2d to 0552679 Compare November 9, 2026 07:42
@furedea-agent
furedea-agent Bot force-pushed the test/73-generated-rules branch from 8652bb8 to 05453d6 Compare November 9, 2026 07:43
@furedea

furedea commented Nov 9, 2026

Copy link
Copy Markdown
Owner

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread tests/test_denial_difference.py Outdated
Comment on lines +88 to +91
pytest.param(2, marks=DROPS_FIELDS),
pytest.param(3, marks=DROPS_FIELDS),
pytest.param(4, marks=DROPS_FIELDS),
pytest.param(5, marks=DROPS_FIELDS),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

修正しました(01f3951).生成された規則が「元の規則から exceptions と programs だけを除いたもの」と完全に一致することを全規則について検査する形を追加しました.これで xfail は既知の欠落だけを覆い,パターンの欠落や正規表現の変更など他の変化は形の検査で赤になります.xfail の印は,exceptions か programs を持つ元の規則から自動で付けるようにしました.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-09T12:04:37.234477Z 81595e5 Manual request
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

Comment thread tests/generated_rules.py


def codex_rules(text: str) -> list[Rule]:
rules = []

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

修正しました(01f3951).prefix_rule( の出現数と解釈できた規則の数が違えば ValueError にします.入れ子のパターン,decision が先に来る形,空のパターン,未知の decision を,単体テストで拒否することを確認しています.

@github-actions

github-actions Bot commented Nov 9, 2026

Copy link
Copy Markdown

Review summary (read-only)

Findings: 1 × P2, no blocking findings.

  • P2 tests/generated_rules.py: codex_rules silently skips any prefix_rule block whose shape doesn't match its regex. An extra generated Codex rule in an unexpected shape could therefore hide a gap. The Claude and Devin parsers refuse unknown shapes instead. See the inline comment.

What checked out:

  • The probe set in decision_gaps covers every possible decision. For any command, the rules that match it are the same as for its longest common prefix with some rule's prefix, or for the unlisted-program probe when nothing matches.
  • denial_difference matches the guard's semantics for program-scoped rules: the program name must match exactly, while patterns and exceptions are checked without regard to case (argument_reason in command_policy.py). Unscoped rules are case-sensitive.
  • The strict xfail markers for rules 2–5 line up with the agent-harness 0.9.9 field drop described in the PR body. The length check keeps GENERATED_RULES in sync with the source.

🤖 Generated with Claude Code

@furedea-agent
furedea-agent Bot force-pushed the test/73-generated-rules branch from 05453d6 to ecec094 Compare November 9, 2026 07:52
@furedea

furedea commented Nov 9, 2026

Copy link
Copy Markdown
Owner

@codex review

Comment thread tests/generated_rules.py Outdated

def codex_rules(text: str) -> list[Rule]:
rules = []
for match in CODEX_RULE.finditer(text):

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

修正しました(01f3951).同じ指摘への対応です.出現数が合わない場合は ValueError,レイアウト違いの Codex 規則を拒否する単体テストを追加しました.

@github-actions

github-actions Bot commented Nov 9, 2026

Copy link
Copy Markdown

Review summary

No blocking findings (P0/P1: 0).

What I checked:

  • Prefix model (decide / probes): for any command, the rules that match are fixed by the longest point where it leaves the prefix trie. So the probe set (each prefix, each shorter form, prefix + one extra word, an unlisted program) covers every decision the rules can make. The test is sound.
  • Regex model (denial_language): it matches command_policy.argument_reason / rule_applies. Rules with programs check the first word case-sensitively and read patterns and exceptions without regard to case. Rules without programs read the raw line case-sensitively. One gap: the model skips the guard's step that removes quotes and drops URL tab/newline characters. That only affects lines that would need those edits, so it doesn't change the 4 xfail results.
  • The xfail(strict=True) markers and the rule-count check will flag the test once agent-harness keeps exceptions / programs, or when rules are added or reordered.
  • The related-test extension mappings are consistent.

Inline:

  • P3 tests/generated_rules.py: codex_rules silently skips any prefix_rule( block in a layout it doesn't recognize, instead of raising. If such a block is an extra, stricter generated rule, the test misses it.

🤖 Generated with Claude Code

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread tests/test_denial_difference.py Outdated
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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

修正しました(01f3951).生成規則は元の規則と patterns の集合で対にし,順序と並びは比較しません.対になる規則がない,または複数ある場合は明示的に失敗します.

@furedea-agent
furedea-agent Bot force-pushed the test/73-generated-rules branch from ecec094 to a7db443 Compare November 9, 2026 08:02
@furedea

furedea commented Nov 9, 2026

Copy link
Copy Markdown
Owner

@codex review

1 similar comment
@furedea

furedea commented Nov 9, 2026

Copy link
Copy Markdown
Owner

@codex review

Comment thread tests/test_denial_difference.py Outdated
# 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"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

Suggested change
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",

@github-actions

github-actions Bot commented Nov 9, 2026

Copy link
Copy Markdown

レビュー結果

ブロッキングな指摘はありません(P0: 0,P1: 0,P2: 0,P3: 1).

P3: tests/test_denial_difference.py の xfail(strict=True) には raises= がありません.そのため,Z3 が 30 秒の上限に達して出る TimeoutError も「想定どおりの失敗」として扱われます.raises=AssertionError を付けることを提案します(インラインコメント参照).

確認したこと:

  • denial_difference.rule_language は guard の判定(command_policy.argument_reason と rule_matches)と一致しています.一致を確認した点は次のとおりです.
    • scope 付きの規則は,最初の単語がプログラム名と完全に一致するときだけ適用される(大文字小文字を区別する).
    • その規則の patterns と exceptions は大文字小文字を無視する.
    • scope のない規則は大文字小文字を区別する.
  • generated_rules.probes が使うプローブ(各 prefix,その短い形,prefix + 未登録の単語,未登録のコマンド)は,2 つの規則集合を合わせた trie のすべての分岐を通ります.最も厳しい判定が勝つモデルの下では,比較にこれで十分です.
  • Codex のパーサは,prefix_rule( の数と一致した数が合わないときに ValueError を出すため,読めない書式を黙って飛ばしません.

補足:PR 本文には「規則を位置で対にした」とありますが,実装(generated_rule_for)は patterns の集合で対にしています.どちらでも判定は正しいので,本文の記述だけ合わせてください.

🤖 Generated with Claude Code

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread tests/generated_rules.py
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)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

反映せず,根拠を残します.このテストが比べるのは,provider の評価結果ではなく,生成された規則集合が元の規則集合と同じ prefix と判定を持つかどうかです.Claude が timeout 30 などの wrapper を外してから規則を当てる処理は,元の規則に対しても生成された規則に対しても同じように働くため,2 つの規則集合が同じなら,どの wrapper 付きコマンドでも判定は一致します.wrapper を外した後の判定を実際に検査するのは #100(P4)で,guard が wrapper の内側の ask と deny を見落とさないことを,10 種の wrapper とシェル経由の組み合わせで確認しています.Claude の評価器を直接動かす検査は,provider の CLI が必要になるためこの範囲に含めていません.

@furedea

furedea commented Nov 9, 2026

Copy link
Copy Markdown
Owner

@codex review

@furedea-agent
furedea-agent Bot force-pushed the test/73-generated-rules branch from 8b7d48e to d4a3f73 Compare November 9, 2026 08:09
@furedea

furedea commented Nov 9, 2026

Copy link
Copy Markdown
Owner

@codex review

@github-actions

github-actions Bot commented Nov 9, 2026

Copy link
Copy Markdown

Automated review: no findings.

Checked:

  • The Z3 denial model in tests/denial_difference.py against the guard (command_policy.rule_matches / argument_reason / unscoped_rules). It handles patterns, exceptions, the exact program match on the first word, and case folding for scoped rules the same way.
  • The prefix-probe argument in tests/generated_rules.py. Under strictest-wins, a decision depends only on which prefixes match, so each prefix, each shorter form, one longer form and one unlisted command are enough probes.
  • That the Codex, Claude and Devin parsers raise an error on entries they don't recognize instead of skipping them.
  • That the module-scoped generated_forbidden fixture depends on the session-scoped agent_harness, so the scopes don't conflict.
  • The xfail(strict=True) markers. They cover exactly the rules that have exceptions or programs.

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

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Can't wait for the next one!

Reviewed commit: d4a3f73897

ℹ️ 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".

@furedea-agent
furedea-agent Bot force-pushed the test/73-forbidden-overlap branch from 2d92152 to a3e58bd Compare November 9, 2026 08:19
@furedea-agent
furedea-agent Bot force-pushed the test/73-generated-rules branch from d4a3f73 to fb4f0db Compare November 9, 2026 08:19
@furedea

furedea commented Nov 9, 2026

Copy link
Copy Markdown
Owner

@codex review

Comment thread tests/generated_rules.py
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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@furedea

furedea commented Nov 9, 2026

Copy link
Copy Markdown
Owner

@codex review

@github-actions

github-actions Bot commented Nov 9, 2026

Copy link
Copy Markdown

レビュー結果

指摘なし(P0/P1/P2/P3 いずれもなし).

確認した点:

  • decision_gaps の probe(各 prefix,その短い形,長い形,未登録コマンド)は,最も厳しい判定が勝つモデルでは網羅的.どのコマンドでも,両方の規則集合で最長に一致する prefix を probe すれば,一致する prefix の集合が同じになる.
  • codex_rules は件数照合で未知の layout を ValueError にしており,入れ子の pattern や順序違いを黙って読み飛ばさない.
  • denial_difference の scoped 規則のモデル(program 名は大小文字を区別,patterns / exceptions は区別しない)は,command_policy.argument_reason の arguments[0] in programs と grep -qiE に合っている.
  • xfail(strict=True) が付くのは exceptions / programs を持つ規則(2〜5)だけなので,agent-harness が修正されると XPASS で気づける.

🤖 Generated with Claude Code

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Hooray!

Reviewed commit: 1cee686b41

ℹ️ 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".

@furedea

furedea commented Nov 9, 2026

Copy link
Copy Markdown
Owner

@codex review

@github-actions

github-actions Bot commented Nov 9, 2026

Copy link
Copy Markdown

Review summary

No P0–P3 findings.

What I checked:

  • Prefix comparison (tests/generated_rules.py): the probe set is complete for the strictest-wins model. For any command, the rules that match it are the same as for the longest rule prefix (or shorter form of one) that begins it, and every such prefix is probed. The parsers raise errors instead of quietly skipping entries they can't read. Codex's word regex stops at the first ] and doesn't unescape \", but either case shows up as an error or a reported gap, never a false pass.
  • Z3 model (tests/denial_difference.py): it matches command_policy.rule_matches (unscoped rules) and argument_reason (scoped rules: first word must match exactly, patterns and exceptions ignore case). The model leaves out the guard's tab and newline stripping (URL_IGNORED_CHARACTERS) and its removal of trailing redirections. That is an accepted approximation for this comparison.
  • Fixtures: generated_forbidden is module-scoped and depends on the session-scoped agent_harness, so there's no scope mismatch.
  • Small inconsistency: the PR body says generated and source rules are paired by position, but generated_rule_for pairs them by pattern set. The body also says no agent-harness issue exists, but the xfail reason cites furedea/agent-harness#203. Please make sure that issue exists so the reminder to remove the xfail has something to point to.

🤖 Generated with Claude Code

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🎉

Reviewed commit: 29a5f34cee

ℹ️ 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".

furedea added a commit that referenced this pull request Nov 9, 2026
…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]>
@furedea-agent
furedea-agent Bot force-pushed the test/73-forbidden-overlap branch from e0b52cb to 1ce78b4 Compare November 9, 2026 09:46
@furedea

furedea commented Nov 9, 2026

Copy link
Copy Markdown
Owner

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. What shall we delve into next?

Reviewed commit: 29a5f34cee

ℹ️ 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".

@furedea
furedea deleted the branch test/73-forbidden-overlap November 9, 2026 11:58
furedea added a commit that referenced this pull request Nov 9, 2026
…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]>
@furedea furedea closed this Nov 9, 2026
@furedea-agent furedea-agent Bot reopened this Nov 9, 2026
@furedea-agent
furedea-agent Bot changed the base branch from test/73-forbidden-overlap to main November 9, 2026 11:59
furedea and others added 4 commits November 9, 2026 20:59
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]>
@furedea-agent
furedea-agent Bot force-pushed the test/73-generated-rules branch from 29a5f34 to 81595e5 Compare November 9, 2026 11:59
@furedea

furedea commented Nov 9, 2026

Copy link
Copy Markdown
Owner

@codex review

@github-actions

github-actions Bot commented Nov 9, 2026

Copy link
Copy Markdown

Review summary (read-only)

I found no P0–P3 issues to report.

Checked:

  • denial_difference.rule_language models the guard's argument_reason (agents/hooks/lib/command_policy.py) correctly. A rule with programs matches the first argument exactly and case-sensitively, and its patterns and exceptions are case-insensitive. A rule without programs is a case-sensitive pattern match minus its exceptions.
  • decision_gaps probes every prefix, every shorter form, one longer form and one unlisted program. Under the strictest-wins model, that set covers every decision a word-prefix trie can make.
  • The Codex and Claude parsers reject unknown layouts instead of skipping them, and unit tests cover this.
  • The tests that need agent-harness are marked integration. The 4 xfail(strict=True) cases match the rules that have exceptions or programs, and the shape test checks that nothing else differs.
  • The xfail tests don't set raises=, and bare Bash entries are still accepted. Both are already tracked in test(rules): address the review findings left open on #100, #102, and #104 #107, so I didn't repeat them.

🤖 Generated with Claude Code

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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",

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@furedea
furedea merged commit 78bba9f into main Nov 9, 2026
22 of 24 checks passed
@furedea
furedea deleted the test/73-generated-rules branch November 9, 2026 12:11
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.

1 participant