The entry's artifact gains package {ecosystem, name} (the seat mesh-catalog's definition, regenerated), read at take-in
from the revision's own files (go.mod, package.json) through the forge; the validator's PackageNameProblems refuses
every module sharing one name in one ecosystem, naming them, in the trunk's judge pass. An image's name is not written:
the design does not say what it is.
Builds: design 47 G §676, §491, §478, §504, §412
Claude-Session: https://claude.ai/code/session_01JG73KEq4zoDfM9WtYpcQgZ
71 lines
3.3 KiB
Go
71 lines
3.3 KiB
Go
package index
|
|
|
|
import (
|
|
"context"
|
|
"reflect"
|
|
"testing"
|
|
|
|
"git.novox.be/novox/mesh-delivery/contracts/go/clients/meshcatalogclient"
|
|
"git.novox.be/novox/mesh-delivery/contracts/go/seats/meshcatalog"
|
|
"git.novox.be/novox/mesh-delivery/sdk/graph"
|
|
"git.novox.be/novox/mesh-sdk/go/catalogue"
|
|
)
|
|
|
|
// Design 47 G §506, §443: an entry carries the manifest whole and the digest of the bytes the forge answered, set at take-in
|
|
// and never computed again from the manifest whole; the module's value read back from the entry holds that digest.
|
|
func TestAnEntryCarriesItsManifestWholeAndTheDigestOfItsBytes(t *testing.T) {
|
|
raw := `{ "module":"avahi", "version":"1" }` // its encoding is not the one a map gives back
|
|
digest := meshcatalogclient.ManifestDigest([]byte(raw))
|
|
cur := meshcatalog.ModulesByModuleValue{Repository: "novox/mesh-catalog", Path: "modules/avahi", Commit: "c", Manifest: digest}
|
|
e := CatalogEntryOf("avahi", cur, catalogue.Manifest{}, raw, graph.Node{})
|
|
if e.ManifestDigest != "sha256:"+digest || e.Manifest["module"] != "avahi" {
|
|
t.Fatalf("entry digest %q manifest %v, want sha256: and the digits %s of the bytes (§578) and the manifest whole", e.ManifestDigest, e.Manifest, digest)
|
|
}
|
|
if back := ModuleValueOf(e); back.Manifest != digest {
|
|
t.Errorf("the module's value read back holds %q, want the bare digits %s (§578)", back.Manifest, digest)
|
|
}
|
|
// §609: an entry taken in before G carries the digits its module value held; reading it back gives the same digits.
|
|
before := e
|
|
before.ManifestDigest = digest
|
|
if back := ModuleValueOf(before); back.Manifest != digest {
|
|
t.Errorf("an entry of before G read back holds %q, want %s (§609)", back.Manifest, digest)
|
|
}
|
|
}
|
|
|
|
// Design 47 G §676: at take-in the entry's artifacts carry the package name read from the revision's own files at the
|
|
// artifact's path: the module of a go.mod, the name of a package.json.
|
|
func TestAnEntryCarriesItsArtifactsPackageNames(t *testing.T) {
|
|
ix := &Indexer{ReadFile: func(_ context.Context, repository, sha, path string) ([]byte, error) {
|
|
files := map[string]string{
|
|
"mods/m/go/go.mod": "module git.example/m/go\n\ngo 1.26\n",
|
|
"mods/m/js/package.json": `{"name":"@example/m"}`,
|
|
}
|
|
if repository != "r" || sha != "c1" {
|
|
t.Errorf("read %s %s %s, want the entry's repository and commit", repository, sha, path)
|
|
}
|
|
if f, ok := files[path]; ok {
|
|
return []byte(f), nil
|
|
}
|
|
return nil, nil
|
|
}}
|
|
m := catalogue.Manifest{Module: "m", Build: &catalogue.Build{Artifacts: []catalogue.Artifact{
|
|
{Name: "gopkg", Kind: catalogue.ArtifactPackage, Language: "go", Paths: []string{"go"}},
|
|
{Name: "jspkg", Kind: catalogue.ArtifactPackage, Language: "typescript", Paths: []string{"js"}},
|
|
{Name: "img", Kind: catalogue.ArtifactImage},
|
|
{Name: "prog", Kind: "bundle", Language: "go"},
|
|
}}}
|
|
e := ix.withArtifacts(context.Background(), meshcatalog.CatalogEntry{Module: "m", Repository: "r", Path: "mods/m", Commit: "c1"}, m)
|
|
got := map[string]string{}
|
|
for _, a := range e.Artifacts {
|
|
name := "none"
|
|
if a.Package != nil {
|
|
name = a.Package.Ecosystem + " " + a.Package.Name
|
|
}
|
|
got[a.Ref] = name
|
|
}
|
|
want := map[string]string{"m:gopkg": "go git.example/m/go", "m:jspkg": "npm @example/m", "m:img": "none", "m:prog": "none"}
|
|
if !reflect.DeepEqual(got, want) {
|
|
t.Errorf("artifacts' packages %v, want %v (§676)", got, want)
|
|
}
|
|
}
|