Repository navigation
refactor: single owners for the git test fixture and read-only subcommand classification - #382
Merged
Merged
Conversation
`init_repo` had 13 private copies across 7 crates, all re-running the same three git invocations, while `forge-test-support` exists precisely to hold fixtures shared across crates. Move the fixture there as `git`, `init_repo` and `init_repo_with_commit` (the committing variant `forge-storage`'s worktree tests needed), cover it with tests, and adopt it in `forge-storage` and `forge-session`. Test-only; no production code changes.
`forge-governance` (deciding whether `bash git …` can be rewritten onto the confined `git` tool without a HITL prompt) and `forge-transcript` (deciding whether a git call is presented as exploration or as a change) each carried an identical copy of the same eight-subcommand list. Drift between them is a user-visible inconsistency between what the transcript says happened and what ran without asking, so move the predicate to `forge-types` — the crate both already depend on — as `is_readonly_git_subcommand`, with tests. Same list, same semantics; no behavior change.
…larity # Conflicts: # crates/forge-governance/src/readonly.rs
mohitranka
added a commit
that referenced
this pull request
Aug 21, 2026
…mand classification (#382) * refactor(test-support): give the git working-copy fixture a single home `init_repo` had 13 private copies across 7 crates, all re-running the same three git invocations, while `forge-test-support` exists precisely to hold fixtures shared across crates. Move the fixture there as `git`, `init_repo` and `init_repo_with_commit` (the committing variant `forge-storage`'s worktree tests needed), cover it with tests, and adopt it in `forge-storage` and `forge-session`. Test-only; no production code changes. * refactor(types): one owner for read-only git subcommand classification `forge-governance` (deciding whether `bash git …` can be rewritten onto the confined `git` tool without a HITL prompt) and `forge-transcript` (deciding whether a git call is presented as exploration or as a change) each carried an identical copy of the same eight-subcommand list. Drift between them is a user-visible inconsistency between what the transcript says happened and what ran without asking, so move the predicate to `forge-types` — the crate both already depend on — as `is_readonly_git_subcommand`, with tests. Same list, same semantics; no behavior change.
mohitranka
added a commit
that referenced
this pull request
Sep 11, 2026
…mand classification (#382) * refactor(test-support): give the git working-copy fixture a single home `init_repo` had 13 private copies across 7 crates, all re-running the same three git invocations, while `forge-test-support` exists precisely to hold fixtures shared across crates. Move the fixture there as `git`, `init_repo` and `init_repo_with_commit` (the committing variant `forge-storage`'s worktree tests needed), cover it with tests, and adopt it in `forge-storage` and `forge-session`. Test-only; no production code changes. * refactor(types): one owner for read-only git subcommand classification `forge-governance` (deciding whether `bash git …` can be rewritten onto the confined `git` tool without a HITL prompt) and `forge-transcript` (deciding whether a git call is presented as exploration or as a change) each carried an identical copy of the same eight-subcommand list. Drift between them is a user-visible inconsistency between what the transcript says happened and what ran without asking, so move the predicate to `forge-types` — the crate both already depend on — as `is_readonly_git_subcommand`, with tests. Same list, same semantics; no behavior change.
mohitranka
added a commit
that referenced
this pull request
Sep 11, 2026
…mand classification (#382) * refactor(test-support): give the git working-copy fixture a single home `init_repo` had 13 private copies across 7 crates, all re-running the same three git invocations, while `forge-test-support` exists precisely to hold fixtures shared across crates. Move the fixture there as `git`, `init_repo` and `init_repo_with_commit` (the committing variant `forge-storage`'s worktree tests needed), cover it with tests, and adopt it in `forge-storage` and `forge-session`. Test-only; no production code changes. * refactor(types): one owner for read-only git subcommand classification `forge-governance` (deciding whether `bash git …` can be rewritten onto the confined `git` tool without a HITL prompt) and `forge-transcript` (deciding whether a git call is presented as exploration or as a change) each carried an identical copy of the same eight-subcommand list. Drift between them is a user-visible inconsistency between what the transcript says happened and what ran without asking, so move the predicate to `forge-types` — the crate both already depend on — as `is_readonly_git_subcommand`, with tests. Same list, same semantics; no behavior change.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two deduplications, each with a single owner replacing copies that had no mechanism to stay in sync. No production behavior changes; the second commit moves a function without altering its semantics.
1. One home for the git working-copy test fixture
The fixture that creates a throwaway git repo had 13 private copies across 7 crates (
grep -l 'fn init_repo':forge-core×2,forge-session,forge-tui×4,forge-storage×4,forge-context, plusvisual_test.rs). A normalized near-duplicate scan flagged 5-way identical blocks of the same threegitinvocations.crates/forge-test-supportalready existed, documented as "Test-only fixtures shared across crates", and held onlymock_http. It now also ownsgit(),init_repo()andinit_repo_with_commit()— the committing variant exists becauseforge-storage's worktree tests need a realHEADrather than an unborn one, a distinction the copies handled inconsistently.Adopted in 5 of the 13 sites (
forge-storage's four modules andforge-session), deleting their local definitions. Theresolver.rscopy used a weaker.unwrap()/bare-assert form; it now gets the informative failure message, so the only observable change is panic text on an already-failing fixture.The remaining 8 copies are in
forge-tui,forge-coreandforge-context— crates that were under concurrent modification when this branch was written. The shared home now exists, so adopting them is a one-line-per-site follow-up.2. One owner for read-only git subcommand classification
is_readonly_git_subcommandhad two identical 8-arm copies:forge-governance/src/readonly.rs— decides whether abash git …call may be rewritten onto the confinedgittool.forge-transcript/src/lib.rs— decides whether a git call renders as exploration or as a change.Divergence would make the transcript and the approval path disagree about the same command: a subcommand the UI calls a read while governance treats it as mutating (or the reverse) is a user-visible inconsistency between what the UI says happened and what was actually allowed to happen without asking.
Now
crates/forge-types/src/git.rs, with three tests and a doc comment recording why both callers must agree.forge-typesis the natural home — the only crate both depend on, and it already carries a shared free function (strip_protocol_markers) alongside its types. Same list, same semantics.Its doc comment is explicit that the classification is matched on the subcommand alone and that callers needing more must layer their own argument checks — which is what
branch_is_readonlydoes, per #381.Merge note
Merged
mainin rather than rebasing, so the two commits stay intact. One conflict, inreadonly.rs: this branch deletesis_readonly_git_subcommand(moved toforge-types) while #381 added a doc comment to the adjacentbranch_is_readonly. Resolved to keep both — the deletion and the new doc comment. Verified afterwards that the diff againstmaincontains only this refactor, with nothing from #379/#380/#381 reverted.Verification
cargo fmt --all -- --check,cargo clippy --workspace --all-targets --locked -- -D warnings, andcargo test --workspace --locked --no-fail-fastall green on the merge commit.