fix(review): propagate HubException from ApproveReviewAsync so blocked merges surface errors
TryInvokeAsync swallowed all exceptions including HubException, so a blocked merge (uncommitted changes in target, mid-merge state, inactive worktree) returned null silently — the task stayed WaitingForReview with no feedback shown. Switch to a direct _hub.InvokeAsync so both VM catch blocks (TasksIsland ErrorReported, DetailsIsland ShowErrorAsync) actually fire. Add regression tests for both call sites verifying that a throwing worker causes the error to be reported.
This commit is contained in:
@@ -450,10 +450,10 @@ public partial class WorkerClient : ObservableObject, IAsyncDisposable, IWorkerC
|
||||
await _hub.InvokeAsync("SetTaskStatus", taskId, status.ToString());
|
||||
}
|
||||
|
||||
public Task<MergeResultDto?> ApproveReviewAsync(string taskId, string targetBranch)
|
||||
public async Task<MergeResultDto?> ApproveReviewAsync(string taskId, string targetBranch)
|
||||
{
|
||||
LastApproveTarget = targetBranch;
|
||||
return TryInvokeAsync<MergeResultDto>("ApproveReview", taskId, targetBranch);
|
||||
return await _hub.InvokeAsync<MergeResultDto>("ApproveReview", taskId, targetBranch);
|
||||
}
|
||||
|
||||
public Task<MergePreviewDto?> PreviewMergeAsync(string taskId, string targetBranch)
|
||||
|
||||
@@ -137,4 +137,28 @@ public class DetailsIslandReviewActionsTests : IDisposable
|
||||
Assert.True(vm.ShowReviewDiffHint);
|
||||
Assert.False(vm.ApproveReviewCommand.CanExecute(null));
|
||||
}
|
||||
|
||||
private sealed class ThrowingWorkerClient : StubWorkerClient
|
||||
{
|
||||
public override bool IsConnected => true;
|
||||
public string ExceptionMessage { get; init; } = "blocked: target working tree has uncommitted changes";
|
||||
public override Task<MergeResultDto?> ApproveReviewAsync(string taskId, string targetBranch) =>
|
||||
throw new Exception(ExceptionMessage);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ApproveReview_WhenWorkerThrows_CallsShowErrorAsync()
|
||||
{
|
||||
var worker = new ThrowingWorkerClient();
|
||||
var vm = BuildVm(worker);
|
||||
vm.Bind(new TaskRowViewModel { Id = "task-err-1", Status = TaskStatus.WaitingForReview });
|
||||
vm.Monitor.ApplyState(TaskStatus.WaitingForReview);
|
||||
|
||||
string? reportedError = null;
|
||||
vm.ShowErrorAsync = msg => { reportedError = msg; return Task.CompletedTask; };
|
||||
|
||||
await vm.ApproveReviewCommand.ExecuteAsync(null);
|
||||
|
||||
Assert.Equal(worker.ExceptionMessage, reportedError);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
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 TasksIslandApproveReviewTests : IDisposable
|
||||
{
|
||||
private readonly string _dbPath;
|
||||
|
||||
public TasksIslandApproveReviewTests()
|
||||
{
|
||||
_dbPath = Path.Combine(Path.GetTempPath(), $"claudedo_approve_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 ThrowingWorkerClient : StubWorkerClient
|
||||
{
|
||||
public string ExceptionMessage { get; init; } = "blocked: target working tree has uncommitted changes";
|
||||
public override Task<MergeResultDto?> ApproveReviewAsync(string taskId, string targetBranch) =>
|
||||
throw new Exception(ExceptionMessage);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ApproveReview_WhenWorkerThrows_RaisesErrorReported()
|
||||
{
|
||||
var worker = new ThrowingWorkerClient();
|
||||
var factory = new TestDbFactory(NewContext);
|
||||
var vm = new TasksIslandViewModel(factory, worker);
|
||||
|
||||
string? reportedError = null;
|
||||
vm.ErrorReported += msg => reportedError = msg;
|
||||
|
||||
var row = new TaskRowViewModel { Id = "task-err-2", Status = TaskStatus.WaitingForReview };
|
||||
await vm.ApproveReviewCommand.ExecuteAsync(row);
|
||||
|
||||
Assert.NotNull(reportedError);
|
||||
Assert.Contains(worker.ExceptionMessage, reportedError);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user