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.
74 lines
2.3 KiB
C#
74 lines
2.3 KiB
C#
using ClaudeDo.Data;
|
|
using ClaudeDo.Data.Models;
|
|
using ClaudeDo.Data.Repositories;
|
|
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.Services;
|
|
|
|
public sealed class StaleTaskRecoveryTests : IDisposable
|
|
{
|
|
private readonly DbFixture _db = new();
|
|
private readonly ClaudeDoDbContext _ctx;
|
|
private readonly TaskRepository _tasks;
|
|
private readonly ListRepository _lists;
|
|
|
|
public StaleTaskRecoveryTests()
|
|
{
|
|
_ctx = _db.CreateContext();
|
|
_tasks = new TaskRepository(_ctx);
|
|
_lists = new ListRepository(_ctx);
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
_ctx.Dispose();
|
|
_db.Dispose();
|
|
}
|
|
|
|
[Fact]
|
|
public async Task StartAsync_Flips_Running_Tasks_To_Failed()
|
|
{
|
|
var listId = Guid.NewGuid().ToString();
|
|
await _lists.AddAsync(new ListEntity { Id = listId, Name = "Test", CreatedAt = DateTime.UtcNow });
|
|
|
|
var running = new TaskEntity
|
|
{
|
|
Id = Guid.NewGuid().ToString(),
|
|
ListId = listId,
|
|
Title = "Running task",
|
|
Status = TaskStatus.Running,
|
|
CreatedAt = DateTime.UtcNow,
|
|
};
|
|
var queued = new TaskEntity
|
|
{
|
|
Id = Guid.NewGuid().ToString(),
|
|
ListId = listId,
|
|
Title = "Queued task",
|
|
Status = TaskStatus.Queued,
|
|
CreatedAt = DateTime.UtcNow,
|
|
};
|
|
|
|
await _tasks.AddAsync(running);
|
|
await _tasks.AddAsync(queued);
|
|
|
|
var built = TaskStateServiceBuilder.Build(_db.CreateFactory());
|
|
var hubContext = new CapturingHubContext();
|
|
var recovery = new StaleTaskRecovery(built.State, new HubBroadcaster(hubContext), NullLogger<StaleTaskRecovery>.Instance);
|
|
await recovery.StartAsync(CancellationToken.None);
|
|
|
|
var r = await _tasks.GetByIdAsync(running.Id);
|
|
Assert.Equal(TaskStatus.Failed, r!.Status);
|
|
Assert.StartsWith("[stale] ", r.Result);
|
|
|
|
var q = await _tasks.GetByIdAsync(queued.Id);
|
|
Assert.Equal(TaskStatus.Queued, q!.Status);
|
|
|
|
Assert.Contains(hubContext.Proxy.Calls, c =>
|
|
c.Method == "OperationProgress" && (string)c.Args[0]! == "startup-recovery");
|
|
}
|
|
}
|