The verb outdated leaves the seat mesh-catalog's definition (its def Outdated, its fixtures, the generated Go and TypeScript, under the form 6 this change raised), the indexer's claim, its tool and its answer, the answer of other branches' builds with it. The indexer's hearings of toolchain-agreed and wait-ended, whose state heard keys only outdated read, go with their consumes in its manifest. Builds: design 47 H2 H-A-548, H-A-558 (1), H-A-532 (DQ-9), H §747
232 lines
10 KiB
Go
232 lines
10 KiB
Go
package index
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"fmt"
|
|
"slices"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
|
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshbuilds"
|
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
|
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/nodebuildgo"
|
|
)
|
|
|
|
// Design 47 G §349: a version is released once every artifact the module's entry names is published at it, said once as
|
|
// version-released; a version lower than the highest released is recorded late and not said; each module keeps its newest
|
|
// 100 versions, never its highest of any MAJOR.MINOR.
|
|
func TestAVersionIsReleasedOnceEveryArtifactIsPublished(t *testing.T) {
|
|
ctx := context.Background()
|
|
now := time.Date(2026, 11, 1, 3, 0, 0, 0, time.UTC)
|
|
var said []meshcatalog.VersionReleasedEvent
|
|
ix := &Indexer{Module: testSelf, Versions: newMem(), Heard: newMem(), Revisions: newMemObjects(1 << 20), Now: func() time.Time { return now },
|
|
SayVersionReleased: func(_ context.Context, e meshcatalog.VersionReleasedEvent, id string) error {
|
|
said = append(said, e)
|
|
return nil
|
|
}}
|
|
entries := map[string]meshcatalog.CatalogEntry{"avahi": {Module: "avahi", Manifest: map[string]any{},
|
|
Artifacts: []meshcatalog.Artifact{{Ref: "avahi:program"}, {Ref: "avahi:image"}}}}
|
|
rev, objects, err := CatalogRevisionOf(meshcatalog.CatalogRevision{Revision: 3, Kind: "trunk"}, entries)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := KeepRevision(ctx, ix.Revisions, rev, objects); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
pub := func(artifact, version string) {
|
|
t.Helper()
|
|
if err := ix.HearPackagePublished(ctx, meshbuilds.PackagePublished{Module: "avahi", Artifact: artifact, Digest: "sha256:" + artifact + version, Version: version, Source: 7, Branch: "main"}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
pub("avahi:program", "0.1.5")
|
|
if v, _ := ModuleVersions(ctx, ix.Versions, "avahi"); len(v) != 0 || len(said) != 0 {
|
|
t.Fatalf("one of two artifacts published released %v, said %v", v, said)
|
|
}
|
|
pub("avahi:image", "0.1.5")
|
|
pub("avahi:image", "0.1.5") // heard again
|
|
v, _ := ModuleVersions(ctx, ix.Versions, "avahi")
|
|
if len(v) != 1 || len(v[0].Artifacts) != 2 || v[0].Source != 7 || v[0].Late || len(said) != 1 || said[0].Version != "0.1.5" {
|
|
t.Fatalf("released %+v, said %+v", v, said)
|
|
}
|
|
if keys, _ := ix.Heard.Keys(ctx); len(keys) != 0 {
|
|
t.Errorf("the artifacts kept as published stay after the release: %v", keys)
|
|
}
|
|
// a late older version is recorded and not said
|
|
pub("avahi:program", "0.1.2")
|
|
pub("avahi:image", "0.1.2")
|
|
v, _ = ModuleVersions(ctx, ix.Versions, "avahi")
|
|
if len(v) != 2 || v[1].Version != "0.1.2" || !v[1].Late || len(said) != 1 {
|
|
t.Fatalf("the late version: %+v, said %d", v, len(said))
|
|
}
|
|
// the newest 100 stay, and the highest of each MAJOR.MINOR
|
|
for i := 6; i < 6+VersionsKept+5; i++ {
|
|
pub("avahi:program", fmt.Sprintf("0.1.%d", i))
|
|
pub("avahi:image", fmt.Sprintf("0.1.%d", i))
|
|
}
|
|
for _, mm := range []string{"0.2", "0.3"} {
|
|
pub("avahi:program", mm+".0")
|
|
pub("avahi:image", mm+".0")
|
|
}
|
|
v, _ = ModuleVersions(ctx, ix.Versions, "avahi")
|
|
if len(v) != VersionsKept || v[0].Version != "0.3.0" {
|
|
t.Fatalf("%d versions kept, newest %s", len(v), v[0].Version)
|
|
}
|
|
var oldest string
|
|
for _, e := range v {
|
|
oldest = e.Version
|
|
}
|
|
if compareVersions(oldest, "0.1.5") < 0 {
|
|
t.Errorf("the oldest kept is %s: the oldest were not the ones deleted", oldest)
|
|
}
|
|
|
|
// H-A-486: an upstream artifact is copied by its pinned digest and never published, so the version is released once every
|
|
// other artifact is, the upstream one named with the pin its manifest gives; one whose manifest names no pin releases none.
|
|
pin := "sha256:" + strings.Repeat("ab", 32)
|
|
nats := func(from string) map[string]meshcatalog.CatalogEntry {
|
|
return map[string]meshcatalog.CatalogEntry{"nats": {Module: "nats", Manifest: map[string]any{"build": map[string]any{"artifacts": []any{
|
|
map[string]any{"name": "server", "kind": "upstream", "from": from},
|
|
map[string]any{"name": "tools", "kind": "bundle", "from": "."}}}},
|
|
Artifacts: []meshcatalog.Artifact{{Ref: "nats:server", Kind: "upstream"}, {Ref: "nats:tools", Kind: "bundle", Language: "go"}}}}
|
|
}
|
|
for i, c := range []struct {
|
|
from, version string
|
|
released bool
|
|
}{{"nats:2.12-alpine@" + pin, "0.1.1", true}, {"nats:2.12-alpine", "0.1.2", false}} {
|
|
rev, objects, err := CatalogRevisionOf(meshcatalog.CatalogRevision{Revision: int64(4 + i), Kind: "trunk"}, nats(c.from))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := KeepRevision(ctx, ix.Revisions, rev, objects); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
err = ix.HearPackagePublished(ctx, meshbuilds.PackagePublished{Module: "nats", Artifact: "nats:tools", Digest: "sha256:tools", Version: c.version, Source: 9, Branch: "main"})
|
|
got, _ := ModuleVersions(ctx, ix.Versions, "nats")
|
|
switch {
|
|
case c.released && (err != nil || len(got) != 1 || len(got[0].Artifacts) != 2 || got[0].Artifacts[0] != (meshcatalog.VersionArtifact{Artifact: "nats:server", Digest: pin})):
|
|
t.Fatalf("pinned %q: released %+v (%v); want the server named with its pin", c.from, got, err)
|
|
case !c.released && (err == nil || !strings.Contains(err.Error(), "no pinned digest") || len(got) != 1):
|
|
t.Fatalf("unpinned %q: released %+v (%v); want a refusal naming the pin", c.from, got, err)
|
|
}
|
|
}
|
|
}
|
|
|
|
// Design 47 G §354: an input is kept under its write time and sha256, read back by the verb input with its digest checked;
|
|
// the keys older than a day among the 20 oldest are deleted at each new keep.
|
|
func TestAnInputIsKeptByItsDigestAndSweptAfterADay(t *testing.T) {
|
|
ctx := context.Background()
|
|
now := time.Date(2026, 11, 1, 3, 0, 0, 0, time.UTC)
|
|
ix := &Indexer{Module: testSelf, Inputs: newMem(), Now: func() time.Time { return now }}
|
|
d1, err := ix.KeepInput(ctx, "ask-1", []byte("first"))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if a, err := InputBody(ctx, ix.Inputs, nil, d1); err != nil || string(a) != "first" {
|
|
t.Fatalf("the input read back: %q, %v", a, err)
|
|
}
|
|
if _, err := InputBody(ctx, ix.Inputs, nil, "sha256:none"); err == nil {
|
|
t.Error("an input never kept is answered")
|
|
}
|
|
now = now.Add(23 * time.Hour)
|
|
if _, err := ix.KeepInput(ctx, "ask-2", []byte("second")); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
inputsOnly := func() []string {
|
|
var out []string
|
|
all, _ := ix.Inputs.Keys(ctx)
|
|
for _, k := range all {
|
|
if !strings.HasPrefix(k, InputsAskPrefix) {
|
|
out = append(out, k)
|
|
}
|
|
}
|
|
return out
|
|
}
|
|
if keys := inputsOnly(); len(keys) != 2 {
|
|
t.Fatalf("inside a day: %v", keys)
|
|
}
|
|
now = now.Add(2 * time.Hour)
|
|
d3, _ := ix.KeepInput(ctx, "ask-3", []byte("third"))
|
|
if keys := inputsOnly(); len(keys) != 2 {
|
|
t.Fatalf("after a day the first stays: %v", keys)
|
|
}
|
|
if all, _ := ix.Inputs.Keys(ctx); slices.Contains(all, InputsAskPrefix+"ask-1") {
|
|
t.Errorf("the name by ask of the swept input stays: %v", all)
|
|
}
|
|
if _, err := InputBody(ctx, ix.Inputs, nil, d1); err == nil {
|
|
t.Error("the input a day old is still answered")
|
|
}
|
|
if _, err := InputBody(ctx, ix.Inputs, nil, d3); err != nil {
|
|
t.Error(err)
|
|
}
|
|
}
|
|
|
|
// Design 47 G §354, A-78 d: an input is also keyed by its run ask's id, so the build seat's step-ended of that ask deletes it, and
|
|
// the key by ask no other read counts as an input.
|
|
func TestAnInputIsDeletedAtTheStepEndedOfItsAsk(t *testing.T) {
|
|
ctx := context.Background()
|
|
now := time.Date(2026, 11, 1, 3, 0, 0, 0, time.UTC)
|
|
ix := &Indexer{Module: testSelf, Inputs: newMem(), Now: func() time.Time { return now }}
|
|
d1, err := ix.KeepInput(ctx, "a.1", []byte("first"))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
d2, _ := ix.KeepInput(ctx, "a.2", []byte("second"))
|
|
if _, err := ix.KeepInput(ctx, "", []byte("x")); err == nil {
|
|
t.Error("an input kept for no ask")
|
|
}
|
|
if err := ix.HearInputEnded(ctx, nodebuildgo.StepEnded{Ask: "a.1"}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := ix.HearInputEnded(ctx, nodebuildgo.StepEnded{Ask: "a.1"}); err != nil {
|
|
t.Errorf("an end heard again: %v", err)
|
|
}
|
|
if _, err := InputBody(ctx, ix.Inputs, nil, d1); err == nil {
|
|
t.Error("the input of an ended ask is still answered")
|
|
}
|
|
if _, err := InputBody(ctx, ix.Inputs, nil, d2); err != nil {
|
|
t.Errorf("the input of another ask: %v", err)
|
|
}
|
|
if got, _ := ix.Inputs.Keys(ctx); len(got) != 2 {
|
|
t.Errorf("keys after one end: %v", got)
|
|
}
|
|
if a, err := InputsReadTool(ix.Inputs, nil).Run(map[string]any{}); err != nil || len(a.(InputsAnswer).Inputs) != 1 {
|
|
t.Errorf("indexer_inputs counts a key by ask: %+v, %v", a, err)
|
|
}
|
|
}
|
|
|
|
// Design 47 G A-490h: a floor entry holds no artifacts, so the package-published heard later at its version is that version's
|
|
// release (the entry takes its artifacts and version-released is said), never dropped as released already. The tag floor that
|
|
// wrote such entries is gone (design 47 H §756, H2 H-A-532 DQ-9); an entry it kept before is still read so.
|
|
func TestAFloorEntryIsReplacedByThePublishHeardAtItsVersion(t *testing.T) {
|
|
ctx := context.Background()
|
|
now := time.Date(2026, 11, 19, 17, 0, 0, 0, time.UTC)
|
|
var said []meshcatalog.VersionReleasedEvent
|
|
ix := &Indexer{Module: testSelf, Versions: newMem(), Heard: newMem(), Findings: newFindings(), Revisions: newMemObjects(1 << 20), Now: func() time.Time { return now },
|
|
SayVersionReleased: func(_ context.Context, e meshcatalog.VersionReleasedEvent, _ string) error {
|
|
said = append(said, e)
|
|
return nil
|
|
}}
|
|
entries := map[string]meshcatalog.CatalogEntry{"mod": {Module: "mod", Repository: "novox/mod", Manifest: map[string]any{}, Artifacts: []meshcatalog.Artifact{
|
|
{Ref: "mod:go", Package: &meshcatalog.ArtifactPackage{Ecosystem: "go", Name: "git.novox.be/novox/mod"}}}}}
|
|
rev, objects, err := CatalogRevisionOf(meshcatalog.CatalogRevision{Revision: 1, Kind: "trunk"}, entries)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := KeepRevision(ctx, ix.Revisions, rev, objects); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
floor, _ := json.Marshal(meshcatalog.VersionEntry{V: 1, Module: "mod", Version: "0.3.0", At: &now})
|
|
if err := ix.Versions.Create(ctx, meshcatalog.VersionsByModuleVersionKey("mod", "0.3.0"), floor); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := ix.HearPackagePublished(ctx, meshbuilds.PackagePublished{Module: "mod", Artifact: "mod:go", Version: "0.3.0", Digest: "sha256:aa", Branch: "main", Source: 5}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
v, _ := ModuleVersions(ctx, ix.Versions, "mod")
|
|
if len(v) != 1 || len(v[0].Artifacts) != 1 || v[0].Artifacts[0].Digest != "sha256:aa" || len(said) != 1 {
|
|
t.Fatalf("the floor 0.3.0 and its publish: versions %+v, version-released said %d", v, len(said))
|
|
}
|
|
}
|