diff --git a/internal/catalogue/foundation_manifests_test.go b/internal/catalogue/foundation_manifests_test.go index 01e0c5d..49993e6 100644 --- a/internal/catalogue/foundation_manifests_test.go +++ b/internal/catalogue/foundation_manifests_test.go @@ -1,6 +1,7 @@ package catalogue import ( + "encoding/json" "fmt" "os" "reflect" @@ -170,7 +171,7 @@ func TestTheForgeHoldsTheNpmAndGitSeats(t *testing.T) { // **And the forge's own address follows it**, composed from the manifest in the catalogue beside // this checkout (novox/hq 04-ISSUES/088). // -// The forge is reached a third way that neither test above covers: by its own sidecar, over the +// The forge is reached a third way that neither test above covers: by its own code, over the // machine's loopback, told where to go in its environment. The `2999:3000` mapping that lets the // forge go on binding 3000 does nothing for a caller dialling the machine — so a literal there is // wrong on every node whose assignment differs, and wrong for a second reason on a node given the @@ -178,13 +179,13 @@ func TestTheForgeHoldsTheNpmAndGitSeats(t *testing.T) { // in an `env` at all is a declaration, not a manifest. func TestTheForgesOwnAddressFollowsThePortTheNodeGaveIt(t *testing.T) { forge, err := catalogueManifest(t, "gitea").Resolve([]Built{{ - Name: "runtime", Kind: ArtifactImage, - Reference: "registry.example/gitea-runtime@sha256:" + strings.Repeat("a", 64), + Name: "code", Kind: ArtifactBundle, + Reference: ArtifactStoreScheme + "gitea/code/blobs/" + bundleDigest, Digest: bundleDigest, }}) if err != nil { t.Fatalf("the forge's manifest does not resolve against its own build: %v", err) } - r := Resolution{Node: "anchor", Modules: []Manifest{forge}, Needs: []Needed{ + r := Resolution{Node: "anchor", Modules: []Manifest{forge, theRuntime(t)}, Needs: []Needed{ {Name: "postgres-database", For: "gitea", From: "anchor", At: "127.0.0.1", Serves: map[string]any{"port": float64(5432)}, Sealed: "sealed-db"}, {Name: "route", For: "gitea", From: "anchor"}, @@ -194,8 +195,8 @@ func TestTheForgesOwnAddressFollowsThePortTheNodeGaveIt(t *testing.T) { // The number this node was given for the forge — the one the machine it is about to run on // already publishes. - out, err := r.Declaration(Rendering{ - Needed: map[string]map[string]string{"gitea": {"broker": "sealed-broker"}}, + out, err := r.Declaration(Rendering{ArtifactStore: "anchor.internal:5101", + Needed: map[string]map[string]string{RuntimeModule: {"broker": "sealed-broker"}}, Given: map[string]map[int]int{"gitea": {3000: 2999}}, }) if err != nil { @@ -210,14 +211,19 @@ func TestTheForgesOwnAddressFollowsThePortTheNodeGaveIt(t *testing.T) { if published := fmt.Sprint(server["ports"]); !strings.Contains(published, "2999:3000") { t.Fatalf("the forge is not published on the port this node gave it: %v", server["ports"]) } - runtime := fileNamed(out, "gitea.runtime") + // The forge's own code runs in the node's runtime (novox/hq ADR 0198), given its words there. + runtime := fileNamed(out, RuntimeModule+"."+RuntimeProcessID()) if runtime == nil { - t.Fatalf("the forge's sidecar is not in the declaration: %v", out) + t.Fatalf("the node's runtime is not in the declaration: %v", ids(out)) } - env, _ := runtime["env"].(map[string]any) - if env["MESH_GITEA_URL"] != "http://127.0.0.1:2999" { - t.Fatalf("the forge's sidecar dials %v while the machine publishes the forge on 2999 — "+ - "whatever reads it dials a dead port", env["MESH_GITEA_URL"]) + env, _ := runtime["env"].(map[string]string) + var given map[string]map[string]string + if err := json.Unmarshal([]byte(env[RuntimeToolEnv]), &given); err != nil { + t.Fatalf("the runtime's %s is not JSON: %q", RuntimeToolEnv, env[RuntimeToolEnv]) + } + if given["gitea"]["MESH_GITEA_URL"] != "http://127.0.0.1:2999" { + t.Fatalf("the forge's code dials %v while the machine publishes the forge on 2999 — "+ + "whatever reads it dials a dead port", given["gitea"]["MESH_GITEA_URL"]) } } @@ -229,13 +235,13 @@ func declaredGiteaSsh(t *testing.T, given map[int]int) map[string]any { t.Helper() forge := catalogueManifest(t, "gitea") resolved, err := forge.Resolve([]Built{{ - Name: "runtime", Kind: ArtifactImage, - Reference: "registry.example/gitea-runtime@sha256:" + strings.Repeat("a", 64), + Name: "code", Kind: ArtifactBundle, + Reference: ArtifactStoreScheme + "gitea/code/blobs/" + bundleDigest, Digest: bundleDigest, }}) if err != nil { t.Fatalf("the forge's manifest does not resolve against its own build: %v", err) } - r := Resolution{Node: "anchor", Modules: []Manifest{resolved}, Needs: []Needed{ + r := Resolution{Node: "anchor", Modules: []Manifest{resolved, theRuntime(t)}, Needs: []Needed{ {Name: "postgres-database", For: "gitea", From: "anchor", At: "127.0.0.1", Serves: map[string]any{"port": float64(5432)}, Sealed: "sealed-db"}, {Name: "route", For: "gitea", From: "anchor"}, @@ -246,8 +252,8 @@ func declaredGiteaSsh(t *testing.T, given map[int]int) map[string]any { for k, v := range given { givenPorts[k] = v } - out, err := r.Declaration(Rendering{ - Needed: map[string]map[string]string{"gitea": {"broker": "sealed-broker"}}, + out, err := r.Declaration(Rendering{ArtifactStore: "anchor.internal:5101", + Needed: map[string]map[string]string{RuntimeModule: {"broker": "sealed-broker"}}, Ports: map[string]map[int]int{"gitea": givenPorts}, Given: map[string]map[int]int{"gitea": given}, })