feat(worker): PlanningSessionManager.DiscardAsync
This commit is contained in:
@@ -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)
|
||||||
|
|||||||
@@ -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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user