Files
mesh-catalog/modules/mesh-recovery/cmd/mesh-recovery-tools/main_test.go
T
jschoubben bd2997cf36 A-129: kept-points says the unrestored asides; recovery_kept_points answers them as the health check
The module's declared health check names recovery_kept_points: it answers what kept-points
answers with the health answer beside it, unhealthy while an aside only it holds the data of
is listed.

Builds: design 47 G A-129, §554, §657

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

79 lines
2.9 KiB
Go

package main
import (
"encoding/json"
"os"
"slices"
"strings"
"testing"
"git.novox.be/novox/mesh-sdk/go/health"
)
// The bundle serves exactly the tools the manifest names, each named recovery_, and each acting tool calls its verb of the
// seat with the asker the tool runner proved, written into the call, and nothing of its own (design 47 G §554, §656, §682).
func TestEachToolCallsItsVerbWithTheProvedAsker(t *testing.T) {
var key string
var sent map[string]any
ask := func(k string, b any) (json.RawMessage, error) {
key, sent = k, b.(map[string]any)
return json.RawMessage(`{"accepted":"act-1"}`), nil
}
tools := Tools(ask, func(map[string]any) string { return "claude@shanks" })
raw, _ := os.ReadFile("../../module.json")
var m struct {
Tools []string `json:"tools"`
Invokes []string `json:"invokes"`
}
_ = json.Unmarshal(raw, &m)
var names []string
verbs := map[string]string{"recovery_take": "take", "recovery_restore": "restore", "recovery_retry": "retry", "recovery_aside": "aside",
"recovery_discard_aside": "discard-aside", "recovery_restore_aside": "restore-aside", "recovery_cancel": "cancel", "recovery_expire_points": "expire-points"}
for _, tool := range tools {
names = append(names, tool.Name)
if !strings.HasPrefix(tool.Name, "recovery_") {
t.Errorf("tool %s is not named recovery_", tool.Name)
}
if verb, acts := verbs[tool.Name]; acts {
if _, err := tool.Run(map[string]any{"module": "app", "why": "w"}); err != nil {
t.Fatal(err)
}
if key != "seat:mesh-recovery."+verb || sent["asker"] != "claude@shanks" || sent["module"] != "app" {
t.Errorf("%s called %s with %v", tool.Name, key, sent)
}
if !slices.Contains(m.Invokes, key) {
t.Errorf("the manifest does not invoke %s", key)
}
}
}
slices.Sort(names)
want := slices.Clone(m.Tools)
slices.Sort(want)
if !slices.Equal(names, want) {
t.Errorf("tools %v, the manifest names %v", names, want)
}
}
// recovery_kept_points answers what kept-points answers with the health answer beside it: unhealthy while an aside is
// unrestored, healthy otherwise, as the declared health check reads it (§657, A-129).
func TestKeptPointsIsTheHealthCheck(t *testing.T) {
for _, c := range []struct {
answer string
state string
}{
{`{"points":[],"asides":[],"unrestored":[]}`, health.StateHealthy},
{`{"points":[],"asides":[{"id":"x","names":["app_notes"],"size":1}],"unrestored":[{"id":"x","names":["app_notes"],"size":1}]}`, health.StateUnhealthy},
} {
tools := Tools(func(string, any) (json.RawMessage, error) { return json.RawMessage(c.answer), nil }, func(map[string]any) string { return "" })
out, err := tools[0].Run(map[string]any{})
if err != nil {
t.Fatal(err)
}
raw, _ := json.Marshal(out)
a, err := health.Read(raw)
if err != nil || a.State != c.state || !strings.Contains(string(raw), `"unrestored"`) {
t.Errorf("%s answered %s: %+v, %v", c.answer, raw, a, err)
}
}
}