466-a review: accept takes the served fields; AC1 and AC3 over every store; the rule counts named
Builds: design 55 §2, §2.2, §7; lead answers L-466-1, L-466-2 (issue 466 note 18), note 20 items (c), (d); 466/AC1, AC3
This commit is contained in:
@@ -100,32 +100,52 @@ func TestAnInsightToADecisionOfOctoberKeepsItsWords(t *testing.T) {
|
||||
}
|
||||
// 466/AC3: an insight keeps every field of the served version that propose does not take, and a drafted clause
|
||||
// stays drafted.
|
||||
t.Run("keeps what propose does not take", func(t *testing.T) {
|
||||
w := newWorld(t, newMemStore(), hqMain(t))
|
||||
if _, err := w.k.Import("import@test", ImportAsk{}, hqMain(t)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
key := Key{KindDecision, 276}
|
||||
e := mustGet(t, w.k.Store, key)
|
||||
r := e.Current.Clone()
|
||||
no := false
|
||||
r.Reconstructed, r.Amended, r.Touches = &no, []string{"2026-10-12"}, []string{"the tool runtime"}
|
||||
r.Extra, r.Source, r.Aliases = map[string]string{"owner": "x"}, "hq@abc:02-DECISIONS/0276.md", map[string]string{"old.md": "New"}
|
||||
r.Insights = []Insight{{Date: "2026-10-14", Before: "earlier", By: "someone@ace"}}
|
||||
r.Clauses[0].Source = SourceDrafted
|
||||
if err := w.k.Store.Save(context.Background(), Version{By: "test", At: time.Now(), Why: "seed", Record: r}, true, true, e.Revision); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := w.k.Propose("corrector@ace", insightTo(t, w, key)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
w.reviewAll(t)
|
||||
got := mustGet(t, w.k.Store, key).Current
|
||||
if len(got.Insights) != 2 || got.Insights[0].Before != "earlier" || got.Reconstructed == nil || *got.Reconstructed ||
|
||||
!reflect.DeepEqual(got.Amended, r.Amended) || !reflect.DeepEqual(got.Touches, r.Touches) ||
|
||||
!reflect.DeepEqual(got.Extra, r.Extra) || got.Source != r.Source || !reflect.DeepEqual(got.Aliases, r.Aliases) ||
|
||||
got.Clauses[0].Source != SourceDrafted {
|
||||
t.Fatalf("an insight dropped what the served version held: %+v", got)
|
||||
}
|
||||
eachStore(t, func(t *testing.T, s Store) {
|
||||
t.Run("keeps what propose does not take", func(t *testing.T) {
|
||||
w := newWorld(t, s, hqMain(t))
|
||||
if _, err := w.k.Import("import@test", ImportAsk{}, hqMain(t)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
key := Key{KindDecision, 276}
|
||||
e := mustGet(t, w.k.Store, key)
|
||||
r := e.Current.Clone()
|
||||
no := false
|
||||
r.Reconstructed, r.Amended, r.Touches = &no, []string{"2026-10-12"}, []string{"the tool runtime"}
|
||||
r.Extra, r.Source, r.Aliases = map[string]string{"owner": "x"}, "hq@abc:02-DECISIONS/0276.md", map[string]string{"old.md": "New"}
|
||||
r.Insights = []Insight{{Date: "2026-10-14", Before: "earlier", By: "someone@ace"}}
|
||||
r.Clauses[0].Source = SourceDrafted
|
||||
if err := w.k.Store.Save(context.Background(), Version{By: "test", At: time.Now(), Why: "seed", Record: r}, true, true, e.Revision); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := w.k.Propose("corrector@ace", insightTo(t, w, key)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
w.reviewAll(t)
|
||||
got := mustGet(t, w.k.Store, key).Current
|
||||
if len(got.Insights) != 2 || got.Insights[0].Before != "earlier" || got.Reconstructed == nil || *got.Reconstructed ||
|
||||
!reflect.DeepEqual(got.Amended, r.Amended) || !reflect.DeepEqual(got.Touches, r.Touches) ||
|
||||
!reflect.DeepEqual(got.Extra, r.Extra) || got.Source != r.Source || !reflect.DeepEqual(got.Aliases, r.Aliases) ||
|
||||
got.Clauses[0].Source != SourceDrafted {
|
||||
t.Fatalf("an insight dropped what the served version held: %+v", got)
|
||||
}
|
||||
// 466/AC3: what another record marks on this one while its insight waits is kept at acceptance.
|
||||
q := insightTo(t, w, key)
|
||||
q.Insight = "it said nothing of the count"
|
||||
if _, err := w.k.Propose("corrector@ace", q); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
e = mustGet(t, w.k.Store, key)
|
||||
sup := e.Current.Clone()
|
||||
sup.Extra = map[string]string{"owner": "x", "superseded-by": "ADR 9999"}
|
||||
sup.Status = StatusSuperseded
|
||||
if err := w.k.Store.Save(context.Background(), Version{By: "test", At: time.Now(), Why: "superseded", Record: sup}, true, false, e.Revision); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
w.reviewAll(t)
|
||||
got = mustGet(t, w.k.Store, key).Current
|
||||
if got.Status != StatusSuperseded || got.Extra["superseded-by"] != "ADR 9999" || len(got.Insights) != 3 {
|
||||
t.Fatalf("an insight accepted after the record was superseded lost the mark: %s %v %d insights", got.Status, got.Extra, len(got.Insights))
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
@@ -521,6 +521,19 @@ func (k *KB) Propose(caller string, a ProposeAsk) (*Proposed, error) {
|
||||
// aliases; and, for a clause whose text is unchanged, its source, so a drafted clause stays drafted.
|
||||
func keepServed(r, served *Record) {
|
||||
r.Insights = append([]Insight(nil), served.Insights...)
|
||||
keepFields(r, served)
|
||||
for i, c := range r.Clauses {
|
||||
if old := served.Clause(c.N); old != nil && strings.TrimSpace(old.Text) == strings.TrimSpace(c.Text) {
|
||||
r.Clauses[i].Source = old.Source
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// keepFields copies the fields of the served version that propose's arguments do not carry: reconstructed, amended,
|
||||
// touches, the imported fields (which hold what the knowledge base marked on the record, such as superseded-by), source
|
||||
// and aliases. accept takes them again from the version served when the version is accepted.
|
||||
func keepFields(r, served *Record) {
|
||||
r.Reconstructed, r.Extra, r.Aliases = nil, nil, nil
|
||||
if served.Reconstructed != nil {
|
||||
v := *served.Reconstructed
|
||||
r.Reconstructed = &v
|
||||
@@ -540,11 +553,6 @@ func keepServed(r, served *Record) {
|
||||
r.Aliases[k] = v
|
||||
}
|
||||
}
|
||||
for i, c := range r.Clauses {
|
||||
if old := served.Clause(c.N); old != nil && strings.TrimSpace(old.Text) == strings.TrimSpace(c.Text) {
|
||||
r.Clauses[i].Source = old.Source
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// activeLimitRefusal (ADR 0629 §4 names only a new effort or one taken up from an idea, never a new version of an active one; a check of the record set beside the one-record rules of ADR 0290 §4) says why a research effort may not be active now: the limit of efforts other than this one
|
||||
@@ -590,6 +598,10 @@ func (k *KB) accept(ctx context.Context, held *Entry, w *Record, by, why, warran
|
||||
in := r.Pending.Insight
|
||||
isInsight := r.IsInsight()
|
||||
r.Pending = nil
|
||||
// What the record holds now, not what it held when the version was proposed: a record superseded, or marked
|
||||
// by another record's acceptance, while this version waited keeps its marks (novox/hq issue 466).
|
||||
r.Insights = append([]Insight(nil), held.Current.Insights...)
|
||||
keepFields(r, held.Current)
|
||||
if isInsight {
|
||||
r.Insights = append(r.Insights, in)
|
||||
}
|
||||
|
||||
@@ -349,64 +349,86 @@ func TestTheOperatorsDeclineLeavesTheRecordProposed(t *testing.T) {
|
||||
// An accepted record changes only by a progressive insight, which is reviewed like a proposal while the accepted
|
||||
// version is served.
|
||||
func TestAnAcceptedRecordChangesOnlyByAnInsightReviewedLikeAProposal(t *testing.T) {
|
||||
w := imported(t, newMemStore())
|
||||
n := w.reserved(t, "author@g14")
|
||||
w.accepted(t, "author@g14", valid(n))
|
||||
p := valid(n)
|
||||
p.Sections[2].Text = "Merges land sooner, by about a minute."
|
||||
if _, err := w.k.Propose("author@g14", p); err == nil || !strings.Contains(err.Error(), "progressive insight") {
|
||||
t.Fatalf("an accepted record rewritten: %v", err)
|
||||
}
|
||||
p.Insight = "it said only that merges land sooner"
|
||||
w.judge.review = `{"verdict":"changes","findings":["Consequences: say what a minute is measured from"]}`
|
||||
if _, err := w.k.Propose("author@g14", p); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
w.reviewAll(t)
|
||||
e := mustGet(t, w.k.Store, Key{KindDecision, n})
|
||||
if e.Pending == nil || e.Current.Section("Consequences") != "Merges land sooner." || len(e.Pending.Reviews) != 1 ||
|
||||
e.Pending.Reviews[0].Verdict != VerdictChanges {
|
||||
t.Fatalf("the insight was served before its review approved it: %+v", e.Current.Sections)
|
||||
}
|
||||
// 1970/AC2: the same for a pending insight.
|
||||
g, err := w.k.Get(GetAsk{Kind: KindDecision, Number: n})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(g.PendingReviews) != 1 || !strings.Contains(g.PendingReviews[0].Findings, "what a minute is measured from") ||
|
||||
!strings.Contains(g.Pending, "changes asked") {
|
||||
t.Fatalf("pending insight findings not shown: %+v, %q", g.PendingReviews, g.Pending)
|
||||
}
|
||||
w.judge.review = ""
|
||||
p.Sections[2].Text = "Merges land sooner, by about a minute from the last merge."
|
||||
if _, err := w.k.Propose("author@g14", p); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
w.reviewAll(t)
|
||||
e = mustGet(t, w.k.Store, Key{KindDecision, n})
|
||||
if e.Pending != nil || e.Current.Status != StatusAccepted || len(e.Current.Insights) != 1 ||
|
||||
e.Current.Section("Consequences") != p.Sections[2].Text {
|
||||
t.Fatalf("after the insight's review: %+v", e.Current)
|
||||
}
|
||||
// 0276 §1 was changed once, by the acceptance; the insight keeps the link and changes it no further.
|
||||
if c := mustGet(t, w.k.Store, Key{KindDecision, 276}).Current.Clause(1); len(c.ChangedBy) != 1 {
|
||||
t.Fatalf("0276 §1 changed again by an insight: %v", c.ChangedBy)
|
||||
}
|
||||
// 466/AC1: a second insight adds to the first and replaces nothing; the pending version already holds the first.
|
||||
p.Insight = "it said only a minute"
|
||||
p.Sections[2].Text = "Merges land sooner, by about a minute from the last merge, as measured."
|
||||
if _, err := w.k.Propose("author@g14", p); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if e = mustGet(t, w.k.Store, Key{KindDecision, n}); e.Pending == nil || len(e.Pending.Insights) != 1 {
|
||||
t.Fatalf("the pending version does not hold the earlier insight: %+v", e.Pending)
|
||||
}
|
||||
w.reviewAll(t)
|
||||
e = mustGet(t, w.k.Store, Key{KindDecision, n})
|
||||
if len(e.Current.Insights) != 2 || e.Current.Insights[0].Before != "it said only that merges land sooner" ||
|
||||
e.Current.Insights[1].Before != "it said only a minute" {
|
||||
t.Fatalf("a second insight did not add to the first: %+v", e.Current.Insights)
|
||||
}
|
||||
eachStore(t, func(t *testing.T, s Store) {
|
||||
w := imported(t, s)
|
||||
n := w.reserved(t, "author@g14")
|
||||
w.accepted(t, "author@g14", valid(n))
|
||||
p := valid(n)
|
||||
p.Sections[2].Text = "Merges land sooner, by about a minute."
|
||||
if _, err := w.k.Propose("author@g14", p); err == nil || !strings.Contains(err.Error(), "progressive insight") {
|
||||
t.Fatalf("an accepted record rewritten: %v", err)
|
||||
}
|
||||
p.Insight = "it said only that merges land sooner"
|
||||
w.judge.review = `{"verdict":"changes","findings":["Consequences: say what a minute is measured from"]}`
|
||||
if _, err := w.k.Propose("author@g14", p); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
w.reviewAll(t)
|
||||
e := mustGet(t, w.k.Store, Key{KindDecision, n})
|
||||
if e.Pending == nil || e.Current.Section("Consequences") != "Merges land sooner." || len(e.Pending.Reviews) != 1 ||
|
||||
e.Pending.Reviews[0].Verdict != VerdictChanges {
|
||||
t.Fatalf("the insight was served before its review approved it: %+v", e.Current.Sections)
|
||||
}
|
||||
// 1970/AC2: the same for a pending insight.
|
||||
g, err := w.k.Get(GetAsk{Kind: KindDecision, Number: n})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(g.PendingReviews) != 1 || !strings.Contains(g.PendingReviews[0].Findings, "what a minute is measured from") ||
|
||||
!strings.Contains(g.Pending, "changes asked") {
|
||||
t.Fatalf("pending insight findings not shown: %+v, %q", g.PendingReviews, g.Pending)
|
||||
}
|
||||
w.judge.review = ""
|
||||
p.Sections[2].Text = "Merges land sooner, by about a minute from the last merge."
|
||||
if _, err := w.k.Propose("author@g14", p); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
w.reviewAll(t)
|
||||
e = mustGet(t, w.k.Store, Key{KindDecision, n})
|
||||
if e.Pending != nil || e.Current.Status != StatusAccepted || len(e.Current.Insights) != 1 ||
|
||||
e.Current.Section("Consequences") != p.Sections[2].Text {
|
||||
t.Fatalf("after the insight's review: %+v", e.Current)
|
||||
}
|
||||
// 0276 §1 was changed once, by the acceptance; the insight keeps the link and changes it no further.
|
||||
if c := mustGet(t, w.k.Store, Key{KindDecision, 276}).Current.Clause(1); len(c.ChangedBy) != 1 {
|
||||
t.Fatalf("0276 §1 changed again by an insight: %v", c.ChangedBy)
|
||||
}
|
||||
// 466/AC1: a second insight, by another author on another day, adds to the first and replaces nothing; the
|
||||
// pending version already holds the first, and history between the two accepted versions shows only the second added.
|
||||
first := mustGet(t, w.k.Store, Key{KindDecision, n}).Versions
|
||||
w.clock = w.clock.AddDate(0, 0, 1)
|
||||
p.Insight = "it said only a minute"
|
||||
p.Sections[2].Text = "Merges land sooner, by about a minute from the last merge, as measured."
|
||||
if _, err := w.k.Propose("corrector@ace", p); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if e = mustGet(t, w.k.Store, Key{KindDecision, n}); e.Pending == nil || len(e.Pending.Insights) != 1 {
|
||||
t.Fatalf("the pending version does not hold the earlier insight: %+v", e.Pending)
|
||||
}
|
||||
w.reviewAll(t)
|
||||
e = mustGet(t, w.k.Store, Key{KindDecision, n})
|
||||
in := e.Current.Insights
|
||||
if len(in) != 2 || in[0].Before != "it said only that merges land sooner" || in[0].By != "author@g14" || in[0].Date != "2026-10-11" ||
|
||||
in[1].Before != "it said only a minute" || in[1].By != "corrector@ace" || in[1].Date != "2026-10-12" {
|
||||
t.Fatalf("a second insight did not add to the first: %+v", in)
|
||||
}
|
||||
h, err := w.k.History(Key{KindDecision, n}, first, e.Versions, 0)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var added, removed []string
|
||||
for _, l := range h.Diff {
|
||||
switch {
|
||||
case strings.HasPrefix(l, "+insight "):
|
||||
added = append(added, l)
|
||||
case strings.HasPrefix(l, "-insight "):
|
||||
removed = append(removed, l)
|
||||
}
|
||||
}
|
||||
if len(added) != 1 || !strings.Contains(added[0], "2026-10-12") || len(removed) != 0 {
|
||||
t.Fatalf("history between the accepted versions: added %v, removed %v\n%v", added, removed, h.Diff)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// No verb takes a review from anyone: the review is the knowledge base's own.
|
||||
|
||||
@@ -4,8 +4,9 @@ package main
|
||||
//
|
||||
// **32 rules judge one record or its prose**, and `propose` refuses a record that breaks any of them, naming every
|
||||
// one it breaks at once. They are hq's checks (00-META/checks/records.py, cycle.py, index.py, words.py) as they
|
||||
// judge one record, moved to the write: 25 on its structure, 4 on its prose; and the brief a record that needs
|
||||
// the operator is asked with (novox/hq issue 639). Each has an id, said in the refusal,
|
||||
// judge one record, moved to the write: 25 on its structure, 4 on its prose; the brief a record that needs
|
||||
// the operator is asked with (novox/hq issue 639); the form of a section (section-form); and the links of a
|
||||
// progressive insight (insight-links, novox/hq issue 466). Each has an id, said in the refusal,
|
||||
// and one case in the table test (TestEveryPerRecordRuleRefusesAProposal).
|
||||
//
|
||||
// **4 rules judge the whole record set** (wholeSetRules) and run after every acceptance, and in the check
|
||||
|
||||
Reference in New Issue
Block a user