Merge claudedo/28d494e791e842fc966eb8691181e6da
This commit is contained in:
@@ -0,0 +1,136 @@
|
||||
using ClaudeDo.Data;
|
||||
using ClaudeDo.Data.Models;
|
||||
using ClaudeDo.Ui.Services;
|
||||
using ClaudeDo.Ui.ViewModels.Islands;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using TaskStatus = ClaudeDo.Data.Models.TaskStatus;
|
||||
|
||||
namespace ClaudeDo.Ui.Tests.ViewModels;
|
||||
|
||||
// Covers the Reset & Retry gate: it discards the branch/uncommitted work and queues an
|
||||
// autonomous run into the same worktree, so it must stay off while an interactive ConPTY
|
||||
// pane is open on the task (mirrors TaskRowViewModel.CanSendToQueue's HasInteractiveSession gate).
|
||||
public class DetailsIslandResetAndRetryTests : IDisposable
|
||||
{
|
||||
private readonly string _dbPath;
|
||||
|
||||
public DetailsIslandResetAndRetryTests()
|
||||
{
|
||||
_dbPath = Path.Combine(Path.GetTempPath(), $"claudedo_reset_retry_test_{Guid.NewGuid():N}.db");
|
||||
using var ctx = NewContext();
|
||||
ctx.Database.EnsureCreated();
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
try { File.Delete(_dbPath); } catch { }
|
||||
try { File.Delete(_dbPath + "-wal"); } catch { }
|
||||
try { File.Delete(_dbPath + "-shm"); } catch { }
|
||||
}
|
||||
|
||||
private ClaudeDoDbContext NewContext()
|
||||
{
|
||||
var opts = new DbContextOptionsBuilder<ClaudeDoDbContext>()
|
||||
.UseSqlite($"Data Source={_dbPath}")
|
||||
.Options;
|
||||
return new ClaudeDoDbContext(opts);
|
||||
}
|
||||
|
||||
private sealed class TestDbFactory : IDbContextFactory<ClaudeDoDbContext>
|
||||
{
|
||||
private readonly Func<ClaudeDoDbContext> _create;
|
||||
public TestDbFactory(Func<ClaudeDoDbContext> create) => _create = create;
|
||||
public ClaudeDoDbContext CreateDbContext() => _create();
|
||||
}
|
||||
|
||||
private sealed class NullServiceProvider : IServiceProvider
|
||||
{
|
||||
public object? GetService(Type serviceType) => null;
|
||||
}
|
||||
|
||||
private sealed class StubNotesApi : ClaudeDo.Ui.Services.Interfaces.INotesApi
|
||||
{
|
||||
public Task<List<DailyNoteDto>> ListAsync(DateOnly day) =>
|
||||
Task.FromResult(new List<DailyNoteDto>());
|
||||
public Task<DailyNoteDto?> AddAsync(DateOnly day, string text) =>
|
||||
Task.FromResult<DailyNoteDto?>(null);
|
||||
public Task UpdateAsync(string id, string text) => Task.CompletedTask;
|
||||
public Task DeleteAsync(string id) => Task.CompletedTask;
|
||||
}
|
||||
|
||||
private sealed class RecordingWorkerClient : StubWorkerClient
|
||||
{
|
||||
public override bool IsConnected => true;
|
||||
}
|
||||
|
||||
private DetailsIslandViewModel BuildVm(StubWorkerClient worker)
|
||||
{
|
||||
var factory = new TestDbFactory(NewContext);
|
||||
return new DetailsIslandViewModel(
|
||||
factory, worker, new NullServiceProvider(), new StubNotesApi(), new ClaudeDo.Ui.Services.MergeCoordinator());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ResetAndRetry_IsDisabled_WhileTaskHasInteractiveSession()
|
||||
{
|
||||
var vm = BuildVm(new RecordingWorkerClient());
|
||||
var row = new TaskRowViewModel { Id = "task-reset-1", Status = TaskStatus.Failed, HasInteractiveSession = true };
|
||||
vm.Bind(row);
|
||||
vm.Monitor.ApplyState(TaskStatus.Failed);
|
||||
|
||||
Assert.True(vm.ShowResetAndRetry);
|
||||
Assert.False(vm.ResetAndRetryCommand.CanExecute(null));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ResetAndRetry_ReEnables_WhenInteractiveSessionCloses()
|
||||
{
|
||||
var vm = BuildVm(new RecordingWorkerClient());
|
||||
var row = new TaskRowViewModel { Id = "task-reset-2", Status = TaskStatus.Failed, HasInteractiveSession = true };
|
||||
vm.Bind(row);
|
||||
vm.Monitor.ApplyState(TaskStatus.Failed);
|
||||
|
||||
Assert.False(vm.ResetAndRetryCommand.CanExecute(null));
|
||||
|
||||
var canExecuteChangedRaised = false;
|
||||
vm.ResetAndRetryCommand.CanExecuteChanged += (_, _) => canExecuteChangedRaised = true;
|
||||
|
||||
// The row is the same instance Mission Control flips when a ConPTY pane closes —
|
||||
// the command's CanExecute must react without the bound Task itself changing.
|
||||
row.HasInteractiveSession = false;
|
||||
|
||||
Assert.True(canExecuteChangedRaised);
|
||||
Assert.True(vm.ResetAndRetryCommand.CanExecute(null));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ResetAndRetry_IsEnabled_ForTerminalTaskWithoutInteractiveSession()
|
||||
{
|
||||
var vm = BuildVm(new RecordingWorkerClient());
|
||||
var row = new TaskRowViewModel { Id = "task-reset-3", Status = TaskStatus.Cancelled };
|
||||
vm.Bind(row);
|
||||
vm.Monitor.ApplyState(TaskStatus.Cancelled);
|
||||
|
||||
Assert.True(vm.ResetAndRetryCommand.CanExecute(null));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ResetAndRetry_StaysDisabled_AfterSwitchingToAnotherInteractiveTask()
|
||||
{
|
||||
var vm = BuildVm(new RecordingWorkerClient());
|
||||
var firstRow = new TaskRowViewModel { Id = "task-reset-4", Status = TaskStatus.Failed };
|
||||
vm.Bind(firstRow);
|
||||
vm.Monitor.ApplyState(TaskStatus.Failed);
|
||||
Assert.True(vm.ResetAndRetryCommand.CanExecute(null));
|
||||
|
||||
var secondRow = new TaskRowViewModel { Id = "task-reset-5", Status = TaskStatus.Failed, HasInteractiveSession = true };
|
||||
vm.Bind(secondRow);
|
||||
vm.Monitor.ApplyState(TaskStatus.Failed);
|
||||
|
||||
Assert.False(vm.ResetAndRetryCommand.CanExecute(null));
|
||||
|
||||
// Flipping the old (unsubscribed) row must not resurrect the command for the new task.
|
||||
firstRow.HasInteractiveSession = true;
|
||||
Assert.False(vm.ResetAndRetryCommand.CanExecute(null));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,129 @@
|
||||
using ClaudeDo.Data;
|
||||
using ClaudeDo.Data.Models;
|
||||
using ClaudeDo.Ui.ViewModels.Islands;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using TaskStatus = ClaudeDo.Data.Models.TaskStatus;
|
||||
|
||||
namespace ClaudeDo.Ui.Tests.ViewModels;
|
||||
|
||||
// The hub's QueuePlanningSubtasksAsync queues every Idle child of a finalized planning parent
|
||||
// unconditionally — it has no notion of a UI-hosted ConPTY session. SendToQueueAsync must block
|
||||
// the whole plan when any child has an open interactive session, otherwise that child's worktree
|
||||
// gets an autonomous run racing the user's own hand-driven edits.
|
||||
public class TasksIslandQueuePlanInteractiveGateTests : IDisposable
|
||||
{
|
||||
private readonly string _dbPath;
|
||||
|
||||
public TasksIslandQueuePlanInteractiveGateTests()
|
||||
{
|
||||
_dbPath = Path.Combine(Path.GetTempPath(), $"claudedo_queueplan_gate_{Guid.NewGuid():N}.db");
|
||||
using var ctx = NewContext();
|
||||
ctx.Database.EnsureCreated();
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
try { File.Delete(_dbPath); } catch { }
|
||||
try { File.Delete(_dbPath + "-wal"); } catch { }
|
||||
try { File.Delete(_dbPath + "-shm"); } catch { }
|
||||
}
|
||||
|
||||
private ClaudeDoDbContext NewContext()
|
||||
{
|
||||
var opts = new DbContextOptionsBuilder<ClaudeDoDbContext>()
|
||||
.UseSqlite($"Data Source={_dbPath}")
|
||||
.Options;
|
||||
return new ClaudeDoDbContext(opts);
|
||||
}
|
||||
|
||||
private sealed class TestDbFactory : IDbContextFactory<ClaudeDoDbContext>
|
||||
{
|
||||
private readonly Func<ClaudeDoDbContext> _create;
|
||||
public TestDbFactory(Func<ClaudeDoDbContext> create) => _create = create;
|
||||
public ClaudeDoDbContext CreateDbContext() => _create();
|
||||
}
|
||||
|
||||
private sealed class RecordingWorkerClient : StubWorkerClient
|
||||
{
|
||||
public override bool IsConnected => true;
|
||||
public string? QueuedParentId;
|
||||
public override Task QueuePlanningSubtasksAsync(string parentTaskId, CancellationToken ct = default)
|
||||
{
|
||||
QueuedParentId = parentTaskId;
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
|
||||
private TasksIslandViewModel BuildViewModel(StubWorkerClient worker) =>
|
||||
new(new TestDbFactory(NewContext), worker);
|
||||
|
||||
[Fact]
|
||||
public async Task SendToQueue_FinalizedPlan_BlockedWhenAChildHasInteractiveSession()
|
||||
{
|
||||
var worker = new RecordingWorkerClient();
|
||||
var vm = BuildViewModel(worker);
|
||||
|
||||
var parent = new TaskRowViewModel
|
||||
{
|
||||
Id = "parent-1",
|
||||
Status = TaskStatus.Idle,
|
||||
PlanningPhase = PlanningPhase.Finalized,
|
||||
HasPlanningChildren = true,
|
||||
};
|
||||
var interactiveChild = new TaskRowViewModel
|
||||
{
|
||||
Id = "child-1",
|
||||
Title = "Fix the flaky test",
|
||||
ParentTaskId = "parent-1",
|
||||
Status = TaskStatus.Idle,
|
||||
HasInteractiveSession = true,
|
||||
};
|
||||
var otherChild = new TaskRowViewModel
|
||||
{
|
||||
Id = "child-2",
|
||||
ParentTaskId = "parent-1",
|
||||
Status = TaskStatus.Idle,
|
||||
};
|
||||
vm.Items.Add(parent);
|
||||
vm.Items.Add(interactiveChild);
|
||||
vm.Items.Add(otherChild);
|
||||
|
||||
Assert.True(parent.CanQueuePlan);
|
||||
|
||||
string? reportedError = null;
|
||||
vm.ErrorReported += msg => reportedError = msg;
|
||||
|
||||
await vm.SendToQueueCommand.ExecuteAsync(parent);
|
||||
|
||||
Assert.Null(worker.QueuedParentId);
|
||||
Assert.NotNull(reportedError);
|
||||
Assert.Contains("Fix the flaky test", reportedError);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task SendToQueue_FinalizedPlan_ProceedsWhenNoChildHasInteractiveSession()
|
||||
{
|
||||
var worker = new RecordingWorkerClient();
|
||||
var vm = BuildViewModel(worker);
|
||||
|
||||
var parent = new TaskRowViewModel
|
||||
{
|
||||
Id = "parent-2",
|
||||
Status = TaskStatus.Idle,
|
||||
PlanningPhase = PlanningPhase.Finalized,
|
||||
HasPlanningChildren = true,
|
||||
};
|
||||
var child = new TaskRowViewModel
|
||||
{
|
||||
Id = "child-3",
|
||||
ParentTaskId = "parent-2",
|
||||
Status = TaskStatus.Idle,
|
||||
};
|
||||
vm.Items.Add(parent);
|
||||
vm.Items.Add(child);
|
||||
|
||||
await vm.SendToQueueCommand.ExecuteAsync(parent);
|
||||
|
||||
Assert.Equal("parent-2", worker.QueuedParentId);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user