Files
mesh-sdk/go/catalogue/runtime_health_test.go
T
jschoubben 1c7356c247
mesh/delivery-group group feat/sdk1 rejected: composed together: the checker's verdict at the members' heads (428d048dd50a): unit: git.novox.be/novox/mesh-sdk/…
mesh/delivery closed: a newer head of the same pull request
mesh/check failed: unit: git.novox.be/novox/mesh-sdk/go/process.TestStatePutWritesAKeyWhole: a Put through a short blackout: 0, mesh-mail's state send…
catalogue: the composition's rules and refusals leave for the node-engine, so mesh-sdk renders no declaration and refuses no composition (ADR 0593 §7)
Claude-Session: https://claude.ai/code/session_01NcbgfJ9Gum47zkFKWRaovL
2026-11-02 19:19:25 +01:00

45 lines
1.8 KiB
Go

package catalogue
import (
"encoding/json"
"testing"
)
// novox/hq ADR 0366: a module that runs as its own account declares its runtime's health under one manifest
// key, `runtime-health`, in the form a resource's `health` takes; the controller puts it on the process it
// writes for that runtime, and a tool check there stands beside the node-engine's judgement that the runtime
// is alive. A module that runs as no account of its own is refused the key.
// ownAccountManifest is a module of its own account with nothing long-running but its own runtime, given
// runtime-health (or none, when health is nil), and running as no account when runsAs is false.
func ownAccountManifest(t *testing.T, runsAs bool, health any) []byte {
t.Helper()
m := map[string]any{"module": "keeper", "tools": []any{"keeper_status", "keeper_health"},
"own-secrets": map[string]any{"broker": map[string]any{"path": "/var/lib/keeper/broker"}},
"resources": []any{map[string]any{"id": "account", "type": "user", "name": "keeper"}}}
if runsAs {
m["runs-as"], m["secrets-owner"] = "keeper", "keeper"
}
if health != nil {
m["runtime-health"] = health
}
raw, err := json.Marshal(m)
if err != nil {
t.Fatal(err)
}
return raw
}
func TestAModuleOfItsOwnAccountDeclaresItsRuntimesHealthByItsOwnTool(t *testing.T) {
m, err := decodeForTest(ownAccountManifest(t, true, map[string]any{"kind": "tool", "tool": "keeper_health"}))
if err != nil {
t.Fatalf("a tool check on its own runtime was refused: %v", err)
}
if got := HealthChecks(m); len(got) != 1 || got[0] != "keeper.keeper_health" {
t.Errorf("the engine is granted %v, want keeper.keeper_health", got)
}
if r, has := OwnRuntimeHealth(m); !has || r["id"] != "keeper."+OwnRuntimeID() {
t.Errorf("its runtime's health reads as %v %v", r, has)
}
}