fix(ui): silent no-ops raise ErrorReported instead of swallowing failures (UX-Audit #1)
Stop/Enqueue/Dequeue/Reset&Retry (DetailsIslandViewModel), status/cancel/reject
commands (TasksIslandViewModel), Mission Control's drag-enqueue and queue
refresh, and "Open findings folder" (ListsIslandViewModel) used to catch {}
or silently return on a blocked precondition. They now report through the
existing ErrorReported -> FlashFooterError path, with new en/de locale keys
and Ui.Tests covering each converted command.
This commit is contained in:
@@ -0,0 +1,149 @@
|
||||
using ClaudeDo.Data;
|
||||
using ClaudeDo.Data.Models;
|
||||
using ClaudeDo.Localization;
|
||||
using ClaudeDo.Ui.Localization;
|
||||
using ClaudeDo.Ui.Services;
|
||||
using ClaudeDo.Ui.ViewModels.Islands;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using TaskStatus = ClaudeDo.Data.Models.TaskStatus;
|
||||
|
||||
namespace ClaudeDo.Ui.Tests.ViewModels;
|
||||
|
||||
// UX-Audit #1: SetStatusOnRow/CancelRunningTask/RejectReviewToQueue/RejectReviewToIdle used
|
||||
// to swallow worker failures with a bare `catch { }` — nothing surfaced in the footer strip.
|
||||
// These now raise ErrorReported.
|
||||
public class TasksIslandErrorFeedbackTests : IDisposable
|
||||
{
|
||||
private readonly string _dbPath;
|
||||
|
||||
public TasksIslandErrorFeedbackTests()
|
||||
{
|
||||
_dbPath = Path.Combine(Path.GetTempPath(), $"claudedo_tasksisland_error_feedback_test_{Guid.NewGuid():N}.db");
|
||||
using var ctx = NewContext();
|
||||
ctx.Database.EnsureCreated();
|
||||
|
||||
var dir = AppContext.BaseDirectory;
|
||||
while (dir is not null && !Directory.Exists(Path.Combine(dir, "src", "ClaudeDo.Localization", "locales")))
|
||||
dir = Path.GetDirectoryName(dir);
|
||||
Loc.Current = new Localizer(
|
||||
LocaleStore.Load(Path.Combine(dir!, "src", "ClaudeDo.Localization", "locales")), "en");
|
||||
}
|
||||
|
||||
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 Exception? ThrowOnSetTaskStatus;
|
||||
public Exception? ThrowOnCancelTask;
|
||||
public Exception? ThrowOnRejectToQueue;
|
||||
public Exception? ThrowOnRejectToIdle;
|
||||
|
||||
public override Task<BaseDirtyWarningDto?> SetTaskStatusAsync(string taskId, TaskStatus status)
|
||||
{
|
||||
if (ThrowOnSetTaskStatus is not null) throw ThrowOnSetTaskStatus;
|
||||
return Task.FromResult<BaseDirtyWarningDto?>(null);
|
||||
}
|
||||
|
||||
public override Task CancelTaskAsync(string taskId)
|
||||
{
|
||||
if (ThrowOnCancelTask is not null) throw ThrowOnCancelTask;
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public override Task RejectReviewToQueueAsync(string taskId, string feedback)
|
||||
{
|
||||
if (ThrowOnRejectToQueue is not null) throw ThrowOnRejectToQueue;
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public override Task RejectReviewToIdleAsync(string taskId)
|
||||
{
|
||||
if (ThrowOnRejectToIdle is not null) throw ThrowOnRejectToIdle;
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task SetStatusOnRow_WhenWorkerThrows_RaisesErrorReported()
|
||||
{
|
||||
var worker = new ThrowingWorkerClient { ThrowOnSetTaskStatus = new Exception("status update offline") };
|
||||
var vm = new TasksIslandViewModel(new TestDbFactory(NewContext), worker);
|
||||
|
||||
string? reportedError = null;
|
||||
vm.ErrorReported += msg => reportedError = msg;
|
||||
|
||||
var row = new TaskRowViewModel { Id = "task-status-1", Status = TaskStatus.Idle };
|
||||
await vm.SetStatusOnRowAsync(row, TaskStatus.Queued);
|
||||
|
||||
Assert.NotNull(reportedError);
|
||||
Assert.Contains("status update offline", reportedError);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task CancelRunningTask_WhenWorkerThrows_RaisesErrorReported()
|
||||
{
|
||||
var worker = new ThrowingWorkerClient { ThrowOnCancelTask = new Exception("cancel offline") };
|
||||
var vm = new TasksIslandViewModel(new TestDbFactory(NewContext), worker);
|
||||
|
||||
string? reportedError = null;
|
||||
vm.ErrorReported += msg => reportedError = msg;
|
||||
|
||||
var row = new TaskRowViewModel { Id = "task-cancel-1", Status = TaskStatus.Running };
|
||||
await vm.CancelRunningTaskCommand.ExecuteAsync(row);
|
||||
|
||||
Assert.NotNull(reportedError);
|
||||
Assert.Contains("cancel offline", reportedError);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task RejectReviewToQueue_WhenWorkerThrows_RaisesErrorReported()
|
||||
{
|
||||
var worker = new ThrowingWorkerClient { ThrowOnRejectToQueue = new Exception("reject-to-queue offline") };
|
||||
var vm = new TasksIslandViewModel(new TestDbFactory(NewContext), worker);
|
||||
|
||||
string? reportedError = null;
|
||||
vm.ErrorReported += msg => reportedError = msg;
|
||||
|
||||
var row = new TaskRowViewModel { Id = "task-reject-queue-1", Status = TaskStatus.WaitingForReview };
|
||||
await vm.RejectReviewToQueueAsync(row, "needs another pass");
|
||||
|
||||
Assert.NotNull(reportedError);
|
||||
Assert.Contains("reject-to-queue offline", reportedError);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task RejectReviewToIdle_WhenWorkerThrows_RaisesErrorReported()
|
||||
{
|
||||
var worker = new ThrowingWorkerClient { ThrowOnRejectToIdle = new Exception("reject-to-idle offline") };
|
||||
var vm = new TasksIslandViewModel(new TestDbFactory(NewContext), worker);
|
||||
|
||||
string? reportedError = null;
|
||||
vm.ErrorReported += msg => reportedError = msg;
|
||||
|
||||
var row = new TaskRowViewModel { Id = "task-reject-idle-1", Status = TaskStatus.WaitingForReview };
|
||||
await vm.RejectReviewToIdleCommand.ExecuteAsync(row);
|
||||
|
||||
Assert.NotNull(reportedError);
|
||||
Assert.Contains("reject-to-idle offline", reportedError);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user