Files
mesh-delivery/modules/mesh-delivery-sdk/steprun/answered.go
T
jschoubben 3bb8413dbd K3 answered-digest, K4 kits: a publish answered other-bytes with the publish's own fingerprint is the held digest in the step result and both in the log, else refused; the publish kit's rows follow H-A-738, the reproducible kit
The shared publish names the ask's own fingerprint on a publish that names none. The kit's Bed gains HoldWith, PublishWith and Held.

Builds: design 47 H2 H-A-589 (4), H-A-589 (5), H-A-591, H-A-593 (2) (3), H-A-738 (1)
2026-11-25 17:28:22 +01:00

63 lines
2.5 KiB
Go

package steprun
import (
"context"
"fmt"
"sync"
)
// **A publish answered with the held digest** (design 47 H2 H-A-589 (4), H-A-738 (1)): a registry holds a name and version
// with another digest than the build made and answers `other-bytes` with that digest and the fingerprint it keeps. The
// shared publish compares that fingerprint with the publish's own (the ask's); equal, the publish is answered as published
// with the held digest, nothing stored, and the ask's publish records the digest the seat answered, which the ask's step
// result names for the artifact (ADR 0605 §9: a done key names what its seat answered) while the step log names both
// digests; other or absent, the publish is refused naming both.
type publishKey struct{}
// heldPublish is one artifact's publish of an ask: the fingerprint it publishes under, and the digest its seat answered when that
// is not the digest built.
type heldPublish struct {
mu sync.Mutex
fingerprint string
answered string
}
// withPublish is ctx for the publish of one artifact of an ask whose fingerprint is fingerprint, and the record the ask
// reads the answered digest from.
func withPublish(ctx context.Context, fingerprint string) (context.Context, *heldPublish) {
a := &heldPublish{fingerprint: fingerprint}
return context.WithValue(ctx, publishKey{}, a), a
}
func publishOf(ctx context.Context) *heldPublish {
a, _ := ctx.Value(publishKey{}).(*heldPublish)
return a
}
// Answered is the digest the seat answered for the artifact when it held the version as another digest, empty when it
// answered the digest built.
func (a *heldPublish) Answered() string {
if a == nil {
return ""
}
a.mu.Lock()
defer a.mu.Unlock()
return a.answered
}
// heldAnswer reads a publish answered `other-bytes` of the digest built: the held digest it is published as, or the refusal.
func heldAnswer(ctx context.Context, seat, name, version, built, heldDigest, heldFingerprint, fingerprint string) error {
if fingerprint == "" || heldFingerprint != fingerprint {
return fmt.Errorf("%s holds %s %s as %s with the fingerprint %q, and the publish names %s with the fingerprint %q: a held version offered with other bytes (ADR 0605 §4)",
seat, name, version, heldDigest, heldFingerprint, built, fingerprint)
}
if a := publishOf(ctx); a != nil {
a.mu.Lock()
a.answered = heldDigest
a.mu.Unlock()
}
Phase(ctx, fmt.Sprintf("%s answered %s %s as published with the held digest %s, built %s: the same fingerprint, nothing stored", seat, name, version, heldDigest, built))
return nil
}