mesh/merge-gate head 9ade199740e3 merged into trunk d79264611071 — pass, with a note: builds mesh-sdk (+41 dependent(s)) → ace, g14, novox, shanks; no bus …
mesh/repo-check head 9ade199740e3 merged into trunk d79264611071 — pass: its merge-check.sh passed, each part in its toolchain: merge-check.sh (typescript)…
mesh/delivery delivered
124 lines
4.3 KiB
Go
124 lines
4.3 KiB
Go
package delivery
|
|
|
|
import (
|
|
"encoding/json"
|
|
"os"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
// The fixture's path is what the controller writes for a build request: strings.Trim(path, "/") at mesh-controller
|
|
// internal/inventory/chain_requests.go:19, the module's directory in its repository (Build.Path, internal/chain/records.go:100).
|
|
// The fixture is a record the controller's own encoder wrote (json.Marshal of a chain.Build, mesh-controller
|
|
// internal/chain, a throwaway test run once and deleted) with build-agent's build-1792395447088936520 values, plus a
|
|
// manifest-digest and one made artifact, which a BuildRecord does not carry.
|
|
func loadBuildFixture(t *testing.T) []byte {
|
|
t.Helper()
|
|
raw, err := os.ReadFile("testdata/build-record-build-agent.json")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
return raw
|
|
}
|
|
|
|
func TestBuildRecordDecodes(t *testing.T) { // 1223/AC1
|
|
var r BuildRecord
|
|
if err := json.Unmarshal(loadBuildFixture(t), &r); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
for _, c := range []struct{ name, got, want string }{
|
|
{"id", r.ID, "build-1792395447088936520"},
|
|
{"module", r.Module, "build-agent"},
|
|
{"repository", r.Repository, "novox/mesh-controller"},
|
|
{"ref", r.Ref, "main"},
|
|
{"commit", r.Commit, "7a74cee83f88e6585a5511c3cc53bdf0f5303d20"},
|
|
{"state", r.State, "built"},
|
|
{"source-fingerprint", r.SourceFingerprint, "src1:e846efe73716b78e80860baaac96153de2cb76551325753838ca245d2160a3d7"},
|
|
} {
|
|
if c.got != c.want {
|
|
t.Errorf("%s = %q, want %q", c.name, c.got, c.want)
|
|
}
|
|
}
|
|
if want := time.Date(2026, 10, 19, 9, 38, 0, 0, time.UTC); !r.At.Equal(want) {
|
|
t.Errorf("at = %v, want %v", r.At, want)
|
|
}
|
|
if r.SourceInputs == nil {
|
|
t.Fatal("source-inputs missing")
|
|
}
|
|
fp, none := SourceFingerprint(*r.SourceInputs)
|
|
if none != "" || fp != r.SourceFingerprint {
|
|
t.Errorf("SourceFingerprint of the decoded inputs = %q (none %q), the record says %q", fp, none, r.SourceFingerprint)
|
|
}
|
|
}
|
|
|
|
func TestBuildRecordPath(t *testing.T) { // 1233/AC1
|
|
var r BuildRecord
|
|
if err := json.Unmarshal(loadBuildFixture(t), &r); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if r.Path != "modules/build-agent" {
|
|
t.Errorf("path = %q, want modules/build-agent", r.Path)
|
|
}
|
|
// mesh-controller's manifest is its repository's root: the controller writes no path (omitempty), so the path is "".
|
|
var m map[string]json.RawMessage
|
|
if err := json.Unmarshal(loadBuildFixture(t), &m); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
delete(m, "path")
|
|
raw, _ := json.Marshal(m)
|
|
var root BuildRecord
|
|
if err := json.Unmarshal(raw, &root); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if root.Path != "" {
|
|
t.Errorf("path of a root module = %q, want empty", root.Path)
|
|
}
|
|
// Every field 1223/AC1 checks is still equal in both.
|
|
if root.ID != r.ID || root.Module != r.Module || root.Repository != r.Repository || root.Ref != r.Ref ||
|
|
root.Commit != r.Commit || root.State != r.State || root.SourceFingerprint != r.SourceFingerprint || !root.At.Equal(r.At) {
|
|
t.Errorf("fields differ: %+v vs %+v", root, r)
|
|
}
|
|
// And the path survives a round trip through the SDK's own type.
|
|
back, _ := json.Marshal(r)
|
|
var again BuildRecord
|
|
if err := json.Unmarshal(back, &again); err != nil || again.Path != r.Path {
|
|
t.Errorf("round trip path = %q (%v)", again.Path, err)
|
|
}
|
|
}
|
|
|
|
func TestBuildRecordWithoutInputs(t *testing.T) { // 1223/AC2
|
|
var m map[string]json.RawMessage
|
|
if err := json.Unmarshal(loadBuildFixture(t), &m); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
delete(m, "source-inputs")
|
|
raw, _ := json.Marshal(m)
|
|
var r BuildRecord
|
|
if err := json.Unmarshal(raw, &r); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if r.SourceInputs != nil {
|
|
t.Errorf("source-inputs = %+v, want nil", r.SourceInputs)
|
|
}
|
|
if r.Module != "build-agent" {
|
|
t.Errorf("module = %q, want build-agent", r.Module)
|
|
}
|
|
}
|
|
|
|
func TestBuildKeys(t *testing.T) { // 1223/AC3
|
|
// Literal values of mesh-controller internal/broker/controller_buckets.go:101 (BucketName(ControllerSeat, ChainBuilds)
|
|
// is "mesh-controller_builds") and internal/chain/keys.go:35-44.
|
|
if BuildsBucket != "mesh-controller_builds" {
|
|
t.Errorf("BuildsBucket = %q", BuildsBucket)
|
|
}
|
|
if got := BuildKey("build-agent", "build-1"); got != "build-agent.build.build-1" {
|
|
t.Errorf("BuildKey = %q", got)
|
|
}
|
|
if got := BuildKey("", "build-1"); got != "req.build-1" {
|
|
t.Errorf("BuildKey without a module = %q", got)
|
|
}
|
|
if got := NewestKey("build-agent"); got != "build-agent.newest" {
|
|
t.Errorf("NewestKey = %q", got)
|
|
}
|
|
}
|