Every caller composes through mesh-sdk's go/compose since issues 1386 to 1388; the controller's second copy of the composition is dead code. The parent of this commit isfb556d6b, whose try (build-1792493691274712799, 17m28s, 2026-10-20 11:12 UTC) ran the equality test green on the live facts: every machine was sent and compared both ways (ADR 0453, issue 1384). Deleted, 40 functions: in plan.go planFor, declarationWith, renderingFor, grantsFor, theRestOfTheMesh and their helpers (boundOfGrant, busCredentialIssued, carriedBuilds, carriedOn, composeBusUsers, engineJudgesRoot, engineReadsHealth, engineTakesHanded, takesHanded, givenUnderAnOldKey, issuedToHolder, keyFor, licencesFor, managerPublicKeyFor, movedProvider, providerMoved, providerModuleOf, sayLeftOut, seatsOn, wireBuilds, zonesInTheMesh); in network.go generators, whoResolves, namesInTheMesh, onThePrivateNetwork; composedAndValidated, adoptionFor, adoptionOf, engineOpensVaultBox, namedModules, localNetworksOf, keepRecorded, passSeatsOn, theMeshPassesSeatsOn, assignmentsOf. Choosing (Reading, Allocating, Foreseeing) is gone: coreBoxesFor and coreBoxesOf take a plain allocating flag. composeForPush no longer takes the private network it ignored. The seat pass of a send is performSeatPasses, over the passes the composition names. Measured: cmd/mesh-controller non-test code 67,643 -> 65,821 lines (-1,822), its tests 57,691 -> 57,286, with the integration part of the equality test removed here because it calls the deleted functions. Not the issue's 3,000: that counts all of plan.go (2,192 lines), of which the callers, the verbs, the perform step and the sends remain (sendable, recorded builds, the held-back and ready-node logic, the plan verb, the gate's trial); and the 37 functions a name walk lists as unreachable are called through interfaces and method sets and are kept. Tests dropped, each with the mesh-sdk go/compose test that holds its cases: - seat_pass_test.go TestACompositionWithTwoClaimantsRecordsNoneAndSaysSo, TestACompositionChangesNothingWhileTheHolderIsAssignedOrNobodyClaims, TestAHolderAssignedButNotOnTheShelfIsNotTakenForGone: rest_test.go TestNoSeatIsPassedForTwoClaimantsAnAssignedHolderOrNoClaimant, TestAHolderAssignedButNotOnTheShelfIsNotTakenForGone, TestASeatWhoseHolderIsAssignedNowhereGoesToItsOnlyClaimant. TestACompositionPassesTheSeatAndWritesOneHandActByTheController and TestALostPassWritesNoActAndAFailedOneLeavesTheRecord stay as tests of the send's step (performSeatPasses); TestAThrowawayMeshPassesTheSeatInMemoryAndWritesNothing stays as TestAThrowawayMeshWritesNoHandActForAPass. - seat_pass_test.go TestNoSeatIsPassedWhenAMachinesAssignmentsCouldNotBeRead: no counterpart, and none is needed: the adapter reads every machine's assignments for the Input and a machine whose read fails fails the Input, so no seat is passed on a partial read. - network_test.go TestOnlyAMachineOnThePrivateNetworkIsNamed: network_test.go TestANodeNotOnThePrivateNetworkGetsNoAddressAndNoNetwork. - held_back_test.go TestASendCarriesTheCurrentBuildsAndALeftOutModuleKeepsItsOwn: node_test.go TestAModuleLeftOutKeepsTheBuildItWasLastSent (and compose_sdk_test.go's table, now literal). - modules_wire_test.go TestTheBuildOfACarriedCommitIsTheAssignmentsOrTheOneBuiltFromIt: node_test.go TestTheBodyCarriesTheOrderTheInputGivesAndTheBuildsOnlyToAnEngineThatReadsThem. - compose_equal_integration_test.go: the old path it compares against is deleted; its last run is the parent's try. Rewritten against mesh-sdk, same cases: issued_test.go (needs now come from compose.Resolve: Needed.IssuedToHolder and ProviderMoved), module_health_test.go and merge_gate_handing tests (the contract in the Input), provisioner_account_integration_test.go (the composition's refusal), one_resolution_integration_test.go (sayFound). Every test of the send, perform, the adapter and the verbs is kept; the tests that used planFor, declarationWith, generators, renderingFor or grantsFor as setup use resolveNode, composeSend, composeQuestion, renderingOf and grantsOf. compose_callers_test.go now fails when any deleted name is declared or called again. Committed by copying the files of a staging branch (stage/r4b-1389 at198be8217c, built fromfb556d6bby patch commits and compared with the author's worktree), so that this commit's parent isfb556d6b.
132 lines
5.6 KiB
Go
132 lines
5.6 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"errors"
|
|
"reflect"
|
|
"strings"
|
|
"testing"
|
|
|
|
"git.novox.be/novox/mesh-sdk/go/catalogue"
|
|
"github.com/novox/mesh-controller/internal/broker"
|
|
"github.com/novox/mesh-controller/internal/conditions"
|
|
"github.com/novox/mesh-controller/internal/inventory"
|
|
)
|
|
|
|
// The core's own credentials travel sealed by the vault to their machine (novox/hq ADR 0349 §16, issue 755; the lead's
|
|
// decision, issue 755 notes 4 and 5): to an engine that opens the vault's box, the send carries the box the vault
|
|
// answered the controller and never the controller's own seal; when the vault does not answer, a kept box is carried
|
|
// again and a module with none is sealed by the controller (ADR 0396, issue 908), with a condition naming the vault and the machine. An engine below the
|
|
// contract composes exactly as before, and the vault is not asked.
|
|
|
|
// coreStandIn answers `get` with a box per name and generation, or its silence.
|
|
type coreStandIn struct {
|
|
asked []string
|
|
keys []string
|
|
generation int
|
|
silent error
|
|
}
|
|
|
|
func (v *coreStandIn) ask(name, key string) (coreAnswer, error) {
|
|
v.asked, v.keys = append(v.asked, name), append(v.keys, key)
|
|
if v.silent != nil {
|
|
return coreAnswer{}, v.silent
|
|
}
|
|
box := `{"v":1,"eph":"ZQ==","iv":"aQ==","tag":"dA==","ct":"` + strings.Repeat("c", len(v.asked)) + `"}`
|
|
return coreAnswer{Name: name, Generation: v.generation, Sealed: json.RawMessage(box)}, nil
|
|
}
|
|
|
|
func withVault(t *testing.T, v *coreStandIn) {
|
|
t.Helper()
|
|
before := coreVault
|
|
coreVault = func(context.Context) coreAsk { return v.ask }
|
|
t.Cleanup(func() { coreVault = before })
|
|
}
|
|
|
|
func clientsBroker(resources []map[string]any) map[string]any {
|
|
for _, r := range resources {
|
|
if r["id"] == "mesh-provisioner-client.needs-"+broker.ProvisionerSecret {
|
|
return r
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func vaultSilence(t *testing.T, node string) (conditions.Condition, bool) {
|
|
t.Helper()
|
|
c, found, err := conditionsFrom.Get(t.Context(), vaultSilentObservation(node, coreBoxes{}).Key())
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
return c, found
|
|
}
|
|
|
|
// Issue 908: a machine at the vault-box contract, the vault silent, no kept box: nats is composed with the
|
|
// controller's own seal, never left out, and the vault-silent condition names it.
|
|
func TestReplay908(t *testing.T) {
|
|
key := "AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8="
|
|
core := map[string][]string{"nats": {"password"}}
|
|
ask := func(name, publicKey string) (coreAnswer, error) { return coreAnswer{}, errors.New("no responders") }
|
|
got := coreBoxesOf("novox", key, core, nil, true, ask)
|
|
if _, sealed := got.sealed["nats"]; sealed || len(got.notPlaced) != 0 {
|
|
t.Fatalf("nats is vault-sealed %v or not placed %v", got.sealed, got.notPlaced)
|
|
}
|
|
if !reflect.DeepEqual(got.byController, []string{"nats"}) {
|
|
t.Fatalf("nats is not left to the controller's seal: %+v", got)
|
|
}
|
|
o := vaultSilentObservation("novox", got)
|
|
if o.Severity != conditions.Warning || !strings.Contains(o.Summary, "sealed by the controller until the vault holds it: nats") {
|
|
t.Fatalf("the condition does not name nats: %+v", o)
|
|
}
|
|
// A kept box is still carried while the vault is silent.
|
|
kept := map[string]map[string]inventory.CoreBox{"nats": {"password": {SealedTo: key, Box: json.RawMessage(`{"v":1}`)}}}
|
|
got = coreBoxesOf("novox", key, core, kept, true, ask)
|
|
if string(got.sealed["nats"]["password"]) != `{"v":1}` || len(got.byController) != 0 {
|
|
t.Fatalf("the kept box was not held: %+v", got)
|
|
}
|
|
}
|
|
|
|
// An engine below VaultBoxContract is sent the controller's own seal, as before, and the vault is not asked.
|
|
|
|
// Every question but a send reads the kept box and asks nothing; with none kept, a stand-in the next send asks for.
|
|
func TestOnlyASendAsksTheVault(t *testing.T) {
|
|
core := map[string][]string{"nats": {"broker"}}
|
|
key := aPublicKey(t)
|
|
kept := map[string]map[string]inventory.CoreBox{"nats": {"broker": {Module: "nats", Name: "broker",
|
|
Generation: 1, SealedTo: key, Box: json.RawMessage(`{"v":1}`)}}}
|
|
never := func(string, string) (coreAnswer, error) {
|
|
t.Fatal("the vault was asked by a question that is not a send")
|
|
return coreAnswer{}, nil
|
|
}
|
|
for _, allocating := range []bool{false} {
|
|
if got := coreBoxesOf("anchor", key, core, kept, allocating, never); string(got.sealed["nats"]["broker"]) != `{"v":1}` {
|
|
t.Errorf("read %s", got.sealed["nats"]["broker"])
|
|
}
|
|
if got := coreBoxesOf("anchor", key, core, nil, allocating, never); string(got.sealed["nats"]["broker"]) !=
|
|
string(catalogue.ForeseenVaultBox) {
|
|
t.Errorf("with none kept, read %s", got.sealed["nats"]["broker"])
|
|
}
|
|
}
|
|
// A box kept for another key of the machine is never carried.
|
|
other := coreBoxesOf("anchor", aPublicKey(t), core, kept, true,
|
|
func(string, string) (coreAnswer, error) { return coreAnswer{}, errors.New("silent") })
|
|
if _, vaultSealed := other.sealed["nats"]; vaultSealed || !reflect.DeepEqual(other.byController, []string{"nats"}) {
|
|
t.Fatalf("a box sealed to the machine's old key was carried: %+v", other)
|
|
}
|
|
}
|
|
|
|
// The core's modules on a machine: on the list, not handed, with their own secrets but one issued outside.
|
|
func TestTheCoresModulesAreTheListsWithTheirOwnSecrets(t *testing.T) {
|
|
modules := []catalogue.Manifest{
|
|
{Module: "nats", OwnSecrets: catalogue.OwnSecrets{"broker": {Path: "/a"}, "given": {Path: "/b",
|
|
IssuedBy: catalogue.IssuedOutside}}},
|
|
{Module: "postgres", OwnSecrets: catalogue.OwnSecrets{"superuser": {Path: "/c"}}},
|
|
{Module: "mesh-provisioner", OwnSecrets: catalogue.OwnSecrets{"broker": {Path: "/d"}}},
|
|
}
|
|
got := coreModulesOf(modules, func(m catalogue.Manifest) bool { return m.Module == "mesh-provisioner" })
|
|
if want := map[string][]string{"nats": {"broker"}}; !reflect.DeepEqual(got, want) {
|
|
t.Fatalf("got %v, want %v", got, want)
|
|
}
|
|
}
|