feat(planning): let CreateChildTask set maxTurns on child tasks
Planning sessions could already steer a subtask's model but not its turn budget, so a visibly large subtask would still die at the global default turn limit. maxTurns is optional (default null = inherit list/global default, matching model); 0/negative values are rejected as invalid input, consistent with the existing model-alias validation.
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user