Initial commit to new repository
This commit is contained in:
62
src/AxCopilot.Tests/Services/OperationModePolicyTests.cs
Normal file
62
src/AxCopilot.Tests/Services/OperationModePolicyTests.cs
Normal file
@@ -0,0 +1,62 @@
|
||||
using AxCopilot.Models;
|
||||
using AxCopilot.Services;
|
||||
using AxCopilot.Services.Agent;
|
||||
using FluentAssertions;
|
||||
using Xunit;
|
||||
|
||||
namespace AxCopilot.Tests.Services;
|
||||
|
||||
public class OperationModePolicyTests
|
||||
{
|
||||
[Fact]
|
||||
public void Normalize_DefaultsToInternalWhenMissingOrUnknown()
|
||||
{
|
||||
OperationModePolicy.Normalize(null).Should().Be(OperationModePolicy.InternalMode);
|
||||
OperationModePolicy.Normalize("").Should().Be(OperationModePolicy.InternalMode);
|
||||
OperationModePolicy.Normalize("unknown").Should().Be(OperationModePolicy.InternalMode);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Normalize_MapsExternalMode()
|
||||
{
|
||||
OperationModePolicy.Normalize("external").Should().Be(OperationModePolicy.ExternalMode);
|
||||
OperationModePolicy.Normalize("EXTERNAL").Should().Be(OperationModePolicy.ExternalMode);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void IsBlockedAgentToolInInternalMode_BlocksExternalHttpAndUrlOpen()
|
||||
{
|
||||
OperationModePolicy.IsBlockedAgentToolInInternalMode("http_tool", "https://example.com").Should().BeTrue();
|
||||
OperationModePolicy.IsBlockedAgentToolInInternalMode("open_external", "https://example.com").Should().BeTrue();
|
||||
OperationModePolicy.IsBlockedAgentToolInInternalMode("open_external", @"E:\work\report.html").Should().BeFalse();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task AgentContext_CheckToolPermissionAsync_BlocksRestrictedToolsInInternalMode()
|
||||
{
|
||||
var context = new AgentContext
|
||||
{
|
||||
OperationMode = OperationModePolicy.InternalMode,
|
||||
Permission = "Auto"
|
||||
};
|
||||
|
||||
var blocked = await context.CheckToolPermissionAsync("http_tool", "https://example.com");
|
||||
var allowed = await context.CheckToolPermissionAsync("file_read", @"E:\work\a.txt");
|
||||
|
||||
blocked.Should().BeFalse();
|
||||
allowed.Should().BeTrue();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task AgentContext_CheckToolPermissionAsync_AllowsRestrictedToolsInExternalMode()
|
||||
{
|
||||
var context = new AgentContext
|
||||
{
|
||||
OperationMode = OperationModePolicy.ExternalMode,
|
||||
Permission = "Auto"
|
||||
};
|
||||
|
||||
var allowed = await context.CheckToolPermissionAsync("http_tool", "https://example.com");
|
||||
allowed.Should().BeTrue();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user