Files
mesh-delivery/modules/mesh-delivery-checker/cmd/mesh-delivery-checker/trunk.go
T
jschoubben 71a35a6376 MV1: move contracts and sdk under modules/, importers follow
The delivery repository's contracts and SDK live under modules/ as
mesh-delivery-contracts and mesh-delivery-sdk, their Go module paths
renamed to match the folders (the TypeScript names already did), and
every importer in mesh-delivery, mesh-catalog, mesh-host, mesh-tools
and mesh-sdk follows in the same group: a design as it should be, one
path per module, checked by the group's check building every importer.

Builds: design 47 G §427, §88

Claude-Session: https://claude.ai/code/session_01NcbgfGKaxw984XyAPfLm4h
2026-11-12 05:09:56 +01:00

58 lines
2.1 KiB
Go

package main
import (
"context"
"encoding/json"
"fmt"
"github.com/nats-io/nats.go/jetstream"
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
"mesh-delivery-checker/internal/check"
)
// The checker takes the trunk heads a check merges onto from the catalog half (design 47 G §197), never from the gate's state
// `source`: a first view by the seat mesh-catalog's verb `revision`, which carries the trunk head of every repository, then
// the seat's event `catalog-revision` of a trunk revision, each read again by the verb.
// readTrunks asks the catalog half's newest trunk revision and sets the heads it carries. It says whether they changed. A
// candidate's revision, or an answer that does not read, changes nothing.
func readTrunks(ask func(string, any) (json.RawMessage, error), trunks *check.Trunks) (bool, error) {
raw, err := ask(check.TrunkVerb, meshcatalog.RevisionInput{})
if err != nil {
return false, fmt.Errorf("the catalog half's revision cannot be read: %w", err)
}
heads, err := check.TrunkHeads(raw)
if err != nil {
return false, err
}
return trunks.Set(heads), nil
}
// followTrunks reads the first view and then follows `catalog-revision`: a trunk revision's event reads the heads again, and a
// change of them is the trunk moving (statuses go pending, a verdict for the old trunk is judged again). A read that fails is
// said, and made again at the next event.
func followTrunks(hub interface {
Handle(string, func(jetstream.Msg)) error
}, ask func(string, any) (json.RawMessage, error), trunks *check.Trunks, moved func(context.Context), logf func(string, ...any)) (first func(context.Context), err error) {
run := func(ctx context.Context) {
changed, err := readTrunks(ask, trunks)
if err != nil {
logf("no trunk is known until the catalog half answers, so nothing is checked: %v", err)
return
}
if changed {
moved(ctx)
}
}
err = hub.Handle(meshcatalog.SubjectCatalogRevisionAll, func(m jetstream.Msg) {
var e meshcatalog.CatalogRevisionEvent
if json.Unmarshal(m.Data(), &e) == nil && e.Kind == "trunk" {
run(context.Background())
}
_ = m.Ack()
})
return run, err
}