Files
mesh-controller/cmd/mesh-controller/members_file_test.go
T
jschoubben e419d0182f Delete the builder, the build asks, the build queue and the merge gate: the builder's keys are the only way a module is built (issues 1851, 1299, 1318; C2b-C5, C10)
The controller asks no build of anybody (ADR 0501 §5, ADR 0525 clause 6, ADR 0503 §3). Every module of a walk is taken from the
builder's done key; a key not done yet waits, named in the plan, and never fails it.

- C2b/C2c: internal/builder and cmd/mesh-controller's asks go (askABuild, onlyTheBuildersOwn, buildOneAsked, takeIn from an
  outcome, buildAgentsOwn, the builder's say and its fallback, the daemon hearing an outcome). The server follows the retired
  seats' built subjects only to let go of them, because the installer's carried user list names them.
- C2d: replay, queue, cancel, clear, kill, pause, resume, delivery-check, check-here and merge-gate are refused by name.
- C3: the check queues (CHECKS_READY, CHECKS_OTHER) and their workers, the checks-running and plans-building buckets and
  their grants, the build queue and its hold (plans_building.go, queue.go, link/holds.go, builds_nats.go, checks_nats.go).
- C4: merge_gate*.go, the pull request's repo-check path, the Checked event and its layers; a pull request asks the
  controller nothing but to tell mesh-config what its head declares.
- C5: the builds bucket is written only by key_takein.
- C10 (help and refusals): the terminal's help lists only what is served.

Integration tests of the plan's tiers, sends, stops and retries now run on a stand-in builder with a done key for every
module (walk_keys_scaffold_integration_test.go); the tests of the asks, the queue, the merge gate and the replays are deleted.
2026-10-23 15:55:15 +02:00

82 lines
2.6 KiB
Go

package main
import (
"encoding/json"
"fmt"
"os"
"slices"
"strings"
"testing"
)
// aLongGroup is members as JSON over 200 KB: 1666 paths of the shape of mesh-delivery #5's change (novox/hq issue 1272).
func aLongGroup(t *testing.T) string {
t.Helper()
var paths []string
for i := 0; i < 1666; i++ {
paths = append(paths, fmt.Sprintf("modules/mesh-delivery-forge-bridge/vendor/github.com/nats-io/nats-server/v2/server/certstore/certstore_windows_file_%04d.go", i))
}
body, err := json.Marshal([]map[string]any{{"id": "novox/mesh-delivery#5", "paths": paths}, {"id": "novox/mesh-catalog#374"}})
if err != nil {
t.Fatal(err)
}
if len(body) < 200<<10 {
t.Fatalf("the members are only %d bytes", len(body))
}
return string(body)
}
func readBackFromTheCommand(t *testing.T, argv []string, members string) {
t.Helper()
for _, a := range argv {
if len(a) > 64<<10 {
t.Errorf("an argument of %d bytes is handed to the command", len(a))
}
}
i := slices.Index(argv, "--members-file")
if i < 0 {
t.Fatalf("the command does not name a members file: %.200v", argv)
}
raw, err := os.ReadFile(argv[i+1])
if err != nil || string(raw) != members {
t.Errorf("the file does not hold the whole members list (%d bytes, %v)", len(raw), err)
}
removeMembersFile(argv)
if _, err := os.Stat(argv[i+1]); !os.IsNotExist(err) {
t.Errorf("the file is still there after the command: %v", err)
}
}
func TestDeliveryOrderHandsALongMembersListInAFile(t *testing.T) { // 1272/AC2
members := aLongGroup(t)
argv, err := argvFor("delivery-order", map[string]any{"members": members})
if err != nil {
t.Fatal(err)
}
if argv[0] != "delivery" || argv[1] != "order" {
t.Errorf("the command is %.100v", strings.Join(argv, " "))
}
readBackFromTheCommand(t, argv, members)
}
func TestAShortMembersListIsStillTheArgumentItWas(t *testing.T) { // 1272/AC3
members := `[{"id":"novox/a#1"},{"id":"novox/b#2"}]`
argv, err := argvFor("delivery-order", map[string]any{"members": members})
want := []string{"delivery", "order", "--members", members}
if err != nil || !slices.Equal(argv, want) {
t.Errorf("a short list gives %v, %v, want %v", argv, err, want)
}
}
func TestTheCommandReadsTheMembersFromTheFileAsFromTheArgument(t *testing.T) { // 1272/AC1
members := `[{"id":"novox/a#1"}]`
argv, _ := membersFlags(strings.Repeat(" ", membersInArgument) + members)
defer removeMembersFile(argv)
if len(argv) != 2 || argv[0] != "--members-file" {
t.Fatalf("a long list gives %v", argv)
}
if st, err := os.Stat(argv[1]); err != nil || st.Mode().Perm() != 0o600 {
t.Errorf("the file is %v, %v", st, err)
}
}