Files
mesh-sdk/go/seatlist/bootstrap_contracts_test.go
T
jschoubben df3b732eca MV1: move contracts and sdk under modules/, importers follow
The delivery repository's contracts and SDK live under modules/ as
mesh-delivery-contracts and mesh-delivery-sdk, their Go module paths
renamed to match the folders (the TypeScript names already did), and
every importer in mesh-delivery, mesh-catalog, mesh-host, mesh-tools
and mesh-sdk follows in the same group: a design as it should be, one
path per module, checked by the group's check building every importer.

Builds: design 47 G §427, §88

Claude-Session: https://claude.ai/code/session_01NcbgfGKaxw984XyAPfLm4h
2026-11-12 05:09:56 +01:00

59 lines
2.3 KiB
Go

package seatlist
import (
"bytes"
"os"
"path/filepath"
"slices"
"testing"
"git.novox.be/novox/mesh-sdk/go/internal/beside"
)
// ADR 0635 §3, ADR 0608 §2: a bootstrapped definition is a copy of its seat's file in its contracts module, byte for
// byte, and a seat with a copy has a row here. The contracts are read beside this repository, as a merge check places
// them (mesh-contracts, and mesh-delivery for its `modules/mesh-delivery-contracts` folder) or, elsewhere, from the copy captured in
// testdata/beside.
func TestEveryBootstrappedDefinitionEqualsItsContractsFile(t *testing.T) {
rows := []struct{ seat, repository, file string }{
{"mesh-broker", "mesh-contracts", "seats/mesh-broker/seat.json"},
{"mesh-config", "mesh-contracts", "seats/mesh-config/seat.json"},
{"node-engine", "mesh-contracts", "seats/node-engine/seat.json"},
{"node-backup", "mesh-contracts", "seats/node-backup/seat.json"},
{"mesh-conditions", "mesh-contracts", "health-and-repair/seats/mesh-conditions/seat.json"},
{"mesh-hand-acts", "mesh-contracts", "health-and-repair/seats/mesh-hand-acts/seat.json"},
{"mesh-watchdogs", "mesh-contracts", "health-and-repair/seats/mesh-watchdogs/seat.json"},
{"operator-channel", "mesh-contracts", "operator-and-conversation/seats/operator-channel/seat.json"},
{"mesh-catalog", "mesh-delivery", "modules/mesh-delivery-contracts/seats/mesh-catalog/seat.json"},
{"mesh-delivery-checker", "mesh-delivery", "modules/mesh-delivery-contracts/seats/mesh-delivery-checker/seat.json"},
}
var have []string
for _, d := range Bootstrapped() {
have = append(have, d.Seat)
}
var want []string
for _, r := range rows {
want = append(want, r.seat)
}
slices.Sort(want)
if !slices.Equal(have, want) {
t.Fatalf("the bootstrapped seats are %v, the rows of this test %v: give each bootstrapped seat a row", have, want)
}
for _, r := range rows {
t.Run(r.seat, func(t *testing.T) {
copied, err := bootstrapFiles.ReadFile("bootstrap/" + r.seat + ".json")
if err != nil {
t.Fatal(err)
}
contract, err := os.ReadFile(filepath.Join(beside.Dir(t, r.repository), filepath.FromSlash(r.file)))
if err != nil {
t.Fatal(err)
}
if !bytes.Equal(copied, contract) {
t.Errorf("seatlist/bootstrap/%s.json differs from %s's %s: replace the copy with the contracts' file (ADR 0635 §3)",
r.seat, r.repository, r.file)
}
})
}
}