466-a: a version over an accepted record keeps the served insights and fields
Builds: design 55 §2, §2.2, §7; lead answers L-466-1, L-466-2 (issue 466 note 18); 466/AC1, AC2, AC3
This commit is contained in:
@@ -53,6 +53,11 @@ func TestAnActiveEffortTakesANewVersionWithANewDocument(t *testing.T) {
|
||||
first := effortAsk(r.Number, StatusActive, overview)
|
||||
w.accepted(t, "author@g14", first)
|
||||
key := Key{KindResearch, r.Number}
|
||||
// 466/AC2: an insight accepted earlier is kept by the new version.
|
||||
corrected := first
|
||||
corrected.Insight = "it said less"
|
||||
w.accepted(t, "author@g14", corrected)
|
||||
insightsAt := mustGet(t, w.k.Store, key).Versions
|
||||
reviews, versions := len(w.judge.reviews), mustGet(t, w.k.Store, key).Versions
|
||||
next := c.next(r.Number)
|
||||
next.Why = c.name
|
||||
@@ -85,7 +90,7 @@ func TestAnActiveEffortTakesANewVersionWithANewDocument(t *testing.T) {
|
||||
}
|
||||
e = mustGet(t, w.k.Store, key)
|
||||
cur := e.Current
|
||||
if e.Pending != nil || cur.Status != c.status || len(cur.Insights) != 0 || !reflect.DeepEqual(cur.Sections, c.docs) {
|
||||
if e.Pending != nil || cur.Status != c.status || len(cur.Insights) != 1 || !reflect.DeepEqual(cur.Sections, c.docs) {
|
||||
t.Fatalf("after the review: %s, pending %v, insights %v, sections %+v", cur.Status, e.Pending != nil, cur.Insights, cur.Sections)
|
||||
}
|
||||
if cur.Title != first.Title || cur.Date != first.Date || !reflect.DeepEqual(cur.Deciders, first.Deciders) {
|
||||
@@ -99,7 +104,7 @@ func TestAnActiveEffortTakesANewVersionWithANewDocument(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, v := range h.Versions {
|
||||
if v.Insight {
|
||||
if v.Insight && v.N > insightsAt {
|
||||
t.Errorf("version %d is marked an insight", v.N)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
// A rule holds a record from the day hq's checks began to hold it (the review of mesh-catalog#206): a dated
|
||||
@@ -95,4 +98,34 @@ func TestAnInsightToADecisionOfOctoberKeepsItsWords(t *testing.T) {
|
||||
t.Errorf("an insight to ADR %04d was refused: %v", n, err)
|
||||
}
|
||||
}
|
||||
// 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)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -415,6 +415,7 @@ func (k *KB) Propose(caller string, a ProposeAsk) (*Proposed, error) {
|
||||
}
|
||||
r.AcceptedAt = held.Current.AcceptedAt
|
||||
r.Parts = held.Current.Parts
|
||||
keepServed(r, held.Current)
|
||||
if held.Pending != nil {
|
||||
// A revision of a pending version keeps its earlier reviews, so the round count goes on (ADR 0665 §1).
|
||||
r.Reviews, r.CountFrom = held.Pending.Reviews, held.Pending.CountFrom
|
||||
@@ -513,6 +514,39 @@ func (k *KB) Propose(caller string, a ProposeAsk) (*Proposed, error) {
|
||||
return &Proposed{Record: key.String(), Version: n, Status: StatusProposed, Says: says + "."}, nil
|
||||
}
|
||||
|
||||
// keepServed gives a version over an accepted record what the served version holds and propose's arguments do not
|
||||
// carry (novox/hq issue 466; a record keeps every progressive insight its accepted versions made, and every field it
|
||||
// was imported with): the insights, oldest first, so the judgement and the operator's digest see what will be served
|
||||
// and accept only adds the new one; reconstructed, amended, touches, the imported fields, the source and the
|
||||
// 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...)
|
||||
if served.Reconstructed != nil {
|
||||
v := *served.Reconstructed
|
||||
r.Reconstructed = &v
|
||||
}
|
||||
r.Amended = append([]string(nil), served.Amended...)
|
||||
r.Touches = append([]string(nil), served.Touches...)
|
||||
if len(served.Extra) > 0 {
|
||||
r.Extra = make(map[string]string, len(served.Extra))
|
||||
for k, v := range served.Extra {
|
||||
r.Extra[k] = v
|
||||
}
|
||||
}
|
||||
r.Source = served.Source
|
||||
if len(served.Aliases) > 0 {
|
||||
r.Aliases = make(map[string]string, len(served.Aliases))
|
||||
for k, v := range served.Aliases {
|
||||
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
|
||||
// already active (accepted at active, or proposed at active and waiting for review) is reached (ADR 0629). Empty
|
||||
// when it may.
|
||||
|
||||
@@ -392,6 +392,21 @@ func TestAnAcceptedRecordChangesOnlyByAnInsightReviewedLikeAProposal(t *testing.
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
// No verb takes a review from anyone: the review is the knowledge base's own.
|
||||
|
||||
Reference in New Issue
Block a user