Skip to content

Cover project-checkout's branch-switch refusals against real git states - #6948

Merged
ymichael merged 1 commit into
mainfrom
bb/verify-project-checkout-branch-switch-refusals-a-thr_cnnhj7pme4
Nov 3, 2026
Merged

ymichael merged 1 commit into
mainfrom
bb/verify-project-checkout-branch-switch-refusals-a-thr_cnnhj7pme4

Conversation

@ymichael

@ymichael ymichael commented Nov 3, 2026

Copy link
Copy Markdown
Collaborator

Human comments

What was wrong

#6937 replaced the checkout inspection in environment-project-checkout (current ref, uncommitted changes, in-progress operation, conflicts) with the shared implementation in bb-environment-provider-host/workspace-git. Before the plugin runs git switch in a user's real checkout, the host's assertSwitchable uses that inspection to refuse a switch on a detached HEAD, during a merge or rebase, with conflicts, or with uncommitted changes. Only the uncommitted-changes refusal had a host test against a real repository. The server-side validate refusals are tested with mocked inspectCheckout results, so no plugin test ran the shared inspection on real detached, merge, conflict or rebase states.

What changed

Test-only. plugins/environment-project-checkout/host.test.ts gains four host tests. Each builds a real repository state, checks what inspectCheckout reports, attaches with an existing-branch switch, asserts the exact refusal message, and checks that HEAD did not move:

  • detached HEAD → checkout: detached; refused as detached
  • merge --no-commit in progress → merge, no conflicts; refused as merge in progress
  • conflicted merge → merge, with conflicts; refused for unresolved conflicts
  • conflicted rebase → rebase, with conflicts, checkout: detached. git detaches HEAD during a rebase, so the detached check refuses it first. That was also true before Delete composer and git move leftovers from core #6937; the test records it.

No production, protocol, SDK or CLI change.

How you verified

  • Removed each refusal in host/checkout.ts in turn:
    • Without the detached refusal, the detached and rebase tests fail.
    • Without the conflicts refusal, the conflicted-merge test fails.
    • Without the in-progress refusal, the merge-in-progress test fails.
    • Without the dirty refusal, the existing uncommitted-changes test fails.
  • pnpm exec turbo run test typecheck lint --filter=bb-plugin-environment-project-checkout passes.
  • Ran it live on a fresh pnpm start:worktree instance (new data dir) with scratch repos, using bb thread spawn --environment-provider project-checkout --environment-inputs '{"branch":{"kind":"existing","name":"release"}}':
    • Server validate returned HTTP 409 with: Checkout blocked while HEAD is detached (detached), …by uncommitted changes (dirty), …by an in-progress merge (merge), …by unresolved conflicts (conflicted merge), …while HEAD is detached (rebase).
    • Host attach: threads were spawned deferred while the repos were clean, each repo was then broken, and the threads were dispatched. Provisioning failed with: Cannot checkout branch while the workspace is on a detached HEAD (detached and rebase), …has uncommitted changes, …merge is in progress, …merge has unresolved conflicts.
    • Every refused repo was unchanged: same HEAD and the same git status.
    • A clean checkout switched to release. Provisioning logged "Switched to branch release" and the environment was ready with branchName: release.

AGENT GENERATED

🤖 Generated with Claude Code

The host attach path refused detached HEAD, in-progress operations and
conflicts, but only the dirty refusal had a test against a real
repository. The server-side refusals were tested with mocked inspection
results, so nothing exercised the shared checkout inspection from #6937
through the plugin for these states.

Add host tests that build a detached HEAD, a merge in progress, a merge
with conflicts and a conflicted rebase in real repositories, check what
inspectCheckout reports, and assert the exact refusal and that HEAD did
not move. A real rebase detaches HEAD, so it is refused by the detached
check; the test records that.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ymichael
ymichael merged commit a787c3c into main Nov 3, 2026
34 checks passed
@ymichael
ymichael deleted the bb/verify-project-checkout-branch-switch-refusals-a-thr_cnnhj7pme4 branch November 3, 2026 21:51
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