using ClaudeDo.Worker.Hub;
using ClaudeDo.Worker.Lifecycle;
using ClaudeDo.Worker.Tests.Infrastructure;
using Microsoft.Extensions.Logging.Abstractions;

namespace ClaudeDo.Worker.Tests.Lifecycle;

public sealed class OrphanRecoveryTests : IDisposable
{
    private readonly DbFixture _db = new();

    public void Dispose() => _db.Dispose();

    [Fact]
    public async Task StartAsync_NoOrphans_BroadcastsStartupRecoveryProgress()
    {
        var hubContext = new CapturingHubContext();
        var sut = new OrphanRecovery(
            _db.CreateFactory(), new HubBroadcaster(hubContext), NullLogger<OrphanRecovery>.Instance);

        await sut.StartAsync(CancellationToken.None);
        await sut.StopAsync(CancellationToken.None);

        Assert.Contains(hubContext.Proxy.Calls, c =>
            c.Method == "OperationProgress" && (string)c.Args[0]! == "startup-recovery");
    }
}
