diff --git a/node-tools/internal/bus/seat.go b/node-tools/internal/bus/seat.go index 2a9f8c8..35729bf 100644 --- a/node-tools/internal/bus/seat.go +++ b/node-tools/internal/bus/seat.go @@ -195,7 +195,8 @@ func (c *Conn) SeatProve(module, subject string, body json.RawMessage) (json.Raw } // SeatAnswer answers every proof on a subject the module's seat traffic lists among its answers, with what -// answer returns. A returned error is answered as `{"error": ""}`, never as silence. +// answer returns. A returned error is answered as `{"error": ""}`, never as silence, but for one that says it is +// unanswered (a proof after the stop or cut at the bound). func (c *Conn) SeatAnswer(module, subject string, answer func(subject string, body json.RawMessage) (json.RawMessage, error)) (func(), error) { t, err := c.trafficOf(module) if err != nil { @@ -219,6 +220,12 @@ func (c *Conn) SeatAnswer(module, subject string, answer func(subject string, bo return } out, err := answer(msg.Subject, body) + // A proof arriving after the runner's stop, or cut at its bound, is answered nothing, as answerCalledOn does + // (design 47 H2 §813 (12), H-A-369). + var unanswered interface{ Unanswered() bool } + if errors.As(err, &unanswered) && unanswered.Unanswered() { + return + } if err != nil { b, _ := json.Marshal(map[string]string{"error": err.Error()}) _ = msg.Respond(b) diff --git a/node-tools/internal/bus/seat_test.go b/node-tools/internal/bus/seat_test.go index 6fd65e5..f2bc5de 100644 --- a/node-tools/internal/bus/seat_test.go +++ b/node-tools/internal/bus/seat_test.go @@ -166,12 +166,21 @@ func TestTheHolderTakesItsWorkOnceAndAFailureComesBack(t *testing.T) { } } +// unansweredProof is the error the runner's drain hands for a call after its stop or cut at its bound. +type unansweredProof struct{} + +func (unansweredProof) Error() string { return "answered nothing" } +func (unansweredProof) Unanswered() bool { return true } + func TestAProofIsAskedAndAnsweredAndNeverKept(t *testing.T) { _, conn, js := seatMesh(t) stop, err := conn.SeatAnswer("messenger", "mesh.seat.intake.proof.code.*", func(subject string, body json.RawMessage) (json.RawMessage, error) { if !strings.HasSuffix(subject, ".telegram") { return nil, errors.New("asked by another kind") } + if string(body) == `{"cut":true}` { + return nil, unansweredProof{} + } return json.RawMessage(`{"linked":true}`), nil }) if err != nil { @@ -186,6 +195,26 @@ func TestAProofIsAskedAndAnsweredAndNeverKept(t *testing.T) { if string(answer) != `{"linked":true}` { t.Fatalf("the proof was answered %s", answer) } + // A proof arriving after the stop, or cut at the bound, is answered nothing (design 47 H2 §813 (12), H-A-369): the + // answerer handles proofs in order, so the first reply on one inbox after a cut proof and a whole one is the whole one's. + raw, err := nats.Connect(mt.URL(t)) + if err != nil { + t.Fatal(err) + } + defer raw.Close() + inbox := nats.NewInbox() + replies, err := raw.SubscribeSync(inbox) + if err != nil { + t.Fatal(err) + } + for _, body := range []string{`{"cut":true}`, `{"code":"123456"}`} { + if err := raw.PublishRequest("mesh.seat.intake.proof.code.telegram", inbox, []byte(body)); err != nil { + t.Fatal(err) + } + } + if first, err := replies.NextMsg(30 * time.Second); err != nil || string(first.Data) != `{"linked":true}` { + t.Fatalf("a proof cut at the stop was answered, or the whole one not: %v %v", first, err) + } if _, err := conn.SeatProve("telegram", "mesh.seat.intake.proof.code.desktop", json.RawMessage(`{}`)); err == nil { t.Error("a channel asked a proof as another kind") }