fix(planning): return to the list base branch after integration cleanup, not a guessed task branch
This commit is contained in:
@@ -214,6 +214,39 @@ public class PlanningAggregatorTests : IDisposable
|
||||
Assert.DoesNotContain(branches, b => b == ok.Value.IntegrationBranch);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(null, "main")]
|
||||
[InlineData("dev", "dev")]
|
||||
public async Task CleanupIntegrationBranchAsync_ReturnsToBaseBranchOrMain_NotATaskBranch(string? baseBranch, string expected)
|
||||
{
|
||||
var db = NewDb();
|
||||
var repo = NewRepo();
|
||||
GitRepoFixture.RunGit(repo.RepoDir, "branch", "-m", "main");
|
||||
GitRepoFixture.RunGit(repo.RepoDir, "branch", "dev");
|
||||
var (parentId, _, _) = await SeedPlanningWithTwoChildrenAsync(db, repo);
|
||||
|
||||
// Sorts before main and is checked out in a worktree — the old guess picked it and the checkout threw.
|
||||
var taskWt = Path.Combine(Path.GetTempPath(), $"wt_{Guid.NewGuid():N}");
|
||||
_wtCleanups.Add((repo.RepoDir, taskWt));
|
||||
GitRepoFixture.RunGit(repo.RepoDir, "worktree", "add", "-b", "chore/1-task", taskWt, repo.BaseCommit);
|
||||
|
||||
if (baseBranch is not null)
|
||||
{
|
||||
using var ctx = db.CreateContext();
|
||||
var listId = (await new TaskRepository(ctx).GetByIdAsync(parentId))!.ListId;
|
||||
await new ListRepository(ctx).SetConfigAsync(new ListConfigEntity { ListId = listId, BaseBranch = baseBranch });
|
||||
}
|
||||
|
||||
var git = new GitService();
|
||||
var svc = new PlanningAggregator(db.CreateFactory(), git, NullLogger<PlanningAggregator>.Instance);
|
||||
var built = Assert.IsType<CombinedDiffResult.Ok>(await svc.BuildIntegrationBranchAsync(parentId, "main", CancellationToken.None));
|
||||
Assert.Equal(built.Value.IntegrationBranch, await git.GetCurrentBranchAsync(repo.RepoDir));
|
||||
|
||||
await svc.CleanupIntegrationBranchAsync(parentId, CancellationToken.None);
|
||||
|
||||
Assert.Equal(expected, await git.GetCurrentBranchAsync(repo.RepoDir));
|
||||
}
|
||||
|
||||
private void SeedWorktreeWithFile(ClaudeDoDbContext ctx, GitRepoFixture repo, string taskId, string filename, string content)
|
||||
{
|
||||
var wtPath = Path.Combine(Path.GetTempPath(), $"wt_{Guid.NewGuid():N}");
|
||||
|
||||
Reference in New Issue
Block a user