package inventory import ( "testing" "time" ) // Issue 1886: R4e entered tier 1 at 02:01, was stopped, and was resumed at 07:43 at the same tier. Its save kept the // tier's entry of 02:01, so at 07:50 the plan read "waiting for mesh-build-image on shanks to be applied for 5h48m53s" // and its progress watchdog measured the tier from before the stop. A walk set open again at the tier it ended at // enters that tier anew: its time in the tier runs from the resume. func TestAWalkResumedAtItsTierEntersItAnew(t *testing.T) { entered := time.Date(2026, 10, 23, 0, 1, 7, 0, time.UTC) resumed := time.Date(2026, 10, 23, 5, 43, 30, 0, time.UTC) old := &Plan{ID: "plan-r4e", State: PlanFailed, Tier: 1, Tiers: [][]string{{"a"}, {"b"}, {"c"}}, Created: entered.Add(-2 * time.Hour), TierEntered: entered} p := *old p.State = PlanBuilding got, d := tierLeftOf(old, p, resumed) if !got.Equal(resumed) || d != nil { t.Fatalf("1886: a walk resumed at tier 1 entered it at %s (duration %v); want %s, no tier left", got, d, resumed) } // A walk still in its tier keeps its entry; one that ended keeps it too. open := *old open.State = PlanRolling if got, _ := tierLeftOf(&open, open, resumed); !got.Equal(entered) { t.Fatalf("an open walk still in its tier was stamped anew: %s", got) } if got, _ := tierLeftOf(old, *old, resumed); !got.Equal(entered) { t.Fatalf("a failed walk saved again was stamped anew: %s", got) } }