fix(worker): route done-toggle and dequeue through guarded TaskStateService transitions

The task-list done toggle (both islands) and RemoveFromQueue wrote TaskEntity.Status
directly via EF, bypassing TaskStateService: no TaskUpdated broadcast, no guard against
a concurrent picker claim (lost update), and no status-based filter. Added guarded
MarkDoneAsync/UnmarkDoneAsync/DequeueToIdleAsync transitions plus matching hub methods
(SetTaskDone/UnsetTaskDone/DequeueTask) and IWorkerClient wrappers; the three UI call
sites now route through the hub with optimistic-then-revert row updates and
ErrorReported on failure. RemoveFromQueueAsync dequeues each queued child individually
through the same guarded path instead of cascading via a raw EF update.

Also closes two hub guard gaps: UpdateListConfig's delete branch now preserves a list's
SerializeOnFileOverlap flag instead of dropping it, and SubmitTaskForReview's Idle/Failed
status gate now runs before either mutation branch so a Done/Cancelled task can't get
committed or stamped and then rejected.
This commit is contained in:
mika kuns
2026-08-21 11:47:24 +02:00
parent ce98f65ca5
commit 7f337b36c7
20 changed files with 806 additions and 49 deletions
@@ -73,6 +73,8 @@ public class DetailsIslandErrorFeedbackTests : IDisposable
public override bool IsConnected => Connected;
public Exception? ThrowOnCancelTask;
public Exception? ThrowOnSetTaskStatus;
public Exception? ThrowOnSetTaskDone;
public Exception? ThrowOnUnsetTaskDone;
public override Task CancelTaskAsync(string taskId)
{
@@ -85,6 +87,18 @@ public class DetailsIslandErrorFeedbackTests : IDisposable
if (ThrowOnSetTaskStatus is not null) throw ThrowOnSetTaskStatus;
return Task.FromResult<BaseDirtyWarningDto?>(null);
}
public override Task SetTaskDoneAsync(string taskId)
{
if (ThrowOnSetTaskDone is not null) throw ThrowOnSetTaskDone;
return Task.CompletedTask;
}
public override Task UnsetTaskDoneAsync(string taskId)
{
if (ThrowOnUnsetTaskDone is not null) throw ThrowOnUnsetTaskDone;
return Task.CompletedTask;
}
}
private DetailsIslandViewModel BuildVm(StubWorkerClient worker)
@@ -179,4 +193,60 @@ public class DetailsIslandErrorFeedbackTests : IDisposable
Assert.NotNull(reportedError);
Assert.Contains("reset offline", reportedError);
}
[Fact]
public async Task ToggleDone_MarkDone_WhenWorkerThrows_ReportsError_AndRevertsTask()
{
var worker = new ThrowingWorkerClient { ThrowOnSetTaskDone = new Exception("mark done offline") };
var vm = BuildVm(worker);
vm.Bind(new TaskRowViewModel { Id = "task-toggle-done-throw", Status = TaskStatus.Idle, Done = false });
vm.Monitor.ApplyState(TaskStatus.Idle);
string? reportedError = null;
vm.ErrorReported += msg => reportedError = msg;
await vm.ToggleDoneCommand.ExecuteAsync(null);
Assert.NotNull(reportedError);
Assert.Contains("mark done offline", reportedError);
Assert.False(vm.Task!.Done);
Assert.Equal(TaskStatus.Idle, vm.Task!.Status);
}
[Fact]
public async Task ToggleDone_Untoggle_WhenWorkerThrows_ReportsError_AndRevertsTask()
{
var worker = new ThrowingWorkerClient { ThrowOnUnsetTaskDone = new Exception("unmark done offline") };
var vm = BuildVm(worker);
vm.Bind(new TaskRowViewModel { Id = "task-untoggle-done-throw", Status = TaskStatus.Done, Done = true });
vm.Monitor.ApplyState(TaskStatus.Done);
string? reportedError = null;
vm.ErrorReported += msg => reportedError = msg;
await vm.ToggleDoneCommand.ExecuteAsync(null);
Assert.NotNull(reportedError);
Assert.Contains("unmark done offline", reportedError);
Assert.True(vm.Task!.Done);
Assert.Equal(TaskStatus.Done, vm.Task!.Status);
}
[Fact]
public async Task ToggleDone_MarkDone_WhenWorkerSucceeds_UpdatesTask_NoError()
{
var worker = new ThrowingWorkerClient();
var vm = BuildVm(worker);
vm.Bind(new TaskRowViewModel { Id = "task-toggle-done-ok", Status = TaskStatus.Idle, Done = false });
vm.Monitor.ApplyState(TaskStatus.Idle);
string? reportedError = null;
vm.ErrorReported += msg => reportedError = msg;
await vm.ToggleDoneCommand.ExecuteAsync(null);
Assert.Null(reportedError);
Assert.True(vm.Task!.Done);
Assert.Equal(TaskStatus.Done, vm.Task!.Status);
}
}