Indexer (A-333): a package-only cycle is not refused, and no delivery edge ends at a package

The cycle rule A-326 built refused today's trunk catalogue and G's own: a cycle of package edges alone (imports given to
every artifact of a module) and a kind-6 edge into a contracts package closing a cycle. A package is delivered only inside
what uses it, so no edge of kinds 2, 4, 5 or 6 is made into one, and a cycle of kind-1 edges alone is left to the
language's build. The dry run's entries of both catalogues are kept as test data and accepted.

Builds: design 47 G §47, §49, §51; A-326, A-333

Claude-Session: https://claude.ai/code/session_01NcbgfGKaxw984XyAPfLm4h
This commit is contained in:
2026-11-13 02:09:34 +01:00
parent df02ee40fd
commit c2e2ac82fa
4 changed files with 59 additions and 26 deletions
@@ -102,7 +102,7 @@ func pathsTo(entries map[string]meshcatalog.CatalogEntry) map[string]map[string]
// of kinds 1 to 4 to B (built[b][a]): a is then what B's new version is built from or needs, which B's running version acts on (§270).
func actingEdges(a meshcatalog.CatalogEntry, all map[string]meshcatalog.CatalogEntry, built map[string]map[string]bool) []meshcatalog.Edge {
to := primaryOf(a)
if to == "" {
if to == "" || deliveryIntoPackage(5, to, a) {
return nil
}
var out []meshcatalog.Edge
@@ -159,6 +159,15 @@ func primaryOf(e meshcatalog.CatalogEntry) meshcatalog.ArtifactRef {
return ""
}
// deliveryIntoPackage says whether an edge of kind ending at artifact to of entry a is a delivery edge (kinds 2, 4, 5, 6) into a
// package artifact, which is not made (A-333): a package is delivered only inside what uses it, which a kind-1 edge carries.
func deliveryIntoPackage(kind int64, to meshcatalog.ArtifactRef, a meshcatalog.CatalogEntry) bool {
if kind == 1 || kind == 3 {
return false
}
return slices.ContainsFunc(a.Artifacts, func(x meshcatalog.Artifact) bool { return x.Ref == to && x.Kind == "package" })
}
// ofLanguage are the artifacts of e a build of language (go or another) produces: its packages' and programs' of that language.
func ofLanguage(e meshcatalog.CatalogEntry, language string) []meshcatalog.ArtifactRef {
var out []meshcatalog.ArtifactRef
@@ -173,7 +182,7 @@ func ofLanguage(e meshcatalog.CatalogEntry, language string) []meshcatalog.Artif
func edgesOf(a meshcatalog.CatalogEntry, all map[string]meshcatalog.CatalogEntry) []meshcatalog.Edge {
var out []meshcatalog.Edge
add := func(e meshcatalog.Edge) {
if e.From != "" && e.To != "" && e.From != e.To && !slices.Contains(out, e) {
if e.From != "" && e.To != "" && e.From != e.To && !slices.Contains(out, e) && !deliveryIntoPackage(e.Kind, e.To, a) {
out = append(out, e)
}
}
@@ -379,12 +388,12 @@ func (ix *Indexer) withActs(ctx context.Context, entries map[string]meshcatalog.
return WithActs(entries, defs)
}
// RefusedCycle is a cycle of the entries' edges that the take-in refuses (design 47 G §49, A-326), as the artifacts it passes
// through with the first named again at its end; nil when there is none. A cycle of delivery edges (kinds 2, 4, 5, 6) alone
// is delivered as one step, so only a cycle holding a build edge (kind 1 or 3) is refused. A build edge of kind 3 that goes
// out of an artifact of a module holding a build seat into an artifact that seat builds is where such a cycle is broken: the
// running version builds the new one (§270), so a cycle through it is allowed, as the cycle through a build module's own
// inputs is.
// RefusedCycle is a cycle of the entries' edges that the take-in refuses (design 47 G §49, A-326, A-333), as the artifacts it
// passes through with the first named again at its end; nil when there is none. A cycle of delivery edges (kinds 2, 4, 5, 6)
// alone is delivered as one step, so only a cycle holding a build edge (kind 1 or 3) is refused, and not one of package edges
// (kind 1) alone: the language's own build refuses a real import cycle (A-333). A build edge of kind 3 that goes out of an
// artifact of a module holding a build seat into an artifact that seat builds is where such a cycle is broken: the running
// version builds the new one (§270), so a cycle through it is allowed, as the cycle through a build module's own inputs is.
func RefusedCycle(entries map[string]meshcatalog.CatalogEntry) []meshcatalog.ArtifactRef {
var edges []meshcatalog.Edge
for _, m := range slices.Sorted(maps.Keys(entries)) {
@@ -394,17 +403,15 @@ func RefusedCycle(entries map[string]meshcatalog.CatalogEntry) []meshcatalog.Art
}
}
}
next := map[meshcatalog.ArtifactRef][]meshcatalog.ArtifactRef{}
next := map[meshcatalog.ArtifactRef][]meshcatalog.Edge{}
for _, x := range edges {
if !slices.Contains(next[x.From], x.To) {
next[x.From] = append(next[x.From], x.To)
}
next[x.From] = append(next[x.From], x)
}
for _, x := range edges {
if x.Kind != 1 && x.Kind != 3 {
continue
}
if path := shortestPath(next, x.To, x.From); path != nil {
if path := pathBack(next, x.To, x.From, x.Kind != 1); path != nil {
return append([]meshcatalog.ArtifactRef{x.From}, path...)
}
}
@@ -434,23 +441,30 @@ func brokenAtTheRunningVersion(x meshcatalog.Edge, entries map[string]meshcatalo
})
}
// shortestPath is the shortest path of next from start to end, start and end included; nil when end cannot be reached.
func shortestPath(next map[meshcatalog.ArtifactRef][]meshcatalog.ArtifactRef, start, end meshcatalog.ArtifactRef) []meshcatalog.ArtifactRef {
before := map[meshcatalog.ArtifactRef]meshcatalog.ArtifactRef{start: ""}
queue := []meshcatalog.ArtifactRef{start}
// pathBack is the shortest path of next from start to end, start and end included, that holds an edge of a kind other than 1
// unless other is true already (a cycle of package edges alone is none of §49's, A-333); nil when there is none.
func pathBack(next map[meshcatalog.ArtifactRef][]meshcatalog.Edge, start, end meshcatalog.ArtifactRef, other bool) []meshcatalog.ArtifactRef {
type at struct {
ref meshcatalog.ArtifactRef
other bool
}
from := at{start, other}
before := map[at]at{from: {}}
queue := []at{from}
for len(queue) > 0 {
at := queue[0]
cur := queue[0]
queue = queue[1:]
if at == end {
if cur.ref == end && cur.other {
var path []meshcatalog.ArtifactRef
for ; at != ""; at = before[at] {
path = append([]meshcatalog.ArtifactRef{at}, path...)
for ; cur != (at{}); cur = before[cur] {
path = append([]meshcatalog.ArtifactRef{cur.ref}, path...)
}
return path
}
for _, n := range next[at] {
for _, x := range next[cur.ref] {
n := at{x.To, cur.other || x.Kind != 1}
if _, seen := before[n]; !seen {
before[n] = at
before[n] = cur
queue = append(queue, n)
}
}
@@ -2,6 +2,8 @@ package index
import (
"context"
"encoding/json"
"os"
"slices"
"testing"
"time"
@@ -228,8 +230,10 @@ func TestAKeptRevisionHoldsTheActsAndTheKindFiveEdges(t *testing.T) {
}
}
// A-326 (design 47 G §49, §51): a cycle through a build module's own inputs is broken at its running version and allowed; any
// other cycle with a build edge is refused, naming every artifact on it; a cycle of delivery edges alone is one step.
// A-326, A-333 (design 47 G §49, §51): a cycle through a build module's own inputs is broken at its running version and
// allowed, as are a cycle of package edges alone and a cycle of delivery edges alone; any other cycle with a build edge is
// refused, naming every artifact on it. Today's trunk catalogue and G's own (the entries of G's dry run, 2026-11-13, kept
// in testdata with what the edges are computed from) are accepted.
func TestACycleWithABuildEdgeIsRefusedUnlessABuildSeatsRunningVersionBreaksIt(t *testing.T) {
builder := meshcatalog.CatalogEntry{Module: "mesh-build-go", Artifacts: []meshcatalog.Artifact{{Ref: "mesh-build-go:files", Language: "go"}},
Acts: []meshcatalog.ActingRule{{Seat: "node-build-go", Step: seatdef.StepBuild, On: "go"}}}
@@ -251,7 +255,7 @@ func TestACycleWithABuildEdgeIsRefusedUnlessABuildSeatsRunningVersionBreaksIt(t
want []meshcatalog.ArtifactRef
}{
{"the trunk catalogue's cycle through a build module's own inputs", []meshcatalog.CatalogEntry{trunkCycle, handActs}, nil},
{"two artifacts each needing the other's new package", []meshcatalog.CatalogEntry{a, b}, []meshcatalog.ArtifactRef{"b:go", "a:go", "b:go"}},
{"two artifacts each needing the other's new package, package edges alone", []meshcatalog.CatalogEntry{a, b}, nil},
{"the same cycle from a module that holds no build seat", []meshcatalog.CatalogEntry{noSeat, handActs},
[]meshcatalog.ArtifactRef{"mesh-build-go:files", "mesh-hand-acts:tools", "mesh-build-go:files"}},
{"a cycle of delivery edges alone", []meshcatalog.CatalogEntry{verbsOnly, verbsBack}, nil},
@@ -264,4 +268,17 @@ func TestACycleWithABuildEdgeIsRefusedUnlessABuildSeatsRunningVersionBreaksIt(t
t.Errorf("%s: refused %v, want %v", c.name, got, c.want)
}
}
for _, name := range []string{"catalog-entries-trunk-2026-11-13", "catalog-entries-47-G-2026-11-13"} {
raw, err := os.ReadFile("testdata/" + name + ".json")
if err != nil {
t.Fatal(err)
}
var entries map[string]meshcatalog.CatalogEntry
if err := json.Unmarshal(raw, &entries); err != nil {
t.Fatal(err)
}
if got := RefusedCycle(WithEdges(entries)); got != nil {
t.Errorf("%s: refused %v, want the catalogue accepted", name, got)
}
}
}
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long