package executionpool

import (
	"testing"
	"time"
)

func TestAdvanceRoutePreferenceRequiresThreeWinsAndMinimumDwell(t *testing.T) {
	now := time.Date(2026, 8, 5, 12, 0, 0, 0, time.UTC)
	state := RoutePreference{CurrentPoolID: "slow", CurrentSince: now}
	scores := map[string]float64{"slow": 0.5, "fast": 0.7}
	for window := 1; window <= 3; window++ {
		state = AdvanceRoutePreference(state, "fast", scores, now.Add(time.Duration(window)*10*time.Second))
		if state.CurrentPoolID != "slow" {
			t.Fatalf("switched before minimum dwell in window %d", window)
		}
	}
	state = AdvanceRoutePreference(state, "fast", scores, now.Add(2*time.Minute))
	if state.CurrentPoolID != "fast" {
		t.Fatalf("current pool=%q, want fast", state.CurrentPoolID)
	}
}

func TestAdvanceRoutePreferenceImmediatelyLeavesIneligibleCurrentPool(t *testing.T) {
	now := time.Now()
	state := AdvanceRoutePreference(RoutePreference{
		CurrentPoolID: "offline", CurrentSince: now.Add(-time.Minute),
	}, "healthy", map[string]float64{"healthy": 0.6}, now)
	if state.CurrentPoolID != "healthy" || state.ChallengerWins != 0 {
		t.Fatalf("unexpected preference: %#v", state)
	}
}
