Skip to content

test(rules): audit wrapper inner commands and close three review findings (#107) - #114

Merged
furedea merged 6 commits into
mainfrom
test/107-wrapper-overlap
Nov 9, 2026
Merged

furedea merged 6 commits into
mainfrom
test/107-wrapper-overlap

Conversation

@furedea-agent

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

Copy link
Copy Markdown
Contributor

概要

#107 のうち 1・4・5・6 番目の項目を,項目ごとのコミットで対応する.2・3 番目(UTF-8 の大小文字,deny 性質)は範囲外.

Refs #107

計画:#107 (comment)

変更

項目 変更
1. wrapper の内側コマンドの重なり find_overlaps(prefixes, rules, wrappers).wrapper の prefix は「語の範囲内から始まる」制約を外し,内側コマンドの規則言語(programs・exceptions を含む)との共通部分を取る.command -v/-V は除外.wrapper 名はガードの WRAPPERS を使う
4. xfail raises=AssertionError を追加し,テストで固定
5. 関連テスト .agents/hooks/rules/related_test_extensions.json の agents/claude/settings.json に tests/test_generated_rules.py を追加し,選択テストを追加
6. 裸の Bash claude_rules が ValueError で拒否し,未知の形のテストに追加

新規の重なり(ユーザーが 2026-11-10 に確認済み)

新しいチェックが報告した xargs の重なり 13 件は,ユーザーが 2026-11-10 に安全と確認した(hook が xargs を外して内側のコマンドを拒否する.git add と git add . と同じ構造).REVIEWED に入れてある.allow prefix のうち wrapper で新たに重なるのは xargs だけだった.

規則(パターンの要点) 例(Z3 の witness を要約)
.venv/bin/python xargs .venv/bin/python
git add の広い形(^ あり・なし) xargs git add .
git commit の --no-verify/-n(^ あり・なし) xargs git commit -n
python -m pip/ensurepip xargs python -mpip
find -delete/-exec/-fprintf など xargs find -fprintf
herdr agent start ... -- xargs herdr agent start --
cargo mutants --in-place xargs cargo mutants --in-place
pnpm exec stryker --inPlace xargs pnpm exec stryker --inPlace
uv run ... mutmut apply xargs uv run mutmut apply(#102 の指摘)
(file|chrome): xargs agent-browser file:
デスクトップアプリ名 xargs agent-desktop パスワード

いずれも「provider は xargs を許可し,hook が内側のコマンドを拒否する」形で,git add と git add . と同じ構造.

検証

  • flake の dev shell で tests/test_forbidden_overlap.py・tests/test_denial_difference.py・tests/test_generated_rules.py・tests/test_related_test_extensions.py:成功(xfail 4 件は想定どおり)
  • 先に失敗するテストを書いた項目:1(wrapper の witness)・5(選択テスト)・6(Bash).4 は raises を付けた後にマーカーを固定するテストを足した
  • verification_session.py verify はローカルで pytest が 8 件失敗した.原因は PATH 上の agent-harness が lock の 0.9.9 より新しく,xfail が XPASS(strict) になるため.flake の dev shell では成功し,本変更とは無関係

計画からの変更

なし.

🤖 Generated with Claude Code

furedea and others added 4 commits November 9, 2026 23:58
…hey run

An allow prefix that is a process wrapper, such as xargs, hands its tail to
the hooks as a command, so the scoped rules of that command apply to it.
find_overlaps took only the wrapper name and skipped those rules. For a
wrapper prefix it now drops the begins-within-the-prefix constraint and
intersects the inner command's rule language, honoring programs and
exceptions. command -v is excluded because it does not run the command.

The thirteen xargs overlaps it reports are listed apart from the reviewed
ones, awaiting confirmation.

Refs #107

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…le gap

The strict xfail for the rules whose exceptions and programs the generator
drops had no raises, so a Z3 TimeoutError counted as the known gap too.
Restrict it to AssertionError and pin that in a test.

Refs #107

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
… change

test_the_generated_claude_rules_decide_like_the_source reads the generated
permissions, but agents/claude/settings.json did not map to
tests/test_generated_rules.py, so a change that only touched its Bash(...)
entries ran no comparison. Add the mapping and a selection test for it.

Refs #107

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
claude_rules skipped an entry named Bash, so a generated allow-all entry
would have passed the equivalence comparison unseen. Treat it as an
unrecognized Bash entry and raise ValueError; add it to the unknown-shape
tests.

Refs #107

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: ❌ Failed

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

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-09T15:32:07.200477Z
We couldn’t complete this review. Comment @codex review to try again.
1044b22 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.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@github-actions

github-actions Bot commented Nov 9, 2026

Copy link
Copy Markdown

Review summary (read-only)

No P0–P3 findings.

What I checked:

  • find_overlaps wrapper path: denied_command intersects the rule (anchored at the inner command's start, with exceptions removed) with run_by_program for scoped rules. The only allow prefixes that start with a guard wrapper are xargs and command -v. The first is unwrapped. The second is skipped, and COMMAND_LOOKUP is pinned against shell_wrappers. XARGS_UNCONFIRMED lists all 13 forbidden patterns, which matches the forbidden list (6+1+1+3+1+1). That is expected, because a wrapper can run any command.
  • Bare Bash now reaches claude_entry and raises ValueError. agents/claude/settings.json has no bare Bash entry, so the real config still parses.
  • raises=AssertionError on the strict xfail means a solver error or timeout now shows up as a failure instead of passing as an expected failure.
  • The related-test mapping and its selection test are consistent.

Note: I could not run the test suite in this environment (command approval was not granted), so this review comes from reading the code only.

🤖 Generated with Claude Code

…r can meet

Restricting the xfail to AssertionError exposed that the largest real rule
needs about 20 s of the 30 s Z3 limit on an idle machine and timed out on a
loaded CI runner, which the broad xfail had hidden. Raise the limit for the
denial comparison to 180 s; an undecided language still raises.

Refs #107

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

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@github-actions

github-actions Bot commented Nov 9, 2026

Copy link
Copy Markdown

レビュー結果

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

確認した点:

  • wrapped_overlaps_of:ガードの forbidden_objection は unscoped 規則を wrapper を外した canonical のコマンドにも当て,scoped 規則は argument_reason で " ".join(arguments)(先頭がプログラム名)に当てる.denied_command の START + program + (END | " " ...) と exceptions の扱いはこれと一致している.
  • 現在の allow prefix で wrapper から始まるのは xargs と command -v だけで,command -v の除外と COMMAND_LOOKUP の一致テストも妥当.
  • claude_rules の裸の Bash は claude_entry で ValueError になり,テストで固定されている.
  • find_line の timeout 引数と raises=AssertionError:タイムアウト(TimeoutError)が xfail に吸収されなくなる意図どおり.

補足(指摘ではありません):XARGS_UNCONFIRMED は REVIEWED に入っているため,ユーザーが確認するまで「確認済み」と同じ扱いでテストが通ります.PR 本文に書かれているとおり,マージ前に 13 件の確認をお願いします.

The user confirmed on 2026-11-10 that the thirteen xargs overlaps are safe:
the hooks unwrap xargs and deny the inner command, the same structure as
git add and git add . Move them into the reviewed list and drop the
unconfirmed marker.

Refs #107

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

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.


sys.path.insert(0, str(REPO_ROOT / "agents/hooks/lib"))

from shell_wrappers import COMMAND_LOOKUP as GUARD_COMMAND_LOOKUP, WRAPPERS

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 — This test now depends on agents/hooks/lib/shell_wrappers.py (WRAPPERS decides which allow prefixes get the wrapper check, and COMMAND_LOOKUP is pinned by test_the_command_lookup_options_match_the_guard). But .agents/hooks/rules/related_test_extensions.json has no entry for agents/hooks/lib/shell_wrappers.py, so a change to that file won't pick this test.

Example: someone adds nice to WRAPPERS while nice is an allow prefix, or edits COMMAND_LOOKUP. The REVIEWED set or the pin test would then fail, but selective verification never runs tests/test_forbidden_overlap.py, so nothing catches it until a full run. Suggest mapping agents/hooks/lib/shell_wrappers.py → tests/test_forbidden_overlap.py and adding a selection case in tests/test_related_test_extensions.py. You already do this for agents/claude/settings.json in this PR.

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.

Not changed. An unmapped hook lib module falls back to the full suite, which is pinned by test_an_unmapped_hook_module_keeps_its_full_suite_fallback; with the mapping I tried locally, selected_tests("agents/hooks/lib/shell_wrappers.py") returned no narrowed test list, so a change to that file already runs every test, including tests/test_forbidden_overlap.py. Adding a mapping would replace that fallback with a narrower selection, which is the opposite of what the finding wants.

@github-actions

github-actions Bot commented Nov 9, 2026

Copy link
Copy Markdown

Review summary

No blocking findings (P0/P1: 0).

  • P2: tests/test_forbidden_overlap.py now imports WRAPPERS and COMMAND_LOOKUP from agents/hooks/lib/shell_wrappers.py, but related_test_extensions.json doesn't map that file to the test. Edits to the guard's wrapper list won't select the overlap audit (inline comment).

What I checked and found fine:

  • find_overlaps wrapper path: denied_command correctly intersects with run_by_program for scoped rules and subtracts exceptions. Unscoped rules match anywhere. The command -v/-V skip matches the guard's take_option.
  • claude_rules now sends bare Bash to claude_entry, which raises ValueError as intended. agents/claude/settings.json has no bare Bash entry, so nothing current breaks.
  • find_line raises TimeoutError on unknown, so xfail(raises=AssertionError) correctly stops a solver timeout from being hidden. The longer SOLVER_TIMEOUT_MS is reasonable.
  • The new settings.json → test_generated_rules.py mapping has a selection test.

🤖 Generated with Claude Code

@furedea
furedea merged commit c005dd9 into main Nov 9, 2026
22 of 24 checks passed
@furedea
furedea deleted the test/107-wrapper-overlap branch November 9, 2026 15:46
furedea added a commit that referenced this pull request Nov 9, 2026
## 概要

agent-harness の入力を 0.9.10 から 0.9.11 相当へ更新し,既知の差分として置いていた xfail を外す.

| 項目 | 変更前 | 変更後 |
| --------------------------------- |
------------------------------------------------------- |
-------------------------------------------------------- |
| `flake.lock` の agent-harness | `6c60666`(v0.9.10) | `757abca`(v0.9.11
に CI のみの 1 commit が載った main) |
| `tests/test_denial_difference.py` | `exceptions` と `programs` を持つ rule
は xfail(strict) | 全 rule が通常のテスト |

- 0.9.11 で `generate-forbidden-commands` が `exceptions` と `programs`
を残すようになった(furedea/agent-harness#203).
- 生成された rule はソースの rule と完全に一致するので,形のテストは rule 全体を比較する.
- xfail に付随していた `DROPPED_FIELDS`,`DROPS_FIELDS`,#114 の
`raises=AssertionError` を確認するテストを削除した.これらは既知の差分のためだけに存在した.
- `tests/test_generated_rules.py` と `tests/test_forbidden_overlap.py` に
xfail はなく,変更していない.

Refs furedea/agent-harness#203

## 検証

- `nix develop --command pytest tests -q`: 4478 passed, 1 skipped(#114
を取り込んだ origin/main への rebase 後).
- rebase で #114 と `tests/test_denial_difference.py` が衝突したので,xfail
関連を全て削除する側で解決した.

## 計画からの変更

なし.

---------

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