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