package serial import ( "testing" "time" ) func TestCRConnectionStatusToleratesTransientMissWithoutInventingCableDown(t *testing.T) { now := time.Date(2026, 9, 14, 1, 0, 0, 0, time.UTC) probe := CRProbeState{Enabled: true, EverUp: true, LastResponseAt: &now} for _, state := range []string{CRProbeStateNoResponse, CRProbeStateBusy, CRProbeStateSuppressed, CRProbeStateError} { probe.State = state for _, age := range []time.Duration{0, 4 * time.Second, CRResponseGracePeriod} { if got := CRConnectionStatus(probe, now.Add(age)); got != "up" { t.Fatalf("transient %s at %s = %s", state, age, got) } } if got := CRConnectionStatus(probe, now.Add(CRResponseGracePeriod+time.Millisecond)); got != "unknown" { t.Fatalf("stale %s = %s; no response cannot prove cable down", state, got) } } probe.EverUp = false if CRConnectionStatus(probe, now) != "unknown" { t.Fatal("unconfirmed response promoted") } probe.Up = true if CRConnectionStatus(probe, now) != "up" { t.Fatal("confirmed reply ignored") } probe.Enabled = false if CRConnectionStatus(probe, now) != "unknown" { t.Fatal("disabled probe promoted") } }