I2a: the movers of a take-in are the moved fingerprints and their importers
A take-in's movers are the modules registered for a repository the source revision moved whose fingerprint differs from their entry in the branch's newest catalog revision, and every module, in any repository, importing a package one of them publishes. A module of another repository is no mover by its fingerprint alone; one with no build is none. Builds: design 47 H §743 (movers); A-476a Claude-Session: https://claude.ai/code/session_01JG73KHUnBze48rdua8u2sy
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
package index
|
||||
|
||||
import (
|
||||
"maps"
|
||||
"slices"
|
||||
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/trunk"
|
||||
)
|
||||
|
||||
// moversOf are the movers of one take-in (design 47 H §743, A-476a): of the modules registered for a repository the source
|
||||
// revision moved (moved, by the entry's repository), those whose fingerprint differs from their entry in before, the branch's
|
||||
// newest catalog revision (one it does not hold included); and every module, in any repository, that imports a package one of
|
||||
// them publishes. A module with no fingerprint (no build) is no mover. One {module, commit, fingerprint, repository} per mover,
|
||||
// by module name.
|
||||
func moversOf(before []meshcatalog.CatalogEntry, after map[string]meshcatalog.CatalogEntry, moved []string) []meshcatalog.TakeInEntry {
|
||||
was := make(map[string]string, len(before))
|
||||
for _, e := range before {
|
||||
was[e.Module] = e.Fp
|
||||
}
|
||||
inMoved := func(repository string) bool {
|
||||
return slices.ContainsFunc(moved, func(r string) bool { return trunk.SameRepository(r, repository) })
|
||||
}
|
||||
movers := map[string]bool{}
|
||||
published := map[string]bool{} // the packages the fingerprint's movers publish, by name
|
||||
for name, e := range after {
|
||||
if e.Fp == "" || !inMoved(e.Repository) {
|
||||
continue
|
||||
}
|
||||
if fp, ok := was[name]; ok && fp == e.Fp {
|
||||
continue
|
||||
}
|
||||
movers[name] = true
|
||||
for _, a := range e.Artifacts {
|
||||
if a.Package != nil && a.Package.Name != "" {
|
||||
published[a.Package.Name] = true
|
||||
}
|
||||
}
|
||||
}
|
||||
for name, e := range after {
|
||||
if movers[name] || e.Fp == "" {
|
||||
continue
|
||||
}
|
||||
for p := range e.Packages {
|
||||
if published[p] {
|
||||
movers[name] = true
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
out := make([]meshcatalog.TakeInEntry, 0, len(movers))
|
||||
for _, name := range slices.Sorted(maps.Keys(movers)) {
|
||||
e := after[name]
|
||||
out = append(out, meshcatalog.TakeInEntry{Module: name, Commit: e.Commit, Fingerprint: e.Fp, Repository: e.Repository})
|
||||
}
|
||||
return out
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
package index
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
|
||||
)
|
||||
|
||||
// A take-in's movers (design 47 H §743, A-476a): the moved repository's modules whose fingerprint moved, and every module that
|
||||
// imports a package of one of them; a module of another repository is no mover by its fingerprint alone.
|
||||
func TestMoversOf(t *testing.T) {
|
||||
sdk := func(fp string) meshcatalog.CatalogEntry {
|
||||
return meshcatalog.CatalogEntry{Module: "mesh-sdk", Repository: "novox/mesh-sdk", Commit: "s" + fp, Fp: fp,
|
||||
Artifacts: []meshcatalog.Artifact{{Language: "go", Package: &meshcatalog.ArtifactPackage{Ecosystem: "go", Name: "git.novox.be/novox/mesh-sdk/go"}}}}
|
||||
}
|
||||
importer := meshcatalog.CatalogEntry{Module: "gate", Repository: "novox/mesh-catalog", Commit: "g1", Fp: "g",
|
||||
Packages: map[string]string{"git.novox.be/novox/mesh-sdk/go": "v0.1.20"}}
|
||||
other := func(fp string) meshcatalog.CatalogEntry {
|
||||
return meshcatalog.CatalogEntry{Module: "feh", Repository: "novox/mesh-catalog", Commit: "f1", Fp: fp}
|
||||
}
|
||||
entries := func(es ...meshcatalog.CatalogEntry) map[string]meshcatalog.CatalogEntry {
|
||||
m := map[string]meshcatalog.CatalogEntry{}
|
||||
for _, e := range es {
|
||||
m[e.Module] = e
|
||||
}
|
||||
return m
|
||||
}
|
||||
for _, c := range []struct {
|
||||
name string
|
||||
before []meshcatalog.CatalogEntry
|
||||
after map[string]meshcatalog.CatalogEntry
|
||||
moved []string
|
||||
want []string
|
||||
}{
|
||||
{"a mesh-sdk commit moves mesh-sdk and its importers", []meshcatalog.CatalogEntry{sdk("1"), importer, other("f")},
|
||||
entries(sdk("2"), importer, other("f")), []string{"novox/mesh-sdk"}, []string{"gate", "mesh-sdk"}},
|
||||
{"a commit changing only a document names no mover", []meshcatalog.CatalogEntry{sdk("1"), importer},
|
||||
entries(sdk("1"), importer), []string{"novox/mesh-sdk"}, nil},
|
||||
{"a module not registered for the moved repository is no mover", []meshcatalog.CatalogEntry{sdk("1"), other("f")},
|
||||
entries(sdk("1"), other("f2")), []string{"novox/mesh-sdk"}, nil},
|
||||
{"a module the newest revision does not hold moves", nil,
|
||||
entries(other("f")), []string{"novox/mesh-catalog"}, []string{"feh"}},
|
||||
{"a module with no fingerprint is no mover", nil,
|
||||
entries(other("")), []string{"novox/mesh-catalog"}, nil},
|
||||
} {
|
||||
t.Run(c.name, func(t *testing.T) {
|
||||
var got []string
|
||||
for _, m := range moversOf(c.before, c.after, c.moved) {
|
||||
if e := c.after[m.Module]; m.Commit != e.Commit || m.Fingerprint != e.Fp || m.Repository != e.Repository {
|
||||
t.Errorf("mover %s = %+v, not its entry's commit, fingerprint and repository", m.Module, m)
|
||||
}
|
||||
got = append(got, m.Module)
|
||||
}
|
||||
if !reflect.DeepEqual(got, c.want) {
|
||||
t.Errorf("movers = %v, want %v", got, c.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user