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) } }