增加单一源保护全局策略

This commit is contained in:
2026-06-15 00:14:40 +08:00
parent bffd4ecb98
commit b860ef37e8
12 changed files with 210 additions and 14 deletions
@@ -37,6 +37,40 @@ func TestFailoverBudgetDefaults(t *testing.T) {
}
}
func TestSingleSourceProtectionDefaultsOn(t *testing.T) {
runnerPolicy := store.RunnerPolicy{Status: "active"}
if !singleSourceProtectionActive([]store.RuntimeModelCandidate{{PlatformID: "only-source"}}, 99, runnerPolicy) {
t.Fatal("single source protection should default to enabled")
}
}
func TestSingleSourceProtectionCanBeDisabled(t *testing.T) {
runnerPolicy := store.RunnerPolicy{
Status: "active",
SingleSourcePolicy: map[string]any{"enabled": false},
}
if singleSourceProtectionActive([]store.RuntimeModelCandidate{{PlatformID: "only-source"}}, 99, runnerPolicy) {
t.Fatal("single source protection should respect the global toggle")
}
}
func TestSingleSourceProtectionUsesEffectivePlatformBudget(t *testing.T) {
candidates := []store.RuntimeModelCandidate{
{PlatformID: "first-source"},
{PlatformID: "second-source"},
}
runnerPolicy := store.RunnerPolicy{Status: "active"}
if !singleSourceProtectionActive(candidates, 1, runnerPolicy) {
t.Fatal("maxPlatforms=1 should make this execution a single-source run")
}
if singleSourceProtectionActive(candidates, 2, runnerPolicy) {
t.Fatal("multiple effective sources should allow disable and cooldown actions")
}
}
func TestFailoverTimeBudgetExceeded(t *testing.T) {
if !failoverTimeBudgetExceeded(time.Now().Add(-601*time.Second), 10*time.Minute) {
t.Fatal("failover time budget should stop retries after the configured duration")