feat(claude-do): depends_on als Menge statt Einzelfeld
Ein Task kann jetzt auf beliebig viele Vorgaenger warten. Die Einzelspalte tasks.depends_on_task_id wird durch die Beziehungstabelle task_dependencies ersetzt (Composite-PK, beide FKs ON DELETE CASCADE -- das reproduziert das alte ON DELETE SET NULL: geloeschter Vorgaenger = Kante weg = Task wieder pickbar). BlockedByTaskId bleibt unberuehrt. - Migration AddTaskDependencies kopiert jede bestehende depends_on_task_id verlustfrei in die Tabelle, bevor die Spalte fallengelassen wird - QueuePicker gatet per doppelt negiertem NOT EXISTS: kein Task mit 0 Kanten wird blockiert, alle Kanten muessen done sein, eine Kante auf einen verschwundenen Task blockiert weiter - SetDependsOnAsync ersetzt die ganze Menge; Zykluspruefung ist jetzt eine BFS ueber den Graphen, faengt also auch A->B->C->A - blockedReason nennt alle offenen Vorgaenger (External/TaskBlocking, von ExternalMcpService und TaskWaitMcpTools gemeinsam genutzt) - add_task/update_task nehmen dependsOnTaskIds; die alte Skalarform bleibt als Ein-Element-Menge inkl. ""-Clear-Sentinel gueltig - UI: Fan-in-Zeile bleibt flach und listet alle Vorgaenger im After-Label, die lineare Kette rendert unveraendert
This commit is contained in:
@@ -70,17 +70,23 @@ public sealed class ForeignKeyTests : IDisposable
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task DependsOnTaskId_is_nulled_when_predecessor_deleted_on_fresh_context()
|
||||
public async Task Dependency_edge_is_dropped_when_predecessor_deleted_on_fresh_context()
|
||||
{
|
||||
// The cascade on task_dependencies is what the old single column got from ON DELETE
|
||||
// SET NULL: the dependent must come out pickable, not blocked on a task that's gone.
|
||||
var listId = Guid.NewGuid().ToString();
|
||||
var predecessorId = Guid.NewGuid().ToString();
|
||||
var otherId = Guid.NewGuid().ToString();
|
||||
var dependentId = Guid.NewGuid().ToString();
|
||||
|
||||
await using (var ctx = Open())
|
||||
{
|
||||
ctx.Lists.Add(new ListEntity { Id = listId, Name = "L", CreatedAt = DateTime.UtcNow });
|
||||
ctx.Tasks.Add(new TaskEntity { Id = predecessorId, Number = 1, ListId = listId, Title = "Predecessor", Status = TaskStatus.Idle, CreatedAt = DateTime.UtcNow });
|
||||
ctx.Tasks.Add(new TaskEntity { Id = dependentId, Number = 2, ListId = listId, Title = "Dependent", Status = TaskStatus.Idle, DependsOnTaskId = predecessorId, CreatedAt = DateTime.UtcNow });
|
||||
ctx.Tasks.Add(new TaskEntity { Id = otherId, Number = 3, ListId = listId, Title = "Other", Status = TaskStatus.Idle, CreatedAt = DateTime.UtcNow });
|
||||
ctx.Tasks.Add(new TaskEntity { Id = dependentId, Number = 2, ListId = listId, Title = "Dependent", Status = TaskStatus.Idle, CreatedAt = DateTime.UtcNow });
|
||||
ctx.TaskDependencies.Add(new TaskDependencyEntity { TaskId = dependentId, DependsOnTaskId = predecessorId });
|
||||
ctx.TaskDependencies.Add(new TaskDependencyEntity { TaskId = dependentId, DependsOnTaskId = otherId });
|
||||
await ctx.SaveChangesAsync();
|
||||
}
|
||||
|
||||
@@ -93,8 +99,9 @@ public sealed class ForeignKeyTests : IDisposable
|
||||
|
||||
await using (var ctx = Open())
|
||||
{
|
||||
var dependent = await ctx.Tasks.AsNoTracking().FirstAsync(t => t.Id == dependentId);
|
||||
Assert.Null(dependent.DependsOnTaskId);
|
||||
var dependent = await ctx.Tasks.AsNoTracking().Include(t => t.Dependencies)
|
||||
.FirstAsync(t => t.Id == dependentId);
|
||||
Assert.Equal([otherId], dependent.DependsOnTaskIds);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,100 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
namespace ClaudeDo.Data.Tests;
|
||||
|
||||
/// <summary>
|
||||
/// AddTaskDependencies moves every <c>tasks.depends_on_task_id</c> value into the new
|
||||
/// <c>task_dependencies</c> table and then drops the column. Runs a real <c>Migrate()</c> — the
|
||||
/// EnsureCreated fixtures every other Data.Tests file uses skip migrations entirely and would
|
||||
/// never notice a data copy that silently dropped rows (see
|
||||
/// <c>.claudedo/traps/ef-migration-parallel-designer-collision.md</c>).
|
||||
/// </summary>
|
||||
public sealed class TaskDependencyMigrationTests : IDisposable
|
||||
{
|
||||
private const string PreviousMigrationId = "20260902102003_AddExpectsNoDiff";
|
||||
|
||||
private readonly string _dbPath;
|
||||
private readonly DbContextOptions<ClaudeDoDbContext> _options;
|
||||
|
||||
public TaskDependencyMigrationTests()
|
||||
{
|
||||
_dbPath = Path.Combine(Path.GetTempPath(), $"claudedo_deps_{Guid.NewGuid():N}.db");
|
||||
_options = new DbContextOptionsBuilder<ClaudeDoDbContext>()
|
||||
.UseSqlite($"Data Source={_dbPath}")
|
||||
.Options;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Microsoft.Data.Sqlite.SqliteConnection.ClearAllPools();
|
||||
foreach (var suffix in new[] { "", "-wal", "-shm" })
|
||||
try { File.Delete(_dbPath + suffix); } catch { }
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Existing_depends_on_links_survive_as_one_element_sets()
|
||||
{
|
||||
SeedLegacyDatabase();
|
||||
|
||||
using (var ctx = new ClaudeDoDbContext(_options))
|
||||
ctx.Database.Migrate();
|
||||
|
||||
using var check = new ClaudeDoDbContext(_options);
|
||||
Assert.Empty(check.Database.GetPendingMigrations());
|
||||
|
||||
var edges = check.TaskDependencies.AsNoTracking()
|
||||
.OrderBy(d => d.TaskId)
|
||||
.Select(d => new { d.TaskId, d.DependsOnTaskId })
|
||||
.ToList();
|
||||
Assert.Equal(2, edges.Count);
|
||||
Assert.Equal(("t2", "t1"), (edges[0].TaskId, edges[0].DependsOnTaskId));
|
||||
Assert.Equal(("t3", "t2"), (edges[1].TaskId, edges[1].DependsOnTaskId));
|
||||
|
||||
// The tasks themselves are untouched, and the independent one gained no edge.
|
||||
Assert.Equal(4, check.Tasks.Count());
|
||||
Assert.DoesNotContain("t4", edges.Select(e => e.TaskId));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Column_is_gone_after_the_migration()
|
||||
{
|
||||
SeedLegacyDatabase();
|
||||
|
||||
using var ctx = new ClaudeDoDbContext(_options);
|
||||
ctx.Database.Migrate();
|
||||
|
||||
var conn = ctx.Database.GetDbConnection();
|
||||
conn.Open();
|
||||
using var cmd = conn.CreateCommand();
|
||||
cmd.CommandText = "SELECT COUNT(*) FROM pragma_table_info('tasks') WHERE name = 'depends_on_task_id'";
|
||||
Assert.Equal(0L, Convert.ToInt64(cmd.ExecuteScalar()));
|
||||
conn.Close();
|
||||
}
|
||||
|
||||
// Migrates *to* the migration before this one, then seeds via raw SQL: EnsureCreated would
|
||||
// build today's schema (no depends_on_task_id column at all), so there'd be nothing to copy.
|
||||
private void SeedLegacyDatabase()
|
||||
{
|
||||
using var seed = new ClaudeDoDbContext(_options);
|
||||
seed.Database.GetService<IMigrator>().Migrate(PreviousMigrationId);
|
||||
|
||||
var conn = seed.Database.GetDbConnection();
|
||||
conn.Open();
|
||||
using var cmd = conn.CreateCommand();
|
||||
cmd.CommandText = """
|
||||
INSERT INTO lists (id, name, created_at) VALUES ('l1', 'List', '2026-01-01 00:00:00');
|
||||
INSERT INTO tasks (id, number, list_id, title, status, created_at)
|
||||
VALUES ('t1', 1, 'l1', 'first', 'done', '2026-01-01 00:00:00');
|
||||
INSERT INTO tasks (id, number, list_id, title, status, created_at, depends_on_task_id)
|
||||
VALUES ('t2', 2, 'l1', 'second', 'queued', '2026-01-01 00:00:00', 't1');
|
||||
INSERT INTO tasks (id, number, list_id, title, status, created_at, depends_on_task_id)
|
||||
VALUES ('t3', 3, 'l1', 'third', 'queued', '2026-01-01 00:00:00', 't2');
|
||||
INSERT INTO tasks (id, number, list_id, title, status, created_at)
|
||||
VALUES ('t4', 4, 'l1', 'independent', 'idle', '2026-01-01 00:00:00');
|
||||
""";
|
||||
cmd.ExecuteNonQuery();
|
||||
conn.Close();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user