chore: establish local platform baseline

This commit is contained in:
Codex Local
2026-08-26 06:41:54 +08:00
commit 29bdf4900f
575 changed files with 95644 additions and 0 deletions
@@ -0,0 +1,72 @@
package alertreceiverconformance
import (
"strings"
"testing"
"time"
)
func TestEvaluateRealReceiverCoverageAndFormalDrill(t *testing.T) {
t.Parallel()
routes, tests, incident, capture, now := conformanceFixture("REAL")
report := Evaluate(routes, tests, incident, capture, "0.64.0-rc.1", "sha256:"+strings.Repeat("a", 64), now)
if report.Result != "PASS" || report.EvidenceScope != "REAL_RECEIVER" || report.ExternalValidationRequired || !report.FormalDrillVerified || report.ActiveRouteCount != 1 || len(report.RouteCoverage) != 1 || report.RouteCoverage[0].Status != "PASS" {
t.Fatalf("unexpected report: %+v", report)
}
}
func TestEvaluateMockOrMissingMappingCannotCompleteExternalGate(t *testing.T) {
t.Parallel()
routes, tests, incident, capture, now := conformanceFixture("MOCK")
report := Evaluate(routes, tests, incident, capture, "0.64.0-rc.1", "sha256:"+strings.Repeat("a", 64), now)
if report.Result != "PASS" || report.EvidenceScope != "MOCK_RECEIVER" || !report.ExternalValidationRequired {
t.Fatalf("mock result did not preserve external gate: %+v", report)
}
capture.GroupMappings = capture.GroupMappings[:1]
report = Evaluate(routes, tests, incident, capture, "0.64.0-rc.1", "sha256:"+strings.Repeat("a", 64), now)
if report.Result != "FAIL" {
t.Fatal("missing escalation receiver mapping was accepted")
}
}
func TestParseCaptureAndReportRejectUnknownFields(t *testing.T) {
t.Parallel()
if _, err := ParseCapture([]byte(`{"schema_version":"alert-receiver-capture-v1","unexpected":true}`)); err == nil {
t.Fatal("unknown capture field was accepted")
}
if _, err := ParseReport([]byte(`{"schema_version":"alert-receiver-conformance-report-v1","unexpected":true}`)); err == nil {
t.Fatal("unknown report field was accepted")
}
}
func conformanceFixture(source string) (CloudRoutes, CloudTests, CloudIncident, ReceiverCapture, time.Time) {
now := time.Date(2026, 8, 25, 12, 0, 0, 0, time.UTC)
routeID := "10000000-0000-0000-0000-000000000001"
tenantID := "20000000-0000-0000-0000-000000000001"
testID := "30000000-0000-0000-0000-000000000001"
testRef := "40000000-0000-0000-0000-000000000001"
incidentID := "50000000-0000-0000-0000-000000000001"
completed := now.Add(-8 * time.Minute)
resolved := now.Add(-2 * time.Minute)
routes := CloudRoutes{Items: []CloudRoute{{
ID: routeID, TenantID: tenantID, Category: "TECHNICAL", Severity: "HIGH", Status: "ACTIVE",
ReceiverGroup: "platform-oncall", EscalationReceiverGroup: "incident-command", RunbookRef: "runbook://platform/alerts",
CreatedAt: now.Add(-time.Hour), UpdatedAt: now.Add(-time.Hour),
}}}
tests := CloudTests{Items: []CloudTest{{
ID: testID, TestRef: testRef, RoutingPolicyID: routeID, ReceiverGroup: "platform-oncall", Status: "DELIVERED",
AttemptCount: 1, CreatedAt: now.Add(-10 * time.Minute), CompletedAt: &completed,
}}}
group := "platform-oncall"
incident := CloudIncident{ID: incidentID, Status: "RESOLVED", ReceiverGroup: &group, FirstDetected: now.Add(-6 * time.Minute), ResolvedAt: &resolved, Actions: []CloudAction{{ActionType: "ACKNOWLEDGED", CreatedAt: now.Add(-4 * time.Minute)}}}
capture := ReceiverCapture{
SchemaVersion: CaptureSchema, EvidenceSource: source, CandidateVersion: "0.64.0-rc.1", BuildDigest: "sha256:" + strings.Repeat("a", 64), ReceiverSystem: "pager-gateway:production", CollectedAt: now,
GroupMappings: []GroupMapping{
{ReceiverGroup: "platform-oncall", MappedTargetRefs: []string{"pager-service:platform-primary"}, VerifiedAt: now.Add(-7 * time.Minute)},
{ReceiverGroup: "incident-command", MappedTargetRefs: []string{"pager-service:incident-command"}, VerifiedAt: now.Add(-7 * time.Minute)},
},
TestReceipts: []TestReceipt{{TestRef: testRef, EventID: testID, ReceiverGroup: "platform-oncall", DeliveryCount: 1, SignatureVerified: true, ReceivedAt: completed.Add(-time.Second)}},
FormalDrill: FormalDrillCapture{IncidentID: incidentID, ReceiverGroup: "platform-oncall", DeliveryCount: 1, SignatureVerified: true, ControlledDrill: true, ReceivedAt: now.Add(-5 * time.Minute), AcknowledgedAt: now.Add(-4 * time.Minute), AcknowledgementRef: "incident-ticket:masked-001"},
}
return routes, tests, incident, capture, now
}