From c7ad2477f0436fb9c33f07512b3e1d2c5cc692cc Mon Sep 17 00:00:00 2001 From: jochen Date: Wed, 11 Nov 2026 20:26:55 +0100 Subject: [PATCH] BL6 (key codec): the catalog key's codec is meshcatalogkey, so the builder's builds package reaches no bus MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit meshcatalogclient imports the new package and keeps two one-line wrappers for the callers of the other parts until they move to it. Builds: design 47 G §670, §614 (wiring unchanged) Claude-Session: https://claude.ai/code/session_01JG73KEq4zoDfM9WtYpcQgZ --- .../clients/meshcatalogclient/fingerprint.go | 27 +++---------- contracts/go/clients/meshcatalogclient/go.mod | 1 + contracts/go/clients/meshcatalogkey/go.mod | 5 +++ contracts/go/clients/meshcatalogkey/key.go | 32 +++++++++++++++ .../go/clients/meshcatalogkey/key_test.go | 39 +++++++++++++++++++ modules/mesh-delivery-builder/builds/go.mod | 2 +- 6 files changed, 84 insertions(+), 22 deletions(-) create mode 100644 contracts/go/clients/meshcatalogkey/go.mod create mode 100644 contracts/go/clients/meshcatalogkey/key.go create mode 100644 contracts/go/clients/meshcatalogkey/key_test.go diff --git a/contracts/go/clients/meshcatalogclient/fingerprint.go b/contracts/go/clients/meshcatalogclient/fingerprint.go index 0565fdb5..6ed3c43a 100644 --- a/contracts/go/clients/meshcatalogclient/fingerprint.go +++ b/contracts/go/clients/meshcatalogclient/fingerprint.go @@ -5,14 +5,11 @@ package meshcatalogclient import ( - "fmt" - "strings" - - "git.novox.be/novox/mesh-sdk/go/keys" + "git.novox.be/novox/mesh-delivery/contracts/go/clients/meshcatalogkey" ) // SourcePrefix2 opens every source fingerprint of the form. -const SourcePrefix2 = "src2:" +const SourcePrefix2 = meshcatalogkey.SourcePrefix2 // Toolchain2 is what an artifact's toolchain enters the fingerprint as (novox/hq ADR 0405 clause 7): the artifact's // language, the installed toolchain's version and the build module's recipe version. @@ -22,20 +19,8 @@ type Toolchain2 struct { Recipe string } -// KeyPart is a fingerprint as a key part: its 64 hex digits without the prefix, since a bus key may not hold ':'. It -// refuses a value that is not `src2:` and 64 lowercase hex digits, a src1 fingerprint included, naming it. -func KeyPart(fp string) (string, error) { - part, ok := strings.CutPrefix(fp, SourcePrefix2) - if !ok || !keys.IsHex64(part) { - return "", fmt.Errorf("fingerprint: %q is not a fingerprint of the form, %s and 64 lowercase hex digits", fp, SourcePrefix2) - } - return part, nil -} +// KeyPart is meshcatalogkey.KeyPart, the codec of a catalog key's parts (design 47 G §670). +func KeyPart(fp string) (string, error) { return meshcatalogkey.KeyPart(fp) } -// ParseKeyPart is the inverse of KeyPart. It refuses a part that is not 64 lowercase hex digits, naming it. -func ParseKeyPart(part string) (string, error) { - if !keys.IsHex64(part) { - return "", fmt.Errorf("fingerprint: %q is not the key part of a fingerprint, 64 lowercase hex digits", part) - } - return SourcePrefix2 + part, nil -} +// ParseKeyPart is meshcatalogkey.ParseKeyPart. +func ParseKeyPart(part string) (string, error) { return meshcatalogkey.ParseKeyPart(part) } diff --git a/contracts/go/clients/meshcatalogclient/go.mod b/contracts/go/clients/meshcatalogclient/go.mod index 433b7918..8a0a9aa3 100644 --- a/contracts/go/clients/meshcatalogclient/go.mod +++ b/contracts/go/clients/meshcatalogclient/go.mod @@ -3,6 +3,7 @@ module git.novox.be/novox/mesh-delivery/contracts/go/clients/meshcatalogclient go 1.26.0 require ( + git.novox.be/novox/mesh-delivery/contracts/go/clients/meshcatalogkey v0.0.0-00010101000000-000000000000 git.novox.be/novox/mesh-delivery/contracts/go/seats/meshcatalog v0.0.0-00010101000000-000000000000 git.novox.be/novox/mesh-sdk/go v0.0.0-00010101000000-000000000000 ) diff --git a/contracts/go/clients/meshcatalogkey/go.mod b/contracts/go/clients/meshcatalogkey/go.mod new file mode 100644 index 00000000..e6b41bd8 --- /dev/null +++ b/contracts/go/clients/meshcatalogkey/go.mod @@ -0,0 +1,5 @@ +module git.novox.be/novox/mesh-delivery/contracts/go/clients/meshcatalogkey + +go 1.26.0 + +require git.novox.be/novox/mesh-sdk/go v0.0.0-00010101000000-000000000000 diff --git a/contracts/go/clients/meshcatalogkey/key.go b/contracts/go/clients/meshcatalogkey/key.go new file mode 100644 index 00000000..17d65d55 --- /dev/null +++ b/contracts/go/clients/meshcatalogkey/key.go @@ -0,0 +1,32 @@ +// Package meshcatalogkey is the codec of a catalog key's parts (design 47 G §670): a fingerprint as the part of a bus +// key, and back. It imports neither mesh-sdk's views nor the bus client, so a package that only reads and writes keys +// (the builder's builds package) reaches no bus; meshcatalogclient imports it. +package meshcatalogkey + +import ( + "fmt" + "strings" + + "git.novox.be/novox/mesh-sdk/go/keys" +) + +// SourcePrefix2 is the prefix of a fingerprint of the current form. +const SourcePrefix2 = "src2:" + +// KeyPart is a fingerprint as a key part: its 64 hex digits without the prefix, since a bus key may not hold ':'. It +// refuses a value that is not `src2:` and 64 lowercase hex digits, a src1 fingerprint included, naming it. +func KeyPart(fp string) (string, error) { + part, ok := strings.CutPrefix(fp, SourcePrefix2) + if !ok || !keys.IsHex64(part) { + return "", fmt.Errorf("fingerprint: %q is not a fingerprint of the form, %s and 64 lowercase hex digits", fp, SourcePrefix2) + } + return part, nil +} + +// ParseKeyPart is the inverse of KeyPart. It refuses a part that is not 64 lowercase hex digits, naming it. +func ParseKeyPart(part string) (string, error) { + if !keys.IsHex64(part) { + return "", fmt.Errorf("fingerprint: %q is not the key part of a fingerprint, 64 lowercase hex digits", part) + } + return SourcePrefix2 + part, nil +} diff --git a/contracts/go/clients/meshcatalogkey/key_test.go b/contracts/go/clients/meshcatalogkey/key_test.go new file mode 100644 index 00000000..f8051de5 --- /dev/null +++ b/contracts/go/clients/meshcatalogkey/key_test.go @@ -0,0 +1,39 @@ +package meshcatalogkey + +import ( + "go/build" + "strings" + "testing" +) + +func TestKeyPartRoundTripsAndRefusesOthers(t *testing.T) { + fp := "src2:" + strings.Repeat("a", 64) + part, err := KeyPart(fp) + if err != nil || part != strings.Repeat("a", 64) { + t.Fatalf("KeyPart = %q, %v", part, err) + } + if back, err := ParseKeyPart(part); err != nil || back != fp { + t.Fatalf("ParseKeyPart = %q, %v", back, err) + } + for _, bad := range []string{"src1:" + strings.Repeat("a", 64), "src2:abc", strings.Repeat("a", 64)} { + if _, err := KeyPart(bad); err == nil { + t.Errorf("KeyPart(%q) accepted", bad) + } + } + if _, err := ParseKeyPart("abc"); err == nil { + t.Error("ParseKeyPart(abc) accepted") + } +} + +// Design 47 G §670: the package imports no bus. +func TestThePackageImportsNoBus(t *testing.T) { + p, err := build.ImportDir(".", 0) + if err != nil { + t.Fatal(err) + } + for _, i := range p.Imports { + if strings.Contains(i, "nats") || strings.Contains(i, "/views") { + t.Errorf("meshcatalogkey imports %s", i) + } + } +} diff --git a/modules/mesh-delivery-builder/builds/go.mod b/modules/mesh-delivery-builder/builds/go.mod index 84dbe8cb..4fb85e3c 100644 --- a/modules/mesh-delivery-builder/builds/go.mod +++ b/modules/mesh-delivery-builder/builds/go.mod @@ -4,7 +4,7 @@ go 1.26.0 require ( git.novox.be/novox/mesh-delivery/contracts/go/clients/containerimageregistryclient v0.0.0-00010101000000-000000000000 - git.novox.be/novox/mesh-delivery/contracts/go/clients/meshcatalogclient v0.0.0-00010101000000-000000000000 + git.novox.be/novox/mesh-delivery/contracts/go/clients/meshcatalogkey v0.0.0-00010101000000-000000000000 git.novox.be/novox/mesh-delivery/contracts/go/seats/containerimageregistry v0.0.0-00010101000000-000000000000 git.novox.be/novox/mesh-delivery/contracts/go/seats/ociartifactregistry v0.0.0-00010101000000-000000000000 git.novox.be/novox/mesh-delivery/sdk v0.0.0-00010101000000-000000000000