controllerdeps refuses any manifest naming the controller's seat, states or buckets, the lease and the entries once kept to its write among them, and any module file naming one of its buckets (ADR 0590 §5). The words check refuses a controller address in any text a module shows. The handacts check and noplacement's list of assignments readers are folded into it (issue 1126 B10). Claude-Session: https://claude.ai/code/session_01NcbgfJ9Gum47zkFKWRaovL
120 lines
4.8 KiB
Go
120 lines
4.8 KiB
Go
package main
|
|
|
|
import (
|
|
"os"
|
|
"testing"
|
|
)
|
|
|
|
// A retired word's plural is the word; anything else joined on is another word.
|
|
func TestPatternMatchesTheWordAndItsPlural(t *testing.T) {
|
|
cases := []struct {
|
|
word, text string
|
|
want bool
|
|
}{
|
|
{"control plane", "ask the control plane", true},
|
|
{"control plane", "two control planes", true},
|
|
{"control plane", "two control\n\tplanes", true},
|
|
{"substrate", "the substrates", true},
|
|
{"flavor", "flavors of a module", true},
|
|
{"flavor", "flavored", false},
|
|
{"node tools", "node toolsets", false},
|
|
{"mesh-console", "the mesh-consoles", true},
|
|
{"mesh-console", "mesh-console-x", false},
|
|
}
|
|
for _, c := range cases {
|
|
if got := pattern(c.word).MatchString(c.text); got != c.want {
|
|
t.Errorf("pattern(%q) on %q = %v, want %v", c.word, c.text, got, c.want)
|
|
}
|
|
}
|
|
}
|
|
|
|
// A daemon's line is found whole — the daemon, its command, and an argument where the command is a line only with
|
|
// one — and prose that merely names the daemon beside a word is not one (novox/hq ADR 0272).
|
|
func TestADaemonsLineIsFoundWhole(t *testing.T) {
|
|
push := retiredLine{daemon: "mesh-controller", command: "push"}
|
|
module := retiredLine{daemon: "mesh-controller", command: "module", withArgument: true}
|
|
handOver := retiredLine{daemon: "nox-mesh-host", command: "hand-over"}
|
|
cases := []struct {
|
|
line retiredLine
|
|
text string
|
|
want bool
|
|
}{
|
|
{push, "run `mesh-controller push laptop` after", true},
|
|
{push, "mesh-controller push", true},
|
|
{push, "mesh-controller\n push", true},
|
|
{push, "mesh-controller pushed it", false},
|
|
{push, "the mesh-controller pushes", false},
|
|
{push, "mesh-controller-push", false},
|
|
{module, "`mesh-controller module check modules/*/module.json`", true},
|
|
{module, "run\n $ mesh-controller module check x", true},
|
|
{module, "the mesh-controller module is assigned", false},
|
|
{module, "mesh-controller module", false},
|
|
{module, "`mesh-controller module`", false},
|
|
{handOver, "`nox-mesh-host hand-over /srv/x` at the machine", true},
|
|
{handOver, "`nox node hand-over laptop /srv/x`", false},
|
|
{retiredLine{daemon: "mesh-host", command: "hand-over"}, "nox-mesh-host hand-over", false},
|
|
}
|
|
for _, c := range cases {
|
|
if got := linePattern(c.line).MatchString(c.text); got != c.want {
|
|
t.Errorf("%s %s on %q = %v, want %v", c.line.daemon, c.line.command, c.text, got, c.want)
|
|
}
|
|
}
|
|
found := checkLines([]retiredLine{push, module}, []text{{file: "m/a.go", line: 3, s: "say\n`mesh-controller push`"},
|
|
{file: "m/b.go", line: 1, s: "the mesh-controller module"}})
|
|
if len(found) != 1 || found[0] != "m/a.go:4: `mesh-controller push` is a daemon's line — the operator types `nox …` (novox/hq ADR 0272) — in \"say `mesh-controller push`\"" {
|
|
t.Fatalf("found %q", found)
|
|
}
|
|
}
|
|
|
|
// The list's lines read as `<daemon> <command>`, a trailing ` …` meaning an argument must follow; anything else is
|
|
// refused rather than read as some line.
|
|
func TestRetiredLinesAreReadAsDaemonAndCommand(t *testing.T) {
|
|
dir := t.TempDir()
|
|
path := dir + "/retired-lines"
|
|
if err := os.WriteFile(path, []byte("# the list\nmesh-controller push\nmesh-controller module …\n\nnox-mesh-host hand-over\n"), 0o644); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
lines, err := readLines(path)
|
|
if err != nil || len(lines) != 3 || lines[0] != (retiredLine{daemon: "mesh-controller", command: "push"}) ||
|
|
lines[1] != (retiredLine{daemon: "mesh-controller", command: "module", withArgument: true}) ||
|
|
lines[2] != (retiredLine{daemon: "nox-mesh-host", command: "hand-over"}) {
|
|
t.Fatalf("read %+v, %v", lines, err)
|
|
}
|
|
if err := os.WriteFile(path, []byte("mesh-controller\n"), 0o644); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if _, err := readLines(path); err == nil {
|
|
t.Fatal("a line with no command was read")
|
|
}
|
|
}
|
|
|
|
// The script's run of this check over the real tree (novox/hq ADR 0529 clause 2): no word the glossary retired, and no
|
|
// daemon's line, in any text a module's tools can show an agent.
|
|
func TestTheCatalogueHoldsNoRetiredWordAndNoDaemonsLine(t *testing.T) {
|
|
if code := run("../.."); code != 0 {
|
|
t.Fatalf("the check of the real catalogue exits %d (see what it printed above)", code)
|
|
}
|
|
}
|
|
|
|
// ADR 0590 §5 (issue 1126 B10): no text a module shows names an address of the controller, which is not placed; prose
|
|
// naming it passes.
|
|
func TestCheckAddressesRefusesTheControllersAddresses(t *testing.T) {
|
|
for _, c := range []struct {
|
|
s string
|
|
want bool
|
|
}{
|
|
{"push this machine (mesh-controller.push)", true},
|
|
{"ask seat:mesh-controller.nodes", true},
|
|
{"the bucket mesh-controller_assignments", true},
|
|
{"`mesh-controller.<verb>`", true},
|
|
{"the mesh-controller module is gone.", false},
|
|
{"located in mesh-controller#246", false},
|
|
{"ask mesh-placement.placement", false},
|
|
} {
|
|
got := checkAddresses([]text{{file: "m/a.go", line: 1, s: c.s}})
|
|
if (len(got) == 1) != c.want {
|
|
t.Errorf("checkAddresses(%q) = %q, want a finding: %v", c.s, got, c.want)
|
|
}
|
|
}
|
|
}
|