ADR 0593 §7: the composer with its refusals leaves mesh-sdk, so mesh-sdk carries no composition rule. The catalogue functions only the node-engine's composition reaches (Resolve, Resolution's Compose, Declaration, DataItems, LeftOut, Rules and the rest, the settings, placeholder and template refusals, the rendering helpers) are copied with their tests into internal/compose/resolution; a method of a mesh-sdk shape becomes a function taking it first. The composition calls its own copies, and the captured catalogue its tests read lives here now, shared by mesh-compose's tests. Claude-Session: https://claude.ai/code/session_01NcbgfJ9Gum47zkFKWRaovL
55 lines
1.6 KiB
Go
55 lines
1.6 KiB
Go
package resolution
|
|
|
|
import (
|
|
"encoding/json"
|
|
"testing"
|
|
|
|
mcat "git.novox.be/novox/mesh-sdk/go/catalogue"
|
|
)
|
|
|
|
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[mcat.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 mcat.Rendering) []map[string]any {
|
|
out, err := Declaration(mcat.Resolution{Node: "laptop", Modules: []mcat.Manifest{m}}, with)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
return out
|
|
}
|
|
older := compose(mcat.Rendering{})
|
|
if b, sent := older[indexOfID(older, "app.agent")][mcat.BusyField]; sent {
|
|
t.Fatalf("busy was sent to an engine that does not read it: %v", b)
|
|
}
|
|
newer := compose(mcat.Rendering{ReadsBusy: true})
|
|
got, _ := newer[indexOfID(newer, "app.agent")][mcat.BusyField].(map[string]any)
|
|
if got["command"] != "mesh-builder busy" || got["timeout"] != "10s" {
|
|
t.Fatalf("busy composed as %v", got)
|
|
}
|
|
if _, has := m.Resources[len(m.Resources)-1][mcat.BusyField].(map[string]any)["timeout"]; has {
|
|
t.Error("composing wrote the timeout into the catalogue's own manifest")
|
|
}
|
|
}
|