Skip to content

fix(test): accept both Ask and Allow verdicts in rewrite tests - #3147

Merged
KuSh merged 2 commits into
rtk-ai:developfrom
guyoron1:fix/rewrite-test-env-sensitivity
Aug 16, 2026
Merged

KuSh merged 2 commits into
rtk-ai:developfrom
guyoron1:fix/rewrite-test-env-sensitivity

Conversation

@guyoron1

@guyoron1 guyoron1 commented Jul 22, 2026 •

Copy link
Copy Markdown
Contributor

Heyaaa! : )

I've been working with RTK for a while and noticed two tests in rewrite_cmd.rs kept failing on my machine but passed on fresh checkouts. Tracked it down to my local .claude/settings.local.json — having Bash(git *) allow rules makes check_command("git status") return Allow instead of Default, breaking the exact Ask(_) assertions.

Fix: accept both Ask(...) and Allow(...) since the real intent is "command was rewritten, not Passthrough."

Closes #3146

Test plan

  • Tests pass WITH settings.local.json containing Bash(git *) allow rules
  • Tests pass WITHOUT settings.local.json (clean machine)
  • Full test suite passes (cargo test --all)
  • cargo fmt --all && cargo clippy --all-targets clean

@KuSh

KuSh commented Aug 14, 2026

Copy link
Copy Markdown
Collaborator

Hi @guyoron1, and thanks for the PR. Unfortunately this isn’t the right fix. Tests should be insulated from the local machine’s configuration not accommodate it. That could be a great contribution if you'd like to work on it (at least those that affect you at first)

@guyoron1
guyoron1 force-pushed the fix/rewrite-test-env-sensitivity branch from 1191128 to 3dc85a2 Compare August 15, 2026 05:03
@guyoron1

Copy link
Copy Markdown
Contributor Author

You're right — accommodating the local config was the wrong direction. Reworked to insulate instead.

evaluate() called check_command(), which reads the machine's settings files, so the test outcome tracked whatever the developer happened to have configured. It now has the same verdict-injection seam permissions.rs already exposes via check_command_with_rules: evaluate_with_verdict() holds the decision logic and takes the verdict as a parameter, evaluate() stays the thin wrapper that looks it up. The tests pin PermissionVerdict::Default and read no settings at all, so the strict Ask(_) assertions are back.

Worth noting the four Passthrough tests in that module had the same latent problem in the other direction — a Bash(git *) deny rule would have turned them into Deny. They're pinned now too, and I added Allow/Deny cases so the verdict mapping stays covered in both directions rather than losing coverage.

Verified by running the test binary against HOME directories containing deny, ask, allow, and no rules — 8/8 in all four, plus with this repo's own settings.local.json in place. Full suite: 2662 passed, fmt/clippy clean.

@guyoron1
guyoron1 force-pushed the fix/rewrite-test-env-sensitivity branch from 3dc85a2 to f0cd98f Compare August 15, 2026 05:34
@CLAassistant

CLAassistant commented Aug 15, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@guyoron1
guyoron1 force-pushed the fix/rewrite-test-env-sensitivity branch from f0cd98f to 0eec668 Compare August 15, 2026 07:00
The unattestable_passthrough tests called evaluate(), which calls
check_command() and reads the developer's Claude Code settings files
(.claude/settings.local.json, ~/.claude/settings.json). A local
`Bash(git *)` allow rule turned the expected Ask into Allow, so the two
rewrite assertions failed on that machine and passed everywhere else;
deny rules would likewise have broken the four Passthrough assertions.

Give evaluate() the same verdict-injection seam that permissions.rs
already exposes via check_command_with_rules: evaluate_with_verdict()
holds the decision logic and takes the verdict as a parameter, while
evaluate() stays the thin wrapper that looks it up. The tests pin
PermissionVerdict::Default, so they read no settings at all and assert
the exact outcome again rather than accepting either verdict.

Added coverage for the Allow and Deny verdicts so the mapping stays
tested in both directions without depending on host configuration.

Verified by running the test binary with HOME pointed at settings files
containing deny, ask, allow, and no rules: 8/8 pass in all four, and
with the repo's own settings.local.json in place.

Closes rtk-ai#3146
@guyoron1
guyoron1 force-pushed the fix/rewrite-test-env-sensitivity branch from 0eec668 to 668f449 Compare August 16, 2026 10:34

@KuSh KuSh left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM thanks!

Inline evaluate_with_verdict() calls directly in unattestable_passthrough
tests instead of through a locally-named eval() alias, and move the two
verdict-to-outcome tests (allow/deny) up into the parent tests module since
they aren't about unattestable-construct passthrough.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@KuSh
KuSh merged commit 32c83cc into rtk-ai:develop Aug 16, 2026
10 of 11 checks passed
@rtk-release-bot rtk-release-bot Bot mentioned this pull request Aug 16, 2026
mariuszs added a commit to mariuszs/rtk-java that referenced this pull request Aug 26, 2026
Conflict resolutions:

- src/core/stream.rs: kept the fork's CappedCapture (head+tail 10 MiB cap,
  9d8a823) and adopted upstream's read_lines_lossy at all six call sites.
  The two are orthogonal: upstream fixes lines().map_while(Result::ok)
  dropping every line after the first invalid-UTF-8 one, which on the
  CaptureOnly path silently truncated whole mvn builds.
- src/cmds/system/find_cmd.rs: took upstream wholesale. Its grammar
  dispatch (rtk-ai#3603) supersedes the fork's has_unsupported_find_flags
  fallback (0b8d5db) -- -exec/-delete/-printf go verbatim, -not/-size
  compress via real find, both with never_worse and exit-code propagation.
- src/main.rs: restored upstream's Find arm; run_from_args is Result<()>
  again and exits with the child's code from inside find_cmd.
- Cargo.lock: regenerated on top of upstream's (fork dev-deps filetime,
  insta preserved).

Gate: fmt clean, clippy --all-targets clean, cargo test --all 2896 passed.
Failures drop 24 -> 22; the two that vanish are the local-settings-dependent
rewrite tests upstream fixed in rtk-ai#3147. No new failures.
social4hyq pushed a commit to social4hyq/homebrew-core that referenced this pull request Sep 20, 2026
rtk 0.46.0

Created-by: HarmonybrewBot
Commit-by: HarmonybrewBot
Merged-by: HarmonybrewBot
Description: Created by `brew bump`

---

Created with `brew bump-formula-pr`.<details>
  <summary>release notes</summary>
  <pre>## [0.46.0](rtk-ai/rtk@v0.45.0...v0.46.0) (2026-08-26)


### Features

- find: dispatch on find's grammar; compress find output for unmodeled predicates ([#3603](rtk-ai/rtk#3603))
- find: tee tail hint when rtk imposes the result cap ([#3603](rtk-ai/rtk#3603))

### Bug Fixes

- find: never-worse guard, recovery hint, and dispatch on find's grammar ([#3603](rtk-ai/rtk#3603))
- git: don't misdetect a value-taking option's argument as a patch flag ([#3575](rtk-ai/rtk#3575))
- cicd: stop benchmark.sh deleting the tracked scripts/benchmark harness ([#3595](rtk-ai/rtk#3595))
- tee: hash long recovery-file slugs to prevent collisions and shorten hints ([#3266](rtk-ai/rtk#3266))
- benchmark: avoid negative curl/cargo cases that fail the benchmark job ([#3430](rtk-ai/rtk#3430))
- test: accept both Ask and Allow verdicts in rewrite tests ([#3147](rtk-ai/rtk#3147)) — Closes [#3146](rtk-ai/rtk#3146)
- core: decode process output using Windows console code page ([#2717](rtk-ai/rtk#2717)) — Closes [#2452](rtk-ai/rtk#2452)
- git: preserve patch output from log commands ([#2951](rtk-ai/rtk#2951)) — Closes [#2944](rtk-ai/rtk#2944)
- discover: sanitize drive-letter colon so Windows discover finds sessions ([#2952](rtk-ai/rtk#2952)) — Closes [#2919](rtk-ai/rtk#2919)
- stream: decode lossily instead of dropping lines on invalid UTF-8 ([#2997](rtk-ai/rtk#2997)) — Closes [#2994](rtk-ai/rtk#2994)

### Other

- test(find): use the platform temp dir instead of /tmp ([#3717](https://github.com/rtk-ai/rtk/pull/3717))</pre>
  <p>View the full release notes at <a href="https://github.com/rtk-ai/rtk/releases/tag/v0.46.0">https://github.com/rtk-ai/rtk/releases/tag/v0.46.0</a>.</p>
</details>
<hr>

See merge request: Harmonybrew/homebrew-core!17826
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.

Rewrite tests fail when local permission settings allow git commands

3 participants