I7 (4b): a repository with no module registers as a source alone

register takes the source form (a check of a build seat and a step kind,
no module, no path, one branch) and keeps it, its history and its
registration-changed under source.<owner>.<name>. One whose tree at the
branch's head holds a module.json at its root or under modules/, read
through the seat git's trees, is refused holds-manifest. A move of its
branch is taken in with no movers.

Builds: design 47 H2 §815, §806; H-A-349 DQ-9, H-A-438, H-A-450
This commit is contained in:
2026-11-22 02:17:59 +01:00
parent 3e90604eb4
commit 5e94328066
5 changed files with 248 additions and 24 deletions
@@ -57,7 +57,9 @@ func newRegistry(js jetstream.JetStream, conn *nats.Conn, cred process.Account,
if err != nil {
return err
}
_, err = js.Publish(ctx, historySubject(cred.Module, r.Module), data, jetstream.WithMsgID(fmt.Sprintf("%s.%d", r.Module, r.Version)))
// A source-only registration's versions are kept under its key source.<owner>.<name> (design 47 H2 §815).
name := index.RegistrationName(r)
_, err = js.Publish(ctx, historySubject(cred.Module, name), data, jetstream.WithMsgID(fmt.Sprintf("%s.%d", name, r.Version)))
if err == nil {
// Past 80 % full the stream's fill is a finding (design 47 G §704); read within a second, and said when it cannot be.
fctx, cancel := context.WithTimeout(ctx, time.Second)
@@ -105,6 +107,10 @@ func newRegistry(js jetstream.JetStream, conn *nats.Conn, cred process.Account,
Say: func(_ context.Context, e meshcatalog.RegistrationChangedEvent) error {
return publishAs(conn, cred, seatEventSubject(meshcatalog.EventRegistrationChanged), fmt.Sprintf("%s-%s-%d", meshcatalog.EventRegistrationChanged, e.Module, e.Version), e)
},
// The directories of a commit that hold a module.json, the seat git's trees (design 47 H2 §815; H-A-450).
ModuleDirs: func(repository, commit string) ([]string, error) {
return trunkVia(call)(context.Background(), repository, commit)
},
Placement: func(module string) ([]mma.ModulePlacement, error) {
raw, err := call("seat:"+mma.Seat+"."+mma.VerbPlacement, mma.PlacementInput{Module: module})
if err != nil {
@@ -625,6 +625,30 @@ func TestIndexerWhole(t *testing.T) {
if _, _, err := index.ReadRevision(ctx, objects, "gamma.1"); err != nil {
t.Errorf("gamma.1 is not kept: %v", err)
}
// Design 47 H2 §815: a source-only registration, kept under source.<owner>.<name>, watches its branch as any registration
// does, and a move of that branch by its repository, which holds no manifest, is taken in with no movers.
const hqCommit = "4444444444444444444444444444444444444444"
forge.put(hqCommit, repoAt{trees: map[string]string{}})
watchBranch(t, ctx, js, "delta")
source, _ := json.Marshal(meshcatalog.Registration{V: 1, Origin: "novox/hq", Branches: []string{"delta"},
Check: &meshcatalog.SourceCheck{Seat: meshcatalog.SourceCheckSeatNodeBuildGo, Step: meshcatalog.SourceCheckStepUnit}})
if _, err := regs.Put(ctx, meshcatalog.RegistrationsBySourceOwnerNameKey("novox", "hq"), source); err != nil {
t.Fatal(err)
}
if _, err := js.Publish(ctx, meshcatalog.SubjectRegistrationChanged, []byte(`{"module":"source.novox.hq"}`)); err != nil {
t.Fatal(err)
}
sayMoved(t, ctx, js, "delta", 1, c10, true)
heard.next(t, "delta", 1)
moved, _ := json.Marshal(meshdelivery.SourceMovedEvent{V: 1, Branch: "delta", Source: 2, Call: "00112233445566aa",
Heads: []meshdelivery.SourceMovedEventHeadsItem{{Repository: "novox/hq", Commit: hqCommit}}})
if _, err := js.Publish(ctx, meshdelivery.SubjectSourceMoved("delta", "2"), moved); err != nil {
t.Fatal(err)
}
if hq := heard.next(t, "delta", 2); len(hq.Entries) != 0 || hq.Revision != 2 {
t.Errorf("the move of novox/hq on delta said %+v, want revision 2 with no movers", hq)
}
}
// toolNamed is the tool of that name.
@@ -5,6 +5,7 @@ import (
"encoding/json"
"errors"
"fmt"
"path"
"slices"
"sort"
"strings"
@@ -107,8 +108,68 @@ func ProposalKey(verb, module, branch string) string {
return k
}
// RegistrationKey is a module's key in registrations.
func RegistrationKey(module string) string { return keys.EscapeName(module) }
// RegistrationKey is a registration's key in registrations: a module's name escaped as a key's name is, and a source-only
// registration's name, its key source.<owner>.<name>, as it stands (design 47 H2 §815; H-A-349 DQ-9).
func RegistrationKey(module string) string {
if isSourceMember(module) {
return module
}
return keys.EscapeName(module)
}
// RegistrationName is the name a registration is kept, asked and said under: its module, or for a source-only registration
// (a check and no module) its key source.<owner>.<name> from its origin (design 47 H2 §815; H-A-438). Empty when a
// source-only registration's origin is not <owner>/<name>.
func RegistrationName(reg meshcatalog.Registration) string {
if reg.Check == nil || reg.Module != "" {
return reg.Module
}
owner, name, ok := strings.Cut(trunk.RepositoryName(reg.Origin), "/")
if !ok || owner == "" || name == "" || strings.ContainsAny(owner+name, "./") {
return ""
}
return meshcatalog.RegistrationsBySourceOwnerNameKey(owner, name)
}
// sourceForm refuses a source-only registration that is not of its form (design 47 H2 §815): it names no module and no
// path, one branch at most (none takes the default branch), and a check of a build seat and a step kind the seat names.
func sourceForm(reg meshcatalog.Registration) error {
if reg.Module != "" || reg.Path != "" {
return errors.New("a source-only registration (check) names no module and no path: a module registers with its manifest's path instead")
}
if len(reg.Branches) > 1 {
return fmt.Errorf("a source-only registration watches one branch, not %d", len(reg.Branches))
}
if !slices.Contains([]string{meshcatalog.SourceCheckSeatNodeBuildGo, meshcatalog.SourceCheckSeatNodeBuildNode, meshcatalog.SourceCheckSeatNodeBuildImage}, reg.Check.Seat) {
return fmt.Errorf("the check's seat %q is no build seat (node-build-go, node-build-node or node-build-image)", reg.Check.Seat)
}
if !slices.Contains([]string{meshcatalog.SourceCheckStepLint, meshcatalog.SourceCheckStepUnit, meshcatalog.SourceCheckStepIntegration}, reg.Check.Step) {
return fmt.Errorf("the check's step %q is no step kind (lint, unit or integration)", reg.Check.Step)
}
if RegistrationName(reg) == "" {
return fmt.Errorf("a source-only registration's origin is its repository as <owner>/<name>, not %q", reg.Origin)
}
return nil
}
// holdsManifest is the manifest a repository holds at a commit, read through the seat git's trees (design 47 H2 §815;
// H-A-450): a module.json at the tree's root or under modules/; empty when it holds none.
func (r *Registry) holdsManifest(repository, commit string) (string, error) {
if r.ModuleDirs == nil {
return "", errors.New("the trees of a repository are not asked of the seat git, so no source-only registration is judged")
}
dirs, err := r.ModuleDirs(repository, commit)
if err != nil {
return "", fmt.Errorf("the seat git does not answer the trees of %s at %.12s: %w", repository, commit, err)
}
slices.Sort(dirs)
for _, d := range dirs {
if d == "" || d == "." || strings.HasPrefix(d, "modules/") {
return path.Join(d, ModuleManifest), nil
}
}
return "", nil
}
// Registry is the registrations and the trusted changes of them. Its parts are the indexer's: the two states, the history
// stream, the event, the seat git's branch, the seat operator-channel's ask.
@@ -128,6 +189,9 @@ type Registry struct {
Pruned func(ctx context.Context, module string, watched []string) error
// Branch reads a branch through the seat git; an empty branch asks the repository's default branch.
Branch func(repository, branch string) (gitseat.BranchAnswer, error)
// ModuleDirs reads the directories of a commit that hold a module.json through the seat git's trees, the root as "": a
// source-only registration whose repository holds a manifest is refused (design 47 H2 §815; H-A-450).
ModuleDirs func(repository, commit string) ([]string, error)
// Placement reads a module's placements through the seat mesh-module-assigner's verb placement: one per watched branch a row
// of its assignments names, with the nodes that run the module from it (design 47 G §704, A-62).
Placement func(module string) ([]mma.ModulePlacement, error)
@@ -192,7 +256,7 @@ func (r *Registry) RegistrationsAnswer(ctx context.Context, in meshcatalog.Regis
out := meshcatalog.RegistrationsAnswer{Registrations: []meshcatalog.Registration{}}
repository := trunk.RepositoryName(strings.TrimSpace(in.Repository))
keep := func(reg meshcatalog.Registration) bool {
return (in.Module == "" || reg.Module == in.Module) && (repository == "" || trunk.SameRepository(reg.Origin, repository))
return (in.Module == "" || RegistrationName(reg) == in.Module) && (repository == "" || trunk.SameRepository(reg.Origin, repository))
}
if in.Module != "" {
reg, found, err := r.Registration(ctx, in.Module)
@@ -335,30 +399,37 @@ func compose(verb string, cur meshcatalog.Registration, found bool, change json.
}
next := in.Registration
next.Version, next.Warrant, next.By, next.At = 0, "", "", nil
name := RegistrationName(next)
var lines []string
if !found {
lines = append(lines, fmt.Sprintf("%s: registered from %s, watching %s", next.Module, next.Origin, strings.Join(next.Branches, ", ")))
lines = append(lines, stepLines(next.Module+" ", meshcatalog.StepStatuses{}, next.Policy.Steps)...)
lines = append(lines, fmt.Sprintf("%s: registered from %s, watching %s", name, next.Origin, strings.Join(next.Branches, ", ")))
if next.Check != nil {
lines = append(lines, fmt.Sprintf("%s: checked by the step %s on the seat %s", name, next.Check.Step, next.Check.Seat))
}
lines = append(lines, stepLines(name+" ", meshcatalog.StepStatuses{}, next.Policy.Steps)...)
return next, lines, nil
}
if cur.Origin != next.Origin {
lines = append(lines, fmt.Sprintf("%s: origin %s -> %s", next.Module, cur.Origin, next.Origin))
lines = append(lines, fmt.Sprintf("%s: origin %s -> %s", name, cur.Origin, next.Origin))
}
if cur.Path != next.Path {
lines = append(lines, fmt.Sprintf("%s: manifest path %s -> %s", next.Module, cur.Path, next.Path))
lines = append(lines, fmt.Sprintf("%s: manifest path %s -> %s", name, cur.Path, next.Path))
}
if was, now := checkWords(cur.Check), checkWords(next.Check); was != now {
lines = append(lines, fmt.Sprintf("%s: check %s -> %s", name, was, now))
}
for _, b := range next.Branches {
if !slices.Contains(cur.Branches, b) {
lines = append(lines, fmt.Sprintf("%s: watches %s", next.Module, b))
lines = append(lines, fmt.Sprintf("%s: watches %s", name, b))
}
}
for _, b := range cur.Branches {
if !slices.Contains(next.Branches, b) {
lines = append(lines, fmt.Sprintf("%s: stops watching %s", next.Module, b))
lines = append(lines, fmt.Sprintf("%s: stops watching %s", name, b))
}
}
lines = append(lines, stepLines(next.Module+" ", cur.Policy.Steps, next.Policy.Steps)...)
lines = append(lines, artifactLines(next.Module, cur.Policy, next.Policy)...)
lines = append(lines, stepLines(name+" ", cur.Policy.Steps, next.Policy.Steps)...)
lines = append(lines, artifactLines(name, cur.Policy, next.Policy)...)
return next, lines, nil
case verbPolicy:
var in meshcatalog.PolicyInput
@@ -402,6 +473,14 @@ func compose(verb string, cur meshcatalog.Registration, found bool, change json.
return cur, nil, fmt.Errorf("%q is no change of a registration", verb)
}
// checkWords says a source-only registration's check as a line names it: none for a module's.
func checkWords(c *meshcatalog.SourceCheck) string {
if c == nil {
return "none"
}
return c.Step + " on " + c.Seat
}
func artifactLines(module string, old, next meshcatalog.Policy) []string {
names := map[string]bool{}
for k := range old.Artifacts {
@@ -433,7 +512,12 @@ func (r *Registry) Propose(ctx context.Context, verb, caller string, change json
if err := json.Unmarshal(change, &in); err != nil {
return meshcatalog.RegistrationAsked{}, fmt.Errorf("register takes a registration: %w", err)
}
module, why = in.Registration.Module, in.Why
if in.Registration.Check != nil {
if err := sourceForm(in.Registration); err != nil {
return meshcatalog.RegistrationAsked{}, err
}
}
module, why = RegistrationName(in.Registration), in.Why
case verbPolicy:
var in meshcatalog.PolicyInput
if err := json.Unmarshal(change, &in); err != nil {
@@ -464,6 +548,10 @@ func (r *Registry) Propose(ctx context.Context, verb, caller string, change json
if verb != verbRegister && !found {
return refused(module, meshcatalog.RegistrationAskedRefusedUnknownModule, module+" is not registered: register it first"), nil
}
// A source-only registration watches one branch (design 47 H2 §815).
if verb == verbWatch && cur.Check != nil && !slices.Contains(cur.Branches, branch) && len(cur.Branches) > 0 {
return meshcatalog.RegistrationAsked{}, fmt.Errorf("%s is a source-only registration, which watches one branch (%s)", module, strings.Join(cur.Branches, ", "))
}
// An unwatch of a branch a placement names is refused, naming the placement (§704, A-62).
if verb == verbUnwatch {
if r.Placement == nil {
@@ -484,9 +572,10 @@ func (r *Registry) Propose(ctx context.Context, verb, caller string, change json
if verb == verbRegister {
var in meshcatalog.RegisterInput
_ = json.Unmarshal(change, &in)
if in.Registration.Origin == "" || in.Registration.Path == "" {
if in.Registration.Origin == "" || (in.Registration.Path == "" && in.Registration.Check == nil) {
return meshcatalog.RegistrationAsked{}, errors.New("name the registration's origin and the path of its manifest")
}
head := ""
if len(in.Registration.Branches) == 0 {
a, err := r.Branch(in.Registration.Origin, "")
if err != nil {
@@ -495,11 +584,34 @@ func (r *Registry) Propose(ctx context.Context, verb, caller string, change json
if a.Error != "" || a.Branch == "" {
return meshcatalog.RegistrationAsked{}, fmt.Errorf("the default branch of %s is not read: %s", in.Registration.Origin, a.Error)
}
in.Registration.Branches = []string{a.Branch}
in.Registration.Branches, head = []string{a.Branch}, a.Head
if change, err = json.Marshal(in); err != nil {
return meshcatalog.RegistrationAsked{}, err
}
}
// A source-only registration of a repository that holds a manifest is refused: its module registers instead
// (design 47 H2 §815; H-A-450), judged from the tree at the branch's head through the seat git.
if in.Registration.Check != nil {
branch := in.Registration.Branches[0]
if head == "" {
a, err := r.Branch(in.Registration.Origin, branch)
if err != nil {
return meshcatalog.RegistrationAsked{}, fmt.Errorf("the seat git does not answer the branch %s of %s: %w", branch, in.Registration.Origin, err)
}
if a.Error != "" || a.Head == "" {
return meshcatalog.RegistrationAsked{}, fmt.Errorf("the head of the branch %s of %s is not read: %s", branch, in.Registration.Origin, a.Error)
}
head = a.Head
}
held, err := r.holdsManifest(in.Registration.Origin, head)
if err != nil {
return meshcatalog.RegistrationAsked{}, err
}
if held != "" {
return refused(module, meshcatalog.RegistrationAskedRefusedHoldsManifest,
fmt.Sprintf("%s holds %s at %.12s of %s: a repository with a manifest registers its module, not a source alone", in.Registration.Origin, held, head, branch)), nil
}
}
}
steps := []meshcatalog.StepStatuses{}
switch verb {
@@ -837,14 +949,16 @@ func (r *Registry) apply(ctx context.Context, key string, p Proposal, w oc.Warra
func (r *Registry) write(ctx context.Context, key string, p Proposal, next meshcatalog.Registration, w oc.Warrant) error {
at := r.now()
next.V, next.Version, next.Warrant, next.By, next.At = 1, p.Was+1, w.Ask, p.Caller, &at
// A source-only registration is kept, said and pruned under its key source.<owner>.<name> (§815; H-A-438).
name := RegistrationName(next)
began := time.Now()
step := func(what string) {
r.logf("registration %s version %d: %s (%s since its start)", next.Module, next.Version, what, time.Since(began).Round(time.Millisecond))
r.logf("registration %s version %d: %s (%s since its start)", name, next.Version, what, time.Since(began).Round(time.Millisecond))
}
step("writing")
if r.History != nil {
if err := r.History(ctx, next); err != nil {
return fmt.Errorf("the version %d of %s is not kept on %s, so it is not written: %w", next.Version, next.Module, RegistrationHistoryStream, err)
return fmt.Errorf("the version %d of %s is not kept on %s, so it is not written: %w", next.Version, name, RegistrationHistoryStream, err)
}
step("kept on " + RegistrationHistoryStream)
}
@@ -852,10 +966,10 @@ func (r *Registry) write(ctx context.Context, key string, p Proposal, next meshc
if err != nil {
return err
}
err = write(ctx, r.Registrations, RegistrationKey(next.Module), func(old []byte, found bool) ([]byte, bool, error) {
err = write(ctx, r.Registrations, RegistrationKey(name), func(old []byte, found bool) ([]byte, bool, error) {
var cur meshcatalog.Registration
if found && json.Unmarshal(old, &cur) == nil && cur.Version != p.Was {
return nil, false, fmt.Errorf("the registration of %s is at version %d, not %d", next.Module, cur.Version, p.Was)
return nil, false, fmt.Errorf("the registration of %s is at version %d, not %d", name, cur.Version, p.Was)
}
return data, false, nil
})
@@ -865,21 +979,21 @@ func (r *Registry) write(ctx context.Context, key string, p Proposal, next meshc
step("written")
if r.Say != nil {
defer step("registration-changed said")
if err := r.Say(ctx, meshcatalog.RegistrationChangedEvent{V: 1, Module: next.Module, Version: next.Version, Moved: p.Lines, By: p.Caller, Warrant: w.Ask, At: &at}); err != nil {
r.logf("registration-changed of %s %d is not said: %v", next.Module, next.Version, err)
if err := r.Say(ctx, meshcatalog.RegistrationChangedEvent{V: 1, Module: name, Version: next.Version, Moved: p.Lines, By: p.Caller, Warrant: w.Ask, At: &at}); err != nil {
r.logf("registration-changed of %s %d is not said: %v", name, next.Version, err)
}
}
// A first registration watched no branch before, so no branch's builds are to be pruned.
if r.Pruned != nil && p.Was > 0 {
defer step("builds of unwatched branches pruned")
if err := r.Pruned(ctx, next.Module, next.Branches); err != nil {
r.logf("the builds of %s on the branches it no longer watches are not pruned: %v", next.Module, err)
if err := r.Pruned(ctx, name, next.Branches); err != nil {
r.logf("the builds of %s on the branches it no longer watches are not pruned: %v", name, err)
}
}
if key == "" {
return nil // a write of the seed's: no proposal key of its own to end
}
return r.endKey(ctx, key, p, ProposalApplied, fmt.Sprintf("applied as version %d of %s on %s", next.Version, next.Module, occ.Says(w)))
return r.endKey(ctx, key, p, ProposalApplied, fmt.Sprintf("applied as version %d of %s on %s", next.Version, name, occ.Says(w)))
}
// Restart reads each open key at the indexer's start (§667 A restart): a decided ask is applied or ended, an open one waited on,
@@ -189,6 +189,71 @@ func TestRegistrationsAreWrittenOnTheirWarrantOnly(t *testing.T) {
if un, _ := g.r.Propose(ctx, "policy", "s@n", pol("zz", meshcatalog.StepStatuses{Unit: "bypass"})); un.Refused != meshcatalog.RegistrationAskedRefusedUnknownModule {
t.Fatalf("a policy of an unregistered module: %+v", un)
}
// Design 47 H2 §815 (H-A-349 DQ-9, H-A-438, H-A-450): a repository with no module registers as a source alone, kept, kept in
// the history and said under source.<owner>.<name>; one whose tree at the branch's head holds a module.json at its root or
// under modules/ is refused holds-manifest, and a registration not of the source form is an error.
t.Run("a source-only registration", func(t *testing.T) {
g := newRegRig()
const head = "0123456789abcdef0123456789abcdef01234567"
dirs := map[string][]string{"novox/hq": {"tools/x"}, "novox/root": {""}, "novox/mods": {"cmd", "modules/x"}}
var asked []string
g.r.Branch = func(repo, branch string) (gitseat.BranchAnswer, error) {
if branch == "" {
branch = "main"
}
return gitseat.BranchAnswer{Branch: branch, Repository: repo, Head: head}, nil
}
g.r.ModuleDirs = func(repo, commit string) ([]string, error) {
asked = append(asked, repo+"@"+commit)
return dirs[repo], nil
}
check := &meshcatalog.SourceCheck{Seat: meshcatalog.SourceCheckSeatNodeBuildGo, Step: meshcatalog.SourceCheckStepUnit}
source := func(origin string, edit func(*meshcatalog.Registration)) json.RawMessage {
r := meshcatalog.Registration{Origin: origin, Check: check, Policy: meshcatalog.Policy{Steps: meshcatalog.StepStatuses{Unit: "required"}}}
if edit != nil {
edit(&r)
}
return mustJSON(meshcatalog.RegisterInput{Registration: r})
}
for _, origin := range []string{"novox/root", "novox/mods"} {
got, err := g.r.Propose(ctx, "register", "s@n", source(origin, nil))
if err != nil || got.Refused != meshcatalog.RegistrationAskedRefusedHoldsManifest || got.Ask != "" || !strings.Contains(got.Words, "module.json") {
t.Errorf("%s: %+v, %v; want refused holds-manifest naming its module.json and no ask", origin, got, err)
}
}
for name, edit := range map[string]func(*meshcatalog.Registration){
"a module": func(r *meshcatalog.Registration) { r.Module = "hq" },
"a path": func(r *meshcatalog.Registration) { r.Path = "module.json" },
"two branches": func(r *meshcatalog.Registration) { r.Branches = []string{"main", "beta"} },
"a free seat": func(r *meshcatalog.Registration) { r.Check = &meshcatalog.SourceCheck{Seat: "sh", Step: "unit"} },
} {
if got, err := g.r.Propose(ctx, "register", "s@n", source("novox/hq", edit)); err == nil {
t.Errorf("a source-only registration naming %s: %+v, want an error", name, got)
}
}
got, err := g.r.Propose(ctx, "register", "s@n", source("novox/hq", nil))
if err != nil || got.Ask == "" || got.Module != "source.novox.hq" || !strings.Contains(strings.Join(got.Lines, "\n"), "source.novox.hq: checked by the step unit on the seat node-build-go") {
t.Fatalf("register a source: %+v, %v; want an ask of source.novox.hq naming its check", got, err)
}
if len(asked) == 0 || asked[len(asked)-1] != "novox/hq@"+head {
t.Errorf("the trees read %v, want novox/hq at the default branch's head", asked)
}
g.decide(t, got.Ask, "approve")
if v, _, found, _ := g.r.Registrations.Get(ctx, "source.novox.hq"); !found || !strings.Contains(string(v), `"check":{"seat":"node-build-go","step":"unit"}`) || strings.Contains(string(v), `"module"`) {
t.Fatalf("registrations under source.novox.hq: %s (%t), want the source form with no module", v, found)
}
if len(g.history) != 1 || RegistrationName(g.history[0]) != "source.novox.hq" || len(g.events) != 1 || g.events[0].Module != "source.novox.hq" {
t.Fatalf("history %+v, events %+v; want one version and registration-changed of source.novox.hq", g.history, g.events)
}
for _, in := range []meshcatalog.RegistrationsInput{{Module: "source.novox.hq"}, {Repository: "novox/hq"}} {
if a, err := g.r.RegistrationsAnswer(ctx, in); err != nil || len(a.Registrations) != 1 || a.Registrations[0].Branches[0] != "main" {
t.Errorf("registrations %+v: %+v, %v; want the source alone, watching main", in, a, err)
}
}
if w, err := g.r.Propose(ctx, "watch", "s@n", mustJSON(meshcatalog.WatchInput{Module: "source.novox.hq", Branch: "beta"})); err == nil {
t.Errorf("a second branch of a source-only registration: %+v, want an error", w)
}
})
}
func mustJSON(v any) json.RawMessage { b, _ := json.Marshal(v); return b }
@@ -105,6 +105,21 @@ func TestASourceRevisionIsTakenInAsOneRevision(t *testing.T) {
if _, err := ix.TakeInSource(ctx, old); !errors.Is(err, ErrOldForm) {
t.Errorf("a source-moved with no call answered %v, want ErrOldForm", err)
}
// Design 47 H2 §815: a move of a source-only registration's branch (a repository with no manifest) is taken in as a
// take-in with no movers.
read := ix.Read
ix.Read = func(ctx context.Context, repository, sha, dir string) (RepoRead, error) {
if repository == "novox/hq" {
return RepoRead{Root: "1111111111111111111111111111111111111111", Trees: map[string]string{}, Manifests: map[string]string{}}, nil
}
return read(ctx, repository, sha, dir)
}
hq := meshdelivery.SourceMovedEvent{V: 1, Branch: "main", Source: 9, Call: "00112233445566aa",
Heads: []meshdelivery.SourceMovedEventHeadsItem{{Repository: "novox/hq", Commit: "2222222222222222222222222222222222222222"}}}
if src, err := ix.TakeInSource(ctx, hq); err != nil || len(src.Entries) != 0 || src.Revision != 3 || src.Source != 9 {
t.Errorf("a source-only repository's move said %+v (%v), want revision 3 of source 9 with no movers", src, err)
}
ix.Read = read
// Design 47 H2 §803, H-A-409: a take-in says what it waits on, in the journal, in takeins and past five minutes as a finding.
t.Run("a take-in says what it waits on", func(t *testing.T) {
running := newMem()