Pulse/internal/agentcapabilities/scopes_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

100 lines
2.8 KiB
Go

package agentcapabilities
import (
"reflect"
"testing"
"github.com/rcourtman/pulse-go-rewrite/pkg/auth"
)
func TestRequiredCapabilityScopesUseAuthOrderAndDeduplicate(t *testing.T) {
capabilities := []Capability{
{Name: "settings_write", Scope: auth.ScopeSettingsWrite},
{Name: "monitoring_read", Scope: auth.ScopeMonitoringRead},
{Name: "empty_scope"},
{Name: "monitoring_write", Scope: auth.ScopeMonitoringWrite},
{Name: "unknown_one", Scope: "custom:alpha"},
{Name: "duplicate_monitoring_read", Scope: " " + auth.ScopeMonitoringRead + " "},
{Name: "ai_execute", Scope: auth.ScopeAIExecute},
{Name: "unknown_two", Scope: "custom:beta"},
}
got := RequiredCapabilityScopes(capabilities)
want := []string{
auth.ScopeMonitoringRead,
auth.ScopeMonitoringWrite,
auth.ScopeSettingsWrite,
auth.ScopeAIExecute,
"custom:alpha",
"custom:beta",
}
if !reflect.DeepEqual(got, want) {
t.Fatalf("RequiredCapabilityScopes = %v, want %v", got, want)
}
}
func TestNormalizeRequiredScopesUseAuthOrderAndDeduplicate(t *testing.T) {
got := NormalizeRequiredScopes([]string{
auth.ScopeSettingsWrite,
auth.ScopeMonitoringRead,
"",
" " + auth.ScopeMonitoringRead + " ",
"custom:alpha",
auth.ScopeAIExecute,
"custom:alpha",
"custom:beta",
})
want := []string{
auth.ScopeMonitoringRead,
auth.ScopeSettingsWrite,
auth.ScopeAIExecute,
"custom:alpha",
"custom:beta",
}
if !reflect.DeepEqual(got, want) {
t.Fatalf("NormalizeRequiredScopes = %v, want %v", got, want)
}
}
func TestRequiredCapabilityScopeListReflectsCanonicalManifest(t *testing.T) {
got := RequiredCapabilityScopeList(CanonicalManifest().Capabilities)
want := "monitoring:read, monitoring:write, settings:read, settings:write, ai:execute"
if got != want {
t.Fatalf("RequiredCapabilityScopeList(CanonicalManifest) = %q, want %q", got, want)
}
}
func TestManifestRequiredScopeListPrefersManifestRequiredScopes(t *testing.T) {
manifest := &Manifest{
RequiredScopes: []string{
auth.ScopeSettingsWrite,
auth.ScopeMonitoringRead,
auth.ScopeMonitoringRead,
auth.ScopeAIExecute,
},
Capabilities: []Capability{
{Name: "legacy_extra", Scope: auth.ScopeMonitoringWrite},
},
}
got := ManifestRequiredScopeList(manifest)
want := "monitoring:read, settings:write, ai:execute"
if got != want {
t.Fatalf("ManifestRequiredScopeList = %q, want %q", got, want)
}
}
func TestManifestRequiredScopeListFallsBackToCapabilitiesForLegacyManifest(t *testing.T) {
manifest := &Manifest{
Capabilities: []Capability{
{Name: "settings_write", Scope: auth.ScopeSettingsWrite},
{Name: "monitoring_read", Scope: auth.ScopeMonitoringRead},
},
}
got := ManifestRequiredScopeList(manifest)
want := "monitoring:read, settings:write"
if got != want {
t.Fatalf("ManifestRequiredScopeList legacy fallback = %q, want %q", got, want)
}
}