using System;
using StellaOps.Scanner.Core.Security;
using Xunit;

namespace StellaOps.Scanner.Core.Tests.Security;

public sealed class RestartOnlyPluginGuardTests
{
    [Fact]
    public void EnsureRegistrationAllowed_AllowsNewPluginsBeforeSeal()
    {
        var guard = new RestartOnlyPluginGuard();
        guard.EnsureRegistrationAllowed("./plugins/analyzer.dll");

        Assert.Contains(guard.KnownPlugins, path => path.EndsWith("analyzer.dll", StringComparison.OrdinalIgnoreCase));
    }

    [Fact]
    public void EnsureRegistrationAllowed_ThrowsAfterSeal()
    {
        var guard = new RestartOnlyPluginGuard(new[] { "./plugins/a.dll" });
        guard.Seal();

        Assert.Throws<InvalidOperationException>(() => guard.EnsureRegistrationAllowed("./plugins/new.dll"));
    }
}
