Skip to content

refactor: single owners for the git test fixture and read-only subcommand classification - #382

Merged
github-actions[bot] merged 3 commits into
mainfrom
refactor/structural-clarity
Aug 17, 2026
Merged

github-actions[bot] merged 3 commits into
mainfrom
refactor/structural-clarity

Conversation

@mohitranka

Copy link
Copy Markdown
Contributor

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, plus visual_test.rs). A normalized near-duplicate scan flagged 5-way identical blocks of the same three git invocations.

crates/forge-test-support already existed, documented as "Test-only fixtures shared across crates", and held only mock_http. It now also owns git(), init_repo() and init_repo_with_commit() — the committing variant exists because forge-storage's worktree tests need a real HEAD rather than an unborn one, a distinction the copies handled inconsistently.

Adopted in 5 of the 13 sites (forge-storage's four modules and forge-session), deleting their local definitions. The resolver.rs copy 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-core and forge-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_subcommand had two identical 8-arm copies:

  • forge-governance/src/readonly.rs — decides whether a bash git … call may be rewritten onto the confined git tool.
  • 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-types is 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_readonly does, per #381.

Merge note

Merged main in rather than rebasing, so the two commits stay intact. One conflict, in readonly.rs: this branch deletes is_readonly_git_subcommand (moved to forge-types) while #381 added a doc comment to the adjacent branch_is_readonly. Resolved to keep both — the deletion and the new doc comment. Verified afterwards that the diff against main contains only this refactor, with nothing from #379/#380/#381 reverted.

Verification

cargo fmt --all -- --check, cargo clippy --workspace --all-targets --locked -- -D warnings, and cargo test --workspace --locked --no-fail-fast all green on the merge commit.

`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
@github-actions
github-actions Bot enabled auto-merge (squash) August 17, 2026 02:20
@github-actions
github-actions Bot merged commit a704821 into main Aug 17, 2026
7 checks passed
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.
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