Files
mesh-controller/cmd/mesh-controller/replay325_test.go
T
jochen 7d63d2e68c Say why assign finds no module, and keep an assignment pending on its build
A merge asks for a new module's build, and assign answered "no module of that
name" until the build registered it, which read as a module nobody registered
(hq issue 325). Keep every build request, tell a build in flight, a module
known and not built, and an unknown name apart, and make an assignment made
while the build runs when the build registers the module.
2026-10-08 16:38:11 +02:00

61 lines
2.5 KiB
Go

package main
import (
"encoding/json"
"slices"
"strings"
"testing"
"github.com/novox/mesh-controller/internal/catalogue"
"github.com/novox/mesh-controller/internal/inventory"
"github.com/novox/mesh-controller/internal/link"
)
// novox/hq issue 325, replayed with only what the controller had before its fix, so it can be laid over the
// older commit. On 2026-10-08 the catalogue's pull request adding `sensors` merged, and the merge asked for
// its build (issue 300). About a minute later `assign g14 sensors` answered "no module of that name:
// sensors"; a few minutes later the same call worked, because the build had registered the module. The
// answer read as "nobody registered it". An assignment made while the build runs says the build — where it
// is from, since when, its id — is kept, and is made when the build registers the module.
func TestReplay325(t *testing.T) {
open := aMesh(t)
ctx := t.Context()
if err := open.inventory.RegisterModule(ctx, catalogue.Manifest{Module: "networkmanager", Version: "1"},
inventory.Source{Repository: "novox/mesh-catalog", Seat: "git", Path: "modules/networkmanager", Ref: "main",
BuiltFrom: "c0", Head: "c0"}); err != nil {
t.Fatal(err)
}
asksWithPaths(t)
m := link.SourceMoved{Owner: "novox", Repo: "mesh-catalog", Base: "main", Commit: "5e450125aa",
Paths: []string{"modules/sensors/module.json", "modules/sensors/cmd/sensors/main.go"},
ModuleDirs: []string{"modules/sensors"}, ModuleDirsSaid: true}
if err := (following{open: open}).SourceMoved(ctx, m); err != nil {
t.Fatal(err)
}
said, err := assign(ctx, open, "laptop", "sensors")
if err != nil {
t.Fatalf("assign while the merge's build runs was refused: %v", err)
}
for _, want := range []string{"being built", "novox/mesh-catalog", "modules/sensors", "b-modules/sensors"} {
if !strings.Contains(said, want) {
t.Fatalf("the answer does not say %q:\n%s", want, said)
}
}
manifest, _ := json.Marshal(catalogue.Manifest{Module: "sensors", Version: "1"})
if err := (builds{open.inventory, open}).Built(ctx, link.BuildResult{ID: "b-modules/sensors",
Repository: "novox/mesh-catalog", Path: "modules/sensors", Ref: "main", Commit: "5e450125aa", On: "anchor",
Module: "sensors", Manifest: manifest,
Source: &link.SourceOnSeat{Repository: "novox/mesh-catalog", Seat: "git"}}); err != nil {
t.Fatal(err)
}
assigned, err := open.inventory.Assigned(ctx, "laptop")
if err != nil {
t.Fatal(err)
}
if !slices.Contains(assigned, "sensors") {
t.Fatalf("the build registered sensors and laptop runs %v", assigned)
}
}