using ClaudeDo.Worker.Runner;
using Xunit;

namespace ClaudeDo.Worker.Tests.Runner;

public class SkillResolutionTests
{
    [Fact]
    public void Null_and_empty_sources_contribute_nothing()
        => Assert.Empty(TaskRunner.UnionSkillNames(null, "", "   ", "[]"));

    [Fact]
    public void Single_source_is_returned_in_order()
        => Assert.Equal(["a", "b"], TaskRunner.UnionSkillNames("""["a","b"]"""));

    [Fact]
    public void Unions_across_task_list_global_levels()
    {
        var result = TaskRunner.UnionSkillNames("""["a"]""", """["b"]""", """["c"]""");
        Assert.Equal(["a", "b", "c"], result);
    }

    [Fact]
    public void Dedups_ordinal_preserving_first_occurrence_order()
    {
        var result = TaskRunner.UnionSkillNames("""["a","b"]""", """["b","c"]""", """["a","d"]""");
        Assert.Equal(["a", "b", "c", "d"], result);
    }

    [Fact]
    public void Dedup_is_case_sensitive_ordinal()
    {
        var result = TaskRunner.UnionSkillNames("""["Foo"]""", """["foo"]""");
        Assert.Equal(["Foo", "foo"], result);
    }

    [Fact]
    public void Malformed_json_is_ignored_not_thrown()
        => Assert.Equal(["a"], TaskRunner.UnionSkillNames("not json", """["a"]"""));

    [Fact]
    public void Blank_entries_within_array_are_skipped()
        => Assert.Equal(["a"], TaskRunner.UnionSkillNames("""["a", "", "   ", null]"""));
}
