//go:build integration package inventory import ( "testing" "time" ) func TestAReportOfABusyContainerIsKeptAndReadBack(t *testing.T) { inv, node := aNodeWithModules(t) ctx := t.Context() record, err := inv.NodeByName(ctx, node) if err != nil { t.Fatal(err) } since := time.Date(2026, 10, 13, 1, 0, 0, 0, time.UTC) waiting := []BusyWait{{ID: "build-agent.server", Container: "mesh-build-agent", State: BusyWaiting, Since: since, Until: since.Add(15 * time.Minute), Said: "busy: a check"}} keep := func(busy []BusyWait) bool { t.Helper() news, err := inv.RecordOrderedDoing(ctx, record.ID, Doing{Outcome: OutcomeApplied, Declared: "d1", Applied: 1, Busy: busy}, ReportOrder{Epoch: 1, Sequence: 1}, func(ReportOrder) bool { return false }) if err != nil { t.Fatal(err) } return news } read := func() []BusyWait { t.Helper() reports, err := inv.LastReports(ctx) if err != nil { t.Fatal(err) } for _, r := range reports { if r.Node == node { return r.Busy } } t.Fatal("the machine's report is not read back") return nil } keep(nil) if got := read(); len(got) != 0 { t.Fatalf("a report with nothing busy reads back %+v", got) } if !keep(waiting) { t.Error("a container starting to wait is not news") } got := read() if b, ok := WaitingFor(got, "build-agent"); !ok || !b.Since.Equal(since) || b.Said != "busy: a check" { t.Fatalf("the wait is not read back: %+v", got) } again := []BusyWait{waiting[0]} again[0].Said = "busy: a check, a minute on" if keep(again) { t.Error("a wait whose output changed is news") } if !keep([]BusyWait{{ID: "build-agent.server", Container: "mesh-build-agent", State: "replaced-when-idle", Since: since, Until: since.Add(15 * time.Minute)}}) { t.Error("a container replaced after it waited is not news") } if _, ok := WaitingFor(read(), "build-agent"); ok { t.Error("a container replaced still reads as waiting") } }