Files
mesh-catalog/modules/mesh-watcher/cmd/mesh-watcher/manifest_test.go
T
jschoubben fc90e6c67b OBS1 (artifact-store-tools, mesh-healers, mesh-vault, mesh-watcher, minio, nfs-server): the finding stream in each manifest
Each of the six declares the stream <module>-findings (finding-written.*, finding-cleared.*,
findings-stated.*, 7 days, 16 MiB) and consumes mesh-conditions.findings-asked; the manifest
tests that hold consumes say it. The other observers' manifests are written by their own families.

Builds: design 47 G §387, §383

Claude-Session: https://claude.ai/code/session_01JG73KEq4zoDfM9WtYpcQgZ
2026-11-11 12:17:03 +01:00

74 lines
2.6 KiB
Go

package main
import (
"encoding/json"
mesh "git.novox.be/novox/mesh-contracts/go/seats/meshmoduleassigner"
"os"
"path/filepath"
"reflect"
"sort"
"strings"
"testing"
"time"
"git.novox.be/novox/mesh-sdk/go/views"
)
// The manifest says what the code does: it consumes the heartbeat and nothing else, calls its own
// ping and the controller's seats verb, holds no seat (it must not be the controller's), keeps its
// Telegram token as its own secret, lists its own tools — and names nothing of one installation.
func TestTheManifestSaysWhatTheCodeDoes(t *testing.T) {
raw, err := os.ReadFile(filepath.Join("..", "..", "module.json"))
if err != nil {
t.Fatal(err)
}
var m struct {
Module string `json:"module"`
Consumes []string `json:"consumes"`
Invokes []string `json:"invokes"`
Reads []string `json:"reads"`
Claims []any `json:"claims"`
Own map[string]string `json:"own-secrets"`
Tools []string `json:"tools"`
Build struct {
Artifacts []map[string]any `json:"artifacts"`
} `json:"build"`
}
if err := json.Unmarshal(raw, &m); err != nil {
t.Fatal(err)
}
// Where the bus runs is the assigner's seat-holders, asked once and followed by its events (ADR 0615), never read.
if !reflect.DeepEqual(m.Consumes, []string{"mesh-self-check.checked", assignerModule + ".views." + mesh.StateSeatHolders, "mesh-conditions.findings-asked"}) {
t.Fatalf("consumes %v", m.Consumes)
}
if !reflect.DeepEqual(m.Invokes, []string{SeatHoldersTool, m.Module + ".watcher_ping", "seat:mesh-hand-acts.hand-act"}) || len(m.Reads) != 0 {
t.Fatalf("invokes %v, reads %v", m.Invokes, m.Reads)
}
if len(m.Claims) != 0 {
t.Fatalf("a watcher holds no seat: %v", m.Claims)
}
env, _ := m.Build.Artifacts[0]["env"].(map[string]any)
if m.Own["telegram-token"] == "" || env["MESH_WATCHER_TELEGRAM_TOKEN_FILE"] != m.Own["telegram-token"] {
t.Fatalf("token: own %v, env %v", m.Own, env)
}
var served []string
for _, tool := range append(tools(NewWatcher(&fakeTelegram{}, time.Now, t.Logf, ""), &listening{}), (&views.Reader{}).Tools("watcher")...) {
served = append(served, tool.Name)
if strings.TrimSpace(tool.Description) == "" {
t.Errorf("%s has no description", tool.Name)
}
}
listed := append([]string(nil), m.Tools...)
sort.Strings(served)
sort.Strings(listed)
if !reflect.DeepEqual(served, listed) {
t.Fatalf("serves %v, lists %v", served, listed)
}
for _, never := range []string{"/home/", "jochen", "g14", "shanks", "novox", "zurag", "api.telegram"} {
if strings.Contains(strings.ToLower(string(raw)), never) {
t.Errorf("module.json names %q", never)
}
}
}