77 lines
3.3 KiB
Go
77 lines
3.3 KiB
Go
package main
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/novox/mesh-controller/internal/conditions"
|
|
)
|
|
|
|
// stalledConditions are n open conditions like those of 2026-10-08: one per delivery held past its bound,
|
|
// each keeping all its evidence.
|
|
func stalledConditions(n int) []conditions.Condition {
|
|
at := time.Date(2026, 10, 8, 9, 0, 0, 0, time.UTC)
|
|
var out []conditions.Condition
|
|
for i := 0; i < n; i++ {
|
|
id := fmt.Sprintf("d-%012x", 0x51a11ed+i)
|
|
lines := stalledObservations([]stalledLine{{ID: id, State: "checking", For: "13h2m", Bound: "45m",
|
|
H2: "close: recheck", Says: "the check was asked and nothing has answered"}})
|
|
o := lines[0]
|
|
c := conditions.Condition{Key: o.Key(), Kind: o.Kind, Subject: conditions.Subject{Scope: o.Scope, ID: o.ID},
|
|
Severity: o.Severity, Summary: o.Summary, Source: probeDeliveriesID, Raised: at, LastObserved: at,
|
|
Observations: 160, Count: 1, Resolver: conditions.ResolverSelf}
|
|
for e := 0; e < conditions.KeptEvidence; e++ {
|
|
c.Evidence = append(c.Evidence, conditions.Evidence{At: at.Add(time.Duration(e) * 5 * time.Minute),
|
|
Said: "checking for " + (13*time.Hour + time.Duration(e)*time.Minute).String()})
|
|
}
|
|
out = append(out, c)
|
|
}
|
|
return out
|
|
}
|
|
|
|
// novox/hq issue 314: a list of hundreds of open conditions carries each one's newest evidence, with
|
|
// how much more it keeps and where to read it, and the verb's answer says it once — as data, not again
|
|
// as the text the command printed. On 2026-10-08, 689 stalled deliveries made that answer more than the
|
|
// bus carries in one message; now it is less than half of one.
|
|
func TestAListOfConditionsCarriesEachInBrief(t *testing.T) {
|
|
list := stalledConditions(689)
|
|
printed, _ := json.MarshalIndent(map[string]any{"conditions": inBrief(list), "open": len(list),
|
|
"counted": counted(list)}, "", " ")
|
|
var parsed any
|
|
if err := json.Unmarshal(printed, &parsed); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
wire, _ := json.Marshal(map[string]any{"result": verbAnswer{OK: true, Answer: parsed,
|
|
Output: "its answer, as data, is `answer`\n"}})
|
|
before, _ := json.MarshalIndent(map[string]any{"conditions": list}, "", " ")
|
|
t.Logf("689 stalled deliveries: %d bytes on the wire, where the whole list printed was %d and was sent twice",
|
|
len(wire), len(before))
|
|
if len(wire) >= 512<<10 {
|
|
t.Fatalf("the answer of 689 conditions is %d bytes, not under half of one message of the bus", len(wire))
|
|
}
|
|
var doc struct {
|
|
Conditions []conditionInBrief `json:"conditions"`
|
|
Counted map[string]int `json:"counted"`
|
|
}
|
|
if err := json.Unmarshal(printed, &doc); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
c := doc.Conditions[0]
|
|
if len(doc.Conditions) != 689 || len(c.Evidence) != 1 || c.EvidenceKept != conditions.KeptEvidence ||
|
|
c.Key != list[0].Key || c.Summary != list[0].Summary || !strings.Contains(c.More, "key="+c.Key) {
|
|
t.Fatalf("a condition in brief reads %+v", c)
|
|
}
|
|
if doc.Counted["D14 stalled"] != 689 {
|
|
t.Fatalf("counted %v", doc.Counted)
|
|
}
|
|
if one := inBrief(list[:1])[0]; len(list[0].Evidence) != conditions.KeptEvidence || one.Evidence[0] != list[0].Evidence[0] {
|
|
t.Fatal("the brief changed the condition it was made from, or kept other than the newest")
|
|
}
|
|
}
|
|
|
|
// The self-check's verdict carries at most overviewFindings of one probe's findings, with their count and
|
|
// how to read them all; `doctor probe=` gives that probe whole (novox/hq issue 314).
|