test(worker): adapt planning tests to git-backed worktree flow

Update constructor calls (6-arg), seed AppSettings with sibling strategy,
git-init working dirs via GitRepoFixture.InitRepoWithInitialCommit, and
replace McpConfigPath assertions with worktree-path / .mcp.json checks.
Also fixes PlanningHubTests which had the same 3-arg constructor.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
mika kuns
2026-04-24 12:14:46 +02:00
parent 9beda55681
commit 0da527dbbc
5 changed files with 58 additions and 17 deletions

View File

@@ -1,6 +1,8 @@
using ClaudeDo.Data;
using ClaudeDo.Data.Git;
using ClaudeDo.Data.Models;
using ClaudeDo.Data.Repositories;
using ClaudeDo.Worker.Config;
using ClaudeDo.Worker.Planning;
using ClaudeDo.Worker.Tests.Infrastructure;
using TaskStatus = ClaudeDo.Data.Models.TaskStatus;
@@ -14,6 +16,9 @@ public sealed class PlanningSessionManagerTests : IDisposable
private readonly TaskRepository _tasks;
private readonly ListRepository _lists;
private readonly string _rootDir;
private readonly GitService _git;
private readonly WorkerConfig _cfg;
private readonly AppSettingsRepository _settingsRepo;
private readonly PlanningSessionManager _sut;
public PlanningSessionManagerTests()
@@ -22,7 +27,11 @@ public sealed class PlanningSessionManagerTests : IDisposable
_tasks = new TaskRepository(_ctx);
_lists = new ListRepository(_ctx);
_rootDir = Path.Combine(Path.GetTempPath(), $"cd_planning_{Guid.NewGuid():N}");
_sut = new PlanningSessionManager(_tasks, _lists, _rootDir);
_git = new GitService();
_cfg = new WorkerConfig { CentralWorktreeRoot = Path.Combine(_rootDir, "central") };
_settingsRepo = new AppSettingsRepository(_ctx);
_settingsRepo.UpdateAsync(new AppSettingsEntity { WorktreeStrategy = "sibling" }).GetAwaiter().GetResult();
_sut = new PlanningSessionManager(_tasks, _lists, _settingsRepo, _git, _cfg, _rootDir);
}
public void Dispose()
@@ -36,7 +45,7 @@ public sealed class PlanningSessionManagerTests : IDisposable
{
var listId = Guid.NewGuid().ToString();
var wd = Path.Combine(Path.GetTempPath(), $"cd_wd_{Guid.NewGuid():N}");
Directory.CreateDirectory(wd);
GitRepoFixture.InitRepoWithInitialCommit(wd);
await _lists.AddAsync(new ListEntity
{
Id = listId,
@@ -72,14 +81,17 @@ public sealed class PlanningSessionManagerTests : IDisposable
var ctx = await _sut.StartAsync(parent.Id, CancellationToken.None);
Assert.Equal(parent.Id, ctx.ParentTaskId);
Assert.Equal(wd, ctx.WorkingDir);
Assert.True(File.Exists(ctx.Files.McpConfigPath));
Assert.Equal(ctx.WorktreePath, ctx.WorkingDir);
Assert.True(Directory.Exists(ctx.WorktreePath));
var mcpPath = Path.Combine(ctx.WorktreePath, ".mcp.json");
Assert.True(File.Exists(mcpPath));
Assert.True(File.Exists(Path.Combine(ctx.WorktreePath, ".claude", "settings.local.json")));
Assert.True(File.Exists(ctx.Files.SystemPromptPath));
Assert.True(File.Exists(ctx.Files.InitialPromptPath));
var mcp = await File.ReadAllTextAsync(ctx.Files.McpConfigPath);
Assert.Contains("\"type\": \"http\"", mcp);
Assert.Contains("Bearer ", mcp);
var mcp = await File.ReadAllTextAsync(mcpPath);
Assert.Contains("${CLAUDEDO_PLANNING_TOKEN}", mcp);
Assert.DoesNotContain(ctx.Token, mcp);
var initial = await File.ReadAllTextAsync(ctx.Files.InitialPromptPath);
Assert.Contains("Brainstorm auth", initial);
@@ -132,10 +144,10 @@ public sealed class PlanningSessionManagerTests : IDisposable
var resumeCtx = await _sut.ResumeAsync(parent.Id, CancellationToken.None);
Assert.Equal(parent.Id, resumeCtx.ParentTaskId);
Assert.Equal(wd, resumeCtx.WorkingDir);
Assert.Equal(resumeCtx.WorktreePath, resumeCtx.WorkingDir);
Assert.Equal("claude-session-42", resumeCtx.ClaudeSessionId);
Assert.Equal(startCtx.Files.McpConfigPath, resumeCtx.McpConfigPath);
Assert.True(File.Exists(resumeCtx.McpConfigPath));
Assert.True(Directory.Exists(resumeCtx.WorktreePath));
Assert.True(File.Exists(Path.Combine(resumeCtx.WorktreePath, ".mcp.json")));
}
[Fact]