Slice 6 of the worker state and queue consolidation refactor. * Drop Manual, Planning, Planned, Draft, Waiting from the TaskStatus enum and from the EF value converter; only the lifecycle values remain (Idle, Queued, Running, Done, Failed, Cancelled). * Add migration RetireLegacyTaskStatus that rewrites existing rows: manual/draft -> idle, planning -> idle+planning_phase=active, planned -> idle+planning_phase=finalized, waiting -> queued+blocked_by derived from sort_order via a CTE with LAG(). * Reroute every call site that compared/set legacy values to the new three-field model (Status + PlanningPhase + BlockedByTaskId), including the planning repo helpers, MCP services, the planning chain coordinator, and the UI view-models. TaskRowViewModel now exposes PlanningPhase to drive the planning badge. * Refresh Worker/CLAUDE.md and Data/CLAUDE.md, the docs/plan.md status section, and the planning verification notes in docs/open.md.
140 lines
4.6 KiB
C#
140 lines
4.6 KiB
C#
using ClaudeDo.Data;
|
|
using ClaudeDo.Data.Models;
|
|
using ClaudeDo.Data.Repositories;
|
|
using ClaudeDo.Worker.Tests.Infrastructure;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using TaskStatus = ClaudeDo.Data.Models.TaskStatus;
|
|
|
|
namespace ClaudeDo.Worker.Tests.Repositories;
|
|
|
|
public sealed class TaskRepositoryParentCompletionTests : IDisposable
|
|
{
|
|
private readonly DbFixture _db = new();
|
|
private readonly ClaudeDoDbContext _ctx;
|
|
private readonly TaskRepository _tasks;
|
|
private readonly ListRepository _lists;
|
|
|
|
public TaskRepositoryParentCompletionTests()
|
|
{
|
|
_ctx = _db.CreateContext();
|
|
_tasks = new TaskRepository(_ctx);
|
|
_lists = new ListRepository(_ctx);
|
|
}
|
|
|
|
public void Dispose() { _ctx.Dispose(); _db.Dispose(); }
|
|
|
|
private async Task<string> ListAsync()
|
|
{
|
|
var id = Guid.NewGuid().ToString();
|
|
await _lists.AddAsync(new ListEntity { Id = id, Name = "L", CreatedAt = DateTime.UtcNow });
|
|
return id;
|
|
}
|
|
|
|
private async Task<TaskEntity> PlannedParentAsync(string listId)
|
|
{
|
|
var parent = new TaskEntity
|
|
{
|
|
Id = Guid.NewGuid().ToString(),
|
|
ListId = listId,
|
|
Title = "p",
|
|
Status = TaskStatus.Idle,
|
|
PlanningPhase = PlanningPhase.Finalized,
|
|
CreatedAt = DateTime.UtcNow,
|
|
CommitType = "chore",
|
|
};
|
|
await _tasks.AddAsync(parent);
|
|
return parent;
|
|
}
|
|
|
|
private async Task<TaskEntity> ChildAsync(string listId, string parentId, TaskStatus status)
|
|
{
|
|
var child = new TaskEntity
|
|
{
|
|
Id = Guid.NewGuid().ToString(),
|
|
ListId = listId,
|
|
Title = "c",
|
|
Status = status,
|
|
CreatedAt = DateTime.UtcNow,
|
|
CommitType = "chore",
|
|
ParentTaskId = parentId,
|
|
};
|
|
await _tasks.AddAsync(child);
|
|
return child;
|
|
}
|
|
|
|
[Fact]
|
|
public async Task TryCompleteParentAsync_AllChildrenDone_ParentBecomesDone()
|
|
{
|
|
var listId = await ListAsync();
|
|
var parent = await PlannedParentAsync(listId);
|
|
await ChildAsync(listId, parent.Id, TaskStatus.Done);
|
|
await ChildAsync(listId, parent.Id, TaskStatus.Done);
|
|
|
|
await _tasks.TryCompleteParentAsync(parent.Id);
|
|
|
|
var loaded = await _tasks.GetByIdAsync(parent.Id);
|
|
Assert.Equal(TaskStatus.Done, loaded!.Status);
|
|
Assert.NotNull(loaded.FinishedAt);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task TryCompleteParentAsync_OneFailedRestDone_ParentBecomesFailed()
|
|
{
|
|
var listId = await ListAsync();
|
|
var parent = await PlannedParentAsync(listId);
|
|
await ChildAsync(listId, parent.Id, TaskStatus.Done);
|
|
await ChildAsync(listId, parent.Id, TaskStatus.Failed);
|
|
|
|
await _tasks.TryCompleteParentAsync(parent.Id);
|
|
|
|
var loaded = await _tasks.GetByIdAsync(parent.Id);
|
|
Assert.Equal(TaskStatus.Failed, loaded!.Status);
|
|
Assert.NotNull(loaded.FinishedAt);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task TryCompleteParentAsync_OneStillRunning_ParentStaysPlanned()
|
|
{
|
|
var listId = await ListAsync();
|
|
var parent = await PlannedParentAsync(listId);
|
|
await ChildAsync(listId, parent.Id, TaskStatus.Done);
|
|
await ChildAsync(listId, parent.Id, TaskStatus.Running);
|
|
|
|
await _tasks.TryCompleteParentAsync(parent.Id);
|
|
|
|
var loaded = await _tasks.GetByIdAsync(parent.Id);
|
|
Assert.Equal(TaskStatus.Idle, loaded!.Status);
|
|
Assert.Equal(PlanningPhase.Finalized, loaded.PlanningPhase);
|
|
Assert.Null(loaded.FinishedAt);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task TryCompleteParentAsync_ChildStillIdle_ParentStaysFinalized()
|
|
{
|
|
var listId = await ListAsync();
|
|
var parent = await PlannedParentAsync(listId);
|
|
await ChildAsync(listId, parent.Id, TaskStatus.Done);
|
|
await ChildAsync(listId, parent.Id, TaskStatus.Idle);
|
|
|
|
await _tasks.TryCompleteParentAsync(parent.Id);
|
|
|
|
var loaded = await _tasks.GetByIdAsync(parent.Id);
|
|
Assert.Equal(PlanningPhase.Finalized, loaded!.PlanningPhase);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task TryCompleteParentAsync_ParentIsNotFinalized_NoChange()
|
|
{
|
|
var listId = await ListAsync();
|
|
var parent = await PlannedParentAsync(listId);
|
|
await _ctx.Database.ExecuteSqlRawAsync(
|
|
"UPDATE tasks SET planning_phase = 'active' WHERE id = {0}", parent.Id);
|
|
await ChildAsync(listId, parent.Id, TaskStatus.Done);
|
|
|
|
await _tasks.TryCompleteParentAsync(parent.Id);
|
|
|
|
var loaded = await _tasks.GetByIdAsync(parent.Id);
|
|
Assert.Equal(PlanningPhase.Active, loaded!.PlanningPhase);
|
|
}
|
|
}
|