using ClaudeDo.Worker.Hub;
using Xunit;

namespace ClaudeDo.Worker.Tests.Hub;

public sealed class WorkerBuildInfoHubTests
{
    [Theory]
    [InlineData(null, null)]
    [InlineData("", null)]
    [InlineData("1.2.3", null)]
    [InlineData("1.2.3+", null)]
    [InlineData("1.2.3+abc1234", "abc1234")]
    // MinVer's own pre-release metadata can already contain a '+' (e.g. "+devsha"); our
    // SourceRevisionId is appended last, so only the segment after the LAST '+' is authoritative.
    [InlineData("0.0.0-alpha.0.4+devsha+f5b1a2c3d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9", "f5b1a2c3d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9")]
    public void ParseBuildSha_ExtractsSegmentAfterLastPlus(string? informationalVersion, string? expected)
    {
        Assert.Equal(expected, WorkerHub.ParseBuildSha(informationalVersion));
    }

    [Fact]
    public void GetWorkerBuildInfo_ReturnsDto()
    {
        var hub = new WorkerHub(
            null!, null!, null!, null!, null!, null!,
            null!, null!, null!, null!, null!, null!, null!, null!, null!, null!, null!, null!, null!,
            null!, new ClaudeDo.Worker.Online.OnlineInboxConfig(), new ClaudeDo.Worker.OnlineRefreshTokenStore(new ClaudeDo.Worker.DpapiTokenStore("unused.token")),
            new ClaudeDo.Worker.Runner.PendingQuestionRegistry(), null!);

        // No assertion on the actual SHA value (depends on the build environment) — just that
        // the call doesn't throw and always returns a DTO, never null.
        var info = hub.GetWorkerBuildInfo();
        Assert.NotNull(info);
    }
}
