package com.easyagents.agent.runtime.tool.operate;

import org.junit.Assert;
import org.junit.Test;

import java.nio.file.Path;
import java.util.List;

/**
 * 测试 Linux 独立进程组能力的启动检查与非 Linux 降级。
 */
public class ShellProcessGroupSupportTest {

    @Test
    public void shouldFailFastWhenLinuxProcessGroupDependenciesAreMissing() {
        try {
            ShellProcessGroupSupport.detect("Linux", null, null);
            Assert.fail("Expected missing dependency failure");
        } catch (WorkspaceToolException expected) {
            Assert.assertEquals("WORKSPACE_CONFIG_INVALID", expected.code());
            Assert.assertFalse(expected.retryable());
        }
    }

    @Test
    public void shouldUsePortableFallbackOutsideLinux() {
        ShellProcessGroupSupport support = ShellProcessGroupSupport.detect(
                "Mac OS X", Path.of("/missing/setsid"), Path.of("/missing/kill"));
        List<String> command = List.of("pwd");

        Assert.assertFalse(support.enabled());
        Assert.assertSame(command, support.wrap(command));
        support.terminate(-1);
    }
}
