fix(worker): allow the done toggle from any non-Running status
MarkDoneAsync was Idle-only, so a finished task (typically a list-handler run with no worktree to merge) could not be ticked off. Guard on Running instead and cover the other statuses with tests.
This commit is contained in:
@@ -382,14 +382,19 @@ public sealed class TaskStateService : ITaskStateService
|
||||
public async Task<TransitionResult> MarkDoneAsync(string taskId, DateTime finishedAt, CancellationToken ct)
|
||||
{
|
||||
await using var ctx = await _dbFactory.CreateDbContextAsync(ct);
|
||||
// The done toggle is a manual "tick it off" affordance and works from every status
|
||||
// except Running (a live run keeps writing the row, so the picker/runner would race).
|
||||
// WaitingForReview is deliberately included: ticking a finished task done skips the
|
||||
// merge on purpose -- for a worktree-less list-handler task there is nothing to merge,
|
||||
// and for a worktree task the branch just stays Active for the worktrees overview.
|
||||
var affected = await ctx.Tasks
|
||||
.Where(t => t.Id == taskId && t.Status == TaskStatus.Idle)
|
||||
.Where(t => t.Id == taskId && t.Status != TaskStatus.Running)
|
||||
.ExecuteUpdateAsync(s => s
|
||||
.SetProperty(t => t.Status, TaskStatus.Done)
|
||||
.SetProperty(t => t.FinishedAt, finishedAt), ct);
|
||||
|
||||
if (affected == 0)
|
||||
return new TransitionResult(false, "Task is not Idle; cannot mark done.");
|
||||
return new TransitionResult(false, "Task is running or no longer exists; cannot mark done.");
|
||||
|
||||
await _broadcaster.TaskUpdated(taskId);
|
||||
return new TransitionResult(true, null);
|
||||
|
||||
Reference in New Issue
Block a user