feat: gate releases on platform health
This commit is contained in:
@@ -3,6 +3,7 @@ package diagnostics
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestValidAcceptanceSnapshotInputLimitsAuditReason(t *testing.T) {
|
||||
@@ -24,6 +25,52 @@ func TestValidAcceptanceSnapshotInputLimitsAuditReason(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
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 TestAcceptanceSnapshotAllowsAllProductionExternalDependencies(t *testing.T) {
|
||||
input := AcceptanceSnapshotInput{
|
||||
CandidateVersion: "0.64.0-rc.1", BuildDigest: "sha256:" + strings.Repeat("b", 64),
|
||||
|
||||
Reference in New Issue
Block a user