The controller tells mesh-config what a pull request declares, asks the approved held values with each check, and the build agent and merge gate lay them over the change's composition only: a key the trunk does not declare yet can then be approved before the merge (ADR 0502).
53 lines
2.7 KiB
Go
53 lines
2.7 KiB
Go
package main
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/novox/mesh-controller/internal/builder"
|
|
"github.com/novox/mesh-controller/internal/link"
|
|
)
|
|
|
|
// The build seat hands the check the judge cache the build agent declares (MESH_JUDGE_CACHE), never a path of its own.
|
|
func TestTheBuildSeatHandsTheCheckTheJudgeCacheItDeclares(t *testing.T) {
|
|
t.Setenv("MESH_JUDGE_CACHE", "/var/lib/mesh/build-agent/judge-cache")
|
|
if got := judgeCache(); got != "/var/lib/mesh/build-agent/judge-cache" {
|
|
t.Fatalf("the judge cache the manifest declares is read as %q", got)
|
|
}
|
|
t.Setenv("MESH_JUDGE_CACHE", "")
|
|
if got := judgeCache(); got != "" {
|
|
t.Fatalf("with no judge cache declared, %q is used", got)
|
|
}
|
|
}
|
|
|
|
// The siblings a check is asked to read reach the build seat's spec and, as read, the outcome (novox/hq ADR 0382).
|
|
func TestTheSiblingsAnAskNamesReachTheSpecAndTheOutcome(t *testing.T) {
|
|
spec := checkSpecOf(link.BuildRequest{Check: &link.CheckRequest{Owner: "novox", Repo: "mesh-host", Base: "main",
|
|
Siblings: []link.CheckSibling{{Repository: "novox/mesh-controller", Number: 346, Head: "a", Base: "main", Dir: "mesh-controller"}},
|
|
SiblingsUnknown: "why"}})
|
|
if len(spec.Siblings) != 1 || spec.Siblings[0] != (builder.Sibling{Repository: "novox/mesh-controller", Number: 346,
|
|
Head: "a", Base: "main", Dir: "mesh-controller"}) || spec.SiblingsUnknown != "why" {
|
|
t.Fatalf("the spec reads %+v", spec)
|
|
}
|
|
out := siblingsOut([]builder.JudgedSibling{{Repository: "novox/mesh-controller", Number: 346, Head: "a", Base: "main", BaseCommit: "b"}})
|
|
if len(out) != 1 || out[0].BaseCommit != "b" || out[0].Number != 346 {
|
|
t.Fatalf("the outcome reads %+v", out)
|
|
}
|
|
if plain := checkSpecOf(link.BuildRequest{Check: &link.CheckRequest{Owner: "o", Repo: "r"}}); plain.Siblings != nil {
|
|
t.Fatalf("a request that names none has siblings %+v", plain.Siblings)
|
|
}
|
|
}
|
|
|
|
// 1826/AC2: the held values a check request carries reach the spec; a request that carries none leaves it empty.
|
|
func TestTheHeldValuesAnAskCarriesReachTheSpec(t *testing.T) {
|
|
spec := checkSpecOf(link.BuildRequest{Check: &link.CheckRequest{Owner: "novox", Repo: "mesh-catalog",
|
|
HeldConfig: []link.HeldConfig{{Pull: "novox/mesh-catalog#434", Head: "a", Node: "ace", Module: "n8n", Key: "media-gid",
|
|
Value: []byte("2000"), Approved: "the operator"}}}})
|
|
if len(spec.Held) != 1 || spec.Held[0].Node != "ace" || spec.Held[0].Key != "media-gid" || string(spec.Held[0].Value) != "2000" ||
|
|
spec.Held[0].Approved != "the operator" {
|
|
t.Fatalf("the spec reads %+v", spec.Held)
|
|
}
|
|
if plain := checkSpecOf(link.BuildRequest{Check: &link.CheckRequest{Owner: "o", Repo: "r"}}); plain.Held != nil {
|
|
t.Fatalf("a request that carries none has %+v", plain.Held)
|
|
}
|
|
}
|