CAT-P3: the page's model is a tool, its re-read a hand act, an unanswered source is said and asked again on a backoff
knowledge_overview answers the page's model as data (reads); knowledge_overview_reread asks one source's verb again by hand, no other, and records the hand act (acts). A source marked from its verb is asked again alone from 10 seconds, doubling to 5 minutes, its first answer clearing the mark; one marked from its subscription asks nothing while silent and the verb once on its next event. The module's health carries the page's last rebuild and says it is degraded while a source is unanswered, staying healthy. Issue 1968. Claude-Session: https://claude.ai/code/session_01JG73KJNrH5EgFXMKKYSrig
This commit is contained in:
@@ -3,6 +3,8 @@ package main
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
@@ -99,3 +101,117 @@ func TestThePageModelHasThreeBlocksKeptByEventsAndAsksNoVerbAgain(t *testing.T)
|
||||
t.Fatalf("the seven-day block: %+v", m.Accepted)
|
||||
}
|
||||
}
|
||||
|
||||
// A source that does not answer says so, never as an empty list (ADR 0616 §5, §6; AC P3): from its verb, on a bounded backoff
|
||||
// asked again alone, its first answer clearing the mark; from its subscription, asking nothing while it is silent and the verb once on its
|
||||
// next event; the model as a tool equals the page's model; the re-read tool asks one source and records the hand act.
|
||||
func TestASourceThatDoesNotAnswerIsSaidAndAskedAgainOnABackoff(t *testing.T) {
|
||||
w := newOverviewWorld(t)
|
||||
w.fail[DeliveryGroupsVerb] = true
|
||||
w.o.Start()
|
||||
m, _ := w.o.Model()
|
||||
var delivery SourceState
|
||||
for _, s := range m.Sources {
|
||||
if s.Name == SourceDelivery {
|
||||
delivery = s
|
||||
}
|
||||
}
|
||||
if delivery.Answered || delivery.Mark == nil || delivery.Mark.Cause != MarkVerb || len(m.Operator.Groups) != 0 || !strings.Contains(delivery.Mark.Why, "no answer in time") {
|
||||
t.Fatalf("%+v", delivery)
|
||||
}
|
||||
if len(m.Designs) != 1 {
|
||||
t.Fatalf("another source's block was lost: %+v", m.Designs)
|
||||
}
|
||||
// Asked again on the backoff alone: 10 s, then doubling, at most 5 minutes; no other source is asked.
|
||||
calls := w.o.Calls(DeliveryGroupsVerb)
|
||||
if got := w.o.Due(); len(got) != 0 {
|
||||
t.Fatalf("asked before the backoff ran out: %v", got)
|
||||
}
|
||||
var waits []time.Duration
|
||||
for i := 0; i < 8; i++ {
|
||||
before := w.now
|
||||
w.now = w.o.state[SourceDelivery].Mark.Next
|
||||
waits = append(waits, w.now.Sub(before))
|
||||
if got := w.o.Due(); len(got) != 1 || got[0] != SourceDelivery {
|
||||
t.Fatalf("%v", got)
|
||||
}
|
||||
}
|
||||
if waits[0] != BackoffFrom || waits[1] != 2*BackoffFrom || waits[7] != BackoffMost || w.o.Calls(DeliveryGroupsVerb) != calls+8 || w.o.Calls(AsksVerb) != 1 {
|
||||
t.Fatalf("waits %v, delivery asked %d, asks asked %d", waits, w.o.Calls(DeliveryGroupsVerb), w.o.Calls(AsksVerb))
|
||||
}
|
||||
// Its first answer rebuilds the block and clears the mark.
|
||||
w.fail[DeliveryGroupsVerb] = false
|
||||
w.now = w.o.state[SourceDelivery].Mark.Next
|
||||
w.o.Due()
|
||||
m, _ = w.o.Model()
|
||||
if len(w.o.Unanswered()) != 0 || len(m.Operator.Groups) != 1 {
|
||||
t.Fatalf("%+v", m)
|
||||
}
|
||||
// A subscription that goes silent marks the source from the subscription and asks nothing while it is silent.
|
||||
asked := w.o.Calls(AsksVerb)
|
||||
w.now = w.now.Add(HeartbeatWithin + time.Second)
|
||||
if got := w.o.Silent(); len(got) != 3 {
|
||||
t.Fatalf("%v", got)
|
||||
}
|
||||
if got := w.o.Due(); len(got) != 0 || w.o.Calls(AsksVerb) != asked {
|
||||
t.Fatalf("a silent subscription was asked: %v", got)
|
||||
}
|
||||
if u := w.o.Unanswered(); len(u) != 3 || u[0].Mark.Cause != MarkSubscription {
|
||||
t.Fatalf("%+v", u)
|
||||
}
|
||||
// Its next event (or heartbeat) makes the module ask the verb once, and that answer clears the mark.
|
||||
w.o.Heard(SourceAsks, "messenger.offered", json.RawMessage(`{"key":"ask-9","headline":"x"}`))
|
||||
if w.o.Calls(AsksVerb) != asked+1 || w.o.state[SourceAsks].Mark != nil {
|
||||
t.Fatalf("asked %d, mark %+v", w.o.Calls(AsksVerb), w.o.state[SourceAsks].Mark)
|
||||
}
|
||||
// An unanswered verb then turns the mark into one from the verb.
|
||||
w.fail[DeliveryGroupsVerb] = true
|
||||
w.o.Heard(SourceDelivery, "", nil)
|
||||
if mk := w.o.state[SourceDelivery].Mark; mk == nil || mk.Cause != MarkVerb {
|
||||
t.Fatalf("%+v", mk)
|
||||
}
|
||||
}
|
||||
|
||||
func TestThePagesModelIsAToolAndItsRereadIsAHandAct(t *testing.T) {
|
||||
w := newOverviewWorld(t)
|
||||
w.entries = []*Entry{recordEntry(301, StatusAccepted, "2026-11-02", w.now.Add(-24*time.Hour), nil)}
|
||||
w.o.Start()
|
||||
var acts []string
|
||||
k := &KB{Overview: w.o, Seats: func(key string, body any) (json.RawMessage, error) {
|
||||
acts = append(acts, key)
|
||||
return json.RawMessage(`{}`), nil
|
||||
}, Now: func() time.Time { return w.now }}
|
||||
var tools []toolRun
|
||||
for _, tool := range moduleTools(k, callerOf) {
|
||||
tools = append(tools, toolRun{tool.Name, tool.Run})
|
||||
}
|
||||
got, err := callTool(t, tools, OverviewTool, map[string]any{})
|
||||
want, _ := w.o.Model()
|
||||
raw, _ := json.Marshal(want)
|
||||
var wantMap map[string]any
|
||||
_ = json.Unmarshal(raw, &wantMap)
|
||||
if err != nil || !reflect.DeepEqual(got, wantMap) {
|
||||
t.Fatalf("the tool's answer is not the page's model: %v", err)
|
||||
}
|
||||
// The re-read asks the one source and no other, and records itself.
|
||||
before := map[string]int{}
|
||||
for _, v := range []string{TrackerListVerb, DeliveryGroupsVerb, AsksVerb} {
|
||||
before[v] = w.o.Calls(v)
|
||||
}
|
||||
w.fail[AsksVerb] = true
|
||||
res, err := callTool(t, tools, RereadTool, map[string]any{"source": SourceAsks, "why": "the page showed it stale"})
|
||||
if err != nil || res["answered"] != false || w.o.Calls(AsksVerb) != before[AsksVerb]+1 || w.o.Calls(DeliveryGroupsVerb) != before[DeliveryGroupsVerb] || w.o.Calls(TrackerListVerb) != before[TrackerListVerb] {
|
||||
t.Fatalf("%v %v", err, res)
|
||||
}
|
||||
if len(acts) != 1 || acts[0] != "seat:mesh-hand-acts.hand-act" {
|
||||
t.Fatalf("the hand act: %v", acts)
|
||||
}
|
||||
if _, err := callTool(t, tools, RereadTool, map[string]any{"source": "nobody"}); err == nil {
|
||||
t.Fatal("a source the page lacks was re-read")
|
||||
}
|
||||
// The health carries the page: degraded while a source is unanswered, healthy.
|
||||
h := k.pageHealth(HealthAnswer{State: "healthy", Healthy: true, Why: "ok"})
|
||||
if !h.Healthy || !strings.Contains(h.Why, "overview page is degraded") || !strings.Contains(h.Why, SourceAsks) {
|
||||
t.Fatalf("%+v", h)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user