feat/planning-sessions-worker #7

Merged
mikakuns merged 15 commits from feat/planning-sessions-worker into main 2026-04-24 06:02:50 +00:00
2 changed files with 29 additions and 0 deletions
Showing only changes of commit 84e6c2d5fc - Show all commits

View File

@@ -53,6 +53,19 @@ public sealed class PlanningSessionManager
return new PlanningSessionStartContext(taskId, list.WorkingDir, files); return new PlanningSessionStartContext(taskId, list.WorkingDir, files);
} }
public async Task DiscardAsync(string taskId, CancellationToken ct)
{
var ok = await _tasks.DiscardPlanningAsync(taskId, ct);
var sessionDir = Path.Combine(_rootDirectory, taskId);
if (Directory.Exists(sessionDir))
{
try { Directory.Delete(sessionDir, recursive: true); }
catch { /* best effort */ }
}
if (!ok)
throw new InvalidOperationException($"Task {taskId} was not in Planning state; nothing to discard.");
}
public async Task<PlanningSessionResumeContext> ResumeAsync(string taskId, CancellationToken ct) public async Task<PlanningSessionResumeContext> ResumeAsync(string taskId, CancellationToken ct)
{ {
var task = await _tasks.GetByIdAsync(taskId, ct) var task = await _tasks.GetByIdAsync(taskId, ct)

View File

@@ -159,4 +159,20 @@ public sealed class PlanningSessionManagerTests : IDisposable
await Assert.ThrowsAsync<InvalidOperationException>(() => await Assert.ThrowsAsync<InvalidOperationException>(() =>
_sut.ResumeAsync(parent.Id, CancellationToken.None)); _sut.ResumeAsync(parent.Id, CancellationToken.None));
} }
[Fact]
public async Task DiscardAsync_DeletesSessionDirAndResetsTask()
{
var (listId, _) = await SeedListAsync();
var parent = await SeedManualTaskAsync(listId);
var startCtx = await _sut.StartAsync(parent.Id, CancellationToken.None);
Assert.True(Directory.Exists(startCtx.Files.SessionDirectory));
await _sut.DiscardAsync(parent.Id, CancellationToken.None);
Assert.False(Directory.Exists(startCtx.Files.SessionDirectory));
var loaded = await _tasks.GetByIdAsync(parent.Id);
Assert.Equal(TaskStatus.Manual, loaded!.Status);
Assert.Null(loaded.PlanningSessionToken);
}
} }