package api import ( "bytes" "encoding/json" "log" "net/http" "strings" "testing" ) // R-1085 over the wire — Scenario C through the PRODUCTION path (the real report handler → ResolveManagedFloor): // a box is never told to install a withdrawn build, and the hub says why in ONE [WARN] naming the tag, not one per // report. Red-proof: delete the SpoiledControllerTag block in store.ResolveManagedFloor → the ACK carries 0.316.3. func TestReportACK_NeverServesAWithdrawnBuild(t *testing.T) { h, st, _ := newTestHandler(t) var logs bytes.Buffer h.logger = log.New(&logs, "", 0) ack := func() (interface{}, bool) { rr := do(h, http.MethodPost, "/report", globalKey, `{"customer_id":"c"}`) if rr.Code != http.StatusOK { t.Fatalf("report status = %d", rr.Code) } var m map[string]interface{} _ = json.Unmarshal(rr.Body.Bytes(), &m) v, ok := m["min_controller_version"] return v, ok } // A value stored the way an old hub (no form refusal) would have stored it. if err := st.SetGlobalMinControllerVersion("0.316.3"); err != nil { t.Fatal(err) } for i := 0; i < 3; i++ { if v, ok := ack(); ok { t.Fatalf("report %d: the ACK must OMIT a withdrawn floor, got %v", i, v) } } if n := strings.Count(logs.String(), "[WARN] managed floor HELD for c:"); n != 1 { t.Errorf("want exactly ONE [WARN] across three reports, got %d:\n%s", n, logs.String()) } if !strings.Contains(logs.String(), "0.316.3") || !strings.Contains(logs.String(), "WITHDRAWN") { t.Errorf("the [WARN] must name the tag and say withdrawn:\n%s", logs.String()) } // The control, on the same handler: an ordinary floor is served. if err := st.SetGlobalMinControllerVersion("0.317.0"); err != nil { t.Fatal(err) } if v, ok := ack(); !ok || v != "0.317.0" { t.Fatalf("an ordinary floor must be served, got %v (present=%v)", v, ok) } }