46 lines
1.4 KiB
Go
46 lines
1.4 KiB
Go
package agentguard
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestBlockerNotificationIsTypedActionableAndPathFree(t *testing.T) {
|
|
rawPath := "/private/example/workspace"
|
|
result := blockedResult(AdmissionRequest{
|
|
Grant: &WorkspaceGrant{
|
|
ProjectID: "project-a",
|
|
Root: rawPath,
|
|
},
|
|
Profile: ProviderProfile{
|
|
ProviderID: "codex",
|
|
ProfileID: "codex-headless",
|
|
},
|
|
}, BlockerCodeProviderApprovalBypassUnavailable, "approval bypass is unavailable")
|
|
|
|
if result.Status != AdmissionStatusBlocked ||
|
|
result.Blocker == nil ||
|
|
result.Notification == nil {
|
|
t.Fatalf("blocked result = %#v", result)
|
|
}
|
|
if result.Blocker.Code != BlockerCodeProviderApprovalBypassUnavailable ||
|
|
result.Notification.Code != result.Blocker.Code {
|
|
t.Fatalf("codes = blocker:%q notification:%q", result.Blocker.Code, result.Notification.Code)
|
|
}
|
|
if result.Notification.SetupGuidance == "" {
|
|
t.Fatal("notification setup guidance is empty")
|
|
}
|
|
rendered := result.Blocker.Error() + result.Notification.Message + result.Notification.SetupGuidance
|
|
if strings.Contains(rendered, rawPath) {
|
|
t.Fatalf("notification leaked raw path: %q", rendered)
|
|
}
|
|
}
|
|
|
|
func TestNormalizeBlockerCodePreservesKnownAndBoundsUnknown(t *testing.T) {
|
|
if got := NormalizeBlockerCode(BlockerCodePermitStale); got != BlockerCodePermitStale {
|
|
t.Fatalf("known code = %q", got)
|
|
}
|
|
if got := NormalizeBlockerCode("future_blocker"); got != BlockerCodeUnknown {
|
|
t.Fatalf("future code = %q", got)
|
|
}
|
|
}
|