I6: a take-in moves another repository's importer by its import set, in either language

Review r1 finding 1: a module of another repository was recomputed only when
a pin's Go module path mapped to the moved repository, so a TypeScript
importer of @novox/mesh-sdk never moved on a mesh-sdk take-in. It now moves
when its reported import set holds a package the moved repository publishes
(the module graph's entries), or, with no set, when a pin names one.

Builds: design 47 H2 H-A-520, H-A-523, H-A-528, H-A-539
This commit is contained in:
2026-11-23 13:17:15 +01:00
parent 3945640247
commit e5a250d774
3 changed files with 60 additions and 8 deletions
@@ -202,13 +202,27 @@ func (ix *Indexer) trunkImportForm(ctx context.Context, key string, imports []st
// keeps nothing from it, ADR 0603 §2), a Go module path or an npm name each: what a reported import set is held against
// at every recompute (design 47 H2 H-A-539, H-A-540). held nil reads the indexer's modules.
func (ix *Indexer) meshPackages(ctx context.Context, held map[string]meshcatalog.ModulesByModuleValue) (map[string]bool, error) {
by, err := ix.packagesPublishedBy(ctx, held)
if err != nil {
return nil, err
}
names := map[string]bool{}
for name := range by {
names[name] = true
}
return names, nil
}
// packagesPublishedBy are the packages meshPackages names, each with the repository of the module that publishes it, so a
// take-in tells the packages its repository publishes (design 47 H2 H-A-520, H-A-539).
func (ix *Indexer) packagesPublishedBy(ctx context.Context, held map[string]meshcatalog.ModulesByModuleValue) (map[string]string, error) {
if held == nil {
var err error
if held, err = ix.heldModules(ctx); err != nil {
return nil, err
}
}
names := map[string]bool{}
names := map[string]string{}
for name, cur := range held {
if cur.Manifest == "" {
continue
@@ -219,7 +233,7 @@ func (ix *Indexer) meshPackages(ctx context.Context, held map[string]meshcatalog
}
for _, a := range ix.withArtifacts(ctx, CatalogEntryOf(name, cur, m, raw, graph.Node{}), m).Artifacts {
if p := a.Package; p != nil && p.Name != "" && (p.Ecosystem == EcosystemGo || p.Ecosystem == EcosystemNpm) {
names[p.Name] = true
names[p.Name] = cur.Repository
}
}
}
@@ -236,7 +236,14 @@ func (ix *Indexer) recomputeLocked(ctx context.Context, overlay map[string]meshc
return fmt.Errorf("no fingerprint is written: %w", err)
}
// The packages the module graph's entries publish: a reported import set counts only those (design 47 H2 H-A-539, H-A-540).
mesh, err := ix.meshPackages(ctx, held)
publishedBy, err := ix.packagesPublishedBy(ctx, held)
mesh, ofRepository := map[string]bool{}, map[string]bool{}
for name, repo := range publishedBy {
mesh[name] = true
if repository != "" && trunk.SameRepository(repo, repository) {
ofRepository[name] = true // what this take-in's repository publishes (H-A-520)
}
}
if err != nil {
ix.logf("no fingerprint is written by this pass: the packages the module graph publishes cannot be read: %v", err)
return fmt.Errorf("no fingerprint is written: %w", err)
@@ -328,9 +335,9 @@ func (ix *Indexer) recomputeLocked(ctx context.Context, overlay map[string]meshc
}
}
if _, merged := overlay[module]; !merged && (repository != "" && !trunk.SameRepository(k.cur.Repository, repository) &&
!importsOf(r.pkgs, repository) || only != nil && !only[module]) {
!touches(r.pkgs, kept.Imports, ofRepository, repository) || only != nil && !only[module]) {
// A module registered for another repository is moved by this repository's commit only when it imports a package the
// commit moved (A-476a, ADR 0593 §3); any other stands as held (A-476 c), and so it is for a base of this repository's.
// commit moved (A-476a, ADR 0593 §3; H2 H-A-520, H-A-523: by its reported import set, in either language); any other stands as held (A-476 c), and so it is for a base of this repository's.
r = result{fp: k.held.Fp2, none: k.held.None2, tcs: k.held.Toolchains, pkgs: sdkstep.PackageVersions(k.held.Packages)}
done[module] = r
return r
@@ -615,10 +622,17 @@ func (ix *Indexer) fillPaths(ctx context.Context) error {
return nil
}
// importsOf says whether pkgs name a package of repository: a pin is a released version (H-A-161), so a commit of
// repository moves a module of another only through a package of it the module imports (A-476a).
func importsOf(pkgs sdkstep.PackageVersions, repository string) bool {
// touches says whether a commit of repository moves a module of another repository (A-476a, design 47 H2 H-A-520, H-A-523,
// H-A-539): its reported import set holds a package the repository publishes (published, from the module graph's entries), or,
// a module with no reported set, one of its pins (pkgs) is such a package or a Go module path of the repository (H-A-528).
func touches(pkgs sdkstep.PackageVersions, imports []string, published map[string]bool, repository string) bool {
if len(inTheMesh(imports, published)) > 0 {
return true // its reported import set holds a package the repository publishes, a Go or an npm one (H-A-520, H-A-523)
}
for p := range pkgs {
if published[p] {
return true
}
if repo, _, ok := trunk.PackageRepository(p); ok && trunk.SameRepository(repo, repository) {
return true
}
@@ -864,3 +864,27 @@ func TestAModuleKeepsTheToolchainsItsFingerprintWasComputedWith(t *testing.T) {
t.Errorf("agreed again: fp2 %q (was %q), want a new fingerprint", a.Fp2, n.Fp2)
}
}
// I6/AC1, AC2 (design 47 H2 H-A-520, H-A-523, H-A-528, H-A-539): a take-in of a repository moves a module of another whose
// reported import set holds a package that repository publishes, a Go or an npm one; one whose set holds none stands; one
// with no set moves by its pins.
func TestATakeInMovesTheImportersOfThePackagesItsRepositoryPublishes(t *testing.T) {
const sdk = "novox/mesh-sdk"
published := map[string]bool{"git.novox.be/novox/mesh-sdk/go": true, "@novox/mesh-sdk": true}
for _, c := range []struct {
name string
pkgs sdkstep.PackageVersions
imports []string
want bool
}{
{"a Go importer by its set", sdkstep.PackageVersions{"git.novox.be/novox/mesh-sdk/go": ""}, []string{"git.novox.be/novox/mesh-sdk/go/stdio"}, true},
{"a TypeScript importer by its set", sdkstep.PackageVersions{"@novox/mesh-sdk": ""}, []string{"@novox/mesh-sdk/stdio"}, true},
{"a TypeScript importer pinned, its set not yet reported", sdkstep.PackageVersions{"@novox/mesh-sdk": "v0.1.9"}, nil, true},
{"a set holding only another repository's package", nil, []string{"git.novox.be/novox/mesh-networking/modules/mesh-wireguard/go"}, false},
{"no set and no pin of the repository", sdkstep.PackageVersions{"golang.org/x/sys": "v0.1.0"}, nil, false},
} {
if got := touches(c.pkgs, c.imports, published, sdk); got != c.want {
t.Errorf("%s: touches = %v, want %v", c.name, got, c.want)
}
}
}