From 0766acdd699b6454819809d6c5ee4bf38841d5e9 Mon Sep 17 00:00:00 2001 From: jochen Date: Wed, 25 Nov 2026 18:50:23 +0100 Subject: [PATCH] AnswerSeat answers away as the result in AwayAnswer's form MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Builds: design 47 H2 H-A-708 (2), H-A-717 DQ-58, §776 --- go/process/call_test.go | 21 ++++++++++++++++++--- go/process/serve.go | 13 ++++++------- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/go/process/call_test.go b/go/process/call_test.go index 162d0a34..00af5d76 100644 --- a/go/process/call_test.go +++ b/go/process/call_test.go @@ -220,11 +220,26 @@ func TestACallIsAskedAgainOnlyWhenItReachedNoOne(t *testing.T) { var got struct{ Kind, Part string } var raw map[string]any _ = json.Unmarshal(body, &raw) + if inner, ok := raw["result"].(map[string]any); ok { + raw = inner + } got.Kind, _ = raw["error-kind"].(string) got.Part, _ = raw["part"].(string) - away := busretry.AwayIn(body) - if got.Kind != row.kind || got.Part != row.part || (away != nil) != row.fault || (away != nil && busretry.Fault(away) != true) { - t.Errorf("%v answered %s", row.err, body) + // Read through the module's own reader, a kept call asks again on an away answer (once more here) and not on a refusal. + asks := 0 + request := func(string, []byte) (json.RawMessage, error) { + asks++ + if asks > 1 { + return json.RawMessage(`{"ok":true}`), nil + } + result, _, err := readReply("mesh.seat.mesh-catalog.tool.revision", body) + return result, err + } + restore := busretry.Waits(10*time.Second, time.Millisecond, 2*time.Millisecond) + _, kerr := callKeptWith(busretry.Kept{Seat: "mesh-catalog", Verb: "revision"}, request, "called", "fallback", nil) + restore() + if got.Kind != row.kind || got.Part != row.part || (asks == 2) != row.fault || (!row.fault && (asks != 1 || kerr == nil)) { + t.Errorf("%v answered %s, asked %d times (%v)", row.err, body, asks, kerr) } } // Design 47 H2 H-A-731: the hook a caller gives on its KeptAsk reaches the kept-call form, and a caller giving none gives none. diff --git a/go/process/serve.go b/go/process/serve.go index 0748aedc..069684ae 100644 --- a/go/process/serve.go +++ b/go/process/serve.go @@ -191,11 +191,7 @@ func (c *Conn) answerBody(msg *nats.Msg, pattern string, h heldHandler) []byte { var reply struct { Result any `json:"result,omitempty"` Error string `json:"error,omitempty"` - // ErrorKind, Part and Words are an answer of the kind away (design 47 H2 §776, H-A-708 (2)). - ErrorKind string `json:"error-kind,omitempty"` - Part string `json:"part,omitempty"` - Words string `json:"words,omitempty"` - Node string `json:"node,omitempty"` + Node string `json:"node,omitempty"` // Held is a kept call's answer (design 47 G §677; lead answer A-244). Held *approval.Held `json:"held,omitempty"` } @@ -215,10 +211,13 @@ func (c *Conn) answerBody(msg *nats.Msg, pattern string, h heldHandler) []byte { result, held, err := h(caller, body, wait) switch { case err != nil: - reply.Error = err.Error() + // An `away` fault is the result in AwayAnswer's form (§776, H-A-708 (2), DQ-58), as stdio's serve answers it, + // so the caller's reader hands it on whole; any other fault is an error. var away *busretry.Away if errors.As(err, &away) { - reply.ErrorKind, reply.Part, reply.Words = busretry.ErrorKindAway, away.Part, away.Words + reply.Result = busretry.AwayAnswer(away.Part, away.Words) + } else { + reply.Error = err.Error() } case held != nil: reply.Held = held