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.
112 lines
5.6 KiB
Go
112 lines
5.6 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"reflect"
|
|
"strings"
|
|
"testing"
|
|
|
|
"git.novox.be/novox/mesh-sdk/go/catalogue"
|
|
"git.novox.be/novox/mesh-sdk/go/compose"
|
|
)
|
|
|
|
// A declaration as the SDK composes it is the one the controller sends, byte for byte, whatever it carries: the body is the
|
|
// envelope's only marshaller on either side (design 47 R4b, issue 1386).
|
|
func TestASendableIsTheComposedDeclarationByteForByte(t *testing.T) {
|
|
d := compose.Declared{
|
|
Resources: []map[string]any{{"id": "files.config", "type": "file"}, {"id": "mesh.hosts", "type": "file"}},
|
|
Sequence: 7, Epoch: 3, Generation: 9, ReadsModules: true,
|
|
ModuleOf: map[string]string{"files.config": "files"}, BuildIDs: map[string]string{"files": "b-1"},
|
|
Adoption: &compose.Adoption{Taken: []string{"files"}, Untaken: map[string][]string{"nats": {"nats.server"}}},
|
|
Filled: []string{"/etc/files/filled.json"}, Provisioner: "mesh-provisioner",
|
|
LeftOut: []string{"cache"}, LeftOutWhy: map[string]string{"cache": "a setting cannot compose"},
|
|
}
|
|
want, err := d.Body()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
got, err := sendableOf(d).Body()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if string(got) != string(want) {
|
|
t.Fatalf("the controller would send\n%s\nand the composition made\n%s", got, want)
|
|
}
|
|
if empty, err := sendableOf(compose.Declared{}).Body(); err != nil || !strings.Contains(string(empty), `"owns_nothing":true`) {
|
|
t.Fatalf("an empty declaration is not deliberate: %s %v", empty, err)
|
|
}
|
|
}
|
|
|
|
// 1386: what a send records as carried: the current build of each module it carries, the build a module left out of it was last
|
|
// sent (when that is known), and a module kept at the build the machine runs at that one. (The controller's carriedOn recorded
|
|
// the same; mesh-sdk's node_test TestAModuleLeftOutKeepsTheBuildItWasLastSent holds the left-out case.)
|
|
func TestWhatASendRecordsAsCarriedIsWhatTheControllerRecorded(t *testing.T) {
|
|
plan := catalogue.Resolution{Modules: []catalogue.Manifest{{Module: "postgres"}, {Module: "files"}, {Module: "cache"}}}
|
|
leftOut := map[string]string{"cache": "a setting cannot compose"}
|
|
for name, c := range map[string]struct {
|
|
sent map[string]string
|
|
known bool
|
|
kept map[string]string
|
|
want map[string]string
|
|
}{
|
|
"nothing sent": {want: map[string]string{"postgres": "p2", "files": "f2"}},
|
|
"sent and kept": {sent: map[string]string{"postgres": "p1", "cache": "c1", "files": "f1"}, known: true,
|
|
kept: map[string]string{"postgres": "p1"}, want: map[string]string{"postgres": "p1", "files": "f2", "cache": "c1"}},
|
|
"sent but not known": {sent: map[string]string{"cache": "c1"}, want: map[string]string{"postgres": "p2", "files": "f2"}},
|
|
"kept a module not in": {known: true, kept: map[string]string{"mail": "m1"}, want: map[string]string{"postgres": "p2", "files": "f2"}},
|
|
} {
|
|
in := compose.Input{CurrentBuilds: map[string]string{"postgres": "p2", "files": "f2", "cache": "c2"}}
|
|
node := compose.Node{SentBuilds: c.sent, SentKnown: c.known, KeptBuilds: c.kept}
|
|
if got := buildsOf(in, node, plan, leftOut); !reflect.DeepEqual(got, c.want) {
|
|
t.Errorf("%s: a send records %v, want %v", name, got, c.want)
|
|
}
|
|
}
|
|
}
|
|
|
|
// 1385: a declaration that stands in for a value anywhere is still foreseen, in a list the composition names or in the body
|
|
// alone (a pair credential's stand-in is in no list); one that stands in for nothing is not. It failed first, before the body
|
|
// was scanned.
|
|
func TestADeclarationThatStandsInForAValueIsStillForeseen(t *testing.T) {
|
|
clean := compose.Declared{Resources: []map[string]any{{"id": "files.config", "type": "file", "content": "ok"}}}
|
|
if left := stillForeseen(clean); len(left) != 0 {
|
|
t.Fatalf("a declaration that stands in for nothing is foreseen: %v", left)
|
|
}
|
|
for name, d := range map[string]compose.Declared{
|
|
"an own secret": {StoodIn: []string{"files/admin"}},
|
|
"a port": {ForeseenPorts: []string{"files:80"}},
|
|
"a core box": {CoreBoxesWanted: []compose.CoreBoxWanted{{Node: "anchor", Module: "mesh-vault", Name: "root"}}},
|
|
"a pass of a seat": {Passes: compose.Passes{Passes: []catalogue.SeatPass{{Seat: catalogue.Seat{Name: "mesh-store"}}}}},
|
|
"a pair credential": {Resources: []map[string]any{{"id": "files.needs-db", "sealed": catalogue.ForeseenSealed}}},
|
|
"the certificate": {Resources: []map[string]any{{"id": "proxy.cert", "content": compose.ForeseenCertificate}}},
|
|
"the bus's list": {Resources: []map[string]any{{"id": "nats.users", "content": compose.ForeseenBusUsers}}},
|
|
"the vault's box": {Resources: []map[string]any{{"id": "x", "box": catalogue.ForeseenVaultBox}}},
|
|
} {
|
|
if left := stillForeseen(d); len(left) == 0 {
|
|
t.Errorf("%s: a declaration that stands in for it is not foreseen", name)
|
|
}
|
|
}
|
|
}
|
|
|
|
// 1386: an Input read for a person's push is never the one read for a send that keeps recorded builds, and the cache is
|
|
// emptied by what a send made.
|
|
func TestAnInputIsCachedPerWhatItKeepsAndForgottenAfterASend(t *testing.T) {
|
|
ctx := withInputCache(context.Background())
|
|
plain := keptSignature(ctx)
|
|
kept := keptSignature(keepingRecorded(ctx))
|
|
bus := keptSignature(keepingRecorded(ctx, "nats"))
|
|
every := keptSignature(keepingEveryBuild(ctx, "anchor"))
|
|
for name, sig := range map[string]string{"a push": plain, "a kept send": kept, "the bus step": bus, "the grants step": every} {
|
|
for other, o := range map[string]string{"a push": plain, "a kept send": kept, "the bus step": bus, "the grants step": every} {
|
|
if name != other && sig == o {
|
|
t.Errorf("%s and %s read the same Input", name, other)
|
|
}
|
|
}
|
|
}
|
|
cache := ctx.Value(inputCacheKey{}).(*inputCache)
|
|
cache.by[plain] = &meshInput{}
|
|
forgetInput(ctx)
|
|
if len(cache.by) != 0 {
|
|
t.Fatal("what a send made left the Input it read in the cache")
|
|
}
|
|
}
|