Approve & Merge is disabled until the pending changes have been inspected: DetailsIslandViewModel tracks ReviewDiffViewed (reset on task switch and on every state change), MergeSectionViewModel raises DiffViewed when a diff or combined diff is opened and exposes HasReviewableDiff, and a hint sits next to the button. A review with nothing to inspect (sandbox run, no worktree) approves straight through. ClaudeDo-Task: f9809a93
141 lines
5.1 KiB
C#
141 lines
5.1 KiB
C#
using ClaudeDo.Data;
|
|
using ClaudeDo.Data.Models;
|
|
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 DetailsIslandReviewActionsTests : IDisposable
|
|
{
|
|
private readonly string _dbPath;
|
|
|
|
public DetailsIslandReviewActionsTests()
|
|
{
|
|
_dbPath = Path.Combine(Path.GetTempPath(), $"claudedo_review_actions_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 TestDbFactory : IDbContextFactory<ClaudeDoDbContext>
|
|
{
|
|
private readonly Func<ClaudeDoDbContext> _create;
|
|
public TestDbFactory(Func<ClaudeDoDbContext> create) => _create = create;
|
|
public ClaudeDoDbContext CreateDbContext() => _create();
|
|
}
|
|
|
|
private sealed class NullServiceProvider : IServiceProvider
|
|
{
|
|
public object? GetService(Type serviceType) => null;
|
|
}
|
|
|
|
private sealed class StubNotesApi : ClaudeDo.Ui.Services.Interfaces.INotesApi
|
|
{
|
|
public Task<List<DailyNoteDto>> ListAsync(DateOnly day) =>
|
|
Task.FromResult(new List<DailyNoteDto>());
|
|
public Task<DailyNoteDto?> AddAsync(DateOnly day, string text) =>
|
|
Task.FromResult<DailyNoteDto?>(null);
|
|
public Task UpdateAsync(string id, string text) => Task.CompletedTask;
|
|
public Task DeleteAsync(string id) => Task.CompletedTask;
|
|
}
|
|
|
|
private sealed class RecordingWorkerClient : StubWorkerClient
|
|
{
|
|
public override bool IsConnected => true;
|
|
public string? ParkedTaskId;
|
|
public override Task RejectReviewToIdleAsync(string taskId)
|
|
{
|
|
ParkedTaskId = taskId;
|
|
return Task.CompletedTask;
|
|
}
|
|
}
|
|
|
|
private DetailsIslandViewModel BuildVm(StubWorkerClient worker)
|
|
{
|
|
var factory = new TestDbFactory(NewContext);
|
|
return new DetailsIslandViewModel(factory, worker, new NullServiceProvider(), new StubNotesApi(), new ClaudeDo.Ui.Services.MergeCoordinator());
|
|
}
|
|
|
|
[Fact]
|
|
public async Task ParkReview_CallsRejectReviewToIdle_ForTheBoundTask()
|
|
{
|
|
var worker = new RecordingWorkerClient();
|
|
var vm = BuildVm(worker);
|
|
vm.Bind(new TaskRowViewModel { Id = "task-park-1", Status = TaskStatus.WaitingForReview });
|
|
|
|
await vm.ParkReviewCommand.ExecuteAsync(null);
|
|
|
|
Assert.Equal("task-park-1", worker.ParkedTaskId);
|
|
}
|
|
|
|
[Fact]
|
|
public void SendBack_IsDisabledUntilFeedbackIsEntered()
|
|
{
|
|
var vm = BuildVm(new RecordingWorkerClient());
|
|
vm.Bind(new TaskRowViewModel { Id = "task-fb-1", Status = TaskStatus.WaitingForReview });
|
|
|
|
Assert.False(vm.RejectReviewCommand.CanExecute(null));
|
|
|
|
vm.ReviewFeedback = "tighten the error handling";
|
|
Assert.True(vm.RejectReviewCommand.CanExecute(null));
|
|
|
|
vm.ReviewFeedback = " ";
|
|
Assert.False(vm.RejectReviewCommand.CanExecute(null));
|
|
}
|
|
|
|
[Fact]
|
|
public void Approve_IsEnabled_WhenThereIsNothingToReview()
|
|
{
|
|
// A childless sandbox run has no worktree diff to inspect, so the gate must
|
|
// not block it — it approves straight through.
|
|
var vm = BuildVm(new RecordingWorkerClient());
|
|
vm.Bind(new TaskRowViewModel { Id = "task-nodiff-1", Status = TaskStatus.WaitingForReview });
|
|
vm.Monitor.ApplyState(TaskStatus.WaitingForReview);
|
|
|
|
Assert.False(vm.Merge.HasReviewableDiff);
|
|
Assert.False(vm.ShowReviewDiffHint);
|
|
Assert.True(vm.ApproveReviewCommand.CanExecute(null));
|
|
}
|
|
|
|
[Fact]
|
|
public void Approve_IsGatedUntilDiffOpened_AndReLocksOnNewRun()
|
|
{
|
|
var vm = BuildVm(new RecordingWorkerClient());
|
|
vm.Bind(new TaskRowViewModel { Id = "task-diff-1", Status = TaskStatus.WaitingForReview });
|
|
vm.Merge.SyncWorktree("/tmp/wt", null, null, "Active", null);
|
|
vm.Monitor.ApplyState(TaskStatus.WaitingForReview);
|
|
|
|
// There is a diff to read, but it has not been opened → merge is blocked.
|
|
Assert.True(vm.Merge.HasReviewableDiff);
|
|
Assert.True(vm.ShowReviewDiffHint);
|
|
Assert.False(vm.ApproveReviewCommand.CanExecute(null));
|
|
|
|
// Opening the diff records the inspection and unlocks the merge.
|
|
vm.Merge.DiffViewed?.Invoke();
|
|
Assert.False(vm.ShowReviewDiffHint);
|
|
Assert.True(vm.ApproveReviewCommand.CanExecute(null));
|
|
|
|
// A new run means a fresh diff — the gate re-engages.
|
|
vm.Monitor.ApplyState(TaskStatus.Running);
|
|
vm.Monitor.ApplyState(TaskStatus.WaitingForReview);
|
|
Assert.True(vm.ShowReviewDiffHint);
|
|
Assert.False(vm.ApproveReviewCommand.CanExecute(null));
|
|
}
|
|
}
|