G15b recreated-before-after: the event recreated says what each object held before and after, its why a sentence

Builds: design 47 H2 H-A-740, H-A-686 (3)
This commit is contained in:
2026-11-25 17:37:29 +01:00
parent 82abaa03ac
commit feb0120330
3 changed files with 22 additions and 8 deletions
+13 -4
View File
@@ -71,9 +71,13 @@ type Event struct {
Asked map[string]Settings `json:"asked,omitempty"`
Held map[string]Settings `json:"held,omitempty"`
Fill *EventFill `json:"fill,omitempty"`
Snapshot string `json:"snapshot,omitempty"`
Why string `json:"why,omitempty"`
Revision uint64 `json:"revision"`
// Before and After are what each object of a recreated entry held before and after it, said by `recreated` (design 47 H2
// H-A-740).
Before []EventFill `json:"before,omitempty"`
After []EventFill `json:"after,omitempty"`
Snapshot string `json:"snapshot,omitempty"`
Why string `json:"why,omitempty"`
Revision uint64 `json:"revision"`
}
// EventFill is the fill an event says: the object it is of, its messages, its bytes and its cap; Object is its name on the
@@ -1049,11 +1053,16 @@ func (k *Keeper) emit(event string, p Plan, revision uint64, why string, asked,
// emitFill is emit with the fill of the object judged, which full and full-cleared carry (design 47 H2 H-A-634 (9)).
func (k *Keeper) emitFill(event string, p Plan, revision uint64, why string, asked, held map[string]Settings, fill *EventFill) {
k.emitBody(event, p, revision, why, asked, held, func(b *Event) { b.Fill = fill })
}
// emitBody is emit with the body changed before it is said.
func (k *Keeper) emitBody(event string, p Plan, revision uint64, why string, asked, held map[string]Settings, change func(*Event)) {
if k.Emit == nil {
return
}
s := k.saying(event, p, revision, why, asked, held)
s.Body.Fill = fill
change(&s.Body)
if err := k.Emit(&s); err != nil {
s.Error = err.Error()
k.setStatus(func(st *Status) { st.Unsaid = append(st.Unsaid, s) })
+3 -1
View File
@@ -1443,7 +1443,9 @@ func TestTheKeeperMakesWhatAVerdictAsksForAndSaysIt(t *testing.T) {
out.reset()
bus.updated = nil
if got := recreate("r3"); got.Error != "" || len(bus.deleted) != 0 || len(bus.updated) != len(objects) ||
fmt.Sprint(out.events) != "[recreated m records]" || k.Held()["m"].Made["records"].Drift != "" {
fmt.Sprint(out.events) != "[recreated m records]" || k.Held()["m"].Made["records"].Drift != "" ||
len(out.bodies) == 0 || len(out.bodies[len(out.bodies)-1].Before) != len(objects) || len(out.bodies[len(out.bodies)-1].After) != len(objects) ||
out.bodies[len(out.bodies)-1].Why != "" {
t.Fatalf("the change in place: %q, updated %v, deleted %v, said %v", got.Error, bus.updated, bus.deleted, out.events)
}
}},
+6 -3
View File
@@ -298,6 +298,7 @@ func (k *Keeper) act(r *Request) (string, error) {
// whose retention changes. A change the bus refuses stops it: no object made empty, none changed after, the refusal naming
// the object, no recreated, drifted left naming what differs (H-A-686 (2)).
var words []string
var before, after []EventFill
for i, st := range steps {
o := st.o
switch {
@@ -319,13 +320,15 @@ func (k *Keeper) act(r *Request) (string, error) {
return "partly done", fmt.Errorf("%s was removed and could not be made again (its snapshot at %s): %w", o.Stream(), path, err)
}
}
_, after, _, _ := k.Bus.Held(ctx, o)
_, now, _, _ := k.Bus.Held(ctx, o)
before = append(before, EventFill{Object: o.Stream(), Part: m.Plan.PartOf(o), Count: st.before.Messages, Bytes: st.before.Bytes, Cap: o.Settings.MaxBytes})
after = append(after, EventFill{Object: o.Stream(), Part: m.Plan.PartOf(o), Count: now.Messages, Bytes: now.Bytes, Cap: o.Settings.MaxBytes})
how := "changed in place"
if !st.inPlace {
how = "made again empty"
}
words = append(words, fmt.Sprintf("%s %s: held %d messages, %d bytes before, %d messages, %d bytes after", o.Stream(), how,
st.before.Messages, st.before.Bytes, after.Messages, after.Bytes))
st.before.Messages, st.before.Bytes, now.Messages, now.Bytes))
}
wasDrift := m.Drift != ""
m.Drift = ""
@@ -339,7 +342,7 @@ func (k *Keeper) act(r *Request) (string, error) {
m.Said = &said
held.Made[r.Local] = m
k.write(held)
k.emit(EventRecreated, m.Plan, held.Revision, r.Why+" ("+strings.Join(words, "; ")+")", nil, nil)
k.emitBody(EventRecreated, m.Plan, held.Revision, r.Why, nil, nil, func(b *Event) { b.Before, b.After = before, after })
if wasDrift {
k.clear(conditionDrifted, r.Module, r.Local)
}