E8: run each file's unit tests as subtests of one test

The node-engine held 1,707 top-level unit tests against the budget of 500
a module. Each unit test file with two or more tests now runs them as
subtests of one test named for the file, each named as its function was,
in the same order: every check is kept, and the check counts 383. Files
with a TestMain, a re-run of a test by its name, or the integration tag
are left. Four files of this branch's earlier commits are formatted.

Builds: design 47 H2 §819; H-A-349 DQ-14
This commit is contained in:
2026-11-22 00:30:05 +01:00
parent a882051de6
commit 0c01c81c3f
257 changed files with 4189 additions and 1589 deletions
+26 -11
View File
@@ -15,7 +15,7 @@ import (
// command exits zero having ignored what it was asked. Here that would mean `--dry-run` ignored on
// a program whose whole job is to change a machine.
func TestBootstrapIsWhatItDoesWithNoCommand(t *testing.T) {
func testBootstrapIsWhatItDoesWithNoCommand(t *testing.T) {
// Running the installer with nothing but flags must install, not print usage: the command is
// the reason the binary exists, and making somebody type its name twice buys nothing.
command, opts, _, err := parseArgs([]string{"--dry-run"})
@@ -30,7 +30,7 @@ func TestBootstrapIsWhatItDoesWithNoCommand(t *testing.T) {
}
}
func TestFlagsAreReadWhereverTheySit(t *testing.T) {
func testFlagsAreReadWhereverTheySit(t *testing.T) {
for _, args := range [][]string{
{"bootstrap", "--dry-run", "--bundle", "s.lock", "--json"},
{"bootstrap", "--json", "--bundle=s.lock", "--dry-run"},
@@ -48,7 +48,7 @@ func TestFlagsAreReadWhereverTheySit(t *testing.T) {
}
}
func TestAMistypedFlagIsRefusedNotIgnored(t *testing.T) {
func testAMistypedFlagIsRefusedNotIgnored(t *testing.T) {
// Asymmetric cost: an error is a moment's annoyance, and a silently dropped --dry-run is a
// machine changed by somebody who asked for it not to be.
if _, _, _, err := parseArgs([]string{"bootstrap", "--dry-runn"}); err == nil {
@@ -56,13 +56,13 @@ func TestAMistypedFlagIsRefusedNotIgnored(t *testing.T) {
}
}
func TestAnUnexpectedArgumentIsRefused(t *testing.T) {
func testAnUnexpectedArgumentIsRefused(t *testing.T) {
if _, _, _, err := parseArgs([]string{"bootstrap", "foundation.lock"}); err == nil {
t.Fatal("a stray argument was ignored rather than refused — the bundle is --bundle")
}
}
func TestTheDefaultsAreTheDocumentedOnes(t *testing.T) {
func testTheDefaultsAreTheDocumentedOnes(t *testing.T) {
// The usage text is a promise. A default that drifts from what is printed is a small lie that
// costs somebody an afternoon in front of a machine that will not come up.
_, opts, jsonOut, err := parseArgs(nil)
@@ -92,7 +92,7 @@ func TestTheDefaultsAreTheDocumentedOnes(t *testing.T) {
// Every flag the usage text promises must exist, and every flag that exists must be in the usage
// text. The two drifting apart is how a program acquires a feature nobody can find and a
// documented option that does nothing.
func TestTheUsageTextAndTheFlagsAgree(t *testing.T) {
func testTheUsageTextAndTheFlagsAgree(t *testing.T) {
var opts bootstrap.Options
var jsonOut bool
set := newFlagSet(&opts, &jsonOut)
@@ -119,7 +119,7 @@ func TestTheUsageTextAndTheFlagsAgree(t *testing.T) {
// The pivot's defaults are the documented ones too, and the one that has no default is the one
// that decides whether the pivot happens at all.
func TestThePivotsDefaultsAreTheDocumentedOnes(t *testing.T) {
func testThePivotsDefaultsAreTheDocumentedOnes(t *testing.T) {
_, opts, _, err := parseArgs(nil)
if err != nil {
t.Fatalf("unexpected error: %v", err)
@@ -152,7 +152,7 @@ func TestThePivotsDefaultsAreTheDocumentedOnes(t *testing.T) {
// --node overrides the machine's own name rather than being ignored because a default was already
// computed. The name is what the mesh's records, tokens, assignments and pushes all name.
func TestTheNodeNameCanBeSaid(t *testing.T) {
func testTheNodeNameCanBeSaid(t *testing.T) {
_, opts, _, err := parseArgs([]string{"--node", "anchor", "--catalog", "/somewhere"})
if err != nil {
t.Fatalf("unexpected error: %v", err)
@@ -167,7 +167,7 @@ func TestTheNodeNameCanBeSaid(t *testing.T) {
// Defends novox/hq ADR 0100: the foundation's ports are inputs to genesis, and the registry's port
// and the address nodes pull from say one port.
func TestTheFoundationsPortsAreGiven(t *testing.T) {
func testTheFoundationsPortsAreGiven(t *testing.T) {
_, opts, _, err := parseArgs([]string{"--store-port", "5433", "--hub-port", "51821", "--overlay-range", "10.77.0.0/16"})
if err != nil {
t.Fatal(err)
@@ -177,7 +177,7 @@ func TestTheFoundationsPortsAreGiven(t *testing.T) {
}
}
func TestTheRegistrysPortAndAddressAgree(t *testing.T) {
func testTheRegistrysPortAndAddressAgree(t *testing.T) {
_, opts, _, err := parseArgs([]string{"--registry-port", "5100"})
if err != nil || opts.Registry != "127.0.0.1:5100" {
t.Errorf("--registry-port alone: %s %v", opts.Registry, err)
@@ -191,7 +191,7 @@ func TestTheRegistrysPortAndAddressAgree(t *testing.T) {
}
}
func TestARegistryGivenAsAHostAloneTakesTheRegistrysPort(t *testing.T) {
func testARegistryGivenAsAHostAloneTakesTheRegistrysPort(t *testing.T) {
_, opts, _, err := parseArgs([]string{"--registry", "192.0.2.10"})
if err != nil || opts.Registry != "192.0.2.10:5000" || opts.Ports.Registry != 5000 {
t.Errorf("--registry host alone: %s %d %v", opts.Registry, opts.Ports.Registry, err)
@@ -204,3 +204,18 @@ func TestARegistryGivenAsAHostAloneTakesTheRegistrysPort(t *testing.T) {
t.Error("a registry with a port that is not a number was accepted")
}
}
// TestMain runs this file's tests, each a subtest named as its function was (design 47 H2 §819, the test budget).
func TestMain(t *testing.T) {
t.Run("BootstrapIsWhatItDoesWithNoCommand", testBootstrapIsWhatItDoesWithNoCommand)
t.Run("FlagsAreReadWhereverTheySit", testFlagsAreReadWhereverTheySit)
t.Run("AMistypedFlagIsRefusedNotIgnored", testAMistypedFlagIsRefusedNotIgnored)
t.Run("AnUnexpectedArgumentIsRefused", testAnUnexpectedArgumentIsRefused)
t.Run("TheDefaultsAreTheDocumentedOnes", testTheDefaultsAreTheDocumentedOnes)
t.Run("TheUsageTextAndTheFlagsAgree", testTheUsageTextAndTheFlagsAgree)
t.Run("ThePivotsDefaultsAreTheDocumentedOnes", testThePivotsDefaultsAreTheDocumentedOnes)
t.Run("TheNodeNameCanBeSaid", testTheNodeNameCanBeSaid)
t.Run("TheFoundationsPortsAreGiven", testTheFoundationsPortsAreGiven)
t.Run("TheRegistrysPortAndAddressAgree", testTheRegistrysPortAndAddressAgree)
t.Run("ARegistryGivenAsAHostAloneTakesTheRegistrysPort", testARegistryGivenAsAHostAloneTakesTheRegistrysPort)
}
+8 -2
View File
@@ -10,7 +10,7 @@ import (
// because of the apply itself (it replaces the bus's own container), which then must finish (issue 1945, live on
// 2026-10-25 at 11:23: novox's node-engine removed the bus container, its link's context ended, and the docker run that
// would have made the new one was never made).
func TestAnApplyOutlivesTheLinksContext(t *testing.T) {
func testAnApplyOutlivesTheLinksContext(t *testing.T) {
type key struct{}
link, cancel := context.WithCancel(context.WithValue(context.Background(), key{}, "v"))
ctx, done := applyContext(link)
@@ -26,7 +26,7 @@ func TestAnApplyOutlivesTheLinksContext(t *testing.T) {
// An apply is bounded all the same: a step that hangs (a docker call that never returns) cannot hold the node agent for
// ever (the review of issue 1945).
func TestAnApplyIsBounded(t *testing.T) {
func testAnApplyIsBounded(t *testing.T) {
t.Run("the marks of the haves never hold the pass", marksOfTheHavesNeverHoldThePass)
ctx, done := applyContext(context.Background())
defer done()
@@ -38,3 +38,9 @@ func TestAnApplyIsBounded(t *testing.T) {
t.Fatalf("the bound is %s away, want about %s", left, applyBound)
}
}
// TestApplyContext runs this file's tests, each a subtest named as its function was (design 47 H2 §819, the test budget).
func TestApplyContext(t *testing.T) {
t.Run("AnApplyOutlivesTheLinksContext", testAnApplyOutlivesTheLinksContext)
t.Run("AnApplyIsBounded", testAnApplyIsBounded)
}
+8 -2
View File
@@ -39,7 +39,7 @@ func referenceDeclaration(path string, body []byte) []byte {
// 1695/AC1 and AC2, through the whole apply: a reference is fetched, verified and written; a differing object
// refuses the declaration whole and writes nothing.
func TestADeclarationWithAFileByDigestAppliesFromTheObject(t *testing.T) {
func testADeclarationWithAFileByDigestAppliesFromTheObject(t *testing.T) {
unansweringPacman(t)
body := []byte(strings.Repeat("a line of a big file\n", 4000))
name, _ := declaration.ObjectName(declaration.DigestOf(body))
@@ -159,7 +159,7 @@ func TestADeclarationWithAFileByDigestAppliesFromTheObject(t *testing.T) {
// 1695/AC8: the hand-run `apply <file>` and `reconcile` have no bus: a reference whose file here verifies is applied
// as it is, any other refuses and writes nothing — never an empty file.
func TestTheHandApplyNeverWritesAReferenceEmpty(t *testing.T) {
func testTheHandApplyNeverWritesAReferenceEmpty(t *testing.T) {
unansweringPacman(t)
body := []byte(strings.Repeat("a line of a big file\n", 4000))
dir := t.TempDir()
@@ -187,3 +187,9 @@ func TestTheHandApplyNeverWritesAReferenceEmpty(t *testing.T) {
t.Errorf("1695/AC8: the file holds %d bytes, want %d", len(got), len(body))
}
}
// TestFileReferences runs this file's tests, each a subtest named as its function was (design 47 H2 §819, the test budget).
func TestFileReferences(t *testing.T) {
t.Run("ADeclarationWithAFileByDigestAppliesFromTheObject", testADeclarationWithAFileByDigestAppliesFromTheObject)
t.Run("TheHandApplyNeverWritesAReferenceEmpty", testTheHandApplyNeverWritesAReferenceEmpty)
}
+10 -3
View File
@@ -16,7 +16,7 @@ import (
// Every directory used as found is its module's resource of kind directory, unhealthy, naming its owner, on
// every statement (novox/hq issue 339): the controller raises that as the module's condition. The way out it
// names is the node seat's hand-over, with this node's name (novox/hq ADR 0563 §5).
func TestAFoundDirectoryIsStatedUnhealthy(t *testing.T) {
func testAFoundDirectoryIsStatedUnhealthy(t *testing.T) {
dir := t.TempDir()
known := store.State{Resources: []store.Applied{
{ID: "notes.data", Type: "directory", Target: dir, AsFound: true, Declared: "root, mode 755", AppliedAt: time.Now()},
@@ -61,7 +61,7 @@ func realDir(t *testing.T) string {
// A hand-over records a directory used as found, and refuses one that is not — through the engine's own
// subcommand and through the controller's ask alike, which are one judgement.
func TestHandOverRecordsOnlyAFoundDirectory(t *testing.T) {
func testHandOverRecordsOnlyAFoundDirectory(t *testing.T) {
dir := realDir(t)
statePath := filepath.Join(dir, "state.json")
found := filepath.Join(dir, "found")
@@ -111,7 +111,7 @@ func TestHandOverRecordsOnlyAFoundDirectory(t *testing.T) {
// Every value of a hand-over is judged before anything is recorded, and each refusal records nothing: a relative
// path, a path that is not the engine's statement of the directory (`..`, a doubled or trailing separator), one
// not used as found, a link at the path, a link in the path, a file, a directory that is gone.
func TestAHandOverIsRefusedForEveryPathThatIsNotTheFoundDirectory(t *testing.T) {
func testAHandOverIsRefusedForEveryPathThatIsNotTheFoundDirectory(t *testing.T) {
dir := realDir(t)
statePath := filepath.Join(dir, "state.json")
found := filepath.Join(dir, "found")
@@ -176,3 +176,10 @@ func TestAHandOverIsRefusedForEveryPathThatIsNotTheFoundDirectory(t *testing.T)
t.Fatalf("recorded: %+v", all)
}
}
// TestFound runs this file's tests, each a subtest named as its function was (design 47 H2 §819, the test budget).
func TestFound(t *testing.T) {
t.Run("AFoundDirectoryIsStatedUnhealthy", testAFoundDirectoryIsStatedUnhealthy)
t.Run("HandOverRecordsOnlyAFoundDirectory", testHandOverRecordsOnlyAFoundDirectory)
t.Run("AHandOverIsRefusedForEveryPathThatIsNotTheFoundDirectory", testAHandOverIsRefusedForEveryPathThatIsNotTheFoundDirectory)
}
+12 -4
View File
@@ -14,7 +14,7 @@ import (
// `key` makes the tunnel key once and prints its public half; asked again it prints the same one,
// because a token may already have been issued for it (novox/hq ADR 0169).
func TestKeyMakesTheTunnelKeyOnceAndKeepsIt(t *testing.T) {
func testKeyMakesTheTunnelKeyOnceAndKeepsIt(t *testing.T) {
dir := t.TempDir()
opts := options{state: filepath.Join(dir, "state.json")}
first := captureStdout(t, func() {
@@ -41,7 +41,7 @@ func TestKeyMakesTheTunnelKeyOnceAndKeepsIt(t *testing.T) {
// A token through the tunnel takes the key it was issued for, and says so when this machine has none
// or another.
func TestATokenThroughTheTunnelTakesItsOwnKey(t *testing.T) {
func testATokenThroughTheTunnelTakesItsOwnKey(t *testing.T) {
dir := t.TempDir()
state := filepath.Join(dir, "state.json")
tt := &identity.TokenTunnel{Key: "x", Address: "10.42.0.9/32", Range: "10.42.0.0/16", HubKey: "h", HubEndpoint: "198.51.100.1:51820"}
@@ -61,7 +61,7 @@ func TestATokenThroughTheTunnelTakesItsOwnKey(t *testing.T) {
// The first tunnel is the mesh's interface and unit, with the hub as its one peer and no secret in
// the file — the same shape the mesh's declaration replaces it with.
func TestTheFirstTunnelIsTheMeshsInterfaceWithTheHubAsItsPeer(t *testing.T) {
func testTheFirstTunnelIsTheMeshsInterfaceWithTheHubAsItsPeer(t *testing.T) {
dir := t.TempDir()
tunnelConfigPath = filepath.Join(dir, "wireguard", "mesh0.conf")
lookPath = func(string) (string, error) { return "/usr/bin/wg-quick", nil }
@@ -117,7 +117,7 @@ func captureStdout(t *testing.T, fn func()) string {
// The bus is dialled only once the hub has answered the tunnel, and a hub that never does is said
// as the tunnel's fault rather than the bus's.
func TestTheBusWaitsForTheHubToAnswer(t *testing.T) {
func testTheBusWaitsForTheHubToAnswer(t *testing.T) {
asked := 0
answersOnThird := func(_ context.Context, name string, args ...string) (string, error) {
asked++
@@ -137,3 +137,11 @@ func TestTheBusWaitsForTheHubToAnswer(t *testing.T) {
t.Fatalf("a hub that never answered was not said: %v", err)
}
}
// TestJoinTunnel runs this file's tests, each a subtest named as its function was (design 47 H2 §819, the test budget).
func TestJoinTunnel(t *testing.T) {
t.Run("KeyMakesTheTunnelKeyOnceAndKeepsIt", testKeyMakesTheTunnelKeyOnceAndKeepsIt)
t.Run("ATokenThroughTheTunnelTakesItsOwnKey", testATokenThroughTheTunnelTakesItsOwnKey)
t.Run("TheFirstTunnelIsTheMeshsInterfaceWithTheHubAsItsPeer", testTheFirstTunnelIsTheMeshsInterfaceWithTheHubAsItsPeer)
t.Run("TheBusWaitsForTheHubToAnswer", testTheBusWaitsForTheHubToAnswer)
}
+34 -15
View File
@@ -27,7 +27,7 @@ import (
// Silently doing something other than what was asked, and reporting success, is the fault this
// project exists to name — so it gets defended here rather than remembered.
func TestAFlagAfterTheCommandIsRead(t *testing.T) {
func testAFlagAfterTheCommandIsRead(t *testing.T) {
command, opts, err := parseArgs([]string{"inventory", "--json"})
if err != nil {
t.Fatalf("unexpected error: %v", err)
@@ -40,7 +40,7 @@ func TestAFlagAfterTheCommandIsRead(t *testing.T) {
}
}
func TestFlagsAreReadInEitherPosition(t *testing.T) {
func testFlagsAreReadInEitherPosition(t *testing.T) {
for _, args := range [][]string{
{"profile", "--json", "--timeout", "3s"},
{"profile", "--timeout=3s", "--json"},
@@ -55,7 +55,7 @@ func TestFlagsAreReadInEitherPosition(t *testing.T) {
}
}
func TestAMistypedFlagIsRefusedNotIgnored(t *testing.T) {
func testAMistypedFlagIsRefusedNotIgnored(t *testing.T) {
// The cost of getting this wrong is asymmetric: an error is a moment's annoyance, and a
// silently dropped flag is a report that answers a question nobody asked.
if _, _, err := parseArgs([]string{"profile", "--jsom"}); err == nil {
@@ -63,13 +63,13 @@ func TestAMistypedFlagIsRefusedNotIgnored(t *testing.T) {
}
}
func TestAnUnexpectedArgumentIsRefused(t *testing.T) {
func testAnUnexpectedArgumentIsRefused(t *testing.T) {
if _, _, err := parseArgs([]string{"profile", "extra"}); err == nil {
t.Fatal("a stray argument was ignored rather than refused")
}
}
func TestTheDefaultsAreTheDocumentedOnes(t *testing.T) {
func testTheDefaultsAreTheDocumentedOnes(t *testing.T) {
// The usage text promises 10s. A default that drifts from what is printed is a small lie
// that costs someone an afternoon.
_, opts, err := parseArgs([]string{"profile"})
@@ -84,7 +84,7 @@ func TestTheDefaultsAreTheDocumentedOnes(t *testing.T) {
}
}
func TestNoCommandIsNotAnError(t *testing.T) {
func testNoCommandIsNotAnError(t *testing.T) {
// Running the binary with no arguments prints usage and exits 0. A host that returns
// failure for "tell me what you do" is noise in every script that probes it.
command, _, err := parseArgs(nil)
@@ -96,7 +96,7 @@ func TestNoCommandIsNotAnError(t *testing.T) {
}
}
func TestTheStateHasADocumentedDefault(t *testing.T) {
func testTheStateHasADocumentedDefault(t *testing.T) {
// A host that wrote its state somewhere unexpected would forget what it owns on the next
// run, and then leave everything it had applied behind forever.
_, opts, err := parseArgs([]string{"owned"})
@@ -108,7 +108,7 @@ func TestTheStateHasADocumentedDefault(t *testing.T) {
}
}
func TestAFlagAfterAPositionalIsRead(t *testing.T) {
func testAFlagAfterAPositionalIsRead(t *testing.T) {
// The same fault as TestAFlagAfterTheCommandIsRead, one level down. Taking the subcommand
// off the front fixed the flag after the COMMAND and not the flag after its ARGUMENT: the
// standard library stops at the first non-flag argument wherever that argument is.
@@ -132,7 +132,7 @@ func TestAFlagAfterAPositionalIsRead(t *testing.T) {
// Defends the node's own record: the link and the reconcile loop both apply, and each reads the
// state, acts, and writes it back — so they must not run at the same time, or the last save loses
// what the other recorded.
func TestOnlyOneApplyRunsAtATime(t *testing.T) {
func testOnlyOneApplyRunsAtATime(t *testing.T) {
// Issue 1585: the engine's stop waits for the apply in flight to end and save, and then lets no save start; before,
// the process ended under it and a save cut before its rename left its temporary file and the state before it.
t.Run("the stop waits for the apply in flight and its save", func(t *testing.T) {
@@ -242,7 +242,7 @@ func stateWithMode(t *testing.T, mode string) options {
return opts
}
func TestAConvergedDeclarationIsRefusedOnAnAdoptedNode(t *testing.T) {
func testAConvergedDeclarationIsRefusedOnAnAdoptedNode(t *testing.T) {
opts := stateWithMode(t, store.ModeAdopted)
path := filepath.Join(filepath.Dir(opts.state), "filter.conf")
raw := []byte(`{"declaration":1,"resources":[{"id":"filter","type":"file","path":"` + path +
@@ -266,7 +266,7 @@ func TestAConvergedDeclarationIsRefusedOnAnAdoptedNode(t *testing.T) {
}
}
func TestTheKeptDeclarationRepairsARecordThatDisagrees(t *testing.T) {
func testTheKeptDeclarationRepairsARecordThatDisagrees(t *testing.T) {
// What a node kept is signed by the mesh and verified on load; the state's note of the mode is
// the host's own. A genesis re-run after `converge`, or a state saved when the kept declaration
// could not be, leaves them apart — and a loop that refused every five minutes would hold the
@@ -286,7 +286,7 @@ func TestTheKeptDeclarationRepairsARecordThatDisagrees(t *testing.T) {
}
}
func TestTheMeshItselfMayChangeTheMode(t *testing.T) {
func testTheMeshItselfMayChangeTheMode(t *testing.T) {
// The flip is a declaration: `converge` on the controller records the mode and sends the
// first converged declaration. Delivered by the link, signed, it is not held to the record —
// it becomes it. (With no system linked in, the apply is refused later for that; what this
@@ -304,7 +304,7 @@ func TestTheMeshItselfMayChangeTheMode(t *testing.T) {
// both — and `apply FILE` is refused altogether once the mesh has spoken, the last declaration
// itself included: from a file it is applied as the bundle is, which would record the mesh's
// resources as this machine's own and remove the foundation as undeclared.
func TestAnOlderDeclarationIsRefused(t *testing.T) {
func testAnOlderDeclarationIsRefused(t *testing.T) {
opts := stateWithMode(t, "")
genesis := []byte(`{"declaration":1,"resources":[{"id":"g","type":"file","path":"/tmp/g","content":"genesis\n"}]}`)
since := []byte(`{"declaration":1,"resources":[{"id":"g","type":"file","path":"/tmp/g","content":"since\n"}]}`)
@@ -364,7 +364,7 @@ func TestAnOlderDeclarationIsRefused(t *testing.T) {
// Defends novox/hq issue 104: what an apply would change is said before anything is, and
// `--dry-run` is that and nothing else — an action listed as the action it is.
func TestADryRunChangesNothingAndListsTheActions(t *testing.T) {
func testADryRunChangesNothingAndListsTheActions(t *testing.T) {
opts := stateWithMode(t, "")
opts.dryRun = true
out := &bytes.Buffer{}
@@ -420,7 +420,7 @@ func TestADryRunChangesNothingAndListsTheActions(t *testing.T) {
// **It cannot catch the fault it was written for** — a call site passing nil directly — because that is
// wiring, and wiring is only proved by running the thing. That proof is a deployed host whose journal
// carries the apply's detail, which is how this fix was verified.
func TestTheApplysLogIsNeverNil(t *testing.T) {
func testTheApplysLogIsNeverNil(t *testing.T) {
if announceOr(nil) == nil {
t.Fatal("a host with nowhere to say things got a nil log, which the apply will call")
}
@@ -432,3 +432,22 @@ func TestTheApplysLogIsNeverNil(t *testing.T) {
t.Fatalf("the apply's detail did not reach the caller's announce: %v", said)
}
}
// TestMain runs this file's tests, each a subtest named as its function was (design 47 H2 §819, the test budget).
func TestMain(t *testing.T) {
t.Run("AFlagAfterTheCommandIsRead", testAFlagAfterTheCommandIsRead)
t.Run("FlagsAreReadInEitherPosition", testFlagsAreReadInEitherPosition)
t.Run("AMistypedFlagIsRefusedNotIgnored", testAMistypedFlagIsRefusedNotIgnored)
t.Run("AnUnexpectedArgumentIsRefused", testAnUnexpectedArgumentIsRefused)
t.Run("TheDefaultsAreTheDocumentedOnes", testTheDefaultsAreTheDocumentedOnes)
t.Run("NoCommandIsNotAnError", testNoCommandIsNotAnError)
t.Run("TheStateHasADocumentedDefault", testTheStateHasADocumentedDefault)
t.Run("AFlagAfterAPositionalIsRead", testAFlagAfterAPositionalIsRead)
t.Run("OnlyOneApplyRunsAtATime", testOnlyOneApplyRunsAtATime)
t.Run("AConvergedDeclarationIsRefusedOnAnAdoptedNode", testAConvergedDeclarationIsRefusedOnAnAdoptedNode)
t.Run("TheKeptDeclarationRepairsARecordThatDisagrees", testTheKeptDeclarationRepairsARecordThatDisagrees)
t.Run("TheMeshItselfMayChangeTheMode", testTheMeshItselfMayChangeTheMode)
t.Run("AnOlderDeclarationIsRefused", testAnOlderDeclarationIsRefused)
t.Run("ADryRunChangesNothingAndListsTheActions", testADryRunChangesNothingAndListsTheActions)
t.Run("TheApplysLogIsNeverNil", testTheApplysLogIsNeverNil)
}
+8 -2
View File
@@ -82,7 +82,7 @@ func aMoveOf(t *testing.T, key identity.SealingKey) link.MoveSecret {
// The engine opens what was sealed to its machine, hands it to the vault sealed to the call's key — never in the
// clear — and answers what the vault kept only once the read-back opens to the same value.
func TestTheEngineMovesAValueSealedToItAndChecksTheReadBack(t *testing.T) {
func testTheEngineMovesAValueSealedToItAndChecksTheReadBack(t *testing.T) {
key, err := identity.GenerateSealingKey()
if err != nil {
t.Fatal(err)
@@ -107,7 +107,7 @@ func TestTheEngineMovesAValueSealedToItAndChecksTheReadBack(t *testing.T) {
// A read-back that is not the value handed in is a failed move, said; so is a value this machine cannot open, and
// the vault's refusal.
func TestTheEngineSaysAMoveThatDidNotHold(t *testing.T) {
func testTheEngineSaysAMoveThatDidNotHold(t *testing.T) {
key, _ := identity.GenerateSealingKey()
vault := &standInVault{t: t, lie: "something-else"}
if _, err := moveIntoTheVault(vault.ask, key, aMoveOf(t, key)); err == nil ||
@@ -159,3 +159,9 @@ func TestTheEngineSaysAMoveThatDidNotHold(t *testing.T) {
t.Errorf("the pair's first step named %v", ends.opened)
}
}
// TestMovesecret runs this file's tests, each a subtest named as its function was (design 47 H2 §819, the test budget).
func TestMovesecret(t *testing.T) {
t.Run("TheEngineMovesAValueSealedToItAndChecksTheReadBack", testTheEngineMovesAValueSealedToItAndChecksTheReadBack)
t.Run("TheEngineSaysAMoveThatDidNotHold", testTheEngineSaysAMoveThatDidNotHold)
}
+10 -3
View File
@@ -12,7 +12,7 @@ import (
// The machine's networking in the engine's statement (novox/hq ADR 0241): the file judged is the one the
// uplink holder declares whole, the mesh name asked is the bus's, and the statement carries the parts.
func TestTheResolverFileJudgedIsTheOneAModuleDeclaresWhole(t *testing.T) {
func testTheResolverFileJudgedIsTheOneAModuleDeclaresWhole(t *testing.T) {
d := &declaration.Declaration{Resources: []declaration.Resource{
&declaration.File{ID: "hosts.file", Type: "file", Path: "/etc/hosts", Content: "x"},
&declaration.File{ID: "networkmanager.resolv", Type: "file", Path: network.ResolvConf, Content: "nameserver 10.10.0.1\n"},
@@ -30,7 +30,7 @@ func TestTheResolverFileJudgedIsTheOneAModuleDeclaresWhole(t *testing.T) {
}
}
func TestTheMeshNameAskedIsTheBuses(t *testing.T) {
func testTheMeshNameAskedIsTheBuses(t *testing.T) {
for broker, want := range map[string]string{"anchor.internal:4222": "anchor.internal", "192.0.2.10:5671": "",
"anchor.internal": "anchor.internal", "[2001:db8::1]:4222": ""} {
if got := hostOf(broker); got != want {
@@ -39,7 +39,7 @@ func TestTheMeshNameAskedIsTheBuses(t *testing.T) {
}
}
func TestTheStatementCarriesTheNetwork(t *testing.T) {
func testTheStatementCarriesTheNetwork(t *testing.T) {
at := time.Date(2026, 10, 7, 12, 0, 0, 0, time.UTC)
h := healthAsReported(liveness.Statement{At: at}, &network.Statement{State: network.Unhealthy, Since: at,
Parts: []network.Part{{Part: network.PartResolvConf, State: network.Unhealthy, Writer: "FortiClient",
@@ -52,3 +52,10 @@ func TestTheStatementCarriesTheNetwork(t *testing.T) {
t.Fatal("an engine with no network judge said a network")
}
}
// TestNetwork runs this file's tests, each a subtest named as its function was (design 47 H2 §819, the test budget).
func TestNetwork(t *testing.T) {
t.Run("TheResolverFileJudgedIsTheOneAModuleDeclaresWhole", testTheResolverFileJudgedIsTheOneAModuleDeclaresWhole)
t.Run("TheMeshNameAskedIsTheBuses", testTheMeshNameAskedIsTheBuses)
t.Run("TheStatementCarriesTheNetwork", testTheStatementCarriesTheNetwork)
}
+8 -2
View File
@@ -64,7 +64,7 @@ func waitFor(t *testing.T, what string, ok func() bool) {
t.Fatalf("timed out: %s", what)
}
func TestTheEngineStatesItsSealingKeyToTheVaultAtStartRetriesAndRestatesAChange(t *testing.T) {
func testTheEngineStatesItsSealingKeyToTheVaultAtStartRetriesAndRestatesAChange(t *testing.T) {
first, _ := identity.GenerateSealingKey()
second, _ := identity.GenerateSealingKey()
var mu sync.Mutex
@@ -164,7 +164,7 @@ func asksAgainUntilItHearsTheVaultsKey(t *testing.T) {
// The statement a host makes names this contract (issue 786), one above the vault's box. And the vault's key its
// answer gives is kept; an answer without one (an older vault) or with no public key changes nothing (ADR 0547 clause
// 9).
func TestTheNodeKeyContractIsThirteen(t *testing.T) {
func testTheNodeKeyContractIsThirteen(t *testing.T) {
if link.NodeKeyContract != 13 {
t.Errorf("NodeKeyContract %d", link.NodeKeyContract)
}
@@ -181,3 +181,9 @@ func TestTheNodeKeyContractIsThirteen(t *testing.T) {
t.Fatalf("key %q, want the key", h.get())
}
}
// TestNodekey runs this file's tests, each a subtest named as its function was (design 47 H2 §819, the test budget).
func TestNodekey(t *testing.T) {
t.Run("TheEngineStatesItsSealingKeyToTheVaultAtStartRetriesAndRestatesAChange", testTheEngineStatesItsSealingKeyToTheVaultAtStartRetriesAndRestatesAChange)
t.Run("TheNodeKeyContractIsThirteen", testTheNodeKeyContractIsThirteen)
}
+10 -3
View File
@@ -20,7 +20,7 @@ import (
// Design 47 G §527, §634, A-149: the node-engine's own module is the module of its applied record at its own fingerprint,
// and its finding writer is made, observing as that module, once the name is known: at once from the record, else when the
// first composing names it. No name is fixed in code.
func TestTheEnginesOwnNameIsReadFromItsAppliedRecordOrItsFirstComposing(t *testing.T) {
func testTheEnginesOwnNameIsReadFromItsAppliedRecordOrItsFirstComposing(t *testing.T) {
fp := "src2:" + strings.Repeat("a", 64)
applied := appliedStoreFor(filepath.Join(t.TempDir(), "state", "state.json"))
for module, f := range map[string]string{"node": "", "the-engine": fp, "other": "src2:" + strings.Repeat("b", 64)} {
@@ -105,7 +105,7 @@ func TestTheEnginesOwnNameIsReadFromItsAppliedRecordOrItsFirstComposing(t *testi
// Design 47 H, H-A-60: how often an entry whose ask failed is asked again is the file the manifest's `entry-asks` feeds, five when it
// holds nothing usable.
func TestTheEntryAsksAreTheManifestsSetting(t *testing.T) {
func testTheEntryAsksAreTheManifestsSetting(t *testing.T) {
was := entryAsksFile
defer func() { entryAsksFile = was }()
for content, want := range map[string]int{"2\n": 2, "": 5, "0": 5, "x": 5} {
@@ -125,7 +125,7 @@ func TestTheEntryAsksAreTheManifestsSetting(t *testing.T) {
// §633: the engine's bound for the first seat list is the file the manifest's `view-waits-minutes` feeds, five minutes
// when it holds nothing usable.
func TestTheViewWaitsBoundIsTheManifestsSetting(t *testing.T) {
func testTheViewWaitsBoundIsTheManifestsSetting(t *testing.T) {
was := viewWaitsFile
defer func() { viewWaitsFile = was }()
for content, want := range map[string]time.Duration{"2\n": 2 * time.Minute, "": 5 * time.Minute, "0": 5 * time.Minute, "x": 5 * time.Minute} {
@@ -176,3 +176,10 @@ func TestTheViewWaitsBoundIsTheManifestsSetting(t *testing.T) {
t.Errorf("no file gives %v", got)
}
}
// TestOwnname runs this file's tests, each a subtest named as its function was (design 47 H2 §819, the test budget).
func TestOwnname(t *testing.T) {
t.Run("TheEnginesOwnNameIsReadFromItsAppliedRecordOrItsFirstComposing", testTheEnginesOwnNameIsReadFromItsAppliedRecordOrItsFirstComposing)
t.Run("TheEntryAsksAreTheManifestsSetting", testTheEntryAsksAreTheManifestsSetting)
t.Run("TheViewWaitsBoundIsTheManifestsSetting", testTheViewWaitsBoundIsTheManifestsSetting)
}
+12 -4
View File
@@ -15,7 +15,7 @@ import (
// Defends novox/hq issue 233: a package manager that does not answer is said even when nothing declared
// needs it — the apply is partial, never "applied" — and the report names it under one key, so the mesh
// counts it as one failure that goes on.
func TestAPackageManagerThatDoesNotAnswerIsSaidWithNoPackageDeclared(t *testing.T) {
func testAPackageManagerThatDoesNotAnswerIsSaidWithNoPackageDeclared(t *testing.T) {
unansweringPacman(t)
dir := t.TempDir()
opts := options{state: filepath.Join(dir, "state.json"), out: &strings.Builder{}}
@@ -46,7 +46,7 @@ func TestAPackageManagerThatDoesNotAnswerIsSaidWithNoPackageDeclared(t *testing.
// A system whose probe asks the system itself, not a tool a resource needs, still refuses whole: nothing
// the mesh declares can remove it, and nothing else stands between that host and the wrong machine.
func TestASystemWithNoPackageManagerStillRefusesWhole(t *testing.T) {
func testASystemWithNoPackageManagerStillRefusesWhole(t *testing.T) {
t.Setenv("PATH", t.TempDir())
sys, err := system.For("android")
if err != nil {
@@ -83,7 +83,7 @@ func pacmanAnsweringOnce(t *testing.T, conf string) {
// installs its packages too**. The probe is asked again once the partial apply wrote something, and when it
// answers the declaration is applied again over what the first pass left — the packages in this apply, not five
// minutes later, and the report clean.
func TestThePackagesGoInWhenTheApplyThatRestoresThePackageManagerWroteIt(t *testing.T) {
func testThePackagesGoInWhenTheApplyThatRestoresThePackageManagerWroteIt(t *testing.T) {
dir := t.TempDir()
conf := filepath.Join(dir, "pacman.conf")
pacmanAnsweringOnce(t, conf)
@@ -108,7 +108,7 @@ func TestThePackagesGoInWhenTheApplyThatRestoresThePackageManagerWroteIt(t *test
// Defends decision (1) of the review of novox/hq issue 233: **a package manager that is not there at all still
// refuses whole**. That is the host installed on the wrong machine, which the probe exists to catch.
func TestAPackageManagerThatIsNotThereRefusesWhole(t *testing.T) {
func testAPackageManagerThatIsNotThereRefusesWhole(t *testing.T) {
t.Setenv("PATH", t.TempDir())
was := builtFor
builtFor = "arch"
@@ -127,3 +127,11 @@ func TestAPackageManagerThatIsNotThereRefusesWhole(t *testing.T) {
t.Error("the refused declaration touched the machine")
}
}
// TestProbe runs this file's tests, each a subtest named as its function was (design 47 H2 §819, the test budget).
func TestProbe(t *testing.T) {
t.Run("APackageManagerThatDoesNotAnswerIsSaidWithNoPackageDeclared", testAPackageManagerThatDoesNotAnswerIsSaidWithNoPackageDeclared)
t.Run("ASystemWithNoPackageManagerStillRefusesWhole", testASystemWithNoPackageManagerStillRefusesWhole)
t.Run("ThePackagesGoInWhenTheApplyThatRestoresThePackageManagerWroteIt", testThePackagesGoInWhenTheApplyThatRestoresThePackageManagerWroteIt)
t.Run("APackageManagerThatIsNotThereRefusesWhole", testAPackageManagerThatIsNotThereRefusesWhole)
}
+12 -4
View File
@@ -13,7 +13,7 @@ import (
// The record check reads the engine's applied state: a composition one of whose resources has no record there is not
// recorded (issue 1945).
func TestACompositionIsRecordedOnlyWhenEveryResourceIs(t *testing.T) {
func testACompositionIsRecordedOnlyWhenEveryResourceIs(t *testing.T) {
path := filepath.Join(t.TempDir(), "state.json")
var s store.State
s.Record(store.Applied{ID: "ca-trust.trust", Type: "file", Target: "/etc/ca"})
@@ -34,7 +34,7 @@ func TestACompositionIsRecordedOnlyWhenEveryResourceIs(t *testing.T) {
}
// The modules applied again are those with a missing resource, each once; one down but there is not among them.
func TestTheModulesAppliedAgainAreThoseWithAMissingResource(t *testing.T) {
func testTheModulesAppliedAgainAreThoseWithAMissingResource(t *testing.T) {
t.Run("1957: the machine shows a resource not active", testTheMachineShowsAResourceNotActive)
st := liveness.Statement{Resources: []liveness.State{
{Resource: liveness.Resource{Module: "matrix", ID: "matrix.homeserver"}, State: liveness.Unhealthy, Missing: true},
@@ -50,7 +50,7 @@ func TestTheModulesAppliedAgainAreThoseWithAMissingResource(t *testing.T) {
// A module is applied again only for a resource newly missing: one still missing at the next change of the statement is
// not acted on again, so a resource that cannot be made is not applied (and backed up) at every unrelated change. One
// that comes back and goes again is newly missing again (the review of issue 1945).
func TestOnlyANewlyMissingResourceAppliesItsModuleAgain(t *testing.T) {
func testOnlyANewlyMissingResourceAppliesItsModuleAgain(t *testing.T) {
t.Run("1957: a resource newly down is an edge", testOnlyAResourceNewlyDownIsAnEdge)
missing := func(ids ...string) liveness.Statement {
var st liveness.Statement
@@ -79,7 +79,7 @@ func TestOnlyANewlyMissingResourceAppliesItsModuleAgain(t *testing.T) {
// A file the provisioner client fills is left to it by the apply and has no record until the client writes it: it does
// not make its composition unrecorded (the review of issue 1945).
func TestAFilledFileDoesNotMakeItsCompositionUnrecorded(t *testing.T) {
func testAFilledFileDoesNotMakeItsCompositionUnrecorded(t *testing.T) {
path := filepath.Join(t.TempDir(), "state.json")
var s store.State
s.Record(store.Applied{ID: "ca-trust.trust", Type: "file", Target: "/etc/ca"})
@@ -93,3 +93,11 @@ func TestAFilledFileDoesNotMakeItsCompositionUnrecorded(t *testing.T) {
t.Fatal("a filled file the client has not written made its composition unrecorded")
}
}
// TestRecorded runs this file's tests, each a subtest named as its function was (design 47 H2 §819, the test budget).
func TestRecorded(t *testing.T) {
t.Run("ACompositionIsRecordedOnlyWhenEveryResourceIs", testACompositionIsRecordedOnlyWhenEveryResourceIs)
t.Run("TheModulesAppliedAgainAreThoseWithAMissingResource", testTheModulesAppliedAgainAreThoseWithAMissingResource)
t.Run("OnlyANewlyMissingResourceAppliesItsModuleAgain", testOnlyANewlyMissingResourceAppliesItsModuleAgain)
t.Run("AFilledFileDoesNotMakeItsCompositionUnrecorded", testAFilledFileDoesNotMakeItsCompositionUnrecorded)
}
+8 -2
View File
@@ -35,7 +35,7 @@ func unansweringPacman(t *testing.T) {
// Held to: a declaration that restores the file is applied while pacman does not answer. Only what needs
// pacman fails, with the probe's words; the file is written and recorded. Written only with what the
// node-engine had before the fix, so it lays over the commit before it, where it fails.
func TestReplay233(t *testing.T) {
func testReplay233(t *testing.T) {
unansweringPacman(t)
dir := t.TempDir()
opts := options{state: filepath.Join(dir, "state.json")}
@@ -78,7 +78,7 @@ func failedWords(failed map[string]string) []string {
// Defends novox/hq issue 233 at the machine: `mesh-host apply` applies what does not need the package
// manager, and says the apply was partial with the probe's words — a non-zero exit, never "applied".
func TestApplyByHandAppliesWhatDoesNotNeedAPackageManagerThatDoesNotAnswer(t *testing.T) {
func testApplyByHandAppliesWhatDoesNotNeedAPackageManagerThatDoesNotAnswer(t *testing.T) {
unansweringPacman(t)
dir := t.TempDir()
out := &bytes.Buffer{}
@@ -107,3 +107,9 @@ func TestApplyByHandAppliesWhatDoesNotNeedAPackageManagerThatDoesNotAnswer(t *te
t.Errorf("what was said before applying does not say the package manager does not answer:\n%s", out.String())
}
}
// TestReplay233File runs this file's tests, each a subtest named as its function was (design 47 H2 §819, the test budget).
func TestReplay233File(t *testing.T) {
t.Run("Replay233", testReplay233)
t.Run("ApplyByHandAppliesWhatDoesNotNeedAPackageManagerThatDoesNotAnswer", testApplyByHandAppliesWhatDoesNotNeedAPackageManagerThatDoesNotAnswer)
}
+8 -2
View File
@@ -10,7 +10,7 @@ import (
// The subject the engine hears for a store settling is the event its manifest consumes: the grants part grants an account
// what its manifest consumes and nothing named in code (novox/hq ADR 0625 §4).
func TestTheSettledEventIsTheManifestsConsume(t *testing.T) {
func testTheSettledEventIsTheManifestsConsume(t *testing.T) {
raw, err := os.ReadFile("../../module.json")
if err != nil {
t.Fatal(err)
@@ -29,7 +29,7 @@ func TestTheSettledEventIsTheManifestsConsume(t *testing.T) {
// The manifest claims the seat node-engine, says its findings on its own stream and hears the keeper's ask and the
// node-engine seat's running (design 47 G §364, §387, §199).
func TestTheManifestClaimsItsSeatAndSaysItsFindings(t *testing.T) {
func testTheManifestClaimsItsSeatAndSaysItsFindings(t *testing.T) {
raw, err := os.ReadFile("../../module.json")
if err != nil {
t.Fatal(err)
@@ -65,3 +65,9 @@ func TestTheManifestClaimsItsSeatAndSaysItsFindings(t *testing.T) {
t.Errorf("version = %q, want MAJOR.MINOR 0.1 (§368, §411)", m.Version)
}
}
// TestSettledManifest runs this file's tests, each a subtest named as its function was (design 47 H2 §819, the test budget).
func TestSettledManifest(t *testing.T) {
t.Run("TheSettledEventIsTheManifestsConsume", testTheSettledEventIsTheManifestsConsume)
t.Run("TheManifestClaimsItsSeatAndSaysItsFindings", testTheManifestClaimsItsSeatAndSaysItsFindings)
}
+12 -4
View File
@@ -19,7 +19,7 @@ import (
// The machine's failed units in the engine's statement (novox/hq issue 315): a module's is among the
// resources, unhealthy, as that module's unit, naming it; the machine's own beside them; and an engine
// not reading them says nothing of them.
func TestTheStatementCarriesTheFailedUnits(t *testing.T) {
func testTheStatementCarriesTheFailedUnits(t *testing.T) {
at := time.Date(2026, 10, 8, 12, 0, 0, 0, time.UTC)
us := &units.Statement{At: at, State: units.Degraded, Failed: []units.Failed{
{Unit: "openrazer-daemon.service", Scope: units.ScopeUser, Load: "loaded", Result: "exit-code",
@@ -55,7 +55,7 @@ func TestTheStatementCarriesTheFailedUnits(t *testing.T) {
// Every resource that runs in an account's own service manager names the account, and so does the account
// a module put in a group (novox/hq ADR 0254): the controller reads a unit that cannot run before a new login
// by the two together. What the machine's own manager runs names none.
func TestTheStatementNamesTheAccountsManager(t *testing.T) {
func testTheStatementNamesTheAccountsManager(t *testing.T) {
at := time.Date(2026, 10, 8, 12, 0, 0, 0, time.UTC)
st := liveness.Statement{At: at, Resources: []liveness.State{
{Resource: liveness.Resource{Module: "openrazer", ID: "openrazer.daemon", Kind: "service",
@@ -82,7 +82,7 @@ func TestTheStatementNamesTheAccountsManager(t *testing.T) {
// An account declared never to become root (novox/hq ADR 0266) is said with root never, under the contract
// that tells the controller this engine judges it; an account judged for its groups alone is not.
func TestTheStatementSaysAnAccountJudgedForRoot(t *testing.T) {
func testTheStatementSaysAnAccountJudgedForRoot(t *testing.T) {
at := time.Date(2026, 10, 8, 12, 0, 0, 0, time.UTC)
as := &accounts.Statement{At: at, Accounts: []accounts.Verdict{
{Account: accounts.Account{Module: "claude-code", ID: "claude-code.agent", Name: "agent", Root: true},
@@ -166,7 +166,7 @@ func TestTheStatementSaysAnAccountJudgedForRoot(t *testing.T) {
// A verdict waiting for the setuid search says how far it got, in the reason the root-free verb repeats and as
// fields (novox/hq issue 361); a mount point, never a path the walk visited or found.
func TestTheStatementSaysHowFarTheSetuidSearchGot(t *testing.T) {
func testTheStatementSaysHowFarTheSetuidSearchGot(t *testing.T) {
at := time.Date(2026, 10, 10, 1, 40, 0, 0, time.UTC)
sp := &accounts.SearchProgress{Started: at, Filesystems: 3, Done: 1, Walking: "/home", Visited: 42, Found: 2,
Kept: at, Finished: []accounts.SearchedFilesystem{{Mount: "/", Took: 90 * time.Second}}}
@@ -185,3 +185,11 @@ func TestTheStatementSaysHowFarTheSetuidSearchGot(t *testing.T) {
t.Fatalf("the fields: %+v", s)
}
}
// TestUnits runs this file's tests, each a subtest named as its function was (design 47 H2 §819, the test budget).
func TestUnits(t *testing.T) {
t.Run("TheStatementCarriesTheFailedUnits", testTheStatementCarriesTheFailedUnits)
t.Run("TheStatementNamesTheAccountsManager", testTheStatementNamesTheAccountsManager)
t.Run("TheStatementSaysAnAccountJudgedForRoot", testTheStatementSaysAnAccountJudgedForRoot)
t.Run("TheStatementSaysHowFarTheSetuidSearchGot", testTheStatementSaysHowFarTheSetuidSearchGot)
}
+8 -2
View File
@@ -28,7 +28,7 @@ import (
const coreCredential = "the-provisioner-clients-bus-password-2025"
func TestNatsTheEngineFillsACoreCredentialFromTheVaultsBoxWithNoValueInTheClear(t *testing.T) {
func testNatsTheEngineFillsACoreCredentialFromTheVaultsBoxWithNoValueInTheClear(t *testing.T) {
url := os.Getenv("MESH_TEST_NATS")
if url == "" {
t.Skip("MESH_TEST_NATS unset")
@@ -133,7 +133,7 @@ func TestNatsTheEngineFillsACoreCredentialFromTheVaultsBoxWithNoValueInTheClear(
}
// The engine opens a value the controller sealed (the NaCl box) as before, and the vault's box, with one key.
func TestTheEnginesOpenerOpensBothBoxes(t *testing.T) {
func testTheEnginesOpenerOpensBothBoxes(t *testing.T) {
state := filepath.Join(t.TempDir(), "state.json")
key, _ := identity.GenerateSealingKey()
if err := os.WriteFile(identity.SealingKeyPath(state), []byte(key.Private), 0o600); err != nil {
@@ -151,3 +151,9 @@ func TestTheEnginesOpenerOpensBothBoxes(t *testing.T) {
t.Errorf("the vault's box opened to %q, %v", got, err)
}
}
// TestVaultboxNats runs this file's tests, each a subtest named as its function was (design 47 H2 §819, the test budget).
func TestVaultboxNats(t *testing.T) {
t.Run("NatsTheEngineFillsACoreCredentialFromTheVaultsBoxWithNoValueInTheClear", testNatsTheEngineFillsACoreCredentialFromTheVaultsBoxWithNoValueInTheClear)
t.Run("TheEnginesOpenerOpensBothBoxes", testTheEnginesOpenerOpensBothBoxes)
}
+10 -3
View File
@@ -10,7 +10,7 @@ import (
// toolchain stamps no version — a build does not know what it will be called — so a delivered host
// read as "development build" and the mesh could not tell which host a machine ran (04-ISSUES/161).
func TestADeliveredHostReadsItsVersionFromItsPath(t *testing.T) {
func testADeliveredHostReadsItsVersionFromItsPath(t *testing.T) {
// A delivered host lives at <libexec>/versions/<version>/<binary>.
dir := t.TempDir()
versioned := filepath.Join(dir, "versions", "637f65559d16")
@@ -26,7 +26,7 @@ func TestADeliveredHostReadsItsVersionFromItsPath(t *testing.T) {
}
}
func TestAHostPlacedByHandKeepsItsStamp(t *testing.T) {
func testAHostPlacedByHandKeepsItsStamp(t *testing.T) {
// The honest answer for one the mesh did not deliver — and every machine is in that state until
// a delivery reaches it.
if got := versionAt("/usr/bin/nox-mesh-host", "04a27ca"); got != "04a27ca" {
@@ -34,7 +34,7 @@ func TestAHostPlacedByHandKeepsItsStamp(t *testing.T) {
}
}
func TestADirectoryThatIsNotAVersionIsNotReadAsOne(t *testing.T) {
func testADirectoryThatIsNotAVersionIsNotReadAsOne(t *testing.T) {
// A binary sitting anywhere else must not have its parent directory's name read as a version.
for _, path := range []string{
"/opt/somewhere/nox-mesh-host",
@@ -46,3 +46,10 @@ func TestADirectoryThatIsNotAVersionIsNotReadAsOne(t *testing.T) {
}
}
}
// TestVersionFromPath runs this file's tests, each a subtest named as its function was (design 47 H2 §819, the test budget).
func TestVersionFromPath(t *testing.T) {
t.Run("ADeliveredHostReadsItsVersionFromItsPath", testADeliveredHostReadsItsVersionFromItsPath)
t.Run("AHostPlacedByHandKeepsItsStamp", testAHostPlacedByHandKeepsItsStamp)
t.Run("ADirectoryThatIsNotAVersionIsNotReadAsOne", testADirectoryThatIsNotAVersionIsNotReadAsOne)
}
+14 -5
View File
@@ -34,7 +34,7 @@ func aFileOf(module, id string) json.RawMessage {
// What runs is the agent's compositions and the kept declaration's resources for each module the agent does not hold;
// the node's own parts are the kept declaration's until the agent holds the node's composition (ADR 0539 §9). One module
// under the agent must not make the rest invisible to the liveness, units, accounts, libraries, filling and the take act.
func TestWhatRunsIsTheAgentsCompositionsAndTheKeptRest(t *testing.T) {
func testWhatRunsIsTheAgentsCompositionsAndTheKeptRest(t *testing.T) {
kept := &declaration.Declaration{Identities: []declaration.Identity{{Module: "db", Name: "mesh-db"}},
Libraries: []declaration.Library{{Library: "media"}}}
everything := []engcomp.Composed{
@@ -62,7 +62,7 @@ func TestWhatRunsIsTheAgentsCompositionsAndTheKeptRest(t *testing.T) {
}
// What the take act, the judgement of directories and the filling read is what runs, not the frozen kept declaration.
func TestDeclaredNowReadsWhatRunsWhenTheAgentIsRunning(t *testing.T) {
func testDeclaredNowReadsWhatRunsWhenTheAgentIsRunning(t *testing.T) {
t.Run("a fill while the agent restarts", aFillWhileTheAgentRestartsIsWrittenAfterwards)
setRunsHere(func(string, ed25519.PublicKey) (*declaration.Declaration, error) {
return &declaration.Declaration{Version: 1, Resources: nil, Provisioner: "from-agent"}, nil
@@ -167,7 +167,7 @@ func TestDeclaredNowReadsWhatRunsWhenTheAgentIsRunning(t *testing.T) {
// 1945/AC17 (unit): a resource the node's own composition shares with a running module's composition is declared once,
// the module's: the declaration joined of both names each file once, so the filling writes it; the node's own resources
// no module declares stay. (Live from 2026-10-25 12:43: "2 resources declare X" on every node.)
func TestTheNodesOwnCopyOfAModulesResourceIsLeftOut(t *testing.T) {
func testTheNodesOwnCopyOfAModulesResourceIsLeftOut(t *testing.T) {
own := engcomp.Composed{Node: "n1", Resources: []json.RawMessage{aFileOf("zsh", "rc"), aFileOf("mesh-wireguard", "conf")},
Filled: []string{"/tmp/r6/zsh/rc"}}
zsh := engcomp.Composed{Node: "n1", Module: "zsh", FP: "src2:aa", Resources: []json.RawMessage{aFileOf("zsh", "rc")},
@@ -203,7 +203,7 @@ func TestTheNodesOwnCopyOfAModulesResourceIsLeftOut(t *testing.T) {
// 1945/AC18 (unit): the kept declaration's filled paths go to the module whose file is at each path, the node's own to
// the node's; and what runs from it, joined with the node's composition, names them filled.
func TestTheKeptDeclarationsFilledPathsGoToTheirModules(t *testing.T) {
func testTheKeptDeclarationsFilledPathsGoToTheirModules(t *testing.T) {
raw := []byte(`{"resources":[
{"id":"claude-code.settings","type":"file","module":"claude-code","path":"/etc/cc.json"},
{"id":"screen-lock.conf","type":"file","module":"screen-lock","path":"/etc/lock.conf"},
@@ -231,7 +231,7 @@ func TestTheKeptDeclarationsFilledPathsGoToTheirModules(t *testing.T) {
// 1945/AC17 (unit, review): a resource of the node's own that shares only its target with a module's (another id: a
// unit or a container of the same name) is not the module's, and is neither dropped nor left to be removed.
func TestASharedTargetWithAnotherIDIsNotDropped(t *testing.T) {
func testASharedTargetWithAnotherIDIsNotDropped(t *testing.T) {
ownFile, _ := json.Marshal(map[string]any{"id": "host.zshrc", "type": "file", "path": "/tmp/r6/zsh/rc", "content": "x"})
own := engcomp.Composed{Node: "n1", Resources: []json.RawMessage{ownFile}}
zsh := engcomp.Composed{Node: "n1", Module: "zsh", FP: "src2:aa", Resources: []json.RawMessage{aFileOf("zsh", "rc")}}
@@ -303,3 +303,12 @@ func aFillWhileTheAgentRestartsIsWrittenAfterwards(t *testing.T) {
t.Fatalf("the kept view stays after the new agent holds the node: %v, %v", err, current.lastView())
}
}
// TestWhatruns runs this file's tests, each a subtest named as its function was (design 47 H2 §819, the test budget).
func TestWhatruns(t *testing.T) {
t.Run("WhatRunsIsTheAgentsCompositionsAndTheKeptRest", testWhatRunsIsTheAgentsCompositionsAndTheKeptRest)
t.Run("DeclaredNowReadsWhatRunsWhenTheAgentIsRunning", testDeclaredNowReadsWhatRunsWhenTheAgentIsRunning)
t.Run("TheNodesOwnCopyOfAModulesResourceIsLeftOut", testTheNodesOwnCopyOfAModulesResourceIsLeftOut)
t.Run("TheKeptDeclarationsFilledPathsGoToTheirModules", testTheKeptDeclarationsFilledPathsGoToTheirModules)
t.Run("ASharedTargetWithAnotherIDIsNotDropped", testASharedTargetWithAnotherIDIsNotDropped)
}
+10 -3
View File
@@ -15,7 +15,7 @@ import (
// The first have this build writes proves it to the launcher; nothing else does — not a report about a declaration, not
// a facts event, not the haves of another build (novox/hq ADR 0539 §9, ADR 0227 §8). R6-A AC7.
func TestOnlyAHaveUnderThisBuildProvesIt(t *testing.T) {
func testOnlyAHaveUnderThisBuildProvesIt(t *testing.T) {
state := filepath.Join(t.TempDir(), "state.json")
t.Setenv("MESH_HOST_LIBEXEC", t.TempDir())
// Never the machine's own engine placed by hand: proving renews it (issue 356).
@@ -65,7 +65,7 @@ func TestOnlyAHaveUnderThisBuildProvesIt(t *testing.T) {
}
// Every verdict that stands is said, and a reconcile that has one says it unasked.
func TestAStandingRollbackIsSaidOnEveryReport(t *testing.T) {
func testAStandingRollbackIsSaidOnEveryReport(t *testing.T) {
state := filepath.Join(t.TempDir(), "state.json")
line := "2.0\t1.0\t1759744800\trolled-back\tit did not report within 600s of starting\n"
if err := os.WriteFile(upgrade.RolledBackPath(state), []byte(line), 0o644); err != nil {
@@ -80,7 +80,7 @@ func TestAStandingRollbackIsSaidOnEveryReport(t *testing.T) {
// The launcher running this host is known to have been replaced only when it certainly was: a shell
// reading the launcher, from a file renamed over. Asked of a real process, not a model of one.
func TestAReplacedLauncherIsSeen(t *testing.T) {
func testAReplacedLauncherIsSeen(t *testing.T) {
dir := t.TempDir()
path := filepath.Join(dir, "launch")
if err := os.WriteFile(path, []byte("#!/bin/sh\nsleep 5\necho done\n"), 0o755); err != nil {
@@ -110,3 +110,10 @@ func TestAReplacedLauncherIsSeen(t *testing.T) {
t.Fatal("a process reading another script reads as this launcher")
}
}
// TestWitnessing runs this file's tests, each a subtest named as its function was (design 47 H2 §819, the test budget).
func TestWitnessing(t *testing.T) {
t.Run("OnlyAHaveUnderThisBuildProvesIt", testOnlyAHaveUnderThisBuildProvesIt)
t.Run("AStandingRollbackIsSaidOnEveryReport", testAStandingRollbackIsSaidOnEveryReport)
t.Run("AReplacedLauncherIsSeen", testAReplacedLauncherIsSeen)
}