Files
mesh-catalog/modules/mesh-knowledge/cmd/mesh-knowledge/wholeset_test.go
T
jschoubben ebba63d71f
mesh/merge-gate pass: builds mesh-knowledge → novox; no bus step; every machine composes with the change as it did without (4 of 4 compose)
mesh/repo-check pass: its merge-check.sh passed, each part in its toolchain: merge-check.sh (go), merge-check-typescript.sh (typescript)
mesh/delivery superseded: a newer head of the same pull request
mesh-knowledge: review every proposal in a judgement of its own, and serve no review verb (hq issue 425, ADR 0290 as updated)
The mesh proves which machine called, not which agent on it (hq issue 365), so a review verb could not tell a
reviewer from the author. Each version proposed is now judged by claude-code.claude_code_judge in a separate
call that sees only the record, the records it links and the rules: approve accepts (or asks the operator for a
needs-operator record), changes keeps it proposed with the findings for its author, and a judgement that cannot
be had or read leaves it proposed, says so, and never counts as approval.
2026-10-11 12:06:18 +02:00

86 lines
3.4 KiB
Go

package main
import (
"strings"
"testing"
)
// to-be 55 §10: "A whole-set rule that fails is loud — the module's test: an acceptance that leaves a decision
// cited by nothing raises the condition." The condition is the mesh's, raised when the module's health answers
// unhealthy; the test reads the health answer the node-engine reads.
func TestAnAcceptanceThatLeavesADecisionCitedByNothingMakesTheModuleUnhealthy(t *testing.T) {
eachStore(t, func(t *testing.T, s Store) {
w := imported(t, s)
if h := w.k.Health(nil); !h.Healthy {
t.Fatalf("unhealthy after the import of real records: %s", h.Why)
}
n := w.reserved(t, "author@g14")
w.accepted(t, "author@g14", valid(n))
h := w.k.Health(nil)
if h.Healthy || h.State != "unhealthy" || !strings.Contains(h.Why, "the rule cited") || !strings.Contains(h.Why, itoaKey(n)) {
t.Fatalf("an accepted decision nothing cites left the module %+v", h)
}
// The acceptance stands: the condition says it, and undoes nothing.
if mustGet(t, s, Key{KindDecision, n}).Current.Status != StatusAccepted {
t.Fatal("the acceptance was undone")
}
// A record that cites it heals it.
m := w.reserved(t, "author@g14")
p := valid(m)
p.Links = append(p.Links, LinkAsk{Kind: LinkCites, To: itoa4(n)})
w.accepted(t, "author@g14", p)
h = w.k.Health(nil)
if strings.Contains(h.Why, itoaKey(n)+" is accepted and nothing cites it") {
t.Fatalf("still said after a record cited it: %s", h.Why)
}
})
}
// Each of the 4 whole-set rules, failing on a record set made to break it.
func TestEachWholeSetRuleFails(t *testing.T) {
acc := func(n int, links ...Link) *Record {
return &Record{Kind: KindDecision, Number: n, Status: StatusAccepted, Links: links,
Clauses: []Clause{{N: 1, Text: "**One.** x", Status: ClauseInForce, Source: SourceWritten}}}
}
to := func(kind string, n, c int) Link {
return Link{Kind: kind, To: Ref{Kind: KindDecision, Number: n, Clause: c}}
}
cases := []struct {
rule string
set []*Record
}{
{"cited", func() []*Record { r := acc(1); r.AcceptedAt = r.AcceptedAt.AddDate(2026, 0, 0); return []*Record{r} }()},
{"supersession", []*Record{func() *Record { r := acc(1); r.Status = StatusSuperseded; return r }()}},
{"supersession", []*Record{acc(1), acc(2, to(LinkSupersedes, 1, 0))}},
{"partial", []*Record{acc(1), acc(2, to(LinkChanges, 1, 1))}},
{"partial", []*Record{func() *Record { r := acc(1); r.Clauses[0].Status = ClauseChanged; return r }()}},
{"rests-on-live", []*Record{func() *Record { r := acc(1); r.Status = StatusSuperseded; return r }(),
acc(3, to(LinkSupersedes, 1, 0)), acc(2, to(LinkExtends, 1, 0))}},
}
seen := map[string]bool{}
for _, c := range cases {
found := false
for _, f := range JudgeSet(c.set) {
found = found || f.Rule == c.rule
}
if !found {
t.Errorf("the rule %s did not fail on its case: %+v", c.rule, JudgeSet(c.set))
}
seen[c.rule] = true
}
for _, r := range WholeSetRules {
if !seen[r.ID] {
t.Errorf("the whole-set rule %s has no case", r.ID)
}
}
if len(WholeSetRules) != 4 {
t.Errorf("%d whole-set rules; ADR 0290 counts 4", len(WholeSetRules))
}
// A consistent set: the superseder names it, the extender is the superseder, the change is applied.
ok := []*Record{func() *Record { r := acc(1); r.Status = StatusSuperseded; return r }(),
acc(2, to(LinkSupersedes, 1, 0), to(LinkExtends, 1, 0))}
if f := JudgeSet(ok); len(f) != 0 {
t.Errorf("a consistent set fails: %+v", f)
}
}