package main import ( "testing" "github.com/novox/mesh-controller/internal/inventory" ) // The holder of the build seat follows the controller that defines its worker (novox/hq issue 206). // On 2026-10-03 a plan put the build machine in tier 0 and the controller in tier 1; the new build // machine could not bind the worker the old controller had defined, and nothing could build the // controller that would have redefined it. The built-by edge from the controller to its build // machine yields to that order: the controller is built by whichever build machine is running. func TestTheBuildSeatsHolderFollowsTheControllerThatDefinesItsWorker(t *testing.T) { edges := []inventory.Edge{ {From: "build-agent", To: "mesh-controller", Kind: inventory.EdgePackages}, {From: "build-agent", To: "mesh-controller", Kind: inventory.EdgeWorkerOf}, {From: "mesh-controller", To: "build-agent", Kind: inventory.EdgeBuiltBy}, {From: "route-proxy", To: "mesh-controller", Kind: inventory.EdgePackages}, {From: "route-proxy", To: "build-agent", Kind: inventory.EdgeBuiltBy}, } // A packages edge recorded before novox/hq ADR 0267 widens nothing: the controller moved alone moves // alone, and a change to a package all three build from moves all three, each by its own build source. if alone := reachableFrom([]string{"mesh-controller"}, edges); len(alone) != 1 { t.Fatalf("the controller alone, whatever packages its repository: %v", alone) } set := reachableFrom([]string{"mesh-controller", "build-agent", "route-proxy"}, edges) tiers := tiersOf(set, edges) pos := map[string]int{} for i, tier := range tiers { for _, m := range tier { pos[m] = i } } if pos["mesh-controller"] != 0 { t.Fatalf("the controller first, built by the build machine that is running: %v", tiers) } if pos["build-agent"] <= pos["mesh-controller"] { t.Fatalf("the build machine after the controller that defines its worker: %v", tiers) } // Built-by orders nothing (novox/hq ADR 0360 ยง3): whichever builder runs builds the proxy, beside the controller. if pos["route-proxy"] != 0 { t.Fatalf("what the builder builds waits for a new one: %v", tiers) } if hasCycle(tiers, edges) { t.Fatalf("no cycle here: %v", tiers) } }