From ad4361322dccb0b9ad354e5ecc71000e04751e92 Mon Sep 17 00:00:00 2001 From: Brad Stein Date: Sun, 5 Apr 2026 13:23:36 -0300 Subject: [PATCH] test startup intent guard helpers --- internal/cluster/orchestrator_test.go | 35 +++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/internal/cluster/orchestrator_test.go b/internal/cluster/orchestrator_test.go index 6cdc6ef..fcf321b 100644 --- a/internal/cluster/orchestrator_test.go +++ b/internal/cluster/orchestrator_test.go @@ -5,8 +5,10 @@ import ( "os" "reflect" "testing" + "time" "scm.bstein.dev/bstein/hecate/internal/config" + "scm.bstein.dev/bstein/hecate/internal/state" ) func TestParseVaultSealed(t *testing.T) { @@ -82,3 +84,36 @@ func TestFallbackWorkersFromInventoryFallsBackToHosts(t *testing.T) { t.Fatalf("fallback workers mismatch: got=%v want=%v", got, want) } } + +func TestIntentFreshTreatsZeroTimestampAsFresh(t *testing.T) { + if !intentFresh(state.Intent{}, 30*time.Second) { + t.Fatalf("zero updated_at intent should be treated as fresh") + } +} + +func TestIntentFreshRespectsAge(t *testing.T) { + stale := state.Intent{UpdatedAt: time.Now().Add(-2 * time.Minute)} + fresh := state.Intent{UpdatedAt: time.Now().Add(-20 * time.Second)} + if intentFresh(stale, 30*time.Second) { + t.Fatalf("expected stale intent to be considered not fresh") + } + if !intentFresh(fresh, 30*time.Second) { + t.Fatalf("expected recent intent to be considered fresh") + } +} + +func TestCoordinationPeersDedupesAndIncludesForwardHost(t *testing.T) { + orch := &Orchestrator{ + cfg: config.Config{ + Coordination: config.Coordination{ + PeerHosts: []string{"titan-24", "titan-db", "titan-24", " "}, + ForwardShutdownHost: "titan-db", + }, + }, + } + got := orch.coordinationPeers() + want := []string{"titan-24", "titan-db"} + if !reflect.DeepEqual(got, want) { + t.Fatalf("coordination peers mismatch: got=%v want=%v", got, want) + } +}