114 lines
4.8 KiB
Go
114 lines
4.8 KiB
Go
package diagnostics
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestValidAcceptanceSnapshotInputLimitsAuditReason(t *testing.T) {
|
|
input := AcceptanceSnapshotInput{
|
|
CandidateVersion: "0.55.0-rc.1",
|
|
BuildDigest: "sha256:" + strings.Repeat("a", 64),
|
|
Environment: "LAB",
|
|
RunType: "PILOT",
|
|
Scope: "本地试点技术预检",
|
|
RequiredDependencies: []string{"oidc_jwks"},
|
|
Reason: strings.Repeat("理", 255),
|
|
}
|
|
if !validAcceptanceSnapshotInput(input) {
|
|
t.Fatal("255-character audit reason should be accepted")
|
|
}
|
|
input.Reason += "由"
|
|
if validAcceptanceSnapshotInput(input) {
|
|
t.Fatal("reason exceeding audit_event.purpose capacity should be rejected")
|
|
}
|
|
}
|
|
|
|
func TestEvaluateAcceptancePlatformHealthBlocksStaleAndUnhealthyReports(t *testing.T) {
|
|
now := time.Date(2026, 8, 26, 14, 0, 0, 0, time.UTC)
|
|
tests := []struct {
|
|
name string
|
|
status string
|
|
observedAt time.Time
|
|
checks []PlatformHealthCheck
|
|
state string
|
|
satisfied bool
|
|
}{
|
|
{
|
|
name: "current healthy", status: "healthy", observedAt: now.Add(-5 * time.Minute),
|
|
checks: []PlatformHealthCheck{{Name: "public_https", Status: "healthy", Value: "http_200"}}, state: "CURRENT", satisfied: true,
|
|
},
|
|
{
|
|
name: "stale healthy", status: "healthy", observedAt: now.Add(-16 * time.Minute),
|
|
checks: []PlatformHealthCheck{{Name: "public_https", Status: "healthy", Value: "http_200"}}, state: "STALE", satisfied: false,
|
|
},
|
|
{
|
|
name: "current warning", status: "warning", observedAt: now.Add(-5 * time.Minute),
|
|
checks: []PlatformHealthCheck{{Name: "backup", Status: "warning", Value: "late"}}, state: "CURRENT", satisfied: false,
|
|
},
|
|
{
|
|
name: "current critical", status: "critical", observedAt: now.Add(-5 * time.Minute),
|
|
checks: []PlatformHealthCheck{{Name: "disk", Status: "critical", Value: "full"}}, state: "CURRENT", satisfied: false,
|
|
},
|
|
}
|
|
for _, test := range tests {
|
|
t.Run(test.name, func(t *testing.T) {
|
|
state := evaluateAcceptancePlatformHealth(test.status, test.observedAt, now, test.checks, now)
|
|
if state.State != test.state || state.GateSatisfied != test.satisfied {
|
|
t.Fatalf("state=%+v", state)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestAcceptancePlatformHealthSummaryCoversMissingAndCounts(t *testing.T) {
|
|
if summary := acceptancePlatformHealthSummary(AcceptancePlatformHealthState{State: "MISSING"}); !strings.Contains(summary, "尚未收到") {
|
|
t.Fatalf("missing summary=%q", summary)
|
|
}
|
|
if summary := acceptancePlatformHealthSummary(AcceptancePlatformHealthState{State: "CURRENT", Status: "warning", WarningCount: 2, CriticalCount: 1}); !strings.Contains(summary, "2项预警") || !strings.Contains(summary, "1项严重异常") {
|
|
t.Fatalf("unhealthy summary=%q", summary)
|
|
}
|
|
}
|
|
|
|
func TestEvaluateAcceptanceProductionInfrastructure(t *testing.T) {
|
|
readyChecks := []PlatformHealthCheck{
|
|
{Name: "deployment_profile", Status: "healthy", Value: "production"},
|
|
{Name: "offsite_backup", Status: "healthy", Value: "age_seconds=120"},
|
|
{Name: "external_alert_receiver", Status: "healthy", Value: "configured"},
|
|
{Name: "mock_services", Status: "healthy", Value: "disabled"},
|
|
}
|
|
ready := evaluateAcceptanceProductionInfrastructure("PRODUCTION", readyChecks)
|
|
if !ready.Applicable || !ready.GateSatisfied || !ready.OffsiteBackupReady || !ready.ExternalAlertReceiverReady || !ready.MockServicesDisabled {
|
|
t.Fatalf("ready=%+v", ready)
|
|
}
|
|
demo := evaluateAcceptanceProductionInfrastructure("PRODUCTION", []PlatformHealthCheck{
|
|
{Name: "deployment_profile", Status: "healthy", Value: "demo"},
|
|
{Name: "offsite_backup", Status: "healthy", Value: "not_required"},
|
|
{Name: "external_alert_receiver", Status: "healthy", Value: "not_configured"},
|
|
{Name: "mock_services", Status: "healthy", Value: "enabled_for_demo"},
|
|
})
|
|
if demo.GateSatisfied || demo.DeploymentProfile != "demo" || !strings.Contains(acceptanceProductionInfrastructureSummary(demo), "异地备份") {
|
|
t.Fatalf("demo=%+v summary=%q", demo, acceptanceProductionInfrastructureSummary(demo))
|
|
}
|
|
lab := evaluateAcceptanceProductionInfrastructure("LAB", nil)
|
|
if lab.Applicable || !lab.GateSatisfied {
|
|
t.Fatalf("lab=%+v", lab)
|
|
}
|
|
}
|
|
|
|
func TestAcceptanceSnapshotAllowsAllProductionExternalDependencies(t *testing.T) {
|
|
input := AcceptanceSnapshotInput{
|
|
CandidateVersion: "0.64.0-rc.1", BuildDigest: "sha256:" + strings.Repeat("b", 64),
|
|
Environment: "PRODUCTION", RunType: "PRODUCTION_RELEASE", Scope: "生产候选外部依赖预检", Reason: "归档发布技术门禁",
|
|
RequiredDependencies: []string{"oidc_jwks", "ark_tls", "volc_rtc_tls", "content_safety_tls"},
|
|
}
|
|
if !validAcceptanceSnapshotInput(input) {
|
|
t.Fatal("all four supported production dependencies should be accepted")
|
|
}
|
|
input.RequiredDependencies = append(input.RequiredDependencies, "content_safety_tls")
|
|
if validAcceptanceSnapshotInput(input) {
|
|
t.Fatal("duplicated content safety dependency should be rejected")
|
|
}
|
|
}
|