refactor(worker): inject GitService and WorkerConfig into PlanningSessionManager
Adds AppSettingsRepository to the test constructor, GitService and WorkerConfig to both constructors, and updates CreateRepos() and all its call-sites to expose the new settings tuple element. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -2,8 +2,10 @@ using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using ClaudeDo.Data;
|
||||
using ClaudeDo.Data.Git;
|
||||
using ClaudeDo.Data.Models;
|
||||
using ClaudeDo.Data.Repositories;
|
||||
using ClaudeDo.Worker.Config;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using TaskStatus = ClaudeDo.Data.Models.TaskStatus;
|
||||
|
||||
@@ -16,34 +18,52 @@ public sealed class PlanningSessionManager
|
||||
private readonly IDbContextFactory<ClaudeDoDbContext>? _factory;
|
||||
private readonly TaskRepository? _tasksOverride;
|
||||
private readonly ListRepository? _listsOverride;
|
||||
private readonly AppSettingsRepository? _settingsOverride;
|
||||
private readonly GitService _git;
|
||||
private readonly WorkerConfig _cfg;
|
||||
private readonly string _rootDirectory;
|
||||
|
||||
// DI constructor — uses factory so this singleton can create scoped repos per call.
|
||||
public PlanningSessionManager(IDbContextFactory<ClaudeDoDbContext> factory, string rootDirectory)
|
||||
// DI constructor.
|
||||
public PlanningSessionManager(
|
||||
IDbContextFactory<ClaudeDoDbContext> factory,
|
||||
GitService git,
|
||||
WorkerConfig cfg,
|
||||
string rootDirectory)
|
||||
{
|
||||
_factory = factory;
|
||||
_git = git;
|
||||
_cfg = cfg;
|
||||
_rootDirectory = rootDirectory;
|
||||
}
|
||||
|
||||
// Test constructor — accepts repos directly (single shared context, test-scoped).
|
||||
public PlanningSessionManager(TaskRepository tasks, ListRepository lists, string rootDirectory)
|
||||
// Test constructor.
|
||||
public PlanningSessionManager(
|
||||
TaskRepository tasks,
|
||||
ListRepository lists,
|
||||
AppSettingsRepository settings,
|
||||
GitService git,
|
||||
WorkerConfig cfg,
|
||||
string rootDirectory)
|
||||
{
|
||||
_tasksOverride = tasks;
|
||||
_listsOverride = lists;
|
||||
_settingsOverride = settings;
|
||||
_git = git;
|
||||
_cfg = cfg;
|
||||
_rootDirectory = rootDirectory;
|
||||
}
|
||||
|
||||
private (TaskRepository tasks, ListRepository lists, ClaudeDoDbContext? ctx) CreateRepos()
|
||||
private (TaskRepository tasks, ListRepository lists, AppSettingsRepository settings, ClaudeDoDbContext? ctx) CreateRepos()
|
||||
{
|
||||
if (_tasksOverride is not null)
|
||||
return (_tasksOverride, _listsOverride!, null);
|
||||
return (_tasksOverride, _listsOverride!, _settingsOverride!, null);
|
||||
var ctx = _factory!.CreateDbContext();
|
||||
return (new TaskRepository(ctx), new ListRepository(ctx), ctx);
|
||||
return (new TaskRepository(ctx), new ListRepository(ctx), new AppSettingsRepository(ctx), ctx);
|
||||
}
|
||||
|
||||
public async Task<PlanningSessionStartContext> StartAsync(string taskId, CancellationToken ct)
|
||||
{
|
||||
var (tasks, lists, ctx) = CreateRepos();
|
||||
var (tasks, lists, settings, ctx) = CreateRepos();
|
||||
await using var _ = ctx;
|
||||
|
||||
var task = await tasks.GetByIdAsync(taskId, ct)
|
||||
@@ -77,14 +97,14 @@ public sealed class PlanningSessionManager
|
||||
|
||||
public async Task<int> FinalizeAsync(string taskId, bool queueAgentTasks, CancellationToken ct)
|
||||
{
|
||||
var (tasks, _, ctx) = CreateRepos();
|
||||
var (tasks, _, settings, ctx) = CreateRepos();
|
||||
await using var __ = ctx;
|
||||
return await tasks.FinalizePlanningAsync(taskId, queueAgentTasks, ct);
|
||||
}
|
||||
|
||||
public async Task<int> GetPendingDraftCountAsync(string taskId, CancellationToken ct)
|
||||
{
|
||||
var (tasks, _, ctx) = CreateRepos();
|
||||
var (tasks, _, settings, ctx) = CreateRepos();
|
||||
await using var __ = ctx;
|
||||
var children = await tasks.GetChildrenAsync(taskId, ct);
|
||||
return children.Count(c => c.Status == TaskStatus.Draft);
|
||||
@@ -92,7 +112,7 @@ public sealed class PlanningSessionManager
|
||||
|
||||
public async Task DiscardAsync(string taskId, CancellationToken ct)
|
||||
{
|
||||
var (tasks, _, ctx) = CreateRepos();
|
||||
var (tasks, _, settings, ctx) = CreateRepos();
|
||||
await using var __ = ctx;
|
||||
|
||||
var ok = await tasks.DiscardPlanningAsync(taskId, ct);
|
||||
@@ -108,7 +128,7 @@ public sealed class PlanningSessionManager
|
||||
|
||||
public async Task<PlanningSessionResumeContext> ResumeAsync(string taskId, CancellationToken ct)
|
||||
{
|
||||
var (tasks, lists, ctx) = CreateRepos();
|
||||
var (tasks, lists, settings, ctx) = CreateRepos();
|
||||
await using var _ = ctx;
|
||||
|
||||
var task = await tasks.GetByIdAsync(taskId, ct)
|
||||
|
||||
Reference in New Issue
Block a user