Files
mesh-catalog/modules/distribution/internal/holder/reserved.go
T
jschoubben 69940d1019 The artifact registry takes a publish whose reservation names no digest yet (H-A-387)
The builder records a build's digests only at its end, while the Go build
module publishes during the build step with the reserved version (H-A-373),
so the distribution holder's strict digest check refused every archive-only
publish with "reserved ... for another digest". Recorded now takes an
artifact whose reserved digest is empty, as A-490j decided for every holder,
still refuses a different recorded digest, and its refusal names the case:
the digest reserved and the one published, or no reservation of the version.

Builds: design 47 H H-A-387, design 47 G A-490j
2026-11-22 00:14:30 +01:00

52 lines
2.6 KiB
Go

package holder
import (
"encoding/json"
"fmt"
"strings"
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshbuilds"
)
// Reserved is the holder's check of a publish against the builder's reservation (novox/hq design 47 §381, §478, §504): it asks the
// seat mesh-builds' verb reserved with the publish's name and version, a package's name in its ecosystem, and accepts the publish
// only when that version is the one reserved and an artifact of it has the publish's digest or none recorded yet (A-490j). It reads no catalog and a publish gains
// no field. It is the Builder the holder's Check asks.
type Reserved struct {
// Ask is the runtime's request and reply over the bus (mesh-sdk stdio.Ask).
Ask func(address string, body any) (json.RawMessage, error)
}
// Address is the seat verb asked, as the manifest's `invokes` names it.
const Address = "seat:" + meshbuilds.Seat + "." + meshbuilds.VerbReserved
// Recorded answers whether name@version with digest is reserved, and why not when it is not. An answer that cannot be read is an
// error, never a yes; a refusal by the builder (a name no entry carries, a version it did not reserve) is a no that names it.
func (r Reserved) Recorded(name, version, digest string) (bool, string, error) {
raw, err := r.Ask(Address, meshbuilds.ReservedInput{Name: name, Version: version})
if err != nil {
return false, "", fmt.Errorf("%s did not answer for %s@%s: %w", Address, name, version, err)
}
var a meshbuilds.ReservedAnswer
if err := json.Unmarshal(raw, &a); err != nil || a.Version == "" {
return false, "", fmt.Errorf("%s answered no reservation for %s@%s: %s", Address, name, version, raw)
}
if a.Version != version {
return false, fmt.Sprintf("%s has no reservation of version %s of %s (it reserved %s)", a.Module, version, name, a.Version), nil
}
var reserved []string
for _, art := range a.Artifacts {
// An artifact whose build has not recorded its digest yet takes the publish: the builder records a build's digests only when
// the build ends, while the build module publishes during it with the reserved version (design 47 G §369, A-415, A-490j,
// H-A-387). A digest the build then records that differs from what the holder holds fails the build.
if art.Digest == digest || art.Digest == "" {
return true, "", nil
}
reserved = append(reserved, art.Digest)
}
if len(reserved) == 0 {
return false, fmt.Sprintf("%s reserved %s@%s with no artifact, so no digest takes %s", a.Module, name, version, digest), nil
}
return false, fmt.Sprintf("%s reserved %s@%s for digest %s, not %s", a.Module, name, version, strings.Join(reserved, ", "), digest), nil
}