diff --git a/modules/mesh-delivery-indexer/internal/index/imports_test.go b/modules/mesh-delivery-indexer/internal/index/imports_test.go index 02ea1a4fe..116ef8920 100644 --- a/modules/mesh-delivery-indexer/internal/index/imports_test.go +++ b/modules/mesh-delivery-indexer/internal/index/imports_test.go @@ -636,6 +636,36 @@ func anUnreadPackagesStateWritesNoFingerprintAndFingerprintsAreComputedAgain(t * t.Errorf("the sibling's directory changed: fingerprint %q, was %q; want a new one", g.fp, f.fp) } }) + t.Run("a TypeScript import set moves the fingerprint by an imported npm package's content alone", func(t *testing.T) { // I11b/AC1 + // Design 47 H2 H-A-523, H-A-546: a TypeScript module's reported set names npm packages, each taken by its digest in the + // packages state, kept by its npm name as I11a publishes it. + const sdkTS, other = "@novox/mesh-sdk", "@novox/other" + npm := func(name, digest string) meshcatalog.PackagesByModuleValue { + return meshcatalog.PackagesByModuleValue{Module: name, Repository: "novox/mesh-sdk", Dir: "ts", Commit: strings.Repeat("c", 40), Requires: "r1", + Packages: []meshcatalog.PackagesByModuleValuePackagesItem{{Package: name, Digest: digest}}} + } + fpOf := func(sdkDigest, otherDigest string) form { + t.Helper() + kept := meshcatalog.ModulesByModuleValueInputs2{Tree: "t", Imports: []string{sdkTS}} + published := map[string]meshcatalog.PackagesByModuleValue{sdkTS: npm(sdkTS, sdkDigest), other: npm(other, otherDigest)} + f := formOf("view", "novox/mesh-catalog", &kept, true, map[string]bool{sdkTS: true, other: true}, nil, meshcatalog.ModulesByModuleValue{}, nil, published, nil, nil) + if f.fp == "" || !f.imports { + t.Fatalf("a TypeScript import set: fingerprint %q (none %q), import form %v; want the import form", f.fp, f.none, f.imports) + } + return f + } + base := fpOf("d1", "o1") + if moved := fpOf("d2", "o1"); moved.fp == base.fp { + t.Error("a change of the imported npm package's files left the fingerprint") + } + if stood := fpOf("d1", "o2"); stood.fp != base.fp { + t.Error("a change of an npm package the module does not import moved the fingerprint") + } + // H-A-546 (3): an npm import of another repository enters the entry's packages as a Go one does. + if _, named := base.versions[sdkTS]; !named { + t.Errorf("versions %v, want %s named", base.versions, sdkTS) + } + }) t.Run("formOf clears the import form when it writes the version line", func(t *testing.T) { for _, c := range []struct { name string