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.
130 lines
4.8 KiB
Go
130 lines
4.8 KiB
Go
//go:build integration
|
|
|
|
package main
|
|
|
|
import (
|
|
"encoding/json"
|
|
"errors"
|
|
"reflect"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
|
|
"git.novox.be/novox/mesh-sdk/go/catalogue"
|
|
"github.com/novox/mesh-controller/internal/broker"
|
|
"github.com/novox/mesh-controller/internal/inventory"
|
|
"github.com/novox/mesh-controller/internal/link"
|
|
)
|
|
|
|
func aCoreMesh(t *testing.T, contract int) (*stores, *coreStandIn) {
|
|
t.Helper()
|
|
open := aMesh(t)
|
|
ctx := t.Context()
|
|
client := aClientModule()
|
|
register(t, open, client)
|
|
if _, err := assign(ctx, open, "laptop", client.Module); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := issueProvisionerClient(ctx, open.inventory, client, "laptop", broker.Broker{Fingerprint: "ab"},
|
|
"10.0.0.1:4222"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if _, err := open.inventory.RecordHealth(ctx, inventory.NodeHealth{Node: "laptop", Contract: contract,
|
|
SaidAt: time.Now()}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
v := &coreStandIn{generation: 1}
|
|
withVault(t, v)
|
|
return open, v
|
|
}
|
|
|
|
func TestTheSendCarriesTheVaultsBoxForACoreCredentialAndKeepsIt(t *testing.T) {
|
|
open, vault := aCoreMesh(t, link.VaultBoxContract)
|
|
key, err := open.inventory.SealingKeyOf(t.Context(), "laptop")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
f := clientsBroker(sentTo(t, open, "laptop"))
|
|
if f == nil || f["sealed"] != nil || f[catalogue.VaultSealedField] == nil {
|
|
t.Fatalf("the core credential is sent as %v: the vault's box, never the controller's seal", f)
|
|
}
|
|
if want := []string{"own/laptop/mesh-provisioner-client/" + broker.ProvisionerSecret}; !reflect.DeepEqual(vault.asked, want) {
|
|
t.Fatalf("the vault was asked %v", vault.asked)
|
|
}
|
|
if want, _ := sealingKeyPEM(key); vault.keys[0] != want {
|
|
t.Fatalf("the vault was asked to seal to %q, not the machine's key", vault.keys[0])
|
|
}
|
|
first, _ := json.Marshal(f[catalogue.VaultSealedField])
|
|
|
|
// The vault answers afresh with the same generation: the kept box is carried again, so the declaration is stable.
|
|
again, _ := json.Marshal(clientsBroker(sentTo(t, open, "laptop"))[catalogue.VaultSealedField])
|
|
if string(again) != string(first) {
|
|
t.Fatalf("a fresh box of the same generation changed the declaration: %s, then %s", first, again)
|
|
}
|
|
// A rotation in the vault (a newer generation) is carried.
|
|
vault.generation = 2
|
|
rotated, _ := json.Marshal(clientsBroker(sentTo(t, open, "laptop"))[catalogue.VaultSealedField])
|
|
if string(rotated) == string(first) {
|
|
t.Fatal("a newer generation was not carried")
|
|
}
|
|
if _, found := vaultSilence(t, "laptop"); found {
|
|
t.Fatal("a send the vault answered raised its silence")
|
|
}
|
|
}
|
|
|
|
func TestASilentVaultHoldsTheKeptBoxAndSaysSo(t *testing.T) {
|
|
open, vault := aCoreMesh(t, link.VaultBoxContract)
|
|
first, _ := json.Marshal(clientsBroker(sentTo(t, open, "laptop"))[catalogue.VaultSealedField])
|
|
vault.silent = errors.New("no responders")
|
|
held := clientsBroker(sentTo(t, open, "laptop"))
|
|
got, _ := json.Marshal(held[catalogue.VaultSealedField])
|
|
if held == nil || held["sealed"] != nil || string(got) != string(first) {
|
|
t.Fatalf("a silent vault's credential is sent as %v: the box kept, never the controller's seal", held)
|
|
}
|
|
c, found := vaultSilence(t, "laptop")
|
|
if !found || !strings.Contains(c.Summary, "vault") || !strings.Contains(c.Summary, "laptop") {
|
|
t.Fatalf("no condition names the vault and the machine: %+v", c)
|
|
}
|
|
// The vault answers again: the condition clears.
|
|
vault.silent = nil
|
|
sentTo(t, open, "laptop")
|
|
if _, found := vaultSilence(t, "laptop"); found {
|
|
t.Fatal("the condition stayed after the vault answered")
|
|
}
|
|
}
|
|
|
|
func TestACoreModuleFirstPlacedWhileTheVaultIsSilentIsSealedByTheController(t *testing.T) {
|
|
open, vault := aCoreMesh(t, link.VaultBoxContract)
|
|
vault.silent = errors.New("no responders")
|
|
plan, settings, err := resolveNode(t.Context(), open, "laptop")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
declared, err := declarationFor(t.Context(), open, "laptop", plan, settings)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
f := clientsBroker(declared.Resources)
|
|
if f == nil || f["sealed"] == nil || f[catalogue.VaultSealedField] != nil {
|
|
t.Fatalf("the core credential is composed as %v: the controller's own seal, until the vault holds it", f)
|
|
}
|
|
if why, left := declared.leftOutWhy["mesh-provisioner-client"]; left {
|
|
t.Fatalf("the core module was left out: %v", why)
|
|
}
|
|
c, found := vaultSilence(t, "laptop")
|
|
if !found || !strings.Contains(c.Summary, "sealed by the controller until the vault holds it") {
|
|
t.Fatalf("the condition does not say why: %+v", c)
|
|
}
|
|
}
|
|
|
|
func TestAnEngineBelowTheContractIsSentTheControllersSealAsBefore(t *testing.T) {
|
|
open, vault := aCoreMesh(t, link.HandedContract)
|
|
f := clientsBroker(sentTo(t, open, "laptop"))
|
|
if f == nil || f["sealed"] == nil || f[catalogue.VaultSealedField] != nil {
|
|
t.Fatalf("an older engine is sent %v", f)
|
|
}
|
|
if len(vault.asked) != 0 {
|
|
t.Fatalf("the vault was asked %v for an older engine", vault.asked)
|
|
}
|
|
}
|