diff --git a/crates/maestro-e2e/tests/e2e.rs b/crates/maestro-e2e/tests/e2e.rs index d883908..1d67e8c 100644 --- a/crates/maestro-e2e/tests/e2e.rs +++ b/crates/maestro-e2e/tests/e2e.rs @@ -323,10 +323,11 @@ async fn spawn_new_branch_creates_worktree_and_runs_in_it() { client.kill_session(s.id).await.expect("kill"); } -/// #66: a second spawn onto a branch that already has a worktree is rejected -/// with a structured worktree error; the first worktree stays intact. +/// #66/#77: a second spawn onto the same branch used to be rejected outright; +/// since the branch-collision suffixing landed, it succeeds instead — the +/// second worktree lands on `-2` and the first stays untouched. #[tokio::test(flavor = "multi_thread")] -async fn second_spawn_on_same_branch_is_rejected() { +async fn second_spawn_on_same_branch_gets_suffixed() { let (_daemon, client) = bring_up().await; let base = TempDir::new().unwrap(); @@ -336,28 +337,33 @@ async fn second_spawn_on_same_branch_is_rejected() { .spawn_session(&worktree_req(base.path(), "feature/dup", true)) .await .expect("first spawn"); - let dup = client + let second = client .spawn_session(&worktree_req(base.path(), "feature/dup", true)) - .await; - match dup { - Err(maestro_e2e::ClientError::Api(maestro_protocol::ClientError::Api { info, .. })) => { - assert_eq!( - info.code, "worktree_failed", - "expected worktree error: {info:?}" - ); - } - other => panic!("expected rejection for duplicate branch, got {other:?}"), - } + .await + .expect("second spawn suffixes instead of rejecting"); - // Exactly one registration, one directory, still usable. - // Count branch records only: the worktree path now contains the branch - // name too (`worktrees/feature/dup`), so a substring match over every line - // would count the same tree twice. - let holders = git_worktree_list(base.path()) - .iter() - .filter(|w| w.as_str() == "branch refs/heads/feature/dup") - .count(); - assert_eq!(holders, 1, "duplicate spawn must not register another tree"); + let suffixed = base.path().join("worktrees").join("feature").join("dup-2"); + assert_eq!( + second.cwd, suffixed, + "second worktree must land on the suffixed path" + ); + assert!(suffixed.is_dir()); + + // Both registrations exist: the original branch, untouched, and the + // suffixed one the second spawn created. + let registrations = git_worktree_list(base.path()); + assert!( + registrations + .iter() + .any(|l| l.as_str() == "branch refs/heads/feature/dup"), + "original branch must stay registered: {registrations:?}" + ); + assert!( + registrations + .iter() + .any(|l| l.as_str() == "branch refs/heads/feature/dup-2"), + "suffixed branch must be registered too: {registrations:?}" + ); assert!( base.path() .join("worktrees") @@ -368,7 +374,8 @@ async fn second_spawn_on_same_branch_is_rejected() { ); let _origin = throwaway_origin(base.path()); - client.kill_session(first.id).await.expect("kill"); + client.kill_session(first.id).await.expect("kill first"); + client.kill_session(second.id).await.expect("kill second"); } /// #66/#56: when the client picks a *linked worktree* as base_repo, placement