The six Lifecycle/*Recovery hosted services now broadcast one
OperationProgress("startup-recovery", <phase>, current, total) message each
after they finish, instead of leaving the UI on a bare "connecting" text
during worker startup. IslandsShellViewModel subscribes and swaps in
"Recovering... (i/n)" (existing ops.worker.startupRecovery key, no locale
changes) while Worker.IsReconnecting is true, and clears it once actually
connected so a later transient reconnect doesn't replay stale text.
OperationProgress broadcasts to Clients.All with no replay-on-connect, so a
UI that hasn't finished its SignalR handshake yet can miss some or all of
these messages and simply keep showing "connecting" as before -- accepted
rather than adding a cached-state + reconnect-replay path (mirroring
RefreshExternalMergeConflictsAsync) for what is a fast, best-effort,
local-only startup sweep with no UI-visible failure mode beyond that.
86 lines
3.1 KiB
C#
86 lines
3.1 KiB
C#
using ClaudeDo.Data;
|
|
using ClaudeDo.Data.Models;
|
|
using ClaudeDo.Worker.Hub;
|
|
using ClaudeDo.Worker.Lifecycle;
|
|
using ClaudeDo.Worker.Tests.Infrastructure;
|
|
using Microsoft.Extensions.Logging.Abstractions;
|
|
using TaskStatus = ClaudeDo.Data.Models.TaskStatus;
|
|
|
|
namespace ClaudeDo.Worker.Tests.Lifecycle;
|
|
|
|
public sealed class AttachmentOrphanRecoveryTests : IDisposable
|
|
{
|
|
private readonly DbFixture _db = new();
|
|
private readonly string _attachRoot;
|
|
|
|
public AttachmentOrphanRecoveryTests()
|
|
{
|
|
_attachRoot = Path.Combine(Path.GetTempPath(), $"claudedo_orph_{Guid.NewGuid():N}");
|
|
Directory.CreateDirectory(_attachRoot);
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
_db.Dispose();
|
|
try { Directory.Delete(_attachRoot, recursive: true); } catch { }
|
|
}
|
|
|
|
[Fact]
|
|
public async Task StartAsync_DeletesOrphanDir_KeepsLiveTaskDir()
|
|
{
|
|
// Seed one real task.
|
|
string listId = Guid.NewGuid().ToString();
|
|
string liveTaskId = Guid.NewGuid().ToString();
|
|
using (var ctx = _db.CreateContext())
|
|
{
|
|
ctx.Lists.Add(new ListEntity { Id = listId, Name = "L", CreatedAt = DateTime.UtcNow });
|
|
ctx.Tasks.Add(new TaskEntity
|
|
{
|
|
Id = liveTaskId, ListId = listId, Title = "T",
|
|
Status = TaskStatus.Idle, CreatedAt = DateTime.UtcNow,
|
|
});
|
|
await ctx.SaveChangesAsync();
|
|
}
|
|
|
|
// Create two attachment directories: one for the live task, one orphan.
|
|
var store = new AttachmentStore(_attachRoot);
|
|
var liveDir = store.TaskDir(liveTaskId);
|
|
var orphanId = Guid.NewGuid().ToString();
|
|
var orphanDir = store.TaskDir(orphanId);
|
|
Directory.CreateDirectory(liveDir);
|
|
Directory.CreateDirectory(orphanDir);
|
|
|
|
var hubContext = new CapturingHubContext();
|
|
var sut = new AttachmentOrphanRecovery(
|
|
_db.CreateFactory(), store,
|
|
new HubBroadcaster(hubContext),
|
|
NullLogger<AttachmentOrphanRecovery>.Instance);
|
|
|
|
await sut.StartAsync(CancellationToken.None);
|
|
|
|
Assert.True(Directory.Exists(liveDir), "Live task dir should be kept");
|
|
Assert.False(Directory.Exists(orphanDir), "Orphan dir should be deleted");
|
|
Assert.Contains(hubContext.Proxy.Calls, c =>
|
|
c.Method == "OperationProgress" && (string)c.Args[0]! == "startup-recovery");
|
|
}
|
|
|
|
[Fact]
|
|
public async Task StartAsync_NoAttachmentRoot_IsNoop()
|
|
{
|
|
// Use a root that does not exist — should complete without throwing.
|
|
var missingRoot = Path.Combine(Path.GetTempPath(), $"claudedo_missing_{Guid.NewGuid():N}");
|
|
var store = new AttachmentStore(missingRoot);
|
|
|
|
var hubContext = new CapturingHubContext();
|
|
var sut = new AttachmentOrphanRecovery(
|
|
_db.CreateFactory(), store,
|
|
new HubBroadcaster(hubContext),
|
|
NullLogger<AttachmentOrphanRecovery>.Instance);
|
|
|
|
await sut.StartAsync(CancellationToken.None); // must not throw
|
|
|
|
Assert.Contains(hubContext.Proxy.Calls, c =>
|
|
c.Method == "OperationProgress" && (string)c.Args[0]! == "startup-recovery");
|
|
}
|
|
}
|