Skip to content

test(rules): audit shared command prefixes for conflicts and redundancy - #98

Merged
furedea merged 2 commits into
mainfrom
test/73-verify-rules
Nov 9, 2026
Merged

furedea merged 2 commits into
mainfrom
test/73-verify-rules

Conversation

@furedea-agent

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

Copy link
Copy Markdown
Contributor

概要

#73 の P1(prefix の全列挙検査)を追加する.P4・P2・P3 は依存追加待ちのため別 PR とし,本 PR は Refs #73.

  • 一致した prefix のうち最も厳しい判定が勝つ,というモデルで検査する(Claude の deny → ask → allow の最初の一致と Codex の最も厳しい判定が勝つ,は同じ結果になる).
  • 検出は一覧として返すだけで,ルールは書き換えない.
検出 条件 CI
conflict 同一 prefix に別判定 赤
ineffective より厳しい祖先の下にある allow / ask 赤
redundant 同じ判定の祖先がある 既知の 7 組と一致しなければ赤

現行の 456 件(allow 278 / ask 48 / deny 130)では conflict と ineffective は 0 件.redundant は Issue が予告した 7 組(cargo fmt --check など).

検証

  • 壊したルール(重複,広げた allow,より厳しい祖先の下の allow / ask)で各検査が赤になるテスト(tests/test_prefix_audit.py)
  • 実ルールの検査(tests/test_prefix_rules.py)
  • pytest 18 件 pass,ruff check / format,ty,共有 verify pass

計画との差

なし.計画:#73 (comment)

残り
  • P4: uv add --group test hypothesis がユーザー実行待ち
  • P2 / P3: uv add --group test z3-solver がユーザー実行待ち

🤖 Generated with Claude Code

Add the P1 check of #73. The audit reads the shared prefixes with the
strictest-decision-wins model both providers share and reports conflicts,
ineffective entries, and redundant entries without rewriting any rule.

Refs #73

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@furedea

furedea commented Nov 9, 2026

Copy link
Copy Markdown
Owner

@codex review

@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-09T06:54:12.905790Z e1134be 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.

@github-actions

github-actions Bot commented Nov 9, 2026

Copy link
Copy Markdown

Review summary: No findings.

I checked the three detection categories against the strictest-decision-wins model:

  • Conflicts: only exact-prefix pairs with different decisions are reported. is_ineffective and is_redundant correctly leave those pairs out, so none is counted twice.
  • Ineffective and redundant: the ancestor check (Entry.extends) compares whole tokens, so git log vs git logx is not treated as ancestor and child. A narrower entry that is stricter than its ancestor is correctly treated as effective.
  • KNOWN_REDUNDANT uses an exact set match. Adding a new redundant entry fails the test, and so does removing a known one, which matches the comment telling authors to update the set.
  • The rules file has no wildcard or alternative tokens, so a plain token-tuple prefix comparison is enough.
  • The forward reference to Entry inside its own class body is fine on the pinned Python 3.15, where annotations are evaluated lazily.

The unit tests cover each category in both directions (it fires, and it does not fire). Note: I couldn't run the tests in this environment, so this review is based on reading the 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: 8fbea7eabb

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

from tests.runtime import REPO_ROOT


RULES = json.loads((REPO_ROOT / "agents/command_permissions.json").read_text())["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 Badge Register the audit with related-test selection

When agents/command_permissions.json changes, the repository's changed-file verification is driven by .agents/hooks/rules/related_test_extensions.json; I checked the resulting selection plan, and it runs nine existing tests but not tests/test_prefix_rules.py. Consequently, the normal targeted verification skips all three assertions introduced here, allowing a conflicting or ineffective prefix to pass locally until the full CI suite runs. Add this test to that mapping and update its mapping expectation.

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.

修正しました(e1134be).agents/command_permissions.json の関連テストに tests/test_prefix_rules.py を追加し,tests/prefix_audit.py から両テストへの対応も登録しました.tests/test_related_test_extensions.py に対応の期待値を追加しています.

Register tests/test_prefix_rules.py as a related test of
agents/command_permissions.json, and map the audit helper to its tests, so
targeted verification no longer skips the P1 check.

Refs #73

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@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

レビュー結果:指摘なし.

  • tests/prefix_audit.py の検査モデル(一致した prefix のうち最も厳しい判定が勝つ)は,command_policy.prefix_rule のトークン単位の prefix 比較と合っている.
  • conflict / ineffective / redundant の分類は,同一 prefix・祖先・兄弟(git log と git logx)の各ケースで正しく分かれ,tests/test_prefix_audit.py がそれぞれを押さえている.
  • Entry.extends の前方参照は,requires-python >= 3.15 なので遅延評価で問題ない.
  • related_test_extensions の追加と,その存在テストも一致している.

P0/P1: 0 件

@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: e1134be642

ℹ️ 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 merged commit bad2a61 into main Nov 9, 2026
24 checks passed
@furedea
furedea deleted the test/73-verify-rules branch November 9, 2026 08:14
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]>
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