The canary window now counts from when a release is installed on the host (installed.json / installed_at in the update snapshot), not from the statement's issued_at, and 'release canary check' judges the release the canary actually runs via its exact-pin tag instead of the moving next tag. A newer release on next queues behind the one being judged instead of restarting the clock, so stable moves once per release. New subcommands: canary status (read-only state, signals, verdict), canary promote (promote now when hard checks pass), canary unpin (back to next), and start -force. A held/pinned canary is verified installable every check and a stranded pin fails the run red instead of looking green. Rollback pre-flight checks stable's zip and agent image digests before pinning. Relative signals are judged whenever both windows carry minimum data, so a breach rolls back mid-window; promote still needs the full window unless the operator promotes early (new promote.yml workflow_dispatch). The window is configurable via -window / CANARY_WINDOW. Also: dashboard canary status card (ui), and task canary:rehearse, a local end-to-end rehearsal of publish -> canary start -> status -> check -> promote against a throwaway registry and host. task check passes; rehearsal run green (REHEARSE_EXIT=0).
66 lines
3.5 KiB
Go
66 lines
3.5 KiB
Go
package releaseupdate
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
// A release promotes only after a full window counted from its install with
|
|
// no hard failure and no relative signal past its threshold; any failure after
|
|
// settling rolls it back at once, even mid-window.
|
|
func TestJudgeCanary(t *testing.T) {
|
|
installed := time.Date(2026, 1, 2, 12, 0, 0, 0, time.UTC)
|
|
healthy := func() CanarySignals {
|
|
return CanarySignals{
|
|
Installed: "1.1.0", Ready: true,
|
|
Baseline: CanaryWindowSignals{Finished: 20, Bad: 2, Errors: 10, Covered: CanaryWindow},
|
|
Canary: CanaryWindowSignals{Finished: 20, Bad: 2, Errors: 12, Covered: CanaryWindow},
|
|
}
|
|
}
|
|
with := func(change func(*CanarySignals)) CanarySignals {
|
|
s := healthy()
|
|
change(&s)
|
|
return s
|
|
}
|
|
cases := []struct {
|
|
name string
|
|
elapsed time.Duration // now minus the install time
|
|
window time.Duration
|
|
signals CanarySignals
|
|
want CanaryDecision
|
|
}{
|
|
{"settling counts from the install", 10 * time.Minute, CanaryWindow, with(func(s *CanarySignals) { s.Ready = false }), CanaryWait},
|
|
{"healthy mid-window waits", 2 * time.Hour, CanaryWindow, healthy(), CanaryWait},
|
|
{"healthy at the window promotes", CanaryWindow, CanaryWindow, healthy(), CanaryPromote},
|
|
{"healthy at a custom window promotes", 12 * time.Hour, 12 * time.Hour, healthy(), CanaryPromote},
|
|
{"the watchdog rolled the install back", 2 * time.Hour, CanaryWindow, with(func(s *CanarySignals) { s.Installed = "1.0.0" }), CanaryRollBack},
|
|
{"readiness degraded", 2 * time.Hour, CanaryWindow, with(func(s *CanarySignals) { s.Ready = false }), CanaryRollBack},
|
|
{"a new action alert", 2 * time.Hour, CanaryWindow, with(func(s *CanarySignals) { s.NewActionAlerts = []string{"queue stalled"} }), CanaryRollBack},
|
|
{"errors past twice the baseline plus ten", CanaryWindow, CanaryWindow, with(func(s *CanarySignals) { s.Canary.Errors = 31 }), CanaryRollBack},
|
|
{"errors at the limit", CanaryWindow, CanaryWindow, with(func(s *CanarySignals) { s.Canary.Errors = 30 }), CanaryPromote},
|
|
{"errors scaled from a partly covered log", CanaryWindow, CanaryWindow, with(func(s *CanarySignals) {
|
|
s.Canary.Errors, s.Canary.Covered = 8, 6*time.Hour
|
|
}), CanaryRollBack},
|
|
{"a baseline the log doesn't reach skips errors", CanaryWindow, CanaryWindow, with(func(s *CanarySignals) {
|
|
s.Baseline.Covered, s.Canary.Errors = 30*time.Minute, 500
|
|
}), CanaryPromote},
|
|
{"a mid-window error breach rolls back early", 2 * time.Hour, CanaryWindow, with(func(s *CanarySignals) { s.Canary.Errors = 31 }), CanaryRollBack},
|
|
{"park rate up more than ten points", CanaryWindow, CanaryWindow, with(func(s *CanarySignals) { s.Canary.Bad = 5 }), CanaryRollBack},
|
|
{"park rate up ten points", CanaryWindow, CanaryWindow, with(func(s *CanarySignals) { s.Canary.Bad = 4 }), CanaryPromote},
|
|
{"too few canary tasks skips the park rate", CanaryWindow, CanaryWindow, with(func(s *CanarySignals) { s.Canary = CanaryWindowSignals{Finished: 4, Bad: 4, Covered: CanaryWindow} }), CanaryPromote},
|
|
{"a thin baseline skips the park rate", CanaryWindow, CanaryWindow, with(func(s *CanarySignals) {
|
|
s.Baseline.Finished, s.Baseline.Bad = 2, 0
|
|
s.Canary.Bad = 5
|
|
}), CanaryPromote},
|
|
{"a mid-window park breach rolls back early", 2 * time.Hour, CanaryWindow, with(func(s *CanarySignals) { s.Canary.Bad = 5 }), CanaryRollBack},
|
|
}
|
|
for _, tc := range cases {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
got := JudgeCanary("1.1.0", installed, installed.Add(tc.elapsed), tc.window, tc.signals)
|
|
if got.Decision != tc.want {
|
|
t.Fatalf("decision = %s, want %s (%v)", got.Decision, tc.want, got.Reasons)
|
|
}
|
|
})
|
|
}
|
|
}
|