AnswerSeat answers away as the result in AwayAnswer's form

Builds: design 47 H2 H-A-708 (2), H-A-717 DQ-58, §776
This commit is contained in:
2026-11-25 18:50:23 +01:00
parent 8c35c72a9d
commit 0766acdd69
2 changed files with 24 additions and 10 deletions
+18 -3
View File
@@ -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.
+6 -7
View File
@@ -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