Files
mesh-catalog/modules/mesh-recovery/internal/recovery/verbs_test.go
T
jschoubben 572a2b3a4b mesh-recovery: the seat's verbs, answered by the process with the proved caller
Builds: design 47 G §516, §554, §656, §682, §691, A-107, A-115
Each acting verb answers one of accepted, busy or error; arguments are read afresh per call and refused when unknown (local-name, from, aside-only, discard-aside) or without why; restore takes exactly one of snapshot and request (request is refused until built); the hand-act log names the proved account and the asker.

Claude-Session: https://claude.ai/code/session_01NcbgfGKaxw984XyAPfLm4h
2026-11-12 01:18:43 +01:00

64 lines
2.8 KiB
Go

package recovery_test
import (
"encoding/json"
"strings"
"testing"
seat "git.novox.be/novox/mesh-contracts/go/seats/meshrecovery"
"mesh-recovery/internal/recovery"
)
func call(t *testing.T, r *rig, verb, body string) recovery.Answer {
t.Helper()
out, err := r.e.Handlers()[verb]("node.engine", json.RawMessage(body))
if err != nil {
t.Fatalf("%s: %v", verb, err)
}
r.e.Wait()
return out.(recovery.Answer)
}
// Every verb of the seat's definition is answered; an acting verb answers one of accepted, busy and error and nothing more
// (§691); an argument the verb does not take (`local-name`, `from`), `aside-only` and `discard-aside` on restore-kept, a
// restore naming both a snapshot and a request, and a call without `why` are refused naming the fault (§516, §682, §554).
func TestEveryVerbIsAnsweredAndAnActingVerbAnswersOneForm(t *testing.T) {
r := newRig(t)
h := r.e.Handlers()
for _, v := range seat.Verbs() {
if h[v] == nil {
t.Errorf("verb %s has no handler", v)
}
}
taken := call(t, r, "snapshot-kept", `{"module":"app","kept":"notes","form":2,"fingerprint":"fp1","why":"form change"}`)
if taken.Accepted == "" || taken.Busy != "" || taken.Error != "" {
t.Fatalf("answer %+v", taken)
}
for name, c := range map[string]struct{ verb, body, want string }{
"local-name": {"snapshot-kept", `{"module":"app","kept":"notes","form":2,"fingerprint":"fp1","why":"w","local-name":"x"}`, "local-name"},
"from": {"restore-kept", `{"module":"app","kept":"notes","form":2,"fingerprint":"fp1","why":"w","from":"x"}`, "from"},
"aside-only": {"restore-kept", `{"module":"app","kept":"notes","form":2,"fingerprint":"fp1","why":"w","aside-only":true}`, "aside-only"},
"discard": {"restore-kept", `{"module":"app","kept":"notes","form":2,"fingerprint":"fp1","why":"w","discard-aside":true}`, "discard-aside"},
"both": {"restore", `{"module":"app","kept":"notes","snapshot":"a","request":"b","why":"w"}`, "exactly one"},
"no why": {"restore", `{"module":"app","kept":"notes","snapshot":"a"}`, "why"},
} {
if got := call(t, r, c.verb, c.body); !strings.Contains(got.Error, c.want) || got.Accepted != "" {
t.Errorf("%s: answer %+v", name, got)
}
}
if len(r.s.named(seat.EventEnded)) != 1 {
t.Errorf("a refused call acted: %+v", r.s.events)
}
out, err := h["kept-points"]("tools", json.RawMessage(`{"module":"app"}`))
if kp, ok := out.(seat.KeptPointsAnswer); err != nil || !ok || len(kp.Points) != 1 {
t.Errorf("kept-points %+v %v", out, err)
}
if got := call(t, r, "take", `{"module":"app","kept":"notes","fingerprint":"fp9","why":"by hand","asker":"op@shanks"}`); got.Accepted == "" {
t.Errorf("take %+v", got)
}
if !strings.Contains(r.s.handActs[len(r.s.handActs)-1], "node.engine|op@shanks|take app notes|by hand") {
t.Errorf("hand acts %v: the account the bus proved and the asker are both logged", r.s.handActs)
}
}