using ClaudeDo.Ui.Services;
using Xunit;

namespace ClaudeDo.Ui.Tests.Services;

public class WorkerLocatorTests
{
    [Fact]
    public void FindByWalkingUp_FindsWorkerExeBesideInstallJson()
    {
        var root = Path.Combine(Path.GetTempPath(), "claudedo_wl_" + Guid.NewGuid().ToString("N"));
        var appDir = Path.Combine(root, "app");
        var workerDir = Path.Combine(root, "worker");
        Directory.CreateDirectory(appDir);
        Directory.CreateDirectory(workerDir);
        File.WriteAllText(Path.Combine(root, "install.json"), "{}");
        var exe = Path.Combine(workerDir, "ClaudeDo.Worker.exe");
        File.WriteAllText(exe, "");

        try
        {
            var found = new WorkerLocator().FindByWalkingUp(appDir);
            Assert.Equal(exe, found);
        }
        finally { Directory.Delete(root, recursive: true); }
    }

    [Fact]
    public void FindByWalkingUp_ReturnsNullWhenNoManifest()
    {
        var dir = Path.Combine(Path.GetTempPath(), "claudedo_wl_none_" + Guid.NewGuid().ToString("N"));
        Directory.CreateDirectory(dir);
        try { Assert.Null(new WorkerLocator().FindByWalkingUp(dir)); }
        finally { Directory.Delete(dir, recursive: true); }
    }
}
