Issue 1585, S19: the strict parser, every manifest problem function and the judge's tables (192 declarations, about 5,200 lines) and their 244 tests leave; composition keeps its own refusals and the helpers it uses. The catalogue's tests decode the manifests they build. ParseManifest, ParseManifestWith, ParseManifestForInputs, CatalogueProblems and the rest are gone; mesh-delivery-indexer/judge holds them. Claude-Session: https://claude.ai/code/session_01NcbgfJ9Gum47zkFKWRaovL
67 lines
2.1 KiB
Go
67 lines
2.1 KiB
Go
package catalogue
|
|
|
|
import (
|
|
"encoding/json"
|
|
"testing"
|
|
|
|
"git.novox.be/novox/mesh-sdk/go/validate"
|
|
)
|
|
|
|
// A long-running container may say it is busy (novox/hq ADR 0335 §1): `module check` holds the field to its
|
|
// shape near its author, and it is sent only to a node-engine that reads it, in words the engine's own
|
|
// validator accepts.
|
|
|
|
func busyManifest(t *testing.T, on string, busy any) []byte {
|
|
t.Helper()
|
|
extra := map[string]any{"id": "agent", "type": "container", "name": "app-agent",
|
|
"image": "registry.example/app" + healthDigest}
|
|
var m map[string]any
|
|
if err := json.Unmarshal(healthManifest(t, "", nil, extra), &m); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
for _, r := range m["resources"].([]any) {
|
|
if r := r.(map[string]any); r["id"] == on {
|
|
r[BusyField] = busy
|
|
}
|
|
}
|
|
out, err := json.Marshal(m)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
return out
|
|
}
|
|
|
|
func TestABusyIsSentOnlyToAnEngineThatReadsIt(t *testing.T) {
|
|
m, err := decodeForTest(busyManifest(t, "agent", map[string]any{"command": "mesh-builder busy"}))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
compose := func(with Rendering) []map[string]any {
|
|
out, err := Resolution{Node: "laptop", Modules: []Manifest{m}}.Declaration(with)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
return out
|
|
}
|
|
older := compose(Rendering{})
|
|
if b, sent := older[indexOfID(older, "app.agent")][BusyField]; sent {
|
|
t.Fatalf("busy was sent to an engine that does not read it: %v", b)
|
|
}
|
|
newer := compose(Rendering{ReadsBusy: true})
|
|
got, _ := newer[indexOfID(newer, "app.agent")][BusyField].(map[string]any)
|
|
if got["command"] != "mesh-builder busy" || got["timeout"] != "10s" {
|
|
t.Fatalf("busy composed as %v", got)
|
|
}
|
|
// And the engine's own validator takes the container with it.
|
|
body, err := json.Marshal(map[string]any{"declaration": validate.Version, "resources": newer})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if problems := validate.Declaration(body); len(problems) > 0 {
|
|
t.Fatalf("the node-engine's validator refuses the composed busy: %v", problems)
|
|
}
|
|
if _, has := m.Resources[len(m.Resources)-1][BusyField].(map[string]any)["timeout"]; has {
|
|
t.Error("composing wrote the timeout into the catalogue's own manifest")
|
|
}
|
|
}
|