99 lines
4.0 KiB
Go
99 lines
4.0 KiB
Go
package main
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
// A rule holds a record from the day hq's checks began to hold it (the review of mesh-catalog#206): a dated
|
|
// correction to an older record is judged by the rules that held it then, never by one that came later.
|
|
|
|
// insightTo is a progressive insight to a held record: the record as it stands, resent whole, with what stood
|
|
// before.
|
|
func insightTo(t *testing.T, w *world, k Key) ProposeAsk {
|
|
t.Helper()
|
|
r := mustGet(t, w.k.Store, k).Current
|
|
p := ProposeAsk{Kind: k.Kind, Number: k.Number, Title: r.Title, Topic: r.Topic, Date: r.Date, Deciders: r.Deciders,
|
|
Sections: r.Sections, Homes: r.Homes, Insight: "the count said 12 where 13 stood"}
|
|
for _, c := range r.Clauses {
|
|
p.Clauses = append(p.Clauses, c.Text)
|
|
}
|
|
for _, l := range r.Links {
|
|
p.Links = append(p.Links, LinkAsk{Kind: l.Kind, To: l.To.String(), From: l.From})
|
|
}
|
|
return p
|
|
}
|
|
|
|
// ADR 0011 (2026-04-03) is a real older record: its decision is prose, it has no section saying how it is checked,
|
|
// and it was written before the words and clause rules held. A correction of fact to it is taken.
|
|
func TestAnInsightToAnOlderRecordIsJudgedByTheRulesThatHeldIt(t *testing.T) {
|
|
w := newWorld(t, newMemStore(), hqMain(t))
|
|
if _, err := w.k.Import("import@test", ImportAsk{}, hqMain(t)); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
p := insightTo(t, w, Key{KindDecision, 11})
|
|
p.Sections[0].Text += "\n\nThe control plane wrote them."
|
|
if _, err := w.k.Propose("corrector@node-a", p); err != nil {
|
|
t.Fatalf("an insight to ADR 0011 was refused by rules that never held it: %v", err)
|
|
}
|
|
// The same words in a record of today are refused.
|
|
n := w.reserved(t, "author@node-b")
|
|
q := valid(n)
|
|
q.Sections[2].Text = "The control plane wrote them."
|
|
if _, err := w.k.Propose("author@node-b", q); err == nil || !strings.Contains(err.Error(), "- retired-word:") {
|
|
t.Fatalf("a retired word in a record of today: %v", err)
|
|
}
|
|
}
|
|
|
|
func TestEachDatedRuleHoldsFromItsDay(t *testing.T) {
|
|
for _, c := range []struct {
|
|
rule, before, from string
|
|
}{
|
|
{"retired-word", "2026-10-06", "2026-10-07"},
|
|
{"daemon-line", "2026-10-08", "2026-10-09"},
|
|
{"deferral", "2026-10-08", "2026-10-09"},
|
|
{"has-clause", "2026-10-10", "2026-10-11"},
|
|
{"clause-lead", "2026-10-10", "2026-10-11"},
|
|
{"checked", "2026-10-10", "2026-10-11"},
|
|
} {
|
|
if Holds(c.rule, KindResearch, c.before) || !Holds(c.rule, KindResearch, c.from) {
|
|
t.Errorf("%s holds research of %s: %v, of %s: %v", c.rule, c.before, Holds(c.rule, KindResearch, c.before), c.from, Holds(c.rule, KindResearch, c.from))
|
|
}
|
|
}
|
|
for _, rule := range []string{"retired-word", "daemon-line"} {
|
|
if Holds(rule, KindDecision, "2026-10-10") || !Holds(rule, KindDecision, "2026-10-11") {
|
|
t.Errorf("%s holds a decision from another day than 2026-10-11", rule)
|
|
}
|
|
}
|
|
if !Holds("title", KindDecision, "2026-01-01") {
|
|
t.Error("an undated rule does not hold an old record")
|
|
}
|
|
}
|
|
|
|
// A new record cannot be dated back past the rules: it is of the day its number was reserved, or later.
|
|
func TestANewRecordIsNotDatedBeforeItsReservation(t *testing.T) {
|
|
w := imported(t, newMemStore())
|
|
n := w.reserved(t, "author@node-b")
|
|
p := valid(n)
|
|
p.Date = "2026-01-01"
|
|
p.Sections[2].Text = "The control plane wrote them."
|
|
_, err := w.k.Propose("author@node-b", p)
|
|
if err == nil || !strings.Contains(err.Error(), "- date:") {
|
|
t.Fatalf("a new record dated before its reservation: %v", err)
|
|
}
|
|
}
|
|
|
|
// hq's words check never read a decision record: a decision keeps the words it was written with. A correction to
|
|
// ADR 0276 (2026-10-10), which writes words and lines those checks held only research and issues to, is taken.
|
|
func TestAnInsightToADecisionOfOctoberKeepsItsWords(t *testing.T) {
|
|
w := newWorld(t, newMemStore(), hqMain(t))
|
|
if _, err := w.k.Import("import@test", ImportAsk{}, hqMain(t)); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
for _, n := range []int{276, 240, 244, 272} {
|
|
if _, err := w.k.Propose("corrector@node-a", insightTo(t, w, Key{KindDecision, n})); err != nil {
|
|
t.Errorf("an insight to ADR %04d was refused: %v", n, err)
|
|
}
|
|
}
|
|
}
|