Merge claudedo/20c78c9558cf4c4fa598a00c7cac374f

This commit is contained in:
mika kuns
2026-08-05 11:42:05 +02:00
7 changed files with 103 additions and 13 deletions
@@ -111,8 +111,8 @@ public sealed class PlanningEndToEndTests : IDisposable
// Wire the ambient context so _svc reads the correct parent
_httpContext.Items["PlanningContext"] = new PlanningMcpContext { ParentTaskId = parent.Id };
await _svc.CreateChildTask("sub 1", null, null, null, CancellationToken.None);
await _svc.CreateChildTask("sub 2", null, null, null, CancellationToken.None);
await _svc.CreateChildTask("sub 1", null, null, null, cancellationToken: CancellationToken.None);
await _svc.CreateChildTask("sub 2", null, null, null, cancellationToken: CancellationToken.None);
var count = await _svc.Finalize(true, CancellationToken.None);
Assert.Equal(2, count);
@@ -155,9 +155,9 @@ public sealed class PlanningEndToEndTests : IDisposable
await _manager.StartAsync(parent.Id, CancellationToken.None);
_httpContext.Items["PlanningContext"] = new PlanningMcpContext { ParentTaskId = parent.Id };
await _svc.CreateChildTask("c1", null, null, null, CancellationToken.None);
await _svc.CreateChildTask("c2", null, null, null, CancellationToken.None);
await _svc.CreateChildTask("c3", null, null, null, CancellationToken.None);
await _svc.CreateChildTask("c1", null, null, null, cancellationToken: CancellationToken.None);
await _svc.CreateChildTask("c2", null, null, null, cancellationToken: CancellationToken.None);
await _svc.CreateChildTask("c3", null, null, null, cancellationToken: CancellationToken.None);
var kidsBefore = await _tasks.GetChildrenAsync(parent.Id);
var firstChildId = kidsBefore[0].Id;
@@ -108,7 +108,7 @@ public sealed class PlanningMcpServiceTests : IDisposable
var parent = await SeedPlanningParentAsync();
var sut = BuildSut(parent.Id);
var result = await sut.CreateChildTask("My child", "desc", null, model: null, CancellationToken.None);
var result = await sut.CreateChildTask("My child", "desc", null, model: null, cancellationToken: CancellationToken.None);
Assert.Equal("Idle", result.Status);
var child = await _tasks.GetByIdAsync(result.TaskId);
@@ -123,7 +123,7 @@ public sealed class PlanningMcpServiceTests : IDisposable
var parent = await SeedPlanningParentAsync();
var sut = BuildSut(parent.Id);
var result = await sut.CreateChildTask("c", null, null, model: "Opus", CancellationToken.None);
var result = await sut.CreateChildTask("c", null, null, model: "Opus", cancellationToken: CancellationToken.None);
var child = await _tasks.GetByIdAsync(result.TaskId);
Assert.Equal("opus", child!.Model);
@@ -136,7 +136,43 @@ public sealed class PlanningMcpServiceTests : IDisposable
var sut = BuildSut(parent.Id);
await Assert.ThrowsAsync<ArgumentException>(
() => sut.CreateChildTask("c", null, null, model: "turbo", CancellationToken.None));
() => sut.CreateChildTask("c", null, null, model: "turbo", cancellationToken: CancellationToken.None));
}
[Fact]
public async Task CreateChildTask_NoMaxTurns_ChildInherits()
{
var parent = await SeedPlanningParentAsync();
var sut = BuildSut(parent.Id);
var result = await sut.CreateChildTask("c", null, null, model: null, cancellationToken: CancellationToken.None);
var child = await _tasks.GetByIdAsync(result.TaskId);
Assert.Null(child!.MaxTurns);
}
[Fact]
public async Task CreateChildTask_PersistsMaxTurns()
{
var parent = await SeedPlanningParentAsync();
var sut = BuildSut(parent.Id);
var result = await sut.CreateChildTask("c", null, null, model: null, maxTurns: 200, cancellationToken: CancellationToken.None);
var child = await _tasks.GetByIdAsync(result.TaskId);
Assert.Equal(200, child!.MaxTurns);
}
[Theory]
[InlineData(0)]
[InlineData(-1)]
public async Task CreateChildTask_RejectsInvalidMaxTurns(int maxTurns)
{
var parent = await SeedPlanningParentAsync();
var sut = BuildSut(parent.Id);
await Assert.ThrowsAsync<ArgumentException>(
() => sut.CreateChildTask("c", null, null, model: null, maxTurns: maxTurns, cancellationToken: CancellationToken.None));
}
[Fact]
@@ -267,7 +303,7 @@ public sealed class PlanningMcpServiceTests : IDisposable
var parent = await SeedPlanningParentAsync();
var sut = BuildSut(parent.Id);
var result = await sut.CreateChildTask("c", null, null, model: null, CancellationToken.None);
var result = await sut.CreateChildTask("c", null, null, model: null, cancellationToken: CancellationToken.None);
var ids = TaskUpdatedIds();
Assert.Contains(result.TaskId, ids);
@@ -119,6 +119,47 @@ public sealed class TaskRepositoryPlanningTests : IDisposable
_tasks.CreateChildAsync("nonexistent-parent-id", "t", null, null));
}
[Fact]
public async Task CreateChildAsync_NoMaxTurns_ChildInherits()
{
var listId = await CreateListAsync();
var parent = MakeTask(listId, phase: PlanningPhase.Active);
await _tasks.AddAsync(parent);
var child = await _tasks.CreateChildAsync(parent.Id, "child", null, null);
Assert.Null(child.MaxTurns);
var loaded = await _tasks.GetByIdAsync(child.Id);
Assert.Null(loaded!.MaxTurns);
}
[Fact]
public async Task CreateChildAsync_WithMaxTurns_Persists()
{
var listId = await CreateListAsync();
var parent = MakeTask(listId, phase: PlanningPhase.Active);
await _tasks.AddAsync(parent);
var child = await _tasks.CreateChildAsync(parent.Id, "child", null, null, maxTurns: 200);
Assert.Equal(200, child.MaxTurns);
var loaded = await _tasks.GetByIdAsync(child.Id);
Assert.Equal(200, loaded!.MaxTurns);
}
[Theory]
[InlineData(0)]
[InlineData(-5)]
public async Task CreateChildAsync_InvalidMaxTurns_Throws(int maxTurns)
{
var listId = await CreateListAsync();
var parent = MakeTask(listId, phase: PlanningPhase.Active);
await _tasks.AddAsync(parent);
await Assert.ThrowsAsync<ArgumentException>(() =>
_tasks.CreateChildAsync(parent.Id, "child", null, null, maxTurns: maxTurns));
}
[Fact]
public async Task SetPlanningStartedAsync_IdleTask_TransitionsToActivePhase()
{