Pulse/pkg/aicontracts/safety_test.go
rcourtman ee8a24e14a backend and governance: MCP contract, agent capabilities, API, and release-control
Manifest-backed MCP tools, prompts, and resources with surface affordance contracts; agent capability manifest and governance projection; API contract tests and capability route projection; operations-loop and intelligence-funnel telemetry; release-control subsystem documentation, registry, and tooling; licensing and configuration.
2026-06-23 17:26:15 +01:00

55 lines
1.2 KiB
Go

package aicontracts
import "testing"
func TestClassifyAutomationRisk(t *testing.T) {
tests := []struct {
name string
command string
want RiskLevel
}{
{
name: "read only command is low risk",
command: "systemctl status nginx",
want: RiskLow,
},
{
name: "stderr redirection on read only command stays low risk",
command: "find /var/log -name '*.log' 2>/dev/null",
want: RiskLow,
},
{
name: "file mutation is medium risk",
command: "touch /tmp/pulse-marker",
want: RiskMedium,
},
{
name: "service restart is high risk",
command: "systemctl restart nginx",
want: RiskHigh,
},
{
name: "stdout redirection is high risk",
command: "cat /etc/hosts > /tmp/hosts",
want: RiskHigh,
},
{
name: "blocked command is critical risk",
command: "rm -rf /tmp/pulse-data",
want: RiskCritical,
},
{
name: "unknown write capability defaults high risk",
command: "custom-repair-tool --apply",
want: RiskHigh,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := ClassifyAutomationRisk(tt.command); got != tt.want {
t.Fatalf("ClassifyAutomationRisk(%q) = %q, want %q", tt.command, got, tt.want)
}
})
}
}