Its 26 `<Module>_<state>` bucket constants (candidates, manifests, verdicts, packages, taken, the control records, pins, pending and the rest), its consumers, findings and first views were named from the constant Module; they are now index.Bucket(cred.Module, <state>), and its words name the state where they named the bucket. Builds: design 47 G A-296 Claude-Session: https://claude.ai/code/session_01NcbgfGKaxw984XyAPfLm4h
451 lines
25 KiB
Go
451 lines
25 KiB
Go
package manifest
|
|
|
|
import (
|
|
"bytes"
|
|
"encoding/json"
|
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/git"
|
|
"io/fs"
|
|
"os"
|
|
"path/filepath"
|
|
"reflect"
|
|
"regexp"
|
|
"slices"
|
|
"strings"
|
|
"testing"
|
|
|
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-indexer/takein"
|
|
"git.novox.be/novox/mesh-sdk/go/catalogue"
|
|
|
|
"git.novox.be/novox/mesh-sdk/go/process"
|
|
"git.novox.be/novox/mesh-sdk/go/views"
|
|
|
|
"mesh-delivery-indexer/internal/index"
|
|
)
|
|
|
|
// The controller's manifest reader is mesh-controller internal/catalogue (Manifest, manifest.go: Consumes :521,
|
|
// Invokes :590, Streams :613, Reads :659; StreamDeclaration, streams.go), an internal package of another repository.
|
|
// These tests decode the manifest strictly into the fields those types name (DisallowUnknownFields) and hold the
|
|
// rules of issue 1238 (ADR 0437 §4). The merge gate's module check proves the controller takes the manifest.
|
|
|
|
type state struct {
|
|
Name string `json:"name"`
|
|
History int `json:"history,omitempty"`
|
|
KeyTTL bool `json:"key-ttl,omitempty"`
|
|
MaxMiB int `json:"max-mib,omitempty"`
|
|
}
|
|
|
|
type artifact struct {
|
|
Name string `json:"name"`
|
|
Kind string `json:"kind"`
|
|
Language string `json:"language"`
|
|
System string `json:"system"`
|
|
From string `json:"from"`
|
|
Binary string `json:"binary"`
|
|
Loads []string `json:"loads"`
|
|
Env map[string]string `json:"env"`
|
|
}
|
|
|
|
type stream struct {
|
|
Name string `json:"name"`
|
|
Events []string `json:"events"`
|
|
MaxAgeDays int `json:"max-age-days"`
|
|
MaxMiB int `json:"max-mib"`
|
|
Retention string `json:"retention"`
|
|
}
|
|
|
|
type manifest struct {
|
|
Module string `json:"module"`
|
|
Version string `json:"version"`
|
|
Slug string `json:"slug"`
|
|
RunsAs string `json:"runs-as"`
|
|
Streams []stream `json:"streams"`
|
|
Objects []struct {
|
|
Name string `json:"name"`
|
|
MaxMiB int `json:"max-mib"`
|
|
Form int `json:"form"`
|
|
CatchUp string `json:"catch-up"`
|
|
} `json:"objects"`
|
|
Claims []struct {
|
|
Name string `json:"name"`
|
|
Scope string `json:"scope"`
|
|
Serves []string `json:"serves"`
|
|
} `json:"claims"`
|
|
Tools []string `json:"tools"`
|
|
Emits []string `json:"emits"`
|
|
Consumes []string `json:"consumes"`
|
|
State []state `json:"state"`
|
|
Reads []string `json:"reads"`
|
|
Invokes []string `json:"invokes"`
|
|
Uses []string `json:"uses"`
|
|
OwnSecrets map[string]string `json:"own-secrets"`
|
|
SecretsOwner string `json:"secrets-owner"`
|
|
Resources []map[string]any `json:"resources"`
|
|
Build struct {
|
|
Artifacts []artifact `json:"artifacts"`
|
|
} `json:"build"`
|
|
}
|
|
|
|
func load(t *testing.T) (manifest, map[string]json.RawMessage) {
|
|
t.Helper()
|
|
raw, err := os.ReadFile("module.json")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
var m manifest
|
|
dec := json.NewDecoder(bytes.NewReader(raw))
|
|
dec.DisallowUnknownFields()
|
|
if err := dec.Decode(&m); err != nil {
|
|
t.Fatalf("the controller's reader refuses a key this manifest has: %v", err)
|
|
}
|
|
var top map[string]json.RawMessage
|
|
if err := json.Unmarshal(raw, &top); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
return m, top
|
|
}
|
|
|
|
func sorted(s []string) []string {
|
|
s = slices.Clone(s)
|
|
slices.Sort(s)
|
|
return s
|
|
}
|
|
|
|
func TestManifestDeclarations(t *testing.T) { // 1238/AC1, 1444 (reads the build modules' toolchains)
|
|
m, top := load(t)
|
|
if m.Module != "mesh-delivery-indexer" {
|
|
t.Errorf("module = %q", m.Module)
|
|
}
|
|
// 1126: assignments is the seat mesh-module-assigner's (ADR 0567): the indexer holds no assignments state. ADR 0578 §1: it says
|
|
// a refused manifest as manifest-refused, and (issue 1966 D3, 1966/AC10) a newly accepted one asking for bus state as
|
|
// manifest-accepted, both events of the seat mesh-catalog it holds (ADR 0636 §4), so not among its `emits`.
|
|
if own := slices.DeleteFunc(slices.Clone(m.Emits), func(e string) bool { return strings.HasPrefix(e, views.EventPrefix) }); !reflect.DeepEqual(own, []string{takein.TakeInPendingEvent, takein.TakeInTakenEvent}) {
|
|
t.Errorf("emits = %v, want the two take-in events (the verdict events are the seat mesh-catalog's)", m.Emits)
|
|
}
|
|
// Design 47 G §700, A-74: the router's record of an ask is read through the seat operator-channel, which the indexer uses,
|
|
// and its holder is asked of the seat mesh-module-assigner.
|
|
if !slices.Equal(m.Uses, []string{"operator-channel"}) || !slices.Contains(m.Invokes, "seat:mesh-module-assigner.assignments") || !slices.Contains(m.Invokes, "seat:mesh-module-assigner.placement") {
|
|
t.Errorf("uses = %v, invokes = %v, want the seat operator-channel used and seat:mesh-module-assigner.assignments invoked", m.Uses, m.Invokes)
|
|
}
|
|
// 1126 note 76: heard keeps the last 64 FORGE messages the indexer handled, for indexer_heard.
|
|
if want := []state{{Name: "candidates", History: 10}, {Name: "heard", History: 64}, {Name: "manifests", History: 1}, {Name: "predefined", History: 5}, {Name: "config-candidates", History: 5}, {Name: "taken", History: 1}, {Name: "takeins", History: 1}, {Name: "verdicts", History: 5}, {Name: "oldsections", History: 1}, {Name: index.RunsState, History: 1}, {Name: "own-build", History: 1}, {Name: index.PackagesState, History: index.PackagesHistory},
|
|
{Name: views.MarksState, History: 1}, {Name: index.FindingsState, History: 5}, {Name: views.StatusState, History: 1},
|
|
{Name: index.RequirementsState, History: 5}, {Name: index.SeatDefinitionsState, History: 5},
|
|
{Name: index.PendingState, History: 1}, {Name: index.UnjudgedState, History: 1}, {Name: index.EntryIndexState, History: 1, MaxMiB: 8}, {Name: index.NamedState, History: 1, MaxMiB: 4}, // design 47 G §695
|
|
{Name: index.RegistrationsState, History: 1}, {Name: index.ProposalsState, History: 1, MaxMiB: 4},
|
|
{Name: index.VersionsState, History: 1, MaxMiB: 64}, {Name: index.BuildEdgesState, History: 1}, {Name: index.InputsState, History: 1}, {Name: index.PinsState, History: 1, MaxMiB: index.PinsCapMiB}, {Name: process.ConsumersState, History: 1}}; !reflect.DeepEqual(m.State, want) { // DLV-I7, DLV-I17
|
|
t.Errorf("state = %+v, want %+v", m.State, want)
|
|
}
|
|
// Milestone 47/G W4.2 (design 47, Two graphs; ADR 0619 §2): the catalog graph revisions are objects in the old section,
|
|
// capped at 512 MiB, under the local name the indexer opens. W4.14 (design 47, Reverted): their form is 1, and the
|
|
// catch-up tool a restore of them is followed by is indexer_take_in, which the bundle serves.
|
|
if len(m.Objects) != 1 || m.Objects[0].Name != index.CatalogRevisionsObjects || m.Objects[0].MaxMiB != 512 ||
|
|
m.Objects[0].Form != 1 || m.Objects[0].CatchUp != index.TakeInTool || !slices.Contains(m.Tools, index.TakeInTool) {
|
|
t.Errorf("objects = %+v, want %s capped at 512 MiB, form 1, catch-up %s (a tool of its own)", m.Objects, index.CatalogRevisionsObjects, index.TakeInTool)
|
|
}
|
|
// D-11 (ADR 0634 §1): the holders and buckets the indexer names (internal/index/names.go) are its manifest's: its own
|
|
// name and states with their revisions, and the states it reads, each as `<holder>.<state>`.
|
|
if index.Module != m.Module {
|
|
t.Errorf("the indexer names itself %q, its manifest's module is %q", index.Module, m.Module)
|
|
}
|
|
// A-296: its own buckets are named from its credential's module (index.Bucket), each a state its manifest keeps.
|
|
own := func(state string) string { return index.Bucket("a-indexer", state) }
|
|
for bucket, history := range map[string]int{own(index.CandidatesState): index.CandidatesHistory, own(index.ManifestsState): index.ManifestsHistory,
|
|
own(index.VerdictsState): index.VerdictsHistory, own(index.PackagesState): index.PackagesHistory, own(index.TakenState): 1, own(index.PredefinedState): 5, own(index.ConfigCandidatesState): 5} {
|
|
if !slices.ContainsFunc(m.State, func(st state) bool { return "a-indexer_"+st.Name == bucket && st.History == history }) {
|
|
t.Errorf("the indexer names its bucket %s with %d revisions, its manifest's states are %+v", bucket, history, m.State)
|
|
}
|
|
}
|
|
for bucket, read := range map[string]string{index.PreviewsBucket: "mesh-delivery-checker.previews",
|
|
index.ToolchainsBucket("mesh-build-go"): "mesh-build-go.toolchains", index.ToolchainsBucket("mesh-build-node"): "mesh-build-node.toolchains"} {
|
|
if !slices.Contains(m.Reads, read) || strings.Replace(read, ".", "_", 1) != bucket {
|
|
t.Errorf("the indexer reads the bucket %s, its manifest's reads are %v (want %s)", bucket, m.Reads, read)
|
|
}
|
|
}
|
|
// DLV-F1r (ADR 0615 §1): the assigner's assignments is read through its first view and views family, never its state.
|
|
if want := []string{"mesh-build-go.toolchains", "mesh-build-node.toolchains", "mesh-delivery-builder.build-log", "mesh-delivery-checker.previews"}; !reflect.DeepEqual(sorted(m.Reads), want) {
|
|
t.Errorf("reads = %v, want %v", m.Reads, want)
|
|
}
|
|
// "Reads FORGE" is a consumes of the indexer's stream: the broker grants only buckets by reads (mesh-control
|
|
// internal/broker/state.go:62-93).
|
|
// The registry seats' published fill each (§413: no consume of version.numbered) package's series (DLV-I5, design 51 *The versions*).
|
|
if want := []string{"go-package-registry.published", "mesh-build-go.toolchain.reported", "mesh-build-node.toolchain.reported", "mesh-builds.package-published", "mesh-builds.toolchain-agreed", "mesh-conditions.findings-asked", "mesh-delivery-checker.verdict", "mesh-delivery-forge-bridge.forge.**",
|
|
"mesh-delivery.freed", "mesh-delivery.heads-replaced", "mesh-delivery.pinned", "mesh-delivery.pins-stated", "mesh-delivery.source-moved", "mesh-pipeline-runner.pipeline-ended", "mesh-pipeline-runner.run-started", "mesh-wants.version-delivered", "mesh-wants.wait-ended", "mesh-wants.wanted", "node-build-go.step-ended", "node-engine.running", "npm-package-registry.published", "operator-channel.decided", "seat:mesh-module-assigner.views.assignments"}; !reflect.DeepEqual(sorted(m.Consumes), want) {
|
|
t.Errorf("consumes = %v, want %v", m.Consumes, want)
|
|
}
|
|
if b, ok := m.OwnSecrets["broker"]; !ok || len(m.OwnSecrets) != 1 || b != "${dir:state}/broker" {
|
|
t.Errorf("own-secrets = %v, want exactly broker", m.OwnSecrets)
|
|
}
|
|
if m.SecretsOwner != "mesh-delivery-indexer" {
|
|
t.Errorf("secrets-owner = %q", m.SecretsOwner)
|
|
}
|
|
// Three invokes: the file of a registered module's manifest and lock files (registered.go), the forge's trees (the named paths' objects, since the indexer is the one reader of a manifest's paths:
|
|
// ADR 0499 clauses 2 and 3, ADR 0495 clause 1; and the module directories of the trunk, issue 1900) and whether a
|
|
// commit is in another (issue 1900).
|
|
if want := []string{"seat:git.trees", "seat:git.file", "seat:git.contains", "seat:git.open-pulls", "seat:git.branch", "mesh-delivery-forge-bridge.bridge_merged_message", "seat:node-engine.composition", "seat:mesh-delivery.source", "seat:mesh-module-assigner.assignments", "seat:mesh-module-assigner.placement", "seat:mesh-hand-acts.hand-act", "seat:mesh-watchdogs.presence", "seat:node-build-go.steps",
|
|
"seat:node-build-go.accept.check", // design 47 G A-231: the validation's run ask (§712) on the check queue
|
|
"seat:node-build-go.output", // design 47 G A-254: a validation's answer kept as an object
|
|
"seat:node-build-node.steps", "seat:node-build-image.steps", "mesh-delivery-builder.builder_versions"}; !reflect.DeepEqual(m.Invokes, want) {
|
|
t.Errorf("invokes = %v, want %v", m.Invokes, want)
|
|
}
|
|
// 1945: indexer_take_in, served by its tools bundle through the takeins state; the process serves none. The same bundle
|
|
// reads the verdicts state (indexer_verdicts) and asks the indexer to judge again through the takeins state
|
|
// (indexer_judge; issue 774, clause 3). 1966/AC11: indexer_old_sections reads the count of the old sections (state oldsections).
|
|
// ADR 0621 §1, ADR 0622 §1, ADR 0631 §1, ADR 0663 §1: the first-view tools manifests, verdicts and graph (modules is the seat
|
|
// verb revision's, served by the claim), and design 25 § 12.2's read
|
|
// tools, all of the tools bundle, which runs in a runtime of its own on the indexer's account (runs-as).
|
|
want := []string{"indexer_take_in", "indexer_old_sections", "indexer_verdicts", "indexer_judge"}
|
|
for _, v := range append(append([]index.ViewedTool{}, index.FirstViewTools...), index.ReadTools...) {
|
|
want = append(want, v.Tool)
|
|
// Milestone 47/G: modules and graph are the newest catalog graph revision's, which catalog-revision says the changes of.
|
|
if _, ok := index.ViewedStates[v.State]; !ok && v.State != index.ModulesState && v.State != "graph" {
|
|
t.Errorf("%s answers the state %s, which the views family does not say", v.Tool, v.State)
|
|
}
|
|
}
|
|
want = append(want, "indexer_first_views", "indexer_first_view_again", index.ConfigReadersTool, index.BusStateTool, index.RequirementsTool, index.PackageUsersTool, index.SayAcceptedTool, // DLV-F3r, DLV-I10, DLV-I11, DLV-I7, DLV-I8, DLV-I9c
|
|
index.SeatDefinitionTool, index.SeatDefinitionsAgainTool, index.OutOfStepTool, // DLV-I19
|
|
index.PendingTool, index.TakeInPendingTool, index.DropPendingTool, index.TakeInMergeTool, index.FingerprintsAgainTool, // issue 1966; 1585/T12, T13 (ADR 0633 §5)
|
|
// milestone 47/G W4.12 (design 47, the indexer's tools): the catalog graph revisions read and steered.
|
|
index.CatalogRevisionTool, index.CatalogRevisionsTool, index.CandidateGraphsTool, index.RecomputeTool, index.DropCandidateGraphTool,
|
|
index.EntryIndexTool, index.NamedDropTool, // design 47 G §675
|
|
index.ProposalsTool, index.ProposalDropTool, index.SeedAgainTool, index.InputsTool, index.PinsTool, index.UnpinTool, index.ConsumerTool, index.RunsTool, index.RunDropTool, // design 47 G §667, §8, §579, §64 (A-194)
|
|
index.ValidateAgainTool) // design 47 G §713
|
|
if !reflect.DeepEqual(m.Tools, want) || len(want) != 50 || slices.Contains(m.Tools, "modules") {
|
|
t.Errorf("tools = %v, want %v", m.Tools, want)
|
|
}
|
|
// Design 47 G §2, §9: every version of every registration is kept with no age limit, 64 MiB, on the old streams section.
|
|
if len(m.Streams) != 2 || m.Streams[0].Name != index.RegistrationHistoryStream || m.Streams[0].Retention != "history" || m.Streams[0].MaxMiB != 64 ||
|
|
m.Streams[1].Name != index.Module+"-findings" || m.Streams[1].MaxAgeDays != 7 || m.Streams[1].MaxMiB != 16 {
|
|
t.Errorf("streams = %+v, want registration-history keeping its history, 64 MiB, and the findings stream (§387)", m.Streams)
|
|
}
|
|
// Design 47 G §368: version is MAJOR.MINOR (0.1 while none is published, §368); §295, §299: the catalog revisions' form and
|
|
// the catch-up tool beside it (checked above).
|
|
if !regexp.MustCompile(`^[0-9]+\.[0-9]+$`).MatchString(m.Version) {
|
|
t.Errorf("version = %q, want MAJOR.MINOR (design 47 G §368)", m.Version)
|
|
}
|
|
// Design 47 G §196, §185 (test 61): no state modules, no tool or view of it, and no mesh-wide hold with its states, tools
|
|
// and the engines' reads it weighed.
|
|
for _, s := range m.State {
|
|
if slices.Contains([]string{"modules", "holds", "engine-reads", "hold-bounds"}, s.Name) {
|
|
t.Errorf("the indexer declares the state %s, which design 47 G retires", s.Name)
|
|
}
|
|
}
|
|
for _, retired := range []string{"indexer_read_modules", "indexer_holds", "indexer_engine_reads"} {
|
|
if slices.Contains(m.Tools, retired) {
|
|
t.Errorf("the indexer serves %s, which design 47 G retires", retired)
|
|
}
|
|
}
|
|
if slices.Contains(m.Emits, "views.modules") || slices.Contains(m.Consumes, "node-engine.manifest-reads-changed") {
|
|
t.Errorf("the indexer says views.modules or hears manifest-reads-changed: emits %v, consumes %v", m.Emits, m.Consumes)
|
|
}
|
|
// Every read tool of the indexer a reader of this repository invokes is one it serves (the checker's seventh first
|
|
// view, indexer_read_seat_definitions, was invoked and not served).
|
|
readers, _ := filepath.Glob("../*/module.json")
|
|
var declaring []string
|
|
for _, p := range readers {
|
|
raw, err := os.ReadFile(p)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
var r struct {
|
|
Invokes json.RawMessage `json:"invokes"`
|
|
}
|
|
if err := json.Unmarshal(raw, &r); err != nil {
|
|
t.Fatalf("%s: %v", p, err)
|
|
}
|
|
// A reader's invokes in either form, a verb or {verb, fields} (§558, A-275), read by mesh-sdk's one reader.
|
|
if len(r.Invokes) == 0 {
|
|
continue
|
|
}
|
|
invoked, err := catalogue.InvokedVerbs(r.Invokes)
|
|
if err != nil {
|
|
t.Fatalf("%s: %v", p, err)
|
|
}
|
|
for _, inv := range invoked {
|
|
// The grants part (W8) and the assigner read modules until their own subtasks move them to revision; the join removes this line.
|
|
if (p == "../mesh-grants/module.json" || p == "../mesh-delivery-assigner/module.json") && inv == "mesh-delivery-indexer.modules" ||
|
|
inv == "mesh-delivery-indexer.indexer_read_modules" { // design 47 G §196: the readers' own subtasks move them to the catalog half
|
|
continue
|
|
}
|
|
if tool, ok := strings.CutPrefix(inv, "mesh-delivery-indexer."); ok && !slices.Contains(m.Tools, tool) {
|
|
t.Errorf("%s invokes %s, which the indexer does not serve", p, inv)
|
|
}
|
|
if inv == index.RevisionInvoke {
|
|
declaring = append(declaring, filepath.Base(filepath.Dir(p)))
|
|
}
|
|
}
|
|
}
|
|
// ADR 0663 §2: the assigner reads which modules exist by declaring the seat's verb revision (the grants part too, from W8).
|
|
if !slices.Contains(declaring, "mesh-delivery-assigner") {
|
|
t.Errorf("the parts of this repository declaring %s are %v, want the assigner", index.RevisionInvoke, declaring)
|
|
}
|
|
if m.RunsAs != m.Module || m.SecretsOwner != m.RunsAs {
|
|
t.Errorf("runs-as = %q, secrets-owner %q: the tools bundle runs on the indexer's own account (ADR 0621 §1)", m.RunsAs, m.SecretsOwner)
|
|
}
|
|
// ADR 0621 §2, ADR 0622 §1, ADR 0631 §1: each first-view tool answers exactly its readers; the indexer is on none, and
|
|
// graph answers the assigner alone.
|
|
// ADR 0663 §2: revision has no callers list; it answers the parts whose entry declares it.
|
|
callers := map[string]string{"manifests": "mesh-grants,node-tools,mesh-delivery-assigner", "verdicts": "mesh-grants",
|
|
"graph": "mesh-delivery-assigner"}
|
|
for _, a := range m.Build.Artifacts {
|
|
if a.Name != "tools" {
|
|
continue
|
|
}
|
|
if len(a.Env) != len(callers) {
|
|
t.Errorf("tools env = %v, want only the three callers lists", a.Env)
|
|
}
|
|
for tool, list := range callers {
|
|
if got := a.Env[views.CallersEnv(tool)]; got != list {
|
|
t.Errorf("%s callers = %q, want %q", tool, got, list)
|
|
}
|
|
if views.ParseCallers(a.Env[views.CallersEnv(tool)]).Allows("n1." + m.Module) {
|
|
t.Errorf("%s answers the indexer itself", tool)
|
|
}
|
|
}
|
|
// ADR 0631 How it is checked: graph refuses every caller but the assigner, the indexer itself included.
|
|
graphCallers := views.ParseCallers(a.Env[views.CallersEnv("graph")])
|
|
for caller, refused := range map[string]bool{"n1.mesh-delivery-assigner": false, "n1.mesh-grants": true, "n1.node-tools": true, "n1." + m.Module: true} {
|
|
if err := views.Refusal("graph", graphCallers, caller); (err != nil) != refused {
|
|
t.Errorf("graph to %s: refused %v, want refused %v", caller, err, refused)
|
|
}
|
|
}
|
|
}
|
|
// ADR 0635 §5: its views family is its ordinary events, `views.<state>` among its emits, and its one stream is the
|
|
// registrations' history (design 47 G §2, asserted above).
|
|
// ADR 0636 §4: seat-definition-changed and -removed are the seat mesh-catalog's events, said on the seat's subject and kept
|
|
// on the shared events stream, and not among its own emits.
|
|
for _, state := range []string{"candidates", "config-candidates", "findings", "graph", "heard", "manifests", "packages", "predefined", "seat-definitions", "taken", "verdicts"} {
|
|
if !slices.Contains(m.Emits, views.EventPrefix+state) {
|
|
t.Errorf("emits = %v: want %s%s", m.Emits, views.EventPrefix, state)
|
|
}
|
|
}
|
|
// ADR 0604 §2, ADR 0636 §4: it holds the seat mesh-catalog, serving its four verbs and seat-definitions from its tools
|
|
// bundle (which stays without a request subject); ADR 0663 §1: and revision, in the same runtime of its own.
|
|
if len(m.Claims) != 1 || m.Claims[0].Name != index.CatalogSeat || m.Claims[0].Scope != catalogue.ScopeMesh ||
|
|
!slices.Equal(m.Claims[0].Serves, []string{"modules", "module", "provides", "dependents", index.SeatDefinitionsVerb, "revision", "entry", "registrations", "register", "policy", "watch", "unwatch", "versions", "outdated", "input"}) {
|
|
t.Errorf("claims = %+v, want mesh-catalog with its seven verbs (entry: design 47 G §675)", m.Claims)
|
|
}
|
|
for _, e := range []string{index.SeatDefinitionChangedEvent, index.SeatDefinitionRemovedEvent} {
|
|
if slices.Contains(m.Emits, e) {
|
|
t.Errorf("emits lists %s, which the seat says (the validator refuses a seat's event among a holder's emits)", e)
|
|
}
|
|
}
|
|
// 1585/T11 (ADR 0633 §1, §5): the take-in events are its ordinary events, with no stream of its own.
|
|
if !slices.Contains(m.Emits, takein.TakeInPendingEvent) || !slices.Contains(m.Emits, takein.TakeInTakenEvent) {
|
|
t.Errorf("emits = %v: want both take-in events emitted", m.Emits)
|
|
}
|
|
// No bus, no other seat (ADR 0437 §4); it uses the seat operator-channel alone (design 47 G §700, A-74, above).
|
|
for _, k := range []string{"logs", "provides", "requires", "defines-seats", "seat", "seats", "bus"} {
|
|
if _, ok := top[k]; ok {
|
|
t.Errorf("the manifest declares %q: the indexer has none", k)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestManifestProcess(t *testing.T) { // 1238/AC1
|
|
m, _ := load(t)
|
|
var procs []map[string]any
|
|
for _, r := range m.Resources {
|
|
if r["type"] == "process" {
|
|
procs = append(procs, r)
|
|
}
|
|
if r["type"] == "tool" || r["type"] == "seat" {
|
|
t.Errorf("resource %v: the indexer serves no tool and holds no seat", r)
|
|
}
|
|
}
|
|
if len(procs) != 1 {
|
|
t.Fatalf("%d process resources, want one", len(procs))
|
|
}
|
|
p := procs[0]
|
|
if p["artifact"] != "program" || !reflect.DeepEqual(p["run"], []any{"./mesh-delivery-indexer"}) {
|
|
t.Errorf("process = %v", p)
|
|
}
|
|
env, _ := p["env"].(map[string]any)
|
|
if len(env) != 1 || env["MESH_BROKER_FILE"] != "${dir:state}/broker" {
|
|
t.Errorf("env = %v", p["env"])
|
|
}
|
|
if _, bus := p["bus"]; bus {
|
|
t.Errorf("the process declares a bus: it runs on its own broker credential")
|
|
}
|
|
if len(m.Build.Artifacts) != 2 {
|
|
t.Fatalf("artifacts = %+v, want the program and the tools", m.Build.Artifacts)
|
|
}
|
|
if a := m.Build.Artifacts[1]; a.Name != "tools" || a.Kind != "bundle" || a.Binary != "mesh-delivery-indexer-tools" || !reflect.DeepEqual(a.Loads, []string{"mesh-delivery-indexer-tools"}) {
|
|
t.Errorf("tools artifact = %+v", a) // 1945
|
|
} else if st, err := os.Stat(a.From); err != nil || !st.IsDir() {
|
|
t.Errorf("the tools' source %s: %v", a.From, err)
|
|
}
|
|
a := m.Build.Artifacts[0]
|
|
if st, err := os.Stat(a.From); err != nil || !st.IsDir() || a.Binary != "mesh-delivery-indexer" || !strings.HasSuffix(a.From, a.Binary) {
|
|
t.Errorf("artifact = %+v", a)
|
|
}
|
|
}
|
|
|
|
func TestServesNoRequestSubjectAndHoldsNoTicker(t *testing.T) { // 1238/AC9 (ADR 0437 §8)
|
|
forbidden := []string{"Subscribe(", "QueueSubscribe", "ChanSubscribe", "time.NewTicker", "time.Tick", "time.NewTimer", "time.AfterFunc", "time.After(", "time.Sleep"}
|
|
var files int
|
|
for _, root := range []string{"cmd", "internal"} {
|
|
err := filepath.WalkDir(root, func(path string, d fs.DirEntry, err error) error {
|
|
if err != nil || d.IsDir() || !strings.HasSuffix(path, ".go") || strings.HasSuffix(path, "_test.go") {
|
|
return err
|
|
}
|
|
files++
|
|
src, err := os.ReadFile(path)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
for _, f := range forbidden {
|
|
// The seat list reader's Bus interface names a method Subscribe; the indexer's own bus hands it its own events
|
|
// directly and subscribes to nothing on the bus.
|
|
if f == "Subscribe(" && strings.HasSuffix(path, "seatlist.go") {
|
|
continue
|
|
}
|
|
if strings.Contains(string(src), f) {
|
|
t.Errorf("%s holds %s: the indexer serves no request subject and holds no timer", path, f)
|
|
}
|
|
}
|
|
return nil
|
|
})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
if files < 2 {
|
|
t.Fatalf("read %d source files, want the program's", files)
|
|
}
|
|
}
|
|
|
|
// Every forge read the program makes is a verb of the seat git granted in invokes, or the bus refuses the call (issue
|
|
// 1900); no program file names the forge module's own tools (milestone 47/G W4.15, design 47 *The seat git*).
|
|
func TestEveryGiteaToolTheCodeCallsIsInInvokes(t *testing.T) {
|
|
m, _ := load(t)
|
|
files, err := filepath.Glob("cmd/mesh-delivery-indexer/*.go")
|
|
if err != nil || len(files) == 0 {
|
|
t.Fatalf("no program files: %v", err)
|
|
}
|
|
verbs := map[string]string{"VerbTrees": git.VerbTrees, "VerbFile": git.VerbFile, "VerbContains": git.VerbContains, "VerbOpenPulls": git.VerbOpenPulls}
|
|
forge, asked := regexp.MustCompile(`gitea\.gitea_[a-z_]+`), regexp.MustCompile(`git\.Verb[A-Za-z]+`)
|
|
seen := 0
|
|
for _, f := range files {
|
|
if strings.HasSuffix(f, "_test.go") {
|
|
continue
|
|
}
|
|
src, err := os.ReadFile(f)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
for _, tool := range forge.FindAllString(string(src), -1) {
|
|
t.Errorf("%s calls the forge module's own tool %s, not the seat git", f, tool)
|
|
}
|
|
for _, v := range asked.FindAllString(string(src), -1) {
|
|
seen++
|
|
verb, ok := verbs[strings.TrimPrefix(v, "git.")]
|
|
if !ok || !slices.Contains(m.Invokes, "seat:"+git.Seat+"."+verb) {
|
|
t.Errorf("%s asks %s, which invokes does not grant", f, v)
|
|
}
|
|
}
|
|
}
|
|
if seen < 4 {
|
|
t.Errorf("found %d verbs of the seat git in the program, want at least the four it asks", seen)
|
|
}
|
|
}
|