The resolver restarts the merge via StartConflictMerge, which had no autostash. After a stash-retry approve reported 'conflict', the restart hit the same dirty target, got 'dirty_target' and the resolver silently never opened. Thread the consent through the hub, client, coordinator and resolver; surface a refusal in the footer instead of dropping it. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
112 lines
4.0 KiB
C#
112 lines
4.0 KiB
C#
using System.Collections.ObjectModel;
|
|
using ClaudeDo.Data;
|
|
using ClaudeDo.Data.Models;
|
|
using ClaudeDo.Data.Repositories;
|
|
using ClaudeDo.Ui.Services;
|
|
using ClaudeDo.Ui.ViewModels.Islands;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using TaskStatus = ClaudeDo.Data.Models.TaskStatus;
|
|
|
|
namespace ClaudeDo.Ui.Tests.ViewModels;
|
|
|
|
public class DetailsIslandConflictSeamTests : IDisposable
|
|
{
|
|
private readonly string _dbPath;
|
|
|
|
public DetailsIslandConflictSeamTests()
|
|
{
|
|
_dbPath = Path.Combine(Path.GetTempPath(), $"claudedo_conflict_seam_test_{Guid.NewGuid():N}.db");
|
|
using var ctx = NewContext();
|
|
ctx.Database.EnsureCreated();
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
try { File.Delete(_dbPath); } catch { }
|
|
try { File.Delete(_dbPath + "-wal"); } catch { }
|
|
try { File.Delete(_dbPath + "-shm"); } catch { }
|
|
}
|
|
|
|
private ClaudeDoDbContext NewContext()
|
|
{
|
|
var opts = new DbContextOptionsBuilder<ClaudeDoDbContext>()
|
|
.UseSqlite($"Data Source={_dbPath}")
|
|
.Options;
|
|
return new ClaudeDoDbContext(opts);
|
|
}
|
|
|
|
|
|
|
|
|
|
private sealed class ConflictApproveWorkerClient : StubWorkerClient
|
|
{
|
|
public override bool IsConnected => true;
|
|
public override Task<MergeResultDto?> ApproveReviewAsync(string taskId, string targetBranch, bool autostash = false) =>
|
|
Task.FromResult<MergeResultDto?>(new MergeResultDto("conflict", new[] { "a.cs" }, null));
|
|
}
|
|
|
|
private DetailsIslandViewModel BuildVm(StubWorkerClient worker, MergeCoordinator merge)
|
|
{
|
|
var factory = new TestDbFactory(NewContext);
|
|
return new DetailsIslandViewModel(factory, worker, new NullServiceProvider(), merge);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task ApproveReview_OnConflict_InvokesConflictResolutionSeam()
|
|
{
|
|
const string taskId = "task-conflict-1";
|
|
|
|
string? capturedTaskId = null;
|
|
string? capturedTarget = null;
|
|
var coordinator = new MergeCoordinator
|
|
{
|
|
Handler = (tid, target, _) =>
|
|
{
|
|
capturedTaskId = tid;
|
|
capturedTarget = target;
|
|
return Task.CompletedTask;
|
|
},
|
|
};
|
|
|
|
var vm = BuildVm(new ConflictApproveWorkerClient(), coordinator);
|
|
vm.Bind(new TaskRowViewModel { Id = taskId, Status = TaskStatus.WaitingForReview });
|
|
vm.Merge.SelectedMergeTarget = "main";
|
|
|
|
await vm.ApproveReviewCommand.ExecuteAsync(null);
|
|
|
|
Assert.Equal(taskId, capturedTaskId);
|
|
Assert.Equal("main", capturedTarget);
|
|
}
|
|
|
|
/// <summary>Models the worker: a dirty target refuses the merge unless the caller consented to the stash.</summary>
|
|
private sealed class DirtyTargetConflictWorkerClient : StubWorkerClient
|
|
{
|
|
public override bool IsConnected => true;
|
|
public override Task<MergeResultDto?> ApproveReviewAsync(string taskId, string targetBranch, bool autostash = false) =>
|
|
Task.FromResult<MergeResultDto?>(autostash
|
|
? new MergeResultDto("conflict", new[] { "a.cs" }, null)
|
|
: new MergeResultDto("dirty_target", Array.Empty<string>(), "target working tree has uncommitted changes"));
|
|
}
|
|
|
|
[Fact]
|
|
public async Task ApproveReview_StashRetryEndsInConflict_HandsTheStashConsentToTheResolver()
|
|
{
|
|
// Regression: the resolver restarts the merge itself; without the consent it hit the same
|
|
// dirty target, got "dirty_target" and silently never opened.
|
|
bool? capturedAutostash = null;
|
|
var coordinator = new MergeCoordinator
|
|
{
|
|
Handler = (_, _, autostash) => { capturedAutostash = autostash; return Task.CompletedTask; },
|
|
};
|
|
|
|
var vm = BuildVm(new DirtyTargetConflictWorkerClient(), coordinator);
|
|
vm.Dialogs = new RecordingDialogService { ConfirmResult = true };
|
|
vm.Bind(new TaskRowViewModel { Id = "task-dirty-1", Status = TaskStatus.WaitingForReview });
|
|
vm.Merge.SelectedMergeTarget = "main";
|
|
|
|
await vm.ApproveReviewCommand.ExecuteAsync(null);
|
|
|
|
Assert.True(capturedAutostash);
|
|
}
|
|
}
|