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.
169 lines
7.2 KiB
Go
169 lines
7.2 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
|
|
"git.novox.be/novox/mesh-sdk/go/catalogue"
|
|
"git.novox.be/novox/mesh-sdk/go/overlay"
|
|
"github.com/novox/mesh-controller/internal/inventory"
|
|
)
|
|
|
|
// novox/hq issue 259, ADR 0221: a push that did not name a machine does not send it a build its
|
|
// upgrade policy records rather than rolls out, nor one an open plan has not sent it yet. Anything
|
|
// else that moved is still a consequence the push sends (ADR 0083).
|
|
func TestAHeldBuildHoldsAMachineANamedPushDidNotName(t *testing.T) {
|
|
current := map[string]inventory.CurrentBuild{
|
|
"resolver": {Commit: "c2c2c2c2c2"},
|
|
"agent": {Commit: "a2", RollOut: true},
|
|
"network": {},
|
|
}
|
|
modules := []string{"network", "resolver", "agent"}
|
|
sent := map[string]string{"network": "", "resolver": "c1c1c1c1c1", "agent": "a2"}
|
|
|
|
// A module whose policy records moved: held, naming it, both builds and why.
|
|
why := heldBack("laptop", modules, sent, true, current, nil)
|
|
if len(why) != 1 || !strings.Contains(why[0], "resolver would move from c1c1c1c1 to c2c2c2c2") ||
|
|
!strings.Contains(why[0], "upgrade policy records") {
|
|
t.Fatalf("a recorded upgrade did not hold the machine: %v", why)
|
|
}
|
|
|
|
// Nothing moved — what differs is a grant, a peer, a setting: not held (issue 057).
|
|
sent["resolver"] = "c2c2c2c2c2"
|
|
if why := heldBack("laptop", modules, sent, true, current, nil); len(why) != 0 {
|
|
t.Fatalf("a machine whose builds are all current was held: %v", why)
|
|
}
|
|
|
|
// A module whose policy rolls out moved, and no plan holds it: sent, as before.
|
|
sent["agent"] = "a1"
|
|
if why := heldBack("laptop", modules, sent, true, current, nil); len(why) != 0 {
|
|
t.Fatalf("a rolled-out upgrade no plan holds was held: %v", why)
|
|
}
|
|
|
|
// The last send's builds are not known: held whole.
|
|
if why := heldBack("laptop", modules, nil, false, current, nil); len(why) != 1 ||
|
|
!strings.Contains(why[0], "not known") {
|
|
t.Fatalf("a machine whose last send was not recorded was not held: %v", why)
|
|
}
|
|
|
|
// A module the machine was never sent, under a recording policy: held, and said so.
|
|
delete(sent, "resolver")
|
|
sent["agent"] = "a2"
|
|
if why := heldBack("laptop", modules, sent, true, current, nil); len(why) != 1 ||
|
|
!strings.Contains(why[0], "resolver would move (never sent it) to c2c2c2c2") {
|
|
t.Fatalf("a module never sent under a recording policy: %v", why)
|
|
}
|
|
}
|
|
|
|
// ADR 0218 meets ADR 0083: a plan waiting on its first machine has not sent the rest, and a push
|
|
// naming some other machine must not send them for it.
|
|
func TestAPlanWaitingOnItsFirstMachineHoldsTheRest(t *testing.T) {
|
|
at := time.Now()
|
|
current := map[string]inventory.CurrentBuild{"agent": {Commit: "a2", RollOut: true}}
|
|
sent := map[string]string{"agent": "a1"}
|
|
waiting := []inventory.Plan{{ID: "plan-7", State: inventory.PlanRolling, Modules: map[string]*inventory.PlanModule{
|
|
"agent": {State: "built", First: []string{"ace"}, FirstAt: &at}}}}
|
|
|
|
why := heldBack("g14", []string{"agent"}, sent, true, current, waiting)
|
|
if len(why) != 1 || !strings.Contains(why[0], "plan-7 has not sent it yet") {
|
|
t.Fatalf("a machine the plan has not reached was not held: %v", why)
|
|
}
|
|
// The first machine itself was sent by the plan: not held by it.
|
|
if why := heldBack("ace", []string{"agent"}, sent, true, current, waiting); len(why) != 0 {
|
|
t.Fatalf("the plan's first machine was held: %v", why)
|
|
}
|
|
// Built but not yet sent anywhere, or not yet built: the plan has it still to send.
|
|
for what, s := range map[string]*inventory.PlanModule{"built, unsent": {State: "built"}, "unasked": nil} {
|
|
plans := []inventory.Plan{{ID: "plan-8", State: inventory.PlanBuilding,
|
|
Modules: map[string]*inventory.PlanModule{"agent": s}}}
|
|
if why := heldBack("ace", []string{"agent"}, sent, true, current, plans); len(why) != 1 {
|
|
t.Errorf("%s: not held: %v", what, why)
|
|
}
|
|
}
|
|
// Sent everywhere, failed, or a plan no longer open: the plan holds nothing back.
|
|
for what, plans := range map[string][]inventory.Plan{
|
|
"sent everywhere": {{ID: "p", State: inventory.PlanRolling, Modules: map[string]*inventory.PlanModule{
|
|
"agent": {State: "built", First: []string{"ace"}, FirstAt: &at, SentAt: &at}}}},
|
|
"failed": {{ID: "p", State: inventory.PlanRolling, Modules: map[string]*inventory.PlanModule{
|
|
"agent": {State: "failed"}}}},
|
|
"closed": {{ID: "p", State: inventory.PlanDone, Modules: map[string]*inventory.PlanModule{
|
|
"agent": {State: "built"}}}},
|
|
} {
|
|
if why := heldBack("g14", []string{"agent"}, sent, true, current, plans); len(why) != 0 {
|
|
t.Errorf("%s: held: %v", what, why)
|
|
}
|
|
}
|
|
}
|
|
|
|
// recordedDelivery sends nothing and records each send as the mesh does, so the next comparison
|
|
// reads the machine as current — and writes down which machines it declared.
|
|
type recordedDelivery struct {
|
|
inv *inventory.Inventory
|
|
declared []string
|
|
}
|
|
|
|
func (r *recordedDelivery) grant(context.Context, []readyNode) error { return nil }
|
|
|
|
func (r *recordedDelivery) declare(ctx context.Context, s readyNode, body []byte) (string, error) {
|
|
r.declared = append(r.declared, s.node)
|
|
return recordSent(ctx, r.inv, s.node, body, s.declared.Builds, s.declared.Epoch, sentRecordOf(ctx, s.declared))
|
|
}
|
|
|
|
// aResolver is a module built from a repository, at a commit, with something on the machine that
|
|
// says which build it is.
|
|
func aResolver(t *testing.T, open *stores, commit string, asked time.Time) {
|
|
t.Helper()
|
|
m := catalogue.Manifest{Module: "resolver", Version: "1", Resources: []map[string]any{
|
|
{"id": "zones", "type": "file", "path": "/etc/resolver/zones", "content": "built from " + commit},
|
|
}}
|
|
if err := open.inventory.RegisterModule(t.Context(), m, inventory.Source{
|
|
Repository: "novox/mesh-catalog", Path: "modules/resolver", BuiltFrom: commit, Asked: asked}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
|
|
// A third machine on the private network: once it is sent, every other machine's peers change with
|
|
// it, which is a consequence a push must still send — no build moved.
|
|
func aThirdMachine(t *testing.T, open *stores) {
|
|
t.Helper()
|
|
ctx := t.Context()
|
|
record, err := open.inventory.AddNode(ctx, "spare")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := open.inventory.SetPlace(ctx, "spare", "spare.example:51820", "here", false, "10.77.0.3"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
reported, err := json.Marshal(map[string]any{"capabilities": []map[string]any{
|
|
{"name": "container-runtime", "present": true}, {"name": "wireguard", "present": true},
|
|
{"name": "systemd", "present": true}}})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
var profile map[string]any
|
|
if err := json.Unmarshal(reported, &profile); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := open.inventory.RecordProfile(ctx, record.ID, profile); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := open.inventory.RecordSealingKey(ctx, record.ID, aPublicKey(t)); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := open.inventory.RecordOverlayKey(ctx, record.ID, aPublicKey(t)); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if _, err := open.inventory.Assign(ctx, "spare", overlay.Name); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
|
|
// The issue as it happened, against the real stores: a change merged with the policy `record`, a push
|
|
// naming the anchor, and the laptop — running the same module — left with what it had, by name.
|
|
|
|
// Issue 057's case is unchanged: a machine whose builds are all current and whose declaration moved
|
|
// for another reason is sent by a push that names someone else.
|