process: a reply's error-kind is read from its bytes, and tested so (H-A-549 (1))

Review round 2: the row for a stopping tool runner built its fault itself, so
requestAsk's reading of error-kind went untested. The reading of a reply (result,
error, error-kind, held) is now readReply, and the kept-call table reads the
runner's raw reply {"error": ..., "error-kind": "stopping"} through it.

Builds: design 47 H2 H-A-549 (1)
This commit is contained in:
2026-11-23 12:09:05 +01:00
parent 07bfc71c33
commit b3509e7d31
2 changed files with 32 additions and 13 deletions
+17 -7
View File
@@ -280,6 +280,19 @@ func (c *Conn) requestAsk(subject string, data []byte, ask string) (json.RawMess
if err != nil {
return nil, err
}
result, held, err := readReply(subject, msg.Data)
if err != nil {
return nil, err
}
if held != nil {
return c.awaitGated(subject, *held)
}
return result, nil
}
// readReply reads one reply ({result, error, error-kind, node, held}): a reply naming an error is the call's failure,
// of the kind stopping a transport fault a kept call paces on (design 47 H2 H-A-549 (1)); a held call names its hold.
func readReply(subject string, data []byte) (json.RawMessage, *approval.Held, error) {
var r struct {
Result json.RawMessage `json:"result"`
Error string `json:"error"`
@@ -287,14 +300,11 @@ func (c *Conn) requestAsk(subject string, data []byte, ask string) (json.RawMess
Node string `json:"node"`
Held *approval.Held `json:"held"`
}
if err := json.Unmarshal(msg.Data, &r); err != nil {
return nil, fmt.Errorf("%s answered something that is not a seat's answer: %w", subject, err)
if err := json.Unmarshal(data, &r); err != nil {
return nil, nil, fmt.Errorf("%s answered something that is not a seat's answer: %w", subject, err)
}
if r.Error != "" {
return nil, replyError(r.Error, r.ErrorKind)
return nil, nil, replyError(r.Error, r.ErrorKind)
}
if r.Held != nil {
return c.awaitGated(subject, *r.Held)
}
return r.Result, nil
return r.Result, r.Held, nil
}
+15 -6
View File
@@ -149,22 +149,31 @@ func TestACallIsAskedAgainOnlyWhenItReachedNoOne(t *testing.T) {
name string
answers []string
asks int
replies bool // the answers are the runner's raw replies, read as requestAsk reads them (readReply)
want string // the call's answer, where it is not the last answer
}{
{"away, then answered", []string{`{"error":"x","error-kind":"away","part":"the forge's store","words":"401"}`, `{"merged":true}`}, 2},
{"stopping, then answered by the new runner", []string{"stopping", `{"merged":true}`}, 2},
{"refused: answered at once", []string{`{"error":"no","error-kind":"refused"}`}, 1},
{"away, then answered", []string{`{"error":"x","error-kind":"away","part":"the forge's store","words":"401"}`, `{"merged":true}`}, 2, false, ""},
// H-A-549 (1): the runner's reply of the kind stopping, read from its bytes, is paced on until the new runner answers.
{"stopping, then answered by the new runner", []string{`{"error":"git's trees was not taken: the tool runner is stopping","error-kind":"stopping"}`,
`{"result":{"merged":true}}`}, 2, true, `{"merged":true}`},
{"refused: answered at once", []string{`{"error":"no","error-kind":"refused"}`}, 1, false, ""},
} {
asks := 0
request := func(string, []byte) (json.RawMessage, error) {
a := row.answers[min(asks, len(row.answers)-1)]
asks++
if a == "stopping" {
return nil, replyError("git's trees was not taken: the tool runner is stopping", "stopping")
if row.replies {
result, _, err := readReply("mesh.seat.git.call.trees", []byte(a))
return result, err
}
return json.RawMessage(a), nil
}
want := row.want
if want == "" {
want = row.answers[len(row.answers)-1]
}
got, err := callKeptWith(busretry.Kept{Seat: "git", Verb: "merge-pull"}, request, "called", "fallback", nil)
if asks != row.asks || err != nil || string(got) != row.answers[len(row.answers)-1] {
if asks != row.asks || err != nil || string(got) != want {
t.Errorf("%s: asked %d times, %s, %v", row.name, asks, got, err)
}
}