gate: gate_record_end takes an all form for the clean state
Every open record ends after one hand act naming how many; the answer says what it ended, counted. Builds: design 47 H H-A-121 (2), §765 (the gate's open records go at the clean state) Claude-Session: https://claude.ai/code/session_01JG73KHUnBze48rdua8u2sy
This commit is contained in:
@@ -593,6 +593,42 @@ func TestTheRecordsToolsReadThemAndEndOneByHand(t *testing.T) {
|
||||
t.Fatal("a record ended is ended again")
|
||||
}
|
||||
})
|
||||
// Design 47 H, H-A-121: the clean state's all form ends every open record after one hand act, and answers them counted.
|
||||
t.Run("gate_record_end with all ends every open record once the hand-act log took it, counted", func(t *testing.T) {
|
||||
rs, r, said := setup(t)
|
||||
other, _, err := rs.Open(opening("main", 48, map[string]string{"novox/app@222222222222": strings.Repeat("2", 40)}))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
log := &handActsFake{refuse: errors.New("no responders")}
|
||||
if _, err := rs.EndAllByHand("", "jochen@shanks", log); err == nil {
|
||||
t.Fatal("ended all with no reason")
|
||||
}
|
||||
if _, err := rs.EndAllByHand("the clean state", "jochen@shanks", log); err == nil {
|
||||
t.Fatal("ended all though the hand-act log refused it")
|
||||
}
|
||||
for _, inst := range []string{r.Instance, other.Instance} {
|
||||
if back, _ := rs.Read(inst); back.Ended != nil {
|
||||
t.Fatalf("%s ended while no hand act was recorded", inst)
|
||||
}
|
||||
}
|
||||
log.refuse = nil
|
||||
got, err := rs.EndAllByHand("the clean state", "jochen@shanks", log)
|
||||
if err != nil || got["count"] != 2 || len(got["ended"].([]string)) != 2 || len(log.took) != 1 {
|
||||
t.Fatalf("%+v %v (log %+v)", got, err, log.took)
|
||||
}
|
||||
for _, inst := range []string{r.Instance, other.Instance} {
|
||||
if back, _ := rs.Read(inst); back.Ended == nil || back.Ended.Why != "the clean state" {
|
||||
t.Fatalf("%s not ended: %+v", inst, back.Ended)
|
||||
}
|
||||
if !slices.Contains(*said, meshdelivery.SubjectRecordEnded+" record-ended."+inst) {
|
||||
t.Fatalf("%s's end is not said: %v", inst, *said)
|
||||
}
|
||||
}
|
||||
if again, err := rs.EndAllByHand("again", "jochen@shanks", log); err != nil || again["count"] != 0 || len(log.took) != 1 {
|
||||
t.Fatalf("with none open: %+v %v, log %d", again, err, len(log.took))
|
||||
}
|
||||
})
|
||||
t.Run("gate_record_repair asks the owners for the outcomes an entry lacks, applies what they answer, and ends the record", func(t *testing.T) {
|
||||
rs, r, said := setup(t)
|
||||
owners := &ownersFake{wanted: "src2:f1", fp: "src2:f1", phase: "running"}
|
||||
|
||||
@@ -139,6 +139,44 @@ func (rs *Records) EndByHand(instance, why, by string, acts handActs) (recordVie
|
||||
return viewOf(r), nil
|
||||
}
|
||||
|
||||
// EndAllByHand ends every open record by hand, with the reason (design 47 H, H-A-121: the clean state's `all` form),
|
||||
// recorded in the hand-act log first as one act naming how many: nothing is ended when the log did not take it. It answers
|
||||
// what it ended, counted; a record that could not be ended stops it, said with what was ended before it.
|
||||
func (rs *Records) EndAllByHand(why, by string, acts handActs) (map[string]any, error) {
|
||||
if strings.TrimSpace(why) == "" {
|
||||
return nil, errors.New("say why every open record is ended by hand, such as the clean state")
|
||||
}
|
||||
list, err := rs.List()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var open []*Record
|
||||
for _, r := range list {
|
||||
if r.Ended == nil {
|
||||
open = append(open, r)
|
||||
}
|
||||
}
|
||||
ended := []string{}
|
||||
if len(open) == 0 {
|
||||
return map[string]any{"ended": ended, "count": 0}, nil
|
||||
}
|
||||
if acts == nil {
|
||||
return nil, errors.New("the hand-act log cannot be reached here, so nothing was ended")
|
||||
}
|
||||
if _, err := acts.Record(meshhandactsclient.Request{What: fmt.Sprintf("ended every open delivery record by hand (%d)", len(open)),
|
||||
Why: why, Cause: "gate_record_end", Verb: "record-end"}); err != nil {
|
||||
return nil, fmt.Errorf("the hand act was not recorded through mesh-hand-acts, so nothing was ended: %w", err)
|
||||
}
|
||||
for _, r := range open {
|
||||
if err := rs.End(r, why, by); err != nil {
|
||||
return map[string]any{"ended": ended, "count": len(ended)}, fmt.Errorf("the record %s was not ended, after %d were: %w", r.Instance, len(ended), err)
|
||||
}
|
||||
rs.keep(r)
|
||||
ended = append(ended, r.Instance)
|
||||
}
|
||||
return map[string]any{"ended": ended, "count": len(ended)}, nil
|
||||
}
|
||||
|
||||
// handActs records an act in the hand-act log (meshhandactsclient.Recorder).
|
||||
type handActs interface {
|
||||
Record(q meshhandactsclient.Request) (meshhandactsclient.Taken, error)
|
||||
@@ -196,14 +234,26 @@ func recordTools(h *Holder, acts handActs) []stdio.Tool {
|
||||
}},
|
||||
{Name: "gate_record_end",
|
||||
Description: "End a delivery record left open by hand (a node gone for good, an entry that never runs), with the " +
|
||||
"reason; recorded in the hand-act log of the seat mesh-hand-acts first, and said as record-ended.",
|
||||
"reason; or, with all, every open record (the clean state), answering what it ended, counted. Recorded in the " +
|
||||
"hand-act log of the seat mesh-hand-acts first, and each said as record-ended.",
|
||||
Input: map[string]any{"type": "object", "properties": map[string]any{
|
||||
"instance": str("the record's instance"), "why": str("why it is ended by hand, in plain words")},
|
||||
"required": []string{"instance", "why"}},
|
||||
"instance": str("the record's instance; or give all"),
|
||||
"all": map[string]any{"type": "boolean", "description": "end every open record instead of one"},
|
||||
"why": str("why it is ended by hand, in plain words")},
|
||||
"required": []string{"why"}},
|
||||
Run: func(a map[string]any) (any, error) {
|
||||
if h.Records == nil {
|
||||
return none()
|
||||
}
|
||||
all, _ := a["all"].(bool)
|
||||
switch instance := strArg(a, "instance"); {
|
||||
case all && instance != "":
|
||||
return nil, errors.New("give an instance or all, not both")
|
||||
case all:
|
||||
return h.Records.EndAllByHand(strArg(a, "why"), stdio.CallerOf(a), acts)
|
||||
case instance == "":
|
||||
return nil, errors.New("give the record's instance, or all for every open record")
|
||||
}
|
||||
return h.Records.EndByHand(strArg(a, "instance"), strArg(a, "why"), stdio.CallerOf(a), acts)
|
||||
}},
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user