using ClaudeDo.Worker.Runner;
using Xunit;

namespace ClaudeDo.Worker.Tests.Runner;

public sealed class TaskRunTokenRegistryTests
{
    [Fact]
    public void Register_then_resolve_returns_taskId()
    {
        var reg = new TaskRunTokenRegistry();
        reg.Register("tok", "task-1");
        Assert.True(reg.TryResolve("tok", out var id));
        Assert.Equal("task-1", id);
    }

    [Fact]
    public void Unregister_removes_token()
    {
        var reg = new TaskRunTokenRegistry();
        reg.Register("tok", "task-1");
        reg.Unregister("tok");
        Assert.False(reg.TryResolve("tok", out _));
    }

    [Fact]
    public void GenerateToken_is_urlsafe_and_unique()
    {
        var a = TaskRunTokenRegistry.GenerateToken();
        var b = TaskRunTokenRegistry.GenerateToken();
        Assert.NotEqual(a, b);
        Assert.DoesNotContain('+', a);
        Assert.DoesNotContain('/', a);
        Assert.DoesNotContain('=', a);
    }
}
