Merge claudedo/123b0241b5e94b69bfa592fde89c51aa
This commit is contained in:
@@ -20,7 +20,7 @@ public sealed class ConfigMcpToolsTests : IDisposable
|
||||
_ctx = _db.CreateContext();
|
||||
_lists = new ListRepository(_ctx);
|
||||
_tasks = new TaskRepository(_ctx);
|
||||
_sut = new ConfigMcpTools(_lists, _tasks, new HubBroadcaster(new CapturingHubContext()));
|
||||
_sut = new ConfigMcpTools(_lists, _tasks, new HubBroadcaster(new CapturingHubContext()), _db.CreateFactory());
|
||||
}
|
||||
|
||||
public void Dispose() { _ctx.Dispose(); _db.Dispose(); }
|
||||
|
||||
@@ -0,0 +1,144 @@
|
||||
using ClaudeDo.Data;
|
||||
using ClaudeDo.Data.Models;
|
||||
using ClaudeDo.Data.Repositories;
|
||||
using ClaudeDo.Worker.External;
|
||||
using ClaudeDo.Worker.Hub;
|
||||
using ClaudeDo.Worker.Tests.Infrastructure;
|
||||
using TaskStatus = ClaudeDo.Data.Models.TaskStatus;
|
||||
|
||||
namespace ClaudeDo.Worker.Tests.External;
|
||||
|
||||
/// <summary>
|
||||
/// get_effective_run_config must report exactly what TaskRunner will actually run with, plus
|
||||
/// where each value came from — task/list/preset/global — so a caller can tell a real default
|
||||
/// from an override before queuing a run. See docs task "MCP: get_effective_run_config".
|
||||
/// </summary>
|
||||
public sealed class EffectiveRunConfigTests : IDisposable
|
||||
{
|
||||
private readonly DbFixture _db = new();
|
||||
private readonly ClaudeDoDbContext _ctx;
|
||||
private readonly ListRepository _lists;
|
||||
private readonly TaskRepository _tasks;
|
||||
private readonly ConfigMcpTools _sut;
|
||||
|
||||
public EffectiveRunConfigTests()
|
||||
{
|
||||
_ctx = _db.CreateContext();
|
||||
_lists = new ListRepository(_ctx);
|
||||
_tasks = new TaskRepository(_ctx);
|
||||
_sut = new ConfigMcpTools(_lists, _tasks, new HubBroadcaster(new CapturingHubContext()), _db.CreateFactory());
|
||||
}
|
||||
|
||||
public void Dispose() { _ctx.Dispose(); _db.Dispose(); }
|
||||
|
||||
private async Task<string> SeedListAsync()
|
||||
{
|
||||
var id = Guid.NewGuid().ToString();
|
||||
await _lists.AddAsync(new ListEntity { Id = id, Name = "L", CreatedAt = DateTime.UtcNow });
|
||||
return id;
|
||||
}
|
||||
|
||||
private async Task<TaskEntity> SeedTaskAsync(string listId, Action<TaskEntity>? configure = null)
|
||||
{
|
||||
var task = new TaskEntity
|
||||
{
|
||||
Id = Guid.NewGuid().ToString(),
|
||||
ListId = listId,
|
||||
Title = "t",
|
||||
Status = TaskStatus.Idle,
|
||||
CreatedAt = DateTime.UtcNow,
|
||||
CommitType = "chore",
|
||||
};
|
||||
configure?.Invoke(task);
|
||||
await _tasks.AddAsync(task);
|
||||
return task;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task No_overrides_reports_preset_and_global_sources()
|
||||
{
|
||||
var listId = await SeedListAsync();
|
||||
var task = await SeedTaskAsync(listId);
|
||||
|
||||
var result = await _sut.GetEffectiveRunConfig(task.Id, CancellationToken.None);
|
||||
|
||||
Assert.Equal("sonnet", result.Model.Value);
|
||||
Assert.Equal("global", result.Model.Source);
|
||||
|
||||
Assert.Equal("preset", result.MaxTurns.Source);
|
||||
Assert.Equal(30, result.MaxTurns.Effective);
|
||||
Assert.Equal(30, result.MaxTurns.Requested);
|
||||
Assert.False(result.MaxTurns.Clamped);
|
||||
|
||||
Assert.Equal("high", result.Effort);
|
||||
Assert.Equal("auto", result.PermissionMode);
|
||||
Assert.Null(result.AgentPath.Value);
|
||||
Assert.Null(result.AgentPath.Source);
|
||||
Assert.Empty(result.SkillNames);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Task_override_beats_list_override_beats_preset()
|
||||
{
|
||||
var listId = await SeedListAsync();
|
||||
await _sut.SetListConfig(listId, "opus", null, "list-agent.md", 50, CancellationToken.None);
|
||||
var task = await SeedTaskAsync(listId, t => { t.Model = "haiku"; t.MaxTurns = 12; });
|
||||
|
||||
var result = await _sut.GetEffectiveRunConfig(task.Id, CancellationToken.None);
|
||||
|
||||
Assert.Equal("haiku", result.Model.Value);
|
||||
Assert.Equal("task", result.Model.Source);
|
||||
Assert.Equal(12, result.MaxTurns.Effective);
|
||||
Assert.Equal("task", result.MaxTurns.Source);
|
||||
Assert.Equal("list-agent.md", result.AgentPath.Value);
|
||||
Assert.Equal("list", result.AgentPath.Source);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task List_override_wins_when_no_task_override()
|
||||
{
|
||||
var listId = await SeedListAsync();
|
||||
await _sut.SetListConfig(listId, "opus", null, null, 50, CancellationToken.None);
|
||||
var task = await SeedTaskAsync(listId);
|
||||
|
||||
var result = await _sut.GetEffectiveRunConfig(task.Id, CancellationToken.None);
|
||||
|
||||
Assert.Equal("opus", result.Model.Value);
|
||||
Assert.Equal("list", result.Model.Source);
|
||||
Assert.Equal(50, result.MaxTurns.Effective);
|
||||
Assert.Equal("list", result.MaxTurns.Source);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Requested_max_turns_above_ceiling_is_clamped_and_both_values_reported()
|
||||
{
|
||||
var listId = await SeedListAsync();
|
||||
var task = await SeedTaskAsync(listId, t => t.MaxTurns = 999);
|
||||
|
||||
var result = await _sut.GetEffectiveRunConfig(task.Id, CancellationToken.None);
|
||||
|
||||
Assert.Equal(999, result.MaxTurns.Requested);
|
||||
Assert.Equal(80, result.MaxTurns.Effective); // AppSettingsEntity.MaxTurnsCeiling default
|
||||
Assert.True(result.MaxTurns.Clamped);
|
||||
Assert.Equal("task", result.MaxTurns.Source);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task System_prompt_reports_set_and_contributing_layers()
|
||||
{
|
||||
var listId = await SeedListAsync();
|
||||
var task = await SeedTaskAsync(listId, t => t.SystemPrompt = "be terse");
|
||||
|
||||
var result = await _sut.GetEffectiveRunConfig(task.Id, CancellationToken.None);
|
||||
|
||||
Assert.True(result.SystemPrompt.Set);
|
||||
Assert.Contains("task", result.SystemPrompt.Sources);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Unknown_task_throws()
|
||||
{
|
||||
await Assert.ThrowsAsync<InvalidOperationException>(
|
||||
() => _sut.GetEffectiveRunConfig("nope", CancellationToken.None));
|
||||
}
|
||||
}
|
||||
@@ -883,7 +883,7 @@ public sealed class ExternalMcpServiceTests : IDisposable
|
||||
|
||||
// ── GetTaskConfig ─────────────────────────────────────────────────────────
|
||||
|
||||
private ConfigMcpTools BuildConfigSut() => new(_lists, _tasks, _broadcaster);
|
||||
private ConfigMcpTools BuildConfigSut() => new(_lists, _tasks, _broadcaster, _db.CreateFactory());
|
||||
|
||||
[Fact]
|
||||
public async Task GetTaskConfig_NotFound_Throws()
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
using ClaudeDo.Data;
|
||||
using ClaudeDo.Data.Git;
|
||||
using ClaudeDo.Data.Models;
|
||||
using ClaudeDo.Data.Repositories;
|
||||
using ClaudeDo.Worker.Config;
|
||||
using ClaudeDo.Worker.External;
|
||||
using ClaudeDo.Worker.Hub;
|
||||
using ClaudeDo.Worker.Runner;
|
||||
using ClaudeDo.Worker.Tests.Infrastructure;
|
||||
using Microsoft.Extensions.Logging.Abstractions;
|
||||
using TaskStatus = ClaudeDo.Data.Models.TaskStatus;
|
||||
using Xunit;
|
||||
|
||||
namespace ClaudeDo.Worker.Tests.Runner;
|
||||
|
||||
/// <summary>
|
||||
/// get_effective_run_config (ConfigMcpTools) must report exactly what TaskRunner actually
|
||||
/// dispatches with — both go through EffectiveRunConfigResolver.Resolve, but this test proves
|
||||
/// it end to end via TaskRunner's real CLI args instead of trusting the shared code path alone.
|
||||
/// </summary>
|
||||
public sealed class EffectiveRunConfigParityTests : IDisposable
|
||||
{
|
||||
private readonly DbFixture _db = new();
|
||||
private readonly string _tempDir;
|
||||
private readonly WorkerConfig _cfg;
|
||||
|
||||
public EffectiveRunConfigParityTests()
|
||||
{
|
||||
_tempDir = Path.Combine(Path.GetTempPath(), $"cd_effparity_{Guid.NewGuid():N}");
|
||||
Directory.CreateDirectory(_tempDir);
|
||||
_cfg = new WorkerConfig { SandboxRoot = _tempDir, LogRoot = _tempDir };
|
||||
}
|
||||
|
||||
public void Dispose() { _db.Dispose(); try { Directory.Delete(_tempDir, true); } catch { } }
|
||||
|
||||
[Fact]
|
||||
public async Task Reported_model_and_max_turns_match_what_TaskRunner_dispatches_with()
|
||||
{
|
||||
var dbFactory = _db.CreateFactory();
|
||||
using (var ctx = _db.CreateContext())
|
||||
{
|
||||
ctx.Lists.Add(new ListEntity { Id = "l1", Name = "L", WorkingDir = null, CreatedAt = DateTime.UtcNow });
|
||||
ctx.ListConfigs.Add(new ListConfigEntity { ListId = "l1", Model = "opus", MaxTurns = 999 });
|
||||
ctx.Tasks.Add(new TaskEntity
|
||||
{
|
||||
Id = "t1", ListId = "l1", Title = "Task", Status = TaskStatus.Idle, CreatedAt = DateTime.UtcNow,
|
||||
});
|
||||
await ctx.SaveChangesAsync();
|
||||
}
|
||||
|
||||
var state = TaskStateServiceBuilder.Build(dbFactory).State;
|
||||
var wt = new WorktreeManager(new GitService(), dbFactory, _cfg, NullLogger<WorktreeManager>.Instance);
|
||||
IReadOnlyList<string>? capturedArgs = null;
|
||||
var fake = new FakeClaudeProcess((_, _, args, _, _) =>
|
||||
{
|
||||
capturedArgs = args;
|
||||
return Task.FromResult(new RunResult { ExitCode = 0, ResultMarkdown = "ok" });
|
||||
});
|
||||
var runner = new TaskRunner(fake, dbFactory, new HubBroadcaster(new CapturingHubContext()), wt,
|
||||
new ClaudeArgsBuilder(), _cfg, NullLogger<TaskRunner>.Instance, state, new TaskRunTokenRegistry(),
|
||||
new AttachmentStore(), new FakeSessionSkillSeeder(), new FakeTranscriptUsageReader());
|
||||
|
||||
using (var ctx = _db.CreateContext())
|
||||
await runner.RunAsync((await new TaskRepository(ctx).GetByIdAsync("t1"))!, "slot-1", CancellationToken.None);
|
||||
|
||||
var args = capturedArgs!.ToList();
|
||||
var actualModel = args[args.IndexOf("--model") + 1];
|
||||
var actualMaxTurns = args[args.IndexOf("--max-turns") + 1];
|
||||
|
||||
using var reportCtx = _db.CreateContext();
|
||||
var tools = new ConfigMcpTools(
|
||||
new ListRepository(reportCtx), new TaskRepository(reportCtx),
|
||||
new HubBroadcaster(new CapturingHubContext()), dbFactory);
|
||||
var effective = await tools.GetEffectiveRunConfig("t1", CancellationToken.None);
|
||||
|
||||
Assert.Equal(actualModel, effective.Model.Value);
|
||||
Assert.Equal(actualMaxTurns, effective.MaxTurns.Effective.ToString());
|
||||
Assert.Equal(999, effective.MaxTurns.Requested);
|
||||
Assert.True(effective.MaxTurns.Clamped);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user