diff --git a/modules/mesh-delivery-contracts/go/clients/meshdeliveryclient/gate.go b/modules/mesh-delivery-contracts/go/clients/meshdeliveryclient/gate.go index 076ffc66..055d9398 100644 --- a/modules/mesh-delivery-contracts/go/clients/meshdeliveryclient/gate.go +++ b/modules/mesh-delivery-contracts/go/clients/meshdeliveryclient/gate.go @@ -5,15 +5,12 @@ import ( "encoding/json" "fmt" "reflect" - "strconv" - "strings" - "time" seat "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshdelivery" "git.novox.be/novox/mesh-sdk/go/keys" ) -// The values of the seat's states `source`, `merges`, `asks`, `owed` and `turns`, in the seat's types: each is stamped +// The values of the seat's states `source` and `owed`, in the seat's types: each is stamped // with Version when encoded, read strictly (an unknown field refused) and its version checked when decoded, and its rules // held on both sides, so the gate that writes them and the readers (the forge bridge, the teller, the assigner, the view) // agree. What the schema cannot say is written here once (ADR 0625 §4). @@ -21,16 +18,6 @@ import ( // Version is the layout version of the seat's values. const Version = 1 -// MergeState is the state of a pull request in a merge. -type MergeState string - -// The states a merge's pull request is in. -const ( - MergeMerging MergeState = "merging" - MergeMerged MergeState = "merged" - MergeRefused MergeState = "refused" -) - // SourceKey is the key of the state source for a watched branch (design 47 *Watched branches and the catalog graph per // branch*: source. in place of source.main). func SourceKey(branch string) string { return seat.SourceByBranchKey(branch) } @@ -43,37 +30,6 @@ func encodeValue(v any, check error, stamp func()) ([]byte, error) { return json.Marshal(v) } -// ApprovedKey is the key, in a merge's approved heads, of a pull request: `@`. -func ApprovedKey(repository string, number int) string { - return repository + "@" + strconv.Itoa(number) -} - -// TurnsKey is the key, in the state turns, of a repository: `.`, lower-case and escaped. -func TurnsKey(repository string) (string, error) { - repository = strings.ToLower(repository) - part, err := escapeRepository(repository) - if err != nil { - return "", err - } - return strings.Replace(part, "/", ".", 1), nil -} - -// ParseTurnsKey is the inverse of TurnsKey; a key that does not name a lower-case / is refused. -func ParseTurnsKey(key string) (string, error) { - owner, name, ok := strings.Cut(key, ".") - if !ok || owner == "" || name == "" || strings.Contains(name, ".") { - return "", fmt.Errorf("meshdeliveryclient: %q is not a turns key, .", key) - } - repository, err := unescapeRepository(owner + "/" + name) - if err != nil { - return "", fmt.Errorf("meshdeliveryclient: %q is not a turns key: %w", key, err) - } - if again, err := TurnsKey(repository); err != nil || again != key { - return "", fmt.Errorf("meshdeliveryclient: %q is not a turns key: it does not name a lowercase /", key) - } - return repository, nil -} - // ----- source // CheckSource refuses a source naming no repository, a repository with no name or an empty head. @@ -112,120 +68,6 @@ func DecodeSource(data []byte) (seat.SourceByBranchValue, error) { // SameSource says whether two sources are the same. func SameSource(a, b seat.SourceByBranchValue) bool { return reflect.DeepEqual(a, b) } -// ----- merge - -// CheckMerge refuses a merge naming no group, ask or pull request, a pull request outside the approved heads or at -// another head than the Approve was for, and a state that lacks what it needs: merged its commit, refused the forge's words. -func CheckMerge(m seat.MergesByGroupValue) error { - if m.Group == "" { - return fmt.Errorf("meshdeliveryclient: a merge names no group") - } - if m.Ask == "" { - return fmt.Errorf("meshdeliveryclient: a merge names no ask") - } - if len(m.Pulls) == 0 { - return fmt.Errorf("meshdeliveryclient: a merge names no pull request") - } - for key, sha := range m.Approved { - if sha == "" { - return fmt.Errorf("meshdeliveryclient: the approved head of %s is empty", key) - } - } - for _, p := range m.Pulls { - who := fmt.Sprintf("%s#%d", p.Repository, p.Number) - if len(m.Approved) > 0 { - sha, ok := m.Approved[ApprovedKey(p.Repository, int(p.Number))] - if !ok { - return fmt.Errorf("meshdeliveryclient: the pull request %s is handed to the merge but is not among the approved heads", who) - } - if sha != p.Head { - return fmt.Errorf("meshdeliveryclient: the pull request %s is handed at head %q but the Approve was for %q", who, p.Head, sha) - } - } - switch MergeState(p.State) { - case MergeMerging: - case MergeMerged: - if p.Commit == "" { - return fmt.Errorf("meshdeliveryclient: the merged pull request %s has no merge commit", who) - } - case MergeRefused: - if p.Words == "" { - return fmt.Errorf("meshdeliveryclient: the refused pull request %s has no words of the forge", who) - } - default: - return fmt.Errorf("meshdeliveryclient: the state %q of %s is not merging, merged or refused", p.State, who) - } - } - return nil -} - -// EncodeMerge is m as the value of a group's key. -func EncodeMerge(m seat.MergesByGroupValue) ([]byte, error) { - return encodeValue(&m, CheckMerge(m), func() { m.V = Version }) -} - -// DecodeMerge reads the value of a group's key. -func DecodeMerge(data []byte) (seat.MergesByGroupValue, error) { - if err := keys.CheckVersion(data); err != nil { - return seat.MergesByGroupValue{}, err - } - m, err := seat.DecodeMergesByGroupValue(data) - if err != nil { - return m, fmt.Errorf("meshdeliveryclient: a merge does not fit its shape: %w", err) - } - return m, CheckMerge(m) -} - -// SameMerge says whether two merges are the same. -func SameMerge(a, b seat.MergesByGroupValue) bool { return reflect.DeepEqual(a, b) } - -// ----- ask - -// HeadsOf are an ask's heads as Heads (for HeadsHash and MergeAskKey). -func HeadsOf(items []seat.AsksByMergeGroupHeadsValueHeadsItem) []Head { - out := make([]Head, len(items)) - for i, h := range items { - out[i] = Head{Repository: h.Repository, Number: int(h.Number), Head: h.Head} - } - return out -} - -// CheckAsk refuses an ask with no group or heads, a negative count, or an ask that is no object. -func CheckAsk(a seat.AsksByMergeGroupHeadsValue) error { - if a.Asking < 0 { - return fmt.Errorf("meshdeliveryclient: the ask's asking %d is negative", a.Asking) - } - if _, err := MergeAskKey(a.Group, HeadsOf(a.Heads)); err != nil { - return fmt.Errorf("meshdeliveryclient: an ask needs its group and at least one pull request's head: %w", err) - } - raw, err := json.Marshal(a.Ask) - var fields map[string]json.RawMessage - if err != nil || len(bytes.TrimSpace(raw)) == 0 || json.Unmarshal(raw, &fields) != nil || fields == nil { - return fmt.Errorf("meshdeliveryclient: the value carries no router's ask") - } - return nil -} - -// EncodeAsk is a as the value of a merge ask's key; a.Ask may be a json.RawMessage. -func EncodeAsk(a seat.AsksByMergeGroupHeadsValue) ([]byte, error) { - return encodeValue(&a, CheckAsk(a), func() { a.V = Version }) -} - -// DecodeAsk reads the value of a merge ask's key; its Ask is the router's ask as a decoded object. -func DecodeAsk(data []byte) (seat.AsksByMergeGroupHeadsValue, error) { - if err := keys.CheckVersion(data); err != nil { - return seat.AsksByMergeGroupHeadsValue{}, err - } - a, err := seat.DecodeAsksByMergeGroupHeadsValue(data) - if err != nil { - return a, fmt.Errorf("meshdeliveryclient: an ask does not fit its shape: %w", err) - } - return a, CheckAsk(a) -} - -// SameAsk says whether two asks are the same (the router's ask by its content). -func SameAsk(a, b seat.AsksByMergeGroupHeadsValue) bool { return reflect.DeepEqual(a, b) } - // ----- owed // EncodeOwed is o as the value of an owed key, after CheckOwed. @@ -248,123 +90,6 @@ func DecodeOwed(data []byte) (seat.OwedByRepositoryNumberHeadActValue, error) { // SameOwed says whether two owed values are the same. func SameOwed(a, b seat.OwedByRepositoryNumberHeadActValue) bool { return a == b } -// ----- turns - -// CheckTurn refuses a turn whose repository is not lower-case, that names no delivery, or whose deliveries repeat a heads -// hash, lack their times, are out of the order of the Approve, or name a wait without a verdict key. -func CheckTurn(t seat.TurnsByRepositoryValue) error { - repository := strings.ToLower(t.Repository) - if repository != t.Repository { - return fmt.Errorf("meshdeliveryclient: the turn's repository %q is not lowercase", t.Repository) - } - if _, err := escapeRepository(repository); err != nil { - return err - } - if len(t.Waiting) == 0 { - return fmt.Errorf("meshdeliveryclient: the turn of %s names no delivery: its key is deleted instead", t.Repository) - } - seen := map[string]bool{} - for i, w := range t.Waiting { - if w.Group == "" { - return fmt.Errorf("meshdeliveryclient: a delivery in the turn of %s names no group", t.Repository) - } - if !hashOK.MatchString(w.Heads) { - return fmt.Errorf("meshdeliveryclient: the heads hash %q in the turn of %s is not 12 lowercase hex digits", w.Heads, t.Repository) - } - if seen[w.Heads] { - return fmt.Errorf("meshdeliveryclient: the turn of %s names the heads %s twice", t.Repository, w.Heads) - } - seen[w.Heads] = true - if w.Approved.IsZero() || w.Since.IsZero() { - return fmt.Errorf("meshdeliveryclient: the delivery %s in the turn of %s says no time of its Approve or of its wait", w.Group, t.Repository) - } - if i > 0 && w.Approved.Before(t.Waiting[i-1].Approved) { - return fmt.Errorf("meshdeliveryclient: the turn of %s is not in the order of the Approve: %s was approved before %s", t.Repository, w.Group, t.Waiting[i-1].Group) - } - if w.WaitsFor != "" { - if _, _, err := parseVerdictKey(w.WaitsFor); err != nil { - return fmt.Errorf("meshdeliveryclient: the delivery %s in the turn of %s waits for what is not a verdict key: %w", w.Group, t.Repository, err) - } - } else if (w.WaitsSince != nil && !w.WaitsSince.IsZero()) || w.Step != "" { - return fmt.Errorf("meshdeliveryclient: the delivery %s in the turn of %s says when and where a check runs, and names no check", w.Group, t.Repository) - } - } - return nil -} - -// parseVerdictKey is the checker's verdict key `.` (the checker's client has the same rule over its -// own seat; a client uses its own seat's contract alone). -func parseVerdictKey(key string) (group, heads string, err error) { - i := strings.LastIndex(key, ".") - if i < 0 || !hashOK.MatchString(key[i+1:]) || i == 0 || strings.Contains(key[:i], ".") { - return "", "", fmt.Errorf("%q is not a verdict key, .", key) - } - if group, err = keys.UnescapeName(key[:i]); err != nil { - return "", "", err - } - return group, key[i+1:], nil -} - -// TurnHolds says whether a delivery at these heads is not in the turn while the turn names others: the delivery's -// check or merge holds back for the one before it. -func TurnHolds(t seat.TurnsByRepositoryValue, heads string) bool { - if len(t.Waiting) == 0 { - return false - } - for _, w := range t.Waiting { - if w.Heads == heads { - return false - } - } - return true -} - -// EncodeTurn is t as the value of a repository's key. -func EncodeTurn(t seat.TurnsByRepositoryValue) ([]byte, error) { - if err := CheckTurn(t); err != nil { - return nil, err - } - t.V = Version - return json.Marshal(t) -} - -// DecodeTurn reads the value of a repository's key. -func DecodeTurn(data []byte) (seat.TurnsByRepositoryValue, error) { - if err := keys.CheckVersion(data); err != nil { - return seat.TurnsByRepositoryValue{}, err - } - t, err := seat.DecodeTurnsByRepositoryValue(data) - if err != nil { - return t, fmt.Errorf("meshdeliveryclient: a turn does not fit its shape: %w", err) - } - return t, CheckTurn(t) -} - -// SameTurn says whether two turns are the same, a time by the instant it names. -func SameTurn(a, b seat.TurnsByRepositoryValue) bool { - if len(a.Waiting) != len(b.Waiting) || a.Repository != b.Repository || a.V != b.V { - return false - } - for i := range a.Waiting { - x, y := a.Waiting[i], b.Waiting[i] - if !x.Approved.Equal(y.Approved) || !x.Since.Equal(y.Since) || !sameTime(x.WaitsSince, y.WaitsSince) { - return false - } - x.Approved, y.Approved, x.Since, y.Since, x.WaitsSince, y.WaitsSince = time.Time{}, time.Time{}, time.Time{}, time.Time{}, nil, nil - if !reflect.DeepEqual(x, y) { - return false - } - } - return true -} - -func sameTime(a, b *time.Time) bool { - if a == nil || a.IsZero() { - return b == nil || b.IsZero() - } - return b != nil && a.Equal(*b) -} - // Answer is the operator's answer to a merge ask as the gate acts on it: the option chosen, the warrant that proves who // answered, and the words said. It is the teller's state `answers` under the ask's key (the teller's own record; this is // its layout for the gate that reads it). diff --git a/modules/mesh-delivery-contracts/go/clients/meshdeliveryclient/gate_test.go b/modules/mesh-delivery-contracts/go/clients/meshdeliveryclient/gate_test.go index 0e751573..c9cf3499 100644 --- a/modules/mesh-delivery-contracts/go/clients/meshdeliveryclient/gate_test.go +++ b/modules/mesh-delivery-contracts/go/clients/meshdeliveryclient/gate_test.go @@ -4,9 +4,7 @@ import ( "encoding/json" "errors" "reflect" - "strings" "testing" - "time" seat "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshdelivery" "git.novox.be/novox/mesh-sdk/go/keys" @@ -31,8 +29,6 @@ func sameJSON(t *testing.T, got []byte, want string) { // The goldens are the output of go/delivery's Encode* before it was deleted; each value must encode to the same // document and decode back to what it was. func TestGateValuesEncodeAsGoDeliveryDid(t *testing.T) { - ap := time.Date(2026, 11, 5, 10, 0, 0, 0, time.UTC) - wait := ap.Add(2 * time.Minute) for _, c := range []struct { name string encode func() ([]byte, error) @@ -41,36 +37,15 @@ func TestGateValuesEncodeAsGoDeliveryDid(t *testing.T) { golden string }{ {"source", func() ([]byte, error) { - return EncodeSource(seat.SourceByBranchValue{Group: "fix/1.2", Heads: map[string]string{"novox/a": "aaaa", "novox/b": "bbbb"}}) + return EncodeSource(seat.SourceByBranchValue{Source: 1044, Call: "0123456789abcdef", Heads: map[string]string{"novox/a": "aaaa", "novox/b": "bbbb"}}) }, func(b []byte) (any, error) { return DecodeSource(b) }, - seat.SourceByBranchValue{V: 1, Group: "fix/1.2", Heads: map[string]string{"novox/a": "aaaa", "novox/b": "bbbb"}}, - `{"v":1,"group":"fix/1.2","heads":{"novox/a":"aaaa","novox/b":"bbbb"}}`}, - {"merge", func() ([]byte, error) { - return EncodeMerge(seat.MergesByGroupValue{Group: "g", Ask: "merge.g.0123456789ab", Approved: map[string]string{"novox/a@7": "h1"}, - Pulls: []seat.MergesByGroupValuePullsItem{{Repository: "novox/a", Number: 7, Head: "h1", State: "merged", Commit: "c1"}}}) - }, func(b []byte) (any, error) { return DecodeMerge(b) }, - seat.MergesByGroupValue{V: 1, Group: "g", Ask: "merge.g.0123456789ab", Approved: map[string]string{"novox/a@7": "h1"}, - Pulls: []seat.MergesByGroupValuePullsItem{{Repository: "novox/a", Number: 7, Head: "h1", State: "merged", Commit: "c1"}}}, - `{"v":1,"group":"g","ask":"merge.g.0123456789ab","approved":{"novox/a@7":"h1"},"pulls":[{"repository":"novox/a","number":7,"head":"h1","state":"merged","commit":"c1"}]}`}, - {"ask", func() ([]byte, error) { - return EncodeAsk(seat.AsksByMergeGroupHeadsValue{Group: "g", Asking: 2, Ask: json.RawMessage(`{"headline":"x"}`), - Heads: []seat.AsksByMergeGroupHeadsValueHeadsItem{{Repository: "novox/a", Number: 7, Head: "h1"}}}) - }, func(b []byte) (any, error) { return DecodeAsk(b) }, - seat.AsksByMergeGroupHeadsValue{V: 1, Group: "g", Asking: 2, Ask: map[string]any{"headline": "x"}, - Heads: []seat.AsksByMergeGroupHeadsValueHeadsItem{{Repository: "novox/a", Number: 7, Head: "h1"}}}, - `{"v":1,"group":"g","heads":[{"repository":"novox/a","number":7,"head":"h1"}],"ask":{"headline":"x"},"asking":2}`}, + seat.SourceByBranchValue{V: 1, Source: 1044, Call: "0123456789abcdef", Heads: map[string]string{"novox/a": "aaaa", "novox/b": "bbbb"}}, + `{"v":1,"source":1044,"call":"0123456789abcdef","heads":{"novox/a":"aaaa","novox/b":"bbbb"}}`}, {"owed", func() ([]byte, error) { return EncodeOwed(seat.OwedByRepositoryNumberHeadActValue{Act: OwedStatus, Context: StatusContextCheck, Target: "t", State: "pending"}) }, func(b []byte) (any, error) { return DecodeOwed(b) }, seat.OwedByRepositoryNumberHeadActValue{V: 1, Act: OwedStatus, Context: StatusContextCheck, Target: "t", State: "pending"}, `{"v":1,"act":"status","context":"mesh/check","target":"t","state":"pending"}`}, - {"turn", func() ([]byte, error) { - return EncodeTurn(seat.TurnsByRepositoryValue{Repository: "novox/a", Waiting: []seat.TurnsByRepositoryValueWaitingItem{{ - Group: "g", Heads: "0123456789ab", Ask: "k", Approved: ap, Since: ap.Add(time.Minute), WaitsFor: "g.0123456789ab", WaitsSince: &wait, Step: "s"}}}) - }, func(b []byte) (any, error) { return DecodeTurn(b) }, - seat.TurnsByRepositoryValue{V: 1, Repository: "novox/a", Waiting: []seat.TurnsByRepositoryValueWaitingItem{{ - Group: "g", Heads: "0123456789ab", Ask: "k", Approved: ap, Since: ap.Add(time.Minute), WaitsFor: "g.0123456789ab", WaitsSince: &wait, Step: "s"}}}, - `{"v":1,"repository":"novox/a","waiting":[{"group":"g","heads":"0123456789ab","ask":"k","approved":"2026-11-05T10:00:00Z","since":"2026-11-05T10:01:00Z","waits-for":"g.0123456789ab","waits-since":"2026-11-05T10:02:00Z","step":"s"}]}`}, {"answer", func() ([]byte, error) { return EncodeAnswer(Answer{Option: "merge", Warrant: "w", Words: "ok"}) }, func(b []byte) (any, error) { return DecodeAnswer(b) }, Answer{V: 1, Option: "merge", Warrant: "w", Words: "ok"}, `{"v":1,"option":"merge","warrant":"w","words":"ok"}`}, @@ -88,26 +63,6 @@ func TestGateValuesEncodeAsGoDeliveryDid(t *testing.T) { } func TestGateKeysAsGoDeliveryHadThem(t *testing.T) { - for in, want := range map[string]string{"novox/Mesh-sdk": "novox.mesh-sdk", "novox/mesh-sdk": "novox.mesh-sdk", "novox/mesh.x": "novox.mesh=2ex"} { - got, err := TurnsKey(in) - if err != nil || got != want { - t.Errorf("TurnsKey(%q) = %q, %v; want %q", in, got, err, want) - } - } - if r, err := ParseTurnsKey("novox.mesh=2ex"); err != nil || r != "novox/mesh.x" { - t.Errorf("%q %v", r, err) - } - for _, bad := range []string{"novox", "novox.Mesh", "a.b.c", ".x", "novox.mesh-sdk."} { - if _, err := ParseTurnsKey(bad); err == nil { - t.Errorf("%q parses as a turns key", bad) - } - } - if _, err := TurnsKey("novox"); err == nil { - t.Error("a repository with no slash keys") - } - if k := ApprovedKey("novox/a", 7); k != "novox/a@7" { - t.Error(k) - } if SourceKey("beta") != seat.SourceByBranchKey("beta") || SourceKey("beta") != "beta" { t.Error("the source's key is the seat's, one per watched branch") } @@ -176,73 +131,16 @@ func TestGateKeysAsGoDeliveryHadThem(t *testing.T) { } func TestGateValuesRefuseWhatTheirRulesRefuse(t *testing.T) { - ap := time.Date(2026, 11, 5, 10, 0, 0, 0, time.UTC) - pull := seat.MergesByGroupValuePullsItem{Repository: "novox/a", Number: 7, Head: "h1", State: "merging"} - merge := func(edit func(*seat.MergesByGroupValue)) error { - m := seat.MergesByGroupValue{Group: "g", Ask: "k", Pulls: []seat.MergesByGroupValuePullsItem{pull}} - edit(&m) - _, err := EncodeMerge(m) - return err - } - turn := func(edit func(*seat.TurnsByRepositoryValue)) error { - tv := seat.TurnsByRepositoryValue{Repository: "novox/a", Waiting: []seat.TurnsByRepositoryValueWaitingItem{{Group: "g", Heads: "0123456789ab", Approved: ap, Since: ap}}} - edit(&tv) - _, err := EncodeTurn(tv) - return err - } - for name, c := range map[string]struct { - err error - want string - }{ - "merge: no group": {merge(func(m *seat.MergesByGroupValue) { m.Group = "" }), "no group"}, - "merge: no pull": {merge(func(m *seat.MergesByGroupValue) { m.Pulls = nil }), "no pull request"}, - "merge: not approved": {merge(func(m *seat.MergesByGroupValue) { m.Approved = map[string]string{"novox/b@1": "x"} }), "not among the approved"}, - "merge: other head": {merge(func(m *seat.MergesByGroupValue) { m.Approved = map[string]string{"novox/a@7": "x"} }), "Approve was for"}, - "merge: merged no commit": {merge(func(m *seat.MergesByGroupValue) { m.Pulls[0].State = "merged" }), "no merge commit"}, - "merge: refused no words": {merge(func(m *seat.MergesByGroupValue) { m.Pulls[0].State = "refused" }), "no words"}, - "merge: unknown state": {merge(func(m *seat.MergesByGroupValue) { m.Pulls[0].State = "lost" }), "not merging, merged or refused"}, - "turn: upper case": {turn(func(v *seat.TurnsByRepositoryValue) { v.Repository = "Novox/a" }), "not lowercase"}, - "turn: empty": {turn(func(v *seat.TurnsByRepositoryValue) { v.Waiting = nil }), "names no delivery"}, - "turn: bad hash": {turn(func(v *seat.TurnsByRepositoryValue) { v.Waiting[0].Heads = "xyz" }), "12 lowercase hex"}, - "turn: no time": {turn(func(v *seat.TurnsByRepositoryValue) { v.Waiting[0].Since = time.Time{} }), "no time"}, - "turn: step with no wait": {turn(func(v *seat.TurnsByRepositoryValue) { v.Waiting[0].Step = "s" }), "names no check"}, - "turn: not a verdict key": {turn(func(v *seat.TurnsByRepositoryValue) { v.Waiting[0].WaitsFor = "nope" }), "not a verdict key"}, - } { - if c.err == nil || !strings.Contains(c.err.Error(), c.want) { - t.Errorf("%s: %v, want %q", name, c.err, c.want) - } - } - if _, err := EncodeSource(seat.SourceByBranchValue{Group: "g"}); err == nil { + if _, err := EncodeSource(seat.SourceByBranchValue{Source: 1, Call: "0123456789abcdef"}); err == nil { t.Error("an empty source encodes") } - if _, err := EncodeAsk(seat.AsksByMergeGroupHeadsValue{Group: "g", Ask: "text", Heads: []seat.AsksByMergeGroupHeadsValueHeadsItem{{Repository: "novox/a", Number: 1, Head: "h"}}}); err == nil { - t.Error("an ask that is no object encodes") - } if _, err := EncodeAnswer(Answer{Option: "merge"}); err == nil { t.Error("an answer with no warrant encodes") } - if _, err := DecodeSource([]byte(`{"v":2,"group":"g","heads":{"a":"b"}}`)); !errors.Is(err, keys.ErrUnknownVersion) { + if _, err := DecodeSource([]byte(`{"v":2,"source":1,"call":"c","heads":{"a":"b"}}`)); !errors.Is(err, keys.ErrUnknownVersion) { t.Errorf("another version: %v", err) } - if _, err := DecodeMerge([]byte(`{"v":1,"group":"g","ask":"k","pulls":[],"extra":1}`)); err == nil { + if _, err := DecodeSource([]byte(`{"v":1,"source":1,"call":"c","heads":{"a":"b"},"extra":1}`)); err == nil { t.Error("an unknown field decodes") } } - -func TestTurnHoldsAndSameTurn(t *testing.T) { - ap := time.Date(2026, 11, 5, 10, 0, 0, 0, time.UTC) - tv := seat.TurnsByRepositoryValue{V: 1, Repository: "novox/a", Waiting: []seat.TurnsByRepositoryValueWaitingItem{{Group: "g", Heads: "0123456789ab", Approved: ap, Since: ap}}} - if TurnHolds(tv, "0123456789ab") || !TurnHolds(tv, "ba9876543210") || TurnHolds(seat.TurnsByRepositoryValue{}, "x") { - t.Error("a turn holds a delivery that is not in it while others wait") - } - other := tv - other.Waiting = []seat.TurnsByRepositoryValueWaitingItem{tv.Waiting[0]} - other.Waiting[0].Approved = ap.In(time.FixedZone("x", 3600)) - if !SameTurn(tv, other) { - t.Error("the same instant in another zone is another turn") - } - other.Waiting[0].Since = ap.Add(time.Second) - if SameTurn(tv, other) { - t.Error("another instant is the same turn") - } -} diff --git a/modules/mesh-delivery-contracts/go/seats/meshdelivery/contract.go b/modules/mesh-delivery-contracts/go/seats/meshdelivery/contract.go index 1d72a015..bd4badad 100644 --- a/modules/mesh-delivery-contracts/go/seats/meshdelivery/contract.go +++ b/modules/mesh-delivery-contracts/go/seats/meshdelivery/contract.go @@ -17,36 +17,30 @@ const Seat = "mesh-delivery" const ( VerbDeliveries = "deliveries" VerbShow = "show" - VerbGroups = "groups" VerbSource = "source" VerbStalled = "stalled" VerbRecovery = "recovery" ) const ( - EventOwed = "owed" - EventPinned = "pinned" - EventFreed = "freed" - EventHeadsReplaced = "heads-replaced" - EventRecordOpened = "record-opened" - EventRecordEnded = "record-ended" - EventFilling = "filling" - EventFull = "full" - EventRoom = "room" - EventSourceMoved = "source-moved" - EventRecoveryMerged = "recovery-merged" - EventApprovalCarried = "approval-carried" - EventPinsStated = "pins-stated" + EventOwed = "owed" + EventRecordOpened = "record-opened" + EventRecordEnded = "record-ended" + EventFilling = "filling" + EventFull = "full" + EventRoom = "room" + EventSourceMoved = "source-moved" + EventRecoveryMerged = "recovery-merged" ) // Verbs is every verb the seat serves, in its definition's order: a new copy each call. func Verbs() []string { - return []string{VerbDeliveries, VerbShow, VerbGroups, VerbSource, VerbStalled, VerbRecovery} + return []string{VerbDeliveries, VerbShow, VerbSource, VerbStalled, VerbRecovery} } // Events is every event published on the seat's subject: a new copy each call. func Events() []string { - return []string{EventOwed, EventPinned, EventFreed, EventHeadsReplaced, EventRecordOpened, EventRecordEnded, EventFilling, EventFull, EventRoom, EventSourceMoved, EventRecoveryMerged, EventApprovalCarried, EventPinsStated} + return []string{EventOwed, EventRecordOpened, EventRecordEnded, EventFilling, EventFull, EventRoom, EventSourceMoved, EventRecoveryMerged} } // Family is where the seat's events are kept: the shared events stream, filtered to the seat's subjects. @@ -66,17 +60,13 @@ func SubjectOwed(repository, number string) string { // SubjectOwedAll hears every owed. const SubjectOwedAll = "mesh.seat.mesh-delivery.event.owed.*.*" -// SubjectPinned is where pinned is published. -const SubjectPinned = "mesh.seat.mesh-delivery.event.pinned" +// SubjectRecordOpened is where record-opened is published, on mesh.seat.mesh-delivery.event.record-opened.. +func SubjectRecordOpened(call string) string { + return "mesh.seat.mesh-delivery.event.record-opened." + call +} -// SubjectFreed is where freed is published. -const SubjectFreed = "mesh.seat.mesh-delivery.event.freed" - -// SubjectHeadsReplaced is where heads-replaced is published. -const SubjectHeadsReplaced = "mesh.seat.mesh-delivery.event.heads-replaced" - -// SubjectRecordOpened is where record-opened is published. -const SubjectRecordOpened = "mesh.seat.mesh-delivery.event.record-opened" +// SubjectRecordOpenedAll hears every record-opened. +const SubjectRecordOpenedAll = "mesh.seat.mesh-delivery.event.record-opened.*" // SubjectRecordEnded is where record-ended is published. const SubjectRecordEnded = "mesh.seat.mesh-delivery.event.record-ended" @@ -90,37 +80,24 @@ const SubjectFull = "mesh.seat.mesh-delivery.event.full" // SubjectRoom is where room is published. const SubjectRoom = "mesh.seat.mesh-delivery.event.room" -// SubjectSourceMoved is where source-moved is published, on mesh.seat.mesh-delivery.event.source-moved.. -func SubjectSourceMoved(branch string) string { - return "mesh.seat.mesh-delivery.event.source-moved." + branch +// StreamSourceMoved is the stream source-moved is kept in. +const StreamSourceMoved = "SEAT_mesh-delivery_source-moved" + +// SubjectSourceMoved is where source-moved is published, on mesh.seat.mesh-delivery.event.source-moved... +func SubjectSourceMoved(branch, source string) string { + return "mesh.seat.mesh-delivery.event.source-moved." + branch + "." + source } // SubjectSourceMovedAll hears every source-moved. -const SubjectSourceMovedAll = "mesh.seat.mesh-delivery.event.source-moved.*" +const SubjectSourceMovedAll = "mesh.seat.mesh-delivery.event.source-moved.*.*" // SubjectRecoveryMerged is where recovery-merged is published. const SubjectRecoveryMerged = "mesh.seat.mesh-delivery.event.recovery-merged" -// StreamApprovalCarried is the stream approval-carried is kept in. -const StreamApprovalCarried = "SEAT_mesh-delivery_approval-carried" - -// SubjectApprovalCarried is where approval-carried is published, on mesh.seat.mesh-delivery.event.approval-carried... -func SubjectApprovalCarried(repository, pull string) string { - return "mesh.seat.mesh-delivery.event.approval-carried." + repository + "." + pull -} - -// SubjectApprovalCarriedAll hears every approval-carried. -const SubjectApprovalCarriedAll = "mesh.seat.mesh-delivery.event.approval-carried.*.*" - -// SubjectPinsStated is where pins-stated is published. -const SubjectPinsStated = "mesh.seat.mesh-delivery.event.pins-stated" - const ( StateSource = "source" - StateMerges = "merges" - StateAsks = "asks" StateOwed = "owed" - StateTurns = "turns" + StateHeads = "heads" ) // SourceByBranchKey is the key of one value of the state source under the form "". @@ -154,77 +131,6 @@ func DecodeSourceByBranchValue(raw []byte) (SourceByBranchValue, error) { return v, nil } -// MergesByGroupKey is the key of one value of the state merges under the form "". -func MergesByGroupKey(group string) string { return group } - -// ParseMergesByGroupKey reads the parts of a key of the form "", in the order of the form; the last result is false for a key of another form. -func ParseMergesByGroupKey(key string) (string, bool) { - rest := key - if rest == "" { - return "", false - } - v0 := rest - rest = "" - if rest != "" { - return "", false - } - return v0, true -} - -// DecodeMergesByGroupValue reads one value of the state merges under the form "", refusing a field MergesByGroupValue does not know and any text after the value. -func DecodeMergesByGroupValue(raw []byte) (MergesByGroupValue, error) { - var v MergesByGroupValue - dec := json.NewDecoder(bytes.NewReader(raw)) - dec.DisallowUnknownFields() - if err := dec.Decode(&v); err != nil { - return v, err - } - if dec.More() { - return v, errors.New("text after the value") - } - return v, nil -} - -// AsksByMergeGroupHeadsKey is the key of one value of the state asks under the form "merge..". -func AsksByMergeGroupHeadsKey(group, heads string) string { return "merge." + group + "." + heads } - -// ParseAsksByMergeGroupHeadsKey reads the parts of a key of the form "merge..", in the order of the form; the last result is false for a key of another form. -func ParseAsksByMergeGroupHeadsKey(key string) (string, string, bool) { - rest := key - if !strings.HasPrefix(rest, "merge.") { - return "", "", false - } - rest = rest[6:] - v1, after1, found1 := strings.Cut(rest, ".") - if !found1 || v1 == "" { - return "", "", false - } - rest = after1 - if rest == "" { - return "", "", false - } - v3 := rest - rest = "" - if rest != "" { - return "", "", false - } - return v1, v3, true -} - -// DecodeAsksByMergeGroupHeadsValue reads one value of the state asks under the form "merge..", refusing a field AsksByMergeGroupHeadsValue does not know and any text after the value. -func DecodeAsksByMergeGroupHeadsValue(raw []byte) (AsksByMergeGroupHeadsValue, error) { - var v AsksByMergeGroupHeadsValue - dec := json.NewDecoder(bytes.NewReader(raw)) - dec.DisallowUnknownFields() - if err := dec.Decode(&v); err != nil { - return v, err - } - if dec.More() { - return v, errors.New("text after the value") - } - return v, nil -} - // OwedByRepositoryNumberHeadActKey is the key of one value of the state owed under the form "...". func OwedByRepositoryNumberHeadActKey(repository, number, head, act string) string { return repository + "." + number + "." + head + "." + act @@ -273,26 +179,31 @@ func DecodeOwedByRepositoryNumberHeadActValue(raw []byte) (OwedByRepositoryNumbe return v, nil } -// TurnsByRepositoryKey is the key of one value of the state turns under the form "". -func TurnsByRepositoryKey(repository string) string { return repository } +// HeadsByRepositoryBranchKey is the key of one value of the state heads under the form ".". +func HeadsByRepositoryBranchKey(repository, branch string) string { return repository + "." + branch } -// ParseTurnsByRepositoryKey reads the parts of a key of the form "", in the order of the form; the last result is false for a key of another form. -func ParseTurnsByRepositoryKey(key string) (string, bool) { +// ParseHeadsByRepositoryBranchKey reads the parts of a key of the form ".", in the order of the form; the last result is false for a key of another form. +func ParseHeadsByRepositoryBranchKey(key string) (string, string, bool) { rest := key - if rest == "" { - return "", false + v0, after0, found0 := strings.Cut(rest, ".") + if !found0 || v0 == "" { + return "", "", false } - v0 := rest + rest = after0 + if rest == "" { + return "", "", false + } + v2 := rest rest = "" if rest != "" { - return "", false + return "", "", false } - return v0, true + return v0, v2, true } -// DecodeTurnsByRepositoryValue reads one value of the state turns under the form "", refusing a field TurnsByRepositoryValue does not know and any text after the value. -func DecodeTurnsByRepositoryValue(raw []byte) (TurnsByRepositoryValue, error) { - var v TurnsByRepositoryValue +// DecodeHeadsByRepositoryBranchValue reads one value of the state heads under the form ".", refusing a field HeadsByRepositoryBranchValue does not know and any text after the value. +func DecodeHeadsByRepositoryBranchValue(raw []byte) (HeadsByRepositoryBranchValue, error) { + var v HeadsByRepositoryBranchValue dec := json.NewDecoder(bytes.NewReader(raw)) dec.DisallowUnknownFields() if err := dec.Decode(&v); err != nil { @@ -304,46 +215,6 @@ func DecodeTurnsByRepositoryValue(raw []byte) (TurnsByRepositoryValue, error) { return v, nil } -// Act is an act the gate said for a group, with its recorded outcome once the forge bridge said one. -type Act struct { - // when the outcome was recorded - At *time.Time `json:"at,omitempty"` - // the outcome the forge bridge said as owed.ended and the gate recorded; absent while unanswered - Outcome string `json:"outcome,omitempty"` - Owed Owed `json:"owed"` - // the forge's own words for a refusal, the error for an act that could not be performed, why one is undecodable or dropped - Words string `json:"words,omitempty"` -} - -// The values of Act's outcome. -const ( - ActOutcomePerformed = "performed" - ActOutcomeRefused = "refused" - ActOutcomeCouldNotBePerformed = "could not be performed" - ActOutcomeUndecodable = "undecodable" - ActOutcomeDropped = "dropped" -) - -// Ask is the one Approve ask of a milestone (ADR 0493 §9), said apart from each delivery's transition. -type Ask struct { - // on answered: approve or decline - Answer string `json:"answer,omitempty"` - // the ask's id - Ask string `json:"ask"` - // when - At *time.Time `json:"at,omitempty"` - // on answered: who answered - By string `json:"by,omitempty"` - // its delivery group - Group string `json:"group"` - // repository to the head asked - Heads map[string]string `json:"heads,omitempty"` - // the milestone - Milestone string `json:"milestone"` - // on withdrawn: why, such as a new head of a member - Why string `json:"why,omitempty"` -} - // Fill is the delivery records' ledger's fill against its cap. type Fill struct { // when @@ -357,40 +228,6 @@ type Fill struct { Store string `json:"store"` } -// Group is one delivery group: its members, its derived state and the acts the gate said for it. -type Group struct { - // the acts the gate said for it, each with its id and its recorded outcome; an id said and not answered is the forge bridge's to perform - Acts []Act `json:"acts"` - // the group's check: its verdict, or asked as - Check string `json:"check,omitempty"` - // the group's id, its branch - ID string `json:"id"` - // its members in merge order - Members []Member `json:"members"` - // its state, derived from its members - State string `json:"state"` - // why it is in that state - Why string `json:"why,omitempty"` -} - -// Member is one member of a group: a pull request. -type Member struct { - // the branch it merges into - Base string `json:"base,omitempty"` - // its head - Head string `json:"head"` - // the member's delivery id - ID string `json:"id"` - // the pull request's number - Number int64 `json:"number"` - // the pull request is open: not merged, closed or final - Open bool `json:"open,omitempty"` - // the repository, / - Repository string `json:"repository"` - // the member's delivery state - State string `json:"state"` -} - // Owed is one act the gate owes the forge, said once under its id and safe to repeat at the forge (design 47 *What the gate owes the forge*); the forge bridge performs it through the seat git's verb of the same act. type Owed struct { // the act: merge (the seat git's merge-pull), status, view, comment or note @@ -434,28 +271,6 @@ const ( OwedActNote = "note" ) -// PinsCatalogItem is one catalog graph revision, named by its watched branch and its number on the seat mesh-catalog (revisions are numbered per branch). -type PinsCatalogItem struct { - // the watched branch the revision belongs to - Branch string `json:"branch"` - // its number on that branch - Revision int64 `json:"revision"` -} - -// Pins is the graph revisions a delivery record starts or stops pointing at. -type Pins struct { - // assignment graph revisions, by their number on the seat mesh-wants - Assignment []int64 `json:"assignment,omitempty"` - // catalog graph revisions, by watched branch and number on the seat mesh-catalog - Catalog []PinsCatalogItem `json:"catalog,omitempty"` - // the record's milestone - Milestone string `json:"milestone"` - // the record's id - Record string `json:"record"` - // on freed: the record ended past its retention, or was removed by hand - Why string `json:"why,omitempty"` -} - // SourceHead is one repository of the source revision: its trunk branch and that trunk's head. type SourceHead struct { // the trunk's head the source revision names @@ -496,27 +311,6 @@ type ShowInput struct { // ShowAnswer is what show answers. type ShowAnswer = map[string]any -// GroupsInput is what groups takes. -type GroupsInput struct { - // "true": the groups that ended too - All string `json:"all,omitempty"` - // one group's id: that group alone, ended or not - Group string `json:"group,omitempty"` -} - -// The values of GroupsInput's all. -const ( - GroupsInputAllTrue = "true" - GroupsInputAllFalse = "false" -) - -// GroupsAnswer is what groups answers. -type GroupsAnswer struct { - // why it could not answer at all; a group it does not know is answered with no groups, never an error - Error string `json:"error,omitempty"` - Groups []Group `json:"groups,omitempty"` -} - // SourceInput is what source takes. type SourceInput struct { // the watched branch, escaped as a key name is; absent: the answer is the list of the branches the gate keeps a source revision of (design 47 G section 690) @@ -529,10 +323,10 @@ type SourceAnswer struct { Branch string `json:"branch,omitempty"` // given no branch: the branch name of each source. key the gate keeps, which every reader of the catalog half follows before the first registrations (design 47 G section 614, section 690) Branches []string `json:"branches,omitempty"` + // the merge call that moved the source revision last; absent before the first + Call string `json:"call,omitempty"` // why it could not be read Error string `json:"error,omitempty"` - // the group that moved the source revision last; absent before the first - Group string `json:"group,omitempty"` // every repository the source revision names, by name Repositories []SourceHead `json:"repositories,omitempty"` // the source revision's number on the bus; 0 before the first @@ -570,48 +364,20 @@ type RecoveryAnswer struct { // OwedEvent is the body of the event owed. type OwedEvent = Owed -// PinnedEvent is the body of the event pinned. -type PinnedEvent = Pins - -// FreedEvent is the body of the event freed. -type FreedEvent = Pins - -// HeadsReplacedEvent is the body of the event heads-replaced. -type HeadsReplacedEvent struct { - // when - At *time.Time `json:"at,omitempty"` - // the pull request closed - Closed bool `json:"closed,omitempty"` - // the group - Group string `json:"group"` - // its new head; absent when it closed - Head string `json:"head,omitempty"` - // the candidate's heads, 12 hex digits, as its revisions are keyed - Heads string `json:"heads"` - // its pull request's number - Number int64 `json:"number"` - // the member whose head moved or which closed - Repository string `json:"repository"` -} - // RecordOpenedEvent is the body of the event record-opened. type RecordOpenedEvent struct { // when At *time.Time `json:"at,omitempty"` - // for a forge-made record, the branch the merge moved - Branch string `json:"branch,omitempty"` - // for a forge-made record, the merge commit - Commit string `json:"commit,omitempty"` - // a merge made at the forge, with no Approve - ForgeMade bool `json:"forge-made,omitempty"` - // its milestone + // the watched branch + Branch string `json:"branch"` + // the merge call + Call string `json:"call"` + // its milestone, . Milestone string `json:"milestone"` - // for a forge-made record, the pull request's number - Pull int64 `json:"pull,omitempty"` // the record's id Record string `json:"record"` - // for a forge-made record, the repository, / - Repository string `json:"repository,omitempty"` + // the source revision + Source int64 `json:"source"` } // RecordEndedEventAwayItem is a type of the contract. @@ -628,12 +394,16 @@ type RecordEndedEvent struct { At *time.Time `json:"at,omitempty"` // the nodes away, each with since when; it ends without them Away []RecordEndedEventAwayItem `json:"away,omitempty"` - // a merge made at the forge, with no Approve - ForgeMade bool `json:"forge-made,omitempty"` - // its milestone + // the watched branch + Branch string `json:"branch"` + // the merge call + Call string `json:"call"` + // its milestone, . Milestone string `json:"milestone"` // the record's id Record string `json:"record"` + // the source revision + Source int64 `json:"source"` } // FillingEvent is the body of the event filling. @@ -645,14 +415,24 @@ type FullEvent = Fill // RoomEvent is the body of the event room. type RoomEvent = Fill +// SourceMovedEventHeadsItem is a type of the contract. +type SourceMovedEventHeadsItem struct { + Commit string `json:"commit"` + Repository string `json:"repository"` +} + // SourceMovedEvent is the body of the event source-moved. type SourceMovedEvent struct { - At *time.Time `json:"at,omitempty"` - Branch string `json:"branch"` - // the group that moved it, when one did - Group string `json:"group,omitempty"` - Revision int64 `json:"revision"` - V int64 `json:"v,omitempty"` + Branch string `json:"branch"` + // the merge call that moved it + Call string `json:"call"` + // the repositories it moved + Heads []SourceMovedEventHeadsItem `json:"heads"` + // the source revision, numbered by the gate alone + Source int64 `json:"source"` + // true only for a branch's first revision (design 47 H §768) + Start bool `json:"start"` + V int64 `json:"v"` } // RecoveryMergedEvent is the body of the event recovery-merged. @@ -673,76 +453,14 @@ type RecoveryMergedEvent struct { Why string `json:"why"` } -// ApprovalCarriedEvent is the body of the event approval-carried. -type ApprovalCarriedEvent struct { - // who approved: the operator - Approver string `json:"approver"` - // when it was said, RFC 3339 - At time.Time `json:"at"` - // the head the Approve named - Commit string `json:"commit"` - // the pull request's number - Pull int64 `json:"pull"` - // the repository - Repository string `json:"repository"` -} - -// PinsStatedEvent is the body of the event pins-stated. -type PinsStatedEvent struct { - // when it was said, RFC 3339 - At time.Time `json:"at"` -} - // SourceByBranchValue is one value of the state source under the key . type SourceByBranchValue struct { - // the group that moved it - Group string `json:"group"` + // the merge call that moved it; a call the newest revision already carries writes nothing (design 47 H §737, H-A-33) + Call string `json:"call"` // repository to the merged head, a full commit Heads map[string]string `json:"heads"` - // the layout version - V int64 `json:"v,omitempty"` -} - -// MergesByGroupValuePullsItem is a type of the contract. -type MergesByGroupValuePullsItem struct { - Commit string `json:"commit,omitempty"` - Head string `json:"head"` - Number int64 `json:"number"` - Repository string `json:"repository"` - // merging, merged or refused - State string `json:"state"` - Words string `json:"words,omitempty"` -} - -// MergesByGroupValue is one value of the state merges under the key . -type MergesByGroupValue struct { - // @ to the approved head - Approved map[string]string `json:"approved,omitempty"` - // the ask key - Ask string `json:"ask"` - Group string `json:"group"` - Pulls []MergesByGroupValuePullsItem `json:"pulls"` - // the layout version - V int64 `json:"v,omitempty"` -} - -// AsksByMergeGroupHeadsValueHeadsItem is a type of the contract. -type AsksByMergeGroupHeadsValueHeadsItem struct { - // the full commit - Head string `json:"head"` - Number int64 `json:"number"` - // / - Repository string `json:"repository"` -} - -// AsksByMergeGroupHeadsValue is one value of the state asks under the key merge... -type AsksByMergeGroupHeadsValue struct { - // the operator-channel ask as raised - Ask any `json:"ask"` - // the number of times it was asked - Asking int64 `json:"asking,omitempty"` - Group string `json:"group"` - Heads []AsksByMergeGroupHeadsValueHeadsItem `json:"heads"` + // the branch's source revision, one above its newest + Source int64 `json:"source"` // the layout version V int64 `json:"v,omitempty"` } @@ -760,25 +478,10 @@ type OwedByRepositoryNumberHeadActValue struct { V int64 `json:"v,omitempty"` } -// TurnsByRepositoryValueWaitingItem is a type of the contract. -type TurnsByRepositoryValueWaitingItem struct { - // when (RFC 3339 time) - Approved time.Time `json:"approved"` - Ask string `json:"ask,omitempty"` - Group string `json:"group"` - Heads string `json:"heads"` - // when (RFC 3339 time) - Since time.Time `json:"since"` - Step string `json:"step,omitempty"` - WaitsFor string `json:"waits-for,omitempty"` - // when (RFC 3339 time) - WaitsSince *time.Time `json:"waits-since,omitempty"` -} - -// TurnsByRepositoryValue is one value of the state turns under the key . -type TurnsByRepositoryValue struct { - Repository string `json:"repository"` - // the layout version - V int64 `json:"v,omitempty"` - Waiting []TurnsByRepositoryValueWaitingItem `json:"waiting"` +// HeadsByRepositoryBranchValue is one value of the state heads under the key .. +type HeadsByRepositoryBranchValue struct { + // the head head-moved said + Head string `json:"head"` + // when it was first heard + Since time.Time `json:"since"` } diff --git a/modules/mesh-delivery-contracts/go/seats/meshdelivery/contract_test.go b/modules/mesh-delivery-contracts/go/seats/meshdelivery/contract_test.go index 74c1e381..364734a0 100644 --- a/modules/mesh-delivery-contracts/go/seats/meshdelivery/contract_test.go +++ b/modules/mesh-delivery-contracts/go/seats/meshdelivery/contract_test.go @@ -21,19 +21,9 @@ func TestFixtures(t *testing.T) { decode: func(b []byte) (any, error) { var v OwedEvent; err := json.Unmarshal(b, &v); return v, err }, subjectIs: regexp.MustCompile("^mesh\\.seat\\.mesh-delivery\\.event\\.owed\\.[^.*> ]+\\.[^.*> ]+$")}, {name: "owed is said, a status", subject: "mesh.seat.mesh-delivery.event.owed.novox/mesh-sdk.178", given: "{\"act\":\"status\",\"context\":\"mesh/merge-gate\",\"description\":\"waits for the operator's Approve\",\"head\":\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"id\":\"status.novox/mesh-sdk#178.aaaaaaaaaaaa.mesh/merge-gate\",\"number\":178,\"repository\":\"novox/mesh-sdk\",\"state\":\"pending\",\"target\":\"https://forge.test/x\"}", wire: "{\"act\":\"status\",\"context\":\"mesh/merge-gate\",\"description\":\"waits for the operator's Approve\",\"head\":\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"id\":\"status.novox/mesh-sdk#178.aaaaaaaaaaaa.mesh/merge-gate\",\"number\":178,\"repository\":\"novox/mesh-sdk\",\"state\":\"pending\",\"target\":\"https://forge.test/x\"}", decode: func(b []byte) (any, error) { var v OwedEvent; err := json.Unmarshal(b, &v); return v, err }, subjectIs: regexp.MustCompile("^mesh\\.seat\\.mesh-delivery\\.event\\.owed\\.[^.*> ]+\\.[^.*> ]+$")}, - {name: "pinned is said", subject: "mesh.seat.mesh-delivery.event.pinned", given: "{\"assignment\":[1204],\"catalog\":[{\"branch\":\"main\",\"revision\":3610}],\"milestone\":\"47/G\",\"record\":\"47-G\"}", wire: "{\"assignment\":[1204],\"catalog\":[{\"branch\":\"main\",\"revision\":3610}],\"milestone\":\"47/G\",\"record\":\"47-G\"}", - decode: func(b []byte) (any, error) { var v PinnedEvent; err := json.Unmarshal(b, &v); return v, err }, subjectIs: regexp.MustCompile("^mesh\\.seat\\.mesh-delivery\\.event\\.pinned$")}, - {name: "freed is said", subject: "mesh.seat.mesh-delivery.event.freed", given: "{\"assignment\":[1204],\"catalog\":[{\"branch\":\"main\",\"revision\":3610}],\"milestone\":\"47/G\",\"record\":\"47-G\",\"why\":\"past its retention of 90 days\"}", wire: "{\"assignment\":[1204],\"catalog\":[{\"branch\":\"main\",\"revision\":3610}],\"milestone\":\"47/G\",\"record\":\"47-G\",\"why\":\"past its retention of 90 days\"}", - decode: func(b []byte) (any, error) { var v FreedEvent; err := json.Unmarshal(b, &v); return v, err }, subjectIs: regexp.MustCompile("^mesh\\.seat\\.mesh-delivery\\.event\\.freed$")}, - {name: "heads-replaced is said", subject: "mesh.seat.mesh-delivery.event.heads-replaced", given: "{\"at\":\"2026-11-09T20:05:00Z\",\"group\":\"feat/47-G\",\"head\":\"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\",\"heads\":\"0123456789ab\",\"number\":178,\"repository\":\"novox/mesh-sdk\"}", wire: "{\"at\":\"2026-11-09T20:05:00Z\",\"group\":\"feat/47-G\",\"head\":\"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\",\"heads\":\"0123456789ab\",\"number\":178,\"repository\":\"novox/mesh-sdk\"}", - decode: func(b []byte) (any, error) { var v HeadsReplacedEvent; err := json.Unmarshal(b, &v); return v, err }, subjectIs: regexp.MustCompile("^mesh\\.seat\\.mesh-delivery\\.event\\.heads-replaced$")}, - {name: "heads-replaced is said for a closed pull request", subject: "mesh.seat.mesh-delivery.event.heads-replaced", given: "{\"closed\":true,\"group\":\"feat/47-G\",\"heads\":\"0123456789ab\",\"number\":178,\"repository\":\"novox/mesh-sdk\"}", wire: "{\"closed\":true,\"group\":\"feat/47-G\",\"heads\":\"0123456789ab\",\"number\":178,\"repository\":\"novox/mesh-sdk\"}", - decode: func(b []byte) (any, error) { var v HeadsReplacedEvent; err := json.Unmarshal(b, &v); return v, err }, subjectIs: regexp.MustCompile("^mesh\\.seat\\.mesh-delivery\\.event\\.heads-replaced$")}, - {name: "record-opened is said", subject: "mesh.seat.mesh-delivery.event.record-opened", given: "{\"at\":\"2026-11-09T18:00:00Z\",\"milestone\":\"47/G\",\"record\":\"47-G\"}", wire: "{\"at\":\"2026-11-09T18:00:00Z\",\"milestone\":\"47/G\",\"record\":\"47-G\"}", - decode: func(b []byte) (any, error) { var v RecordOpenedEvent; err := json.Unmarshal(b, &v); return v, err }, subjectIs: regexp.MustCompile("^mesh\\.seat\\.mesh-delivery\\.event\\.record-opened$")}, - {name: "record-opened is said for a merge made at the forge", subject: "mesh.seat.mesh-delivery.event.record-opened", given: "{\"at\":\"2026-11-09T18:00:00Z\",\"branch\":\"main\",\"commit\":\"0123456789abcdef0123456789abcdef01234567\",\"forge-made\":true,\"milestone\":\"47/G\",\"pull\":35,\"record\":\"mesh-tools-35\",\"repository\":\"novox/mesh-tools\"}", wire: "{\"at\":\"2026-11-09T18:00:00Z\",\"branch\":\"main\",\"commit\":\"0123456789abcdef0123456789abcdef01234567\",\"forge-made\":true,\"milestone\":\"47/G\",\"pull\":35,\"record\":\"mesh-tools-35\",\"repository\":\"novox/mesh-tools\"}", - decode: func(b []byte) (any, error) { var v RecordOpenedEvent; err := json.Unmarshal(b, &v); return v, err }, subjectIs: regexp.MustCompile("^mesh\\.seat\\.mesh-delivery\\.event\\.record-opened$")}, - {name: "record-ended is said", subject: "mesh.seat.mesh-delivery.event.record-ended", given: "{\"at\":\"2026-11-09T21:00:00Z\",\"away\":[{\"node\":\"laptop\",\"since\":\"2026-11-09T18:00:00Z\"}],\"milestone\":\"47/G\",\"record\":\"47-G\"}", wire: "{\"at\":\"2026-11-09T21:00:00Z\",\"away\":[{\"node\":\"laptop\",\"since\":\"2026-11-09T18:00:00Z\"}],\"milestone\":\"47/G\",\"record\":\"47-G\"}", + {name: "record-opened is said", subject: "mesh.seat.mesh-delivery.event.record-opened.0123456789abcdef", given: "{\"at\":\"2026-11-20T02:00:00Z\",\"branch\":\"main\",\"call\":\"0123456789abcdef\",\"milestone\":\"main.1044\",\"record\":\"main.1044\",\"source\":1044}", wire: "{\"at\":\"2026-11-20T02:00:00Z\",\"branch\":\"main\",\"call\":\"0123456789abcdef\",\"milestone\":\"main.1044\",\"record\":\"main.1044\",\"source\":1044}", + decode: func(b []byte) (any, error) { var v RecordOpenedEvent; err := json.Unmarshal(b, &v); return v, err }, subjectIs: regexp.MustCompile("^mesh\\.seat\\.mesh-delivery\\.event\\.record-opened\\.[^.*> ]+$")}, + {name: "record-ended is said", subject: "mesh.seat.mesh-delivery.event.record-ended", given: "{\"at\":\"2026-11-09T21:00:00Z\",\"away\":[{\"node\":\"laptop\",\"since\":\"2026-11-09T18:00:00Z\"}],\"branch\":\"main\",\"call\":\"0123456789abcdef\",\"milestone\":\"main.1044\",\"record\":\"main.1044\",\"source\":1044}", wire: "{\"at\":\"2026-11-09T21:00:00Z\",\"away\":[{\"node\":\"laptop\",\"since\":\"2026-11-09T18:00:00Z\"}],\"branch\":\"main\",\"call\":\"0123456789abcdef\",\"milestone\":\"main.1044\",\"record\":\"main.1044\",\"source\":1044}", decode: func(b []byte) (any, error) { var v RecordEndedEvent; err := json.Unmarshal(b, &v); return v, err }, subjectIs: regexp.MustCompile("^mesh\\.seat\\.mesh-delivery\\.event\\.record-ended$")}, {name: "filling is said", subject: "mesh.seat.mesh-delivery.event.filling", given: "{\"bytes\":650000000,\"cap\":805306368,\"store\":\"records\"}", wire: "{\"bytes\":650000000,\"cap\":805306368,\"store\":\"records\"}", decode: func(b []byte) (any, error) { var v FillingEvent; err := json.Unmarshal(b, &v); return v, err }, subjectIs: regexp.MustCompile("^mesh\\.seat\\.mesh-delivery\\.event\\.filling$")}, @@ -41,43 +31,31 @@ func TestFixtures(t *testing.T) { decode: func(b []byte) (any, error) { var v FullEvent; err := json.Unmarshal(b, &v); return v, err }, subjectIs: regexp.MustCompile("^mesh\\.seat\\.mesh-delivery\\.event\\.full$")}, {name: "room is said", subject: "mesh.seat.mesh-delivery.event.room", given: "{\"bytes\":400000000,\"cap\":805306368,\"store\":\"records\"}", wire: "{\"bytes\":400000000,\"cap\":805306368,\"store\":\"records\"}", decode: func(b []byte) (any, error) { var v RoomEvent; err := json.Unmarshal(b, &v); return v, err }, subjectIs: regexp.MustCompile("^mesh\\.seat\\.mesh-delivery\\.event\\.room$")}, - {name: "main moved to its next source revision", subject: "mesh.seat.mesh-delivery.event.source-moved.main", given: "{\"at\":\"2026-11-10T10:00:00Z\",\"branch\":\"main\",\"revision\":3590,\"v\":1}", wire: "{\"at\":\"2026-11-10T10:00:00Z\",\"branch\":\"main\",\"revision\":3590,\"v\":1}", - decode: func(b []byte) (any, error) { var v SourceMovedEvent; err := json.Unmarshal(b, &v); return v, err }, subjectIs: regexp.MustCompile("^mesh\\.seat\\.mesh-delivery\\.event\\.source-moved\\.[^.*> ]+$")}, + {name: "main moved to its next source revision", subject: "mesh.seat.mesh-delivery.event.source-moved.main.1044", given: "{\"branch\":\"main\",\"call\":\"0123456789abcdef\",\"heads\":[{\"commit\":\"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\",\"repository\":\"novox/mesh-sdk\"}],\"source\":1044,\"start\":false,\"v\":1}", wire: "{\"branch\":\"main\",\"call\":\"0123456789abcdef\",\"heads\":[{\"commit\":\"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\",\"repository\":\"novox/mesh-sdk\"}],\"source\":1044,\"start\":false,\"v\":1}", + decode: func(b []byte) (any, error) { var v SourceMovedEvent; err := json.Unmarshal(b, &v); return v, err }, subjectIs: regexp.MustCompile("^mesh\\.seat\\.mesh-delivery\\.event\\.source-moved\\.[^.*> ]+\\.[^.*> ]+$")}, {name: "a recovery merged", subject: "mesh.seat.mesh-delivery.event.recovery-merged", given: "{\"at\":\"2026-11-11T10:00:00Z\",\"branch\":\"main\",\"by\":\"alice\",\"commit\":\"0123456789abcdef0123456789abcdef01234567\",\"module\":\"mesh-sdk\",\"repository\":\"novox/mesh-sdk\",\"v\":1,\"why\":\"the live delivery was broken\"}", wire: "{\"at\":\"2026-11-11T10:00:00Z\",\"branch\":\"main\",\"by\":\"alice\",\"commit\":\"0123456789abcdef0123456789abcdef01234567\",\"module\":\"mesh-sdk\",\"repository\":\"novox/mesh-sdk\",\"v\":1,\"why\":\"the live delivery was broken\"}", decode: func(b []byte) (any, error) { var v RecoveryMergedEvent; err := json.Unmarshal(b, &v); return v, err }, subjectIs: regexp.MustCompile("^mesh\\.seat\\.mesh-delivery\\.event\\.recovery-merged$")}, - {name: "approval-carried is said for a pull request approved before G", subject: "mesh.seat.mesh-delivery.event.approval-carried.mesh-tools.35", given: "{\"approver\":\"operator\",\"at\":\"2026-11-11T10:00:00Z\",\"commit\":\"0123456789abcdef0123456789abcdef01234567\",\"pull\":35,\"repository\":\"mesh-tools\"}", wire: "{\"approver\":\"operator\",\"at\":\"2026-11-11T10:00:00Z\",\"commit\":\"0123456789abcdef0123456789abcdef01234567\",\"pull\":35,\"repository\":\"mesh-tools\"}", - decode: func(b []byte) (any, error) { var v ApprovalCarriedEvent; err := json.Unmarshal(b, &v); return v, err }, subjectIs: regexp.MustCompile("^mesh\\.seat\\.mesh-delivery\\.event\\.approval-carried\\.[^.*> ]+\\.[^.*> ]+$")}, - {name: "pins-stated is said once the pins are", subject: "mesh.seat.mesh-delivery.event.pins-stated", given: "{\"at\":\"2026-11-11T10:00:00Z\"}", wire: "{\"at\":\"2026-11-11T10:00:00Z\"}", - decode: func(b []byte) (any, error) { var v PinsStatedEvent; err := json.Unmarshal(b, &v); return v, err }, subjectIs: regexp.MustCompile("^mesh\\.seat\\.mesh-delivery\\.event\\.pins-stated$")}, - {name: "the source revision", subject: "", given: "{\"group\":\"feat/registry\",\"heads\":{\"novox/mesh-sdk\":\"cccccccccccccccccccccccccccccccccccccccc\"},\"v\":1}", wire: "{\"group\":\"feat/registry\",\"heads\":{\"novox/mesh-sdk\":\"cccccccccccccccccccccccccccccccccccccccc\"},\"v\":1}", + {name: "a branch's first source revision, seeded", subject: "mesh.seat.mesh-delivery.event.source-moved.main.1", given: "{\"branch\":\"main\",\"call\":\"fedcba9876543210\",\"heads\":[{\"commit\":\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"repository\":\"novox/mesh-sdk\"},{\"commit\":\"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\",\"repository\":\"novox/mesh-catalog\"}],\"source\":1,\"start\":true,\"v\":1}", wire: "{\"branch\":\"main\",\"call\":\"fedcba9876543210\",\"heads\":[{\"commit\":\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"repository\":\"novox/mesh-sdk\"},{\"commit\":\"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\",\"repository\":\"novox/mesh-catalog\"}],\"source\":1,\"start\":true,\"v\":1}", + decode: func(b []byte) (any, error) { var v SourceMovedEvent; err := json.Unmarshal(b, &v); return v, err }, subjectIs: regexp.MustCompile("^mesh\\.seat\\.mesh-delivery\\.event\\.source-moved\\.[^.*> ]+\\.[^.*> ]+$")}, + {name: "the source revision", subject: "", given: "{\"call\":\"0123456789abcdef\",\"heads\":{\"novox/mesh-sdk\":\"cccccccccccccccccccccccccccccccccccccccc\"},\"source\":1044,\"v\":1}", wire: "{\"call\":\"0123456789abcdef\",\"heads\":{\"novox/mesh-sdk\":\"cccccccccccccccccccccccccccccccccccccccc\"},\"source\":1044,\"v\":1}", decode: func(b []byte) (any, error) { var v SourceByBranchValue; err := json.Unmarshal(b, &v); return v, err }, subjectIs: nil}, - {name: "a merge", subject: "", given: "{\"ask\":\"merge.feat=registry.0123456789ab\",\"group\":\"feat/registry\",\"pulls\":[{\"head\":\"cccccccccccccccccccccccccccccccccccccccc\",\"number\":1,\"repository\":\"novox/mesh-sdk\",\"state\":\"merging\"}],\"v\":1}", wire: "{\"ask\":\"merge.feat=registry.0123456789ab\",\"group\":\"feat/registry\",\"pulls\":[{\"head\":\"cccccccccccccccccccccccccccccccccccccccc\",\"number\":1,\"repository\":\"novox/mesh-sdk\",\"state\":\"merging\"}],\"v\":1}", - decode: func(b []byte) (any, error) { var v MergesByGroupValue; err := json.Unmarshal(b, &v); return v, err }, subjectIs: nil}, {name: "an act owed", subject: "", given: "{\"act\":\"view\",\"v\":1}", wire: "{\"act\":\"view\",\"v\":1}", decode: func(b []byte) (any, error) { var v OwedByRepositoryNumberHeadActValue err := json.Unmarshal(b, &v) return v, err }, subjectIs: nil}, - {name: "a turn", subject: "", given: "{\"repository\":\"novox/mesh-sdk\",\"v\":1,\"waiting\":[{\"approved\":\"2026-11-05T10:00:00Z\",\"group\":\"feat/registry\",\"heads\":\"0123456789ab\",\"since\":\"2026-11-05T10:01:00Z\"}]}", wire: "{\"repository\":\"novox/mesh-sdk\",\"v\":1,\"waiting\":[{\"approved\":\"2026-11-05T10:00:00Z\",\"group\":\"feat/registry\",\"heads\":\"0123456789ab\",\"since\":\"2026-11-05T10:01:00Z\"}]}", - decode: func(b []byte) (any, error) { var v TurnsByRepositoryValue; err := json.Unmarshal(b, &v); return v, err }, subjectIs: nil}, - {name: "an ask", subject: "", given: "{\"ask\":{\"headline\":\"merge\"},\"group\":\"feat/registry\",\"heads\":[{\"head\":\"cccccccccccccccccccccccccccccccccccccccc\",\"number\":1,\"repository\":\"novox/mesh-sdk\"}],\"v\":1}", wire: "{\"ask\":{\"headline\":\"merge\"},\"group\":\"feat/registry\",\"heads\":[{\"head\":\"cccccccccccccccccccccccccccccccccccccccc\",\"number\":1,\"repository\":\"novox/mesh-sdk\"}],\"v\":1}", + {name: "an untaken head", subject: "", given: "{\"head\":\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"since\":\"2026-11-20T02:00:00Z\"}", wire: "{\"head\":\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"since\":\"2026-11-20T02:00:00Z\"}", decode: func(b []byte) (any, error) { - var v AsksByMergeGroupHeadsValue + var v HeadsByRepositoryBranchValue err := json.Unmarshal(b, &v) return v, err }, subjectIs: nil}, - {name: "groups asks for one group", subject: "", given: "{\"group\":\"feat/47-G\"}", wire: "{\"group\":\"feat/47-G\"}", - decode: func(b []byte) (any, error) { var v GroupsInput; err := json.Unmarshal(b, &v); return v, err }, subjectIs: nil}, - {name: "groups answers a group with its members and acts", subject: "", given: "{\"groups\":[{\"acts\":[{\"at\":\"2026-11-09T20:01:00Z\",\"outcome\":\"performed\",\"owed\":{\"act\":\"merge\",\"ask\":\"merge.feat=47-G.0123456789ab\",\"group\":\"feat/47-G\",\"head\":\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"id\":\"merge.feat=47-G.0123456789ab.novox/mesh-sdk#178\",\"number\":178,\"repository\":\"novox/mesh-sdk\",\"said\":\"2026-11-09T20:00:00Z\"}},{\"owed\":{\"act\":\"status\",\"context\":\"mesh/merge-gate\",\"description\":\"waits for the operator's Approve\",\"head\":\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"id\":\"status.novox/mesh-sdk#178.aaaaaaaaaaaa.mesh/merge-gate\",\"number\":178,\"repository\":\"novox/mesh-sdk\",\"state\":\"pending\",\"target\":\"https://forge.test/x\"}}],\"check\":\"pass\",\"id\":\"feat/47-G\",\"members\":[{\"base\":\"main\",\"head\":\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"id\":\"novox/mesh-sdk#178\",\"number\":178,\"open\":true,\"repository\":\"novox/mesh-sdk\",\"state\":\"merging\"}],\"state\":\"merging\",\"why\":\"novox/mesh-sdk#178 merges first\"}]}", wire: "{\"groups\":[{\"acts\":[{\"at\":\"2026-11-09T20:01:00Z\",\"outcome\":\"performed\",\"owed\":{\"act\":\"merge\",\"ask\":\"merge.feat=47-G.0123456789ab\",\"group\":\"feat/47-G\",\"head\":\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"id\":\"merge.feat=47-G.0123456789ab.novox/mesh-sdk#178\",\"number\":178,\"repository\":\"novox/mesh-sdk\",\"said\":\"2026-11-09T20:00:00Z\"}},{\"owed\":{\"act\":\"status\",\"context\":\"mesh/merge-gate\",\"description\":\"waits for the operator's Approve\",\"head\":\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"id\":\"status.novox/mesh-sdk#178.aaaaaaaaaaaa.mesh/merge-gate\",\"number\":178,\"repository\":\"novox/mesh-sdk\",\"state\":\"pending\",\"target\":\"https://forge.test/x\"}}],\"check\":\"pass\",\"id\":\"feat/47-G\",\"members\":[{\"base\":\"main\",\"head\":\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"id\":\"novox/mesh-sdk#178\",\"number\":178,\"open\":true,\"repository\":\"novox/mesh-sdk\",\"state\":\"merging\"}],\"state\":\"merging\",\"why\":\"novox/mesh-sdk#178 merges first\"}]}", - decode: func(b []byte) (any, error) { var v GroupsAnswer; err := json.Unmarshal(b, &v); return v, err }, subjectIs: nil}, - {name: "groups answers a group it does not know with no groups", subject: "", given: "{}", wire: "{}", - decode: func(b []byte) (any, error) { var v GroupsAnswer; err := json.Unmarshal(b, &v); return v, err }, subjectIs: nil}, {name: "source is asked for one branch", subject: "", given: "{\"branch\":\"main\"}", wire: "{\"branch\":\"main\"}", decode: func(b []byte) (any, error) { var v SourceInput; err := json.Unmarshal(b, &v); return v, err }, subjectIs: nil}, {name: "source is asked with no branch", subject: "", given: "{}", wire: "{}", decode: func(b []byte) (any, error) { var v SourceInput; err := json.Unmarshal(b, &v); return v, err }, subjectIs: nil}, - {name: "source answers each repository's trunk and head", subject: "", given: "{\"branch\":\"main\",\"group\":\"feat/47-G\",\"repositories\":[{\"head\":\"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\",\"repository\":\"novox/mesh-sdk\",\"trunk\":\"main\"}],\"revision\":42}", wire: "{\"branch\":\"main\",\"group\":\"feat/47-G\",\"repositories\":[{\"head\":\"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\",\"repository\":\"novox/mesh-sdk\",\"trunk\":\"main\"}],\"revision\":42}", + {name: "source answers each repository's trunk and head", subject: "", given: "{\"branch\":\"main\",\"call\":\"0123456789abcdef\",\"repositories\":[{\"head\":\"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\",\"repository\":\"novox/mesh-sdk\",\"trunk\":\"main\"}],\"revision\":42}", wire: "{\"branch\":\"main\",\"call\":\"0123456789abcdef\",\"repositories\":[{\"head\":\"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\",\"repository\":\"novox/mesh-sdk\",\"trunk\":\"main\"}],\"revision\":42}", decode: func(b []byte) (any, error) { var v SourceAnswer; err := json.Unmarshal(b, &v); return v, err }, subjectIs: nil}, {name: "source answers the branches it keeps", subject: "", given: "{\"branches\":[\"main\",\"beta\"]}", wire: "{\"branches\":[\"main\",\"beta\"]}", decode: func(b []byte) (any, error) { var v SourceAnswer; err := json.Unmarshal(b, &v); return v, err }, subjectIs: nil}, diff --git a/modules/mesh-delivery-contracts/seats/mesh-delivery/fixtures/events.json b/modules/mesh-delivery-contracts/seats/mesh-delivery/fixtures/events.json index b59fb1f1..03bf11b8 100644 --- a/modules/mesh-delivery-contracts/seats/mesh-delivery/fixtures/events.json +++ b/modules/mesh-delivery-contracts/seats/mesh-delivery/fixtures/events.json @@ -30,91 +30,17 @@ "target": "https://forge.test/x" } }, - { - "name": "pinned is said", - "of": "event:pinned", - "subject": "mesh.seat.mesh-delivery.event.pinned", - "given": { - "record": "47-G", - "milestone": "47/G", - "catalog": [ - { - "branch": "main", - "revision": 3610 - } - ], - "assignment": [ - 1204 - ] - } - }, - { - "name": "freed is said", - "of": "event:freed", - "subject": "mesh.seat.mesh-delivery.event.freed", - "given": { - "record": "47-G", - "milestone": "47/G", - "catalog": [ - { - "branch": "main", - "revision": 3610 - } - ], - "assignment": [ - 1204 - ], - "why": "past its retention of 90 days" - } - }, - { - "name": "heads-replaced is said", - "of": "event:heads-replaced", - "subject": "mesh.seat.mesh-delivery.event.heads-replaced", - "given": { - "group": "feat/47-G", - "heads": "0123456789ab", - "repository": "novox/mesh-sdk", - "number": 178, - "head": "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", - "at": "2026-11-09T20:05:00Z" - } - }, - { - "name": "heads-replaced is said for a closed pull request", - "of": "event:heads-replaced", - "subject": "mesh.seat.mesh-delivery.event.heads-replaced", - "given": { - "group": "feat/47-G", - "heads": "0123456789ab", - "repository": "novox/mesh-sdk", - "number": 178, - "closed": true - } - }, { "name": "record-opened is said", "of": "event:record-opened", - "subject": "mesh.seat.mesh-delivery.event.record-opened", + "subject": "mesh.seat.mesh-delivery.event.record-opened.0123456789abcdef", "given": { - "record": "47-G", - "milestone": "47/G", - "at": "2026-11-09T18:00:00Z" - } - }, - { - "name": "record-opened is said for a merge made at the forge", - "of": "event:record-opened", - "subject": "mesh.seat.mesh-delivery.event.record-opened", - "given": { - "record": "mesh-tools-35", - "milestone": "47/G", - "forge-made": true, - "repository": "novox/mesh-tools", - "pull": 35, - "commit": "0123456789abcdef0123456789abcdef01234567", + "record": "main.1044", + "milestone": "main.1044", "branch": "main", - "at": "2026-11-09T18:00:00Z" + "source": 1044, + "call": "0123456789abcdef", + "at": "2026-11-20T02:00:00Z" } }, { @@ -122,15 +48,18 @@ "of": "event:record-ended", "subject": "mesh.seat.mesh-delivery.event.record-ended", "given": { - "record": "47-G", - "milestone": "47/G", + "record": "main.1044", + "milestone": "main.1044", "away": [ { "node": "laptop", "since": "2026-11-09T18:00:00Z" } ], - "at": "2026-11-09T21:00:00Z" + "at": "2026-11-09T21:00:00Z", + "branch": "main", + "source": 1044, + "call": "0123456789abcdef" } }, { @@ -167,12 +96,19 @@ { "name": "main moved to its next source revision", "of": "event:source-moved", - "subject": "mesh.seat.mesh-delivery.event.source-moved.main", + "subject": "mesh.seat.mesh-delivery.event.source-moved.main.1044", "given": { "v": 1, "branch": "main", - "revision": 3590, - "at": "2026-11-10T10:00:00Z" + "source": 1044, + "call": "0123456789abcdef", + "start": false, + "heads": [ + { + "repository": "novox/mesh-sdk", + "commit": "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" + } + ] } }, { @@ -191,23 +127,25 @@ } }, { - "name": "approval-carried is said for a pull request approved before G", - "of": "event:approval-carried", - "subject": "mesh.seat.mesh-delivery.event.approval-carried.mesh-tools.35", + "name": "a branch's first source revision, seeded", + "of": "event:source-moved", + "subject": "mesh.seat.mesh-delivery.event.source-moved.main.1", "given": { - "repository": "mesh-tools", - "pull": 35, - "commit": "0123456789abcdef0123456789abcdef01234567", - "approver": "operator", - "at": "2026-11-11T10:00:00Z" - } - }, - { - "name": "pins-stated is said once the pins are", - "of": "event:pins-stated", - "subject": "mesh.seat.mesh-delivery.event.pins-stated", - "given": { - "at": "2026-11-11T10:00:00Z" + "v": 1, + "branch": "main", + "source": 1, + "call": "fedcba9876543210", + "start": true, + "heads": [ + { + "repository": "novox/mesh-sdk", + "commit": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + }, + { + "repository": "novox/mesh-catalog", + "commit": "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" + } + ] } } ] diff --git a/modules/mesh-delivery-contracts/seats/mesh-delivery/fixtures/states.json b/modules/mesh-delivery-contracts/seats/mesh-delivery/fixtures/states.json index 78776547..1381da75 100644 --- a/modules/mesh-delivery-contracts/seats/mesh-delivery/fixtures/states.json +++ b/modules/mesh-delivery-contracts/seats/mesh-delivery/fixtures/states.json @@ -4,27 +4,11 @@ "of": "state:source/", "given": { "v": 1, - "group": "feat/registry", "heads": { "novox/mesh-sdk": "cccccccccccccccccccccccccccccccccccccccc" - } - } - }, - { - "name": "a merge", - "of": "state:merges/", - "given": { - "v": 1, - "group": "feat/registry", - "ask": "merge.feat=registry.0123456789ab", - "pulls": [ - { - "repository": "novox/mesh-sdk", - "number": 1, - "head": "cccccccccccccccccccccccccccccccccccccccc", - "state": "merging" - } - ] + }, + "source": 1044, + "call": "0123456789abcdef" } }, { @@ -36,37 +20,11 @@ } }, { - "name": "a turn", - "of": "state:turns/", + "name": "an untaken head", + "of": "state:heads/.", "given": { - "v": 1, - "repository": "novox/mesh-sdk", - "waiting": [ - { - "group": "feat/registry", - "heads": "0123456789ab", - "approved": "2026-11-05T10:00:00Z", - "since": "2026-11-05T10:01:00Z" - } - ] - } - }, - { - "name": "an ask", - "of": "state:asks/merge..", - "given": { - "v": 1, - "group": "feat/registry", - "heads": [ - { - "repository": "novox/mesh-sdk", - "number": 1, - "head": "cccccccccccccccccccccccccccccccccccccccc" - } - ], - "ask": { - "headline": "merge" - } + "head": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", + "since": "2026-11-20T02:00:00Z" } } ] diff --git a/modules/mesh-delivery-contracts/seats/mesh-delivery/fixtures/verbs.json b/modules/mesh-delivery-contracts/seats/mesh-delivery/fixtures/verbs.json index 65bc3c2c..3d38ba18 100644 --- a/modules/mesh-delivery-contracts/seats/mesh-delivery/fixtures/verbs.json +++ b/modules/mesh-delivery-contracts/seats/mesh-delivery/fixtures/verbs.json @@ -1,70 +1,4 @@ [ - { - "name": "groups asks for one group", - "of": "verb:groups.input", - "given": { - "group": "feat/47-G" - } - }, - { - "name": "groups answers a group with its members and acts", - "of": "verb:groups.answer", - "given": { - "groups": [ - { - "id": "feat/47-G", - "state": "merging", - "why": "novox/mesh-sdk#178 merges first", - "check": "pass", - "members": [ - { - "id": "novox/mesh-sdk#178", - "repository": "novox/mesh-sdk", - "number": 178, - "head": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", - "base": "main", - "state": "merging", - "open": true - } - ], - "acts": [ - { - "owed": { - "id": "merge.feat=47-G.0123456789ab.novox/mesh-sdk#178", - "act": "merge", - "repository": "novox/mesh-sdk", - "number": 178, - "head": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", - "group": "feat/47-G", - "ask": "merge.feat=47-G.0123456789ab", - "said": "2026-11-09T20:00:00Z" - }, - "outcome": "performed", - "at": "2026-11-09T20:01:00Z" - }, - { - "owed": { - "id": "status.novox/mesh-sdk#178.aaaaaaaaaaaa.mesh/merge-gate", - "act": "status", - "repository": "novox/mesh-sdk", - "number": 178, - "head": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", - "context": "mesh/merge-gate", - "state": "pending", - "description": "waits for the operator's Approve", - "target": "https://forge.test/x" - } - } - ] - } - ] - } - }, - { - "name": "groups answers a group it does not know with no groups", - "of": "verb:groups.answer", - "given": {} - }, { "name": "source is asked for one branch", "of": "verb:source.input", @@ -81,7 +15,6 @@ "name": "source answers each repository's trunk and head", "of": "verb:source.answer", "given": { - "group": "feat/47-G", "revision": 42, "repositories": [ { @@ -90,7 +23,8 @@ "head": "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" } ], - "branch": "main" + "branch": "main", + "call": "0123456789abcdef" } }, { diff --git a/modules/mesh-delivery-contracts/seats/mesh-delivery/seat.json b/modules/mesh-delivery-contracts/seats/mesh-delivery/seat.json index f6f75f8b..5546f304 100644 --- a/modules/mesh-delivery-contracts/seats/mesh-delivery/seat.json +++ b/modules/mesh-delivery-contracts/seats/mesh-delivery/seat.json @@ -62,46 +62,9 @@ }, "class": "read" }, - { - "name": "groups", - "description": "Every delivery group: its members in merge order, its check and its state, derived from its members, and the acts the gate said it owes the forge for it, each with its id and its recorded outcome (design 47 *What the gate owes the forge*). With a group, that group alone, and none for a group it does not know: the forge bridge reads a group's members and catches up on what it owes from here, never from the gate's state.", - "input": { - "type": "object", - "properties": { - "all": { - "description": "\"true\": the groups that ended too", - "enum": [ - "true", - "false" - ], - "type": "string" - }, - "group": { - "type": "string", - "description": "one group's id: that group alone, ended or not" - } - } - }, - "answer": { - "type": "object", - "properties": { - "groups": { - "type": "array", - "items": { - "$ref": "#/defs/Group" - } - }, - "error": { - "type": "string", - "description": "why it could not answer at all; a group it does not know is answered with no groups, never an error" - } - } - }, - "class": "read" - }, { "name": "source", - "description": "One watched branch's source revision (design 47 *Watched branches and the catalog graph per branch*: source. in place of source.main): The source revision the gate holds: every repository it names, its trunk branch and that trunk's head as the gate merged or seeded it, and the group that moved it last. Read, never written: the node-engines read it to call a reverted build's catch-up tool once per repository, never the gate's state (design 47). Given no branch it answers branches alone, the branch of each source key the gate keeps; given a branch, that branch's source revision (design 47 G section 690).", + "description": "One watched branch's source revision (design 47 *Watched branches and the catalog graph per branch*: source. in place of source.main): The source revision the gate holds: every repository it names, its trunk branch and that trunk's head as the gate merged or seeded it, and the merge call that moved it last. Read, never written: the node-engines read it to call a reverted build's catch-up tool once per repository, never the gate's state (design 47). Given no branch it answers branches alone, the branch of each source key the gate keeps; given a branch, that branch's source revision (design 47 G section 690).", "input": { "type": "object", "properties": { @@ -114,14 +77,14 @@ "answer": { "type": "object", "properties": { - "group": { - "type": "string", - "description": "the group that moved the source revision last; absent before the first" - }, "revision": { "type": "integer", "description": "the source revision's number on the bus; 0 before the first" }, + "call": { + "type": "string", + "description": "the merge call that moved the source revision last; absent before the first" + }, "repositories": { "type": "array", "items": { @@ -229,68 +192,11 @@ "$ref": "#/defs/Owed" } }, - { - "name": "pinned", - "body": { - "$ref": "#/defs/Pins" - } - }, - { - "name": "freed", - "body": { - "$ref": "#/defs/Pins" - } - }, - { - "name": "heads-replaced", - "body": { - "type": "object", - "description": "a candidate's heads replaced or its pull request closed: its graphs mean nothing any more", - "properties": { - "group": { - "type": "string", - "description": "the group" - }, - "heads": { - "type": "string", - "description": "the candidate's heads, 12 hex digits, as its revisions are keyed" - }, - "repository": { - "type": "string", - "description": "the member whose head moved or which closed" - }, - "number": { - "type": "integer", - "description": "its pull request's number" - }, - "head": { - "type": "string", - "description": "its new head; absent when it closed", - "pattern": "^[0-9a-f]{40}$" - }, - "closed": { - "type": "boolean", - "description": "the pull request closed" - }, - "at": { - "type": "string", - "format": "date-time", - "description": "when" - } - }, - "required": [ - "group", - "heads", - "repository", - "number" - ] - } - }, { "name": "record-opened", "body": { "type": "object", - "description": "a delivery record opened: its merge was taken in, and the watchman times it against 24 hours", + "description": "a delivery record opened for one source revision of a merge call (design 47 H \u00a7737)", "properties": { "record": { "type": "string", @@ -298,27 +204,19 @@ }, "milestone": { "type": "string", - "description": "its milestone" - }, - "forge-made": { - "type": "boolean", - "description": "a merge made at the forge, with no Approve" - }, - "repository": { - "type": "string", - "description": "for a forge-made record, the repository, /" - }, - "pull": { - "type": "integer", - "description": "for a forge-made record, the pull request's number" - }, - "commit": { - "type": "string", - "description": "for a forge-made record, the merge commit" + "description": "its milestone, ." }, "branch": { "type": "string", - "description": "for a forge-made record, the branch the merge moved" + "description": "the watched branch" + }, + "source": { + "type": "integer", + "description": "the source revision" + }, + "call": { + "type": "string", + "description": "the merge call" }, "at": { "type": "string", @@ -328,9 +226,13 @@ }, "required": [ "record", - "milestone" + "milestone", + "branch", + "source", + "call" ] - } + }, + "subject": "record-opened." }, { "name": "record-ended", @@ -344,11 +246,19 @@ }, "milestone": { "type": "string", - "description": "its milestone" + "description": "its milestone, ." }, - "forge-made": { - "type": "boolean", - "description": "a merge made at the forge, with no Approve" + "branch": { + "type": "string", + "description": "the watched branch" + }, + "source": { + "type": "integer", + "description": "the source revision" + }, + "call": { + "type": "string", + "description": "the merge call" }, "away": { "type": "array", @@ -379,7 +289,10 @@ }, "required": [ "record", - "milestone" + "milestone", + "branch", + "source", + "call" ] } }, @@ -403,10 +316,10 @@ }, { "name": "source-moved", - "subject": "source-moved.", + "subject": "source-moved..", "body": { "type": "object", - "description": "a new source revision of a watched branch (design 47 *The verbs*)", + "description": "a source revision of a watched branch, named once per merge call (design 47 H \u00a7737)", "properties": { "v": { "type": "integer" @@ -414,22 +327,51 @@ "branch": { "type": "string" }, - "revision": { - "type": "integer" + "source": { + "type": "integer", + "description": "the source revision, numbered by the gate alone" }, - "group": { + "call": { "type": "string", - "description": "the group that moved it, when one did" + "description": "the merge call that moved it" }, - "at": { - "type": "string", - "format": "date-time" + "start": { + "type": "boolean", + "description": "true only for a branch's first revision (design 47 H \u00a7768)" + }, + "heads": { + "type": "array", + "description": "the repositories it moved", + "items": { + "type": "object", + "properties": { + "repository": { + "type": "string" + }, + "commit": { + "type": "string", + "pattern": "^[0-9a-f]{40}$" + } + }, + "required": [ + "repository", + "commit" + ] + } } }, "required": [ + "v", "branch", - "revision" + "source", + "call", + "start", + "heads" ] + }, + "keep": { + "max-age-days": 30, + "max-mib": 64 } }, { @@ -477,65 +419,6 @@ "why" ] } - }, - { - "name": "approval-carried", - "subject": "approval-carried..", - "keep": { - "max-age-days": 90 - }, - "body": { - "type": "object", - "description": "an Approve given before G, carried as that pull request's approval step: said at G's switch for each merges key the old bridge had not performed (design 47 G 542)", - "properties": { - "repository": { - "type": "string", - "description": "the repository" - }, - "pull": { - "type": "integer", - "description": "the pull request's number", - "minimum": 1 - }, - "commit": { - "type": "string", - "description": "the head the Approve named" - }, - "approver": { - "type": "string", - "description": "who approved: the operator" - }, - "at": { - "type": "string", - "description": "when it was said, RFC 3339", - "format": "date-time" - } - }, - "required": [ - "repository", - "pull", - "commit", - "approver", - "at" - ] - } - }, - { - "name": "pins-stated", - "body": { - "type": "object", - "description": "the gate states every pin it holds once its pinned events are said, so an indexer whose state pins was made later hears them all; kept as pinned is, on the seat's family (design 47 G 579, 652)", - "properties": { - "at": { - "type": "string", - "description": "when it was said, RFC 3339", - "format": "date-time" - } - }, - "required": [ - "at" - ] - } } ], "states": [ @@ -552,20 +435,25 @@ "type": "integer", "description": "the layout version" }, - "group": { - "type": "string", - "description": "the group that moved it" - }, "heads": { "type": "object", "additionalProperties": { "type": "string" }, "description": "repository to the merged head, a full commit" + }, + "source": { + "type": "integer", + "description": "the branch's source revision, one above its newest" + }, + "call": { + "type": "string", + "description": "the merge call that moved it; a call the newest revision already carries writes nothing (design 47 H \u00a7737, H-A-33)" } }, "required": [ - "group", + "source", + "call", "heads" ], "description": "every repository's merged head; its revision is the mesh's source revision" @@ -576,140 +464,6 @@ "description": "the mesh's source revision", "history": 64 }, - { - "name": "merges", - "template": "state", - "key-forms": [ - { - "key": "", - "value": { - "type": "object", - "properties": { - "v": { - "type": "integer", - "description": "the layout version" - }, - "group": { - "type": "string" - }, - "ask": { - "type": "string", - "description": "the ask key" - }, - "approved": { - "type": "object", - "additionalProperties": { - "type": "string" - }, - "description": "@ to the approved head" - }, - "pulls": { - "type": "array", - "items": { - "type": "object", - "properties": { - "repository": { - "type": "string" - }, - "number": { - "type": "integer" - }, - "head": { - "type": "string" - }, - "state": { - "type": "string", - "description": "merging, merged or refused" - }, - "commit": { - "type": "string" - }, - "words": { - "type": "string" - } - }, - "required": [ - "repository", - "number", - "head", - "state" - ] - } - } - }, - "required": [ - "group", - "ask", - "pulls" - ], - "description": "one group's merge and how far each pull request is" - }, - "description": "a group's merge" - } - ], - "description": "the merges", - "history": 10 - }, - { - "name": "asks", - "template": "state", - "key-forms": [ - { - "key": "merge..", - "value": { - "type": "object", - "properties": { - "v": { - "type": "integer", - "description": "the layout version" - }, - "group": { - "type": "string" - }, - "heads": { - "type": "array", - "items": { - "type": "object", - "properties": { - "repository": { - "type": "string", - "description": "/" - }, - "number": { - "type": "integer" - }, - "head": { - "type": "string", - "description": "the full commit" - } - }, - "required": [ - "repository", - "number", - "head" - ] - } - }, - "ask": { - "description": "the operator-channel ask as raised" - }, - "asking": { - "type": "integer", - "description": "the number of times it was asked" - } - }, - "required": [ - "group", - "heads", - "ask" - ] - }, - "description": "the ask of the operator for one group at one set of heads" - } - ], - "description": "the asks of the operator for a merge", - "history": 5 - }, { "name": "owed", "template": "state", @@ -755,77 +509,36 @@ "history": 5 }, { - "name": "turns", + "name": "heads", "template": "state", + "history": 1, + "description": "each head the forge bridge's head-moved said that source. does not name for that repository; deleted when source. names it (design 47 H \u00a7740)", "key-forms": [ { - "key": "", + "key": ".", "value": { "type": "object", "properties": { - "v": { - "type": "integer", - "description": "the layout version" + "head": { + "type": "string", + "description": "the head head-moved said", + "pattern": "^[0-9a-f]{40}$" }, - "repository": { - "type": "string" - }, - "waiting": { - "type": "array", - "items": { - "type": "object", - "properties": { - "group": { - "type": "string" - }, - "heads": { - "type": "string" - }, - "ask": { - "type": "string" - }, - "approved": { - "type": "string", - "format": "date-time", - "description": "when (RFC 3339 time)" - }, - "since": { - "type": "string", - "format": "date-time", - "description": "when (RFC 3339 time)" - }, - "waits-for": { - "type": "string" - }, - "waits-since": { - "type": "string", - "format": "date-time", - "description": "when (RFC 3339 time)" - }, - "step": { - "type": "string" - } - }, - "required": [ - "group", - "heads", - "approved", - "since" - ] - } + "since": { + "type": "string", + "format": "date-time", + "description": "when it was first heard" } }, "required": [ - "repository", - "waiting" + "head", + "since" ], - "description": "the merges of a repository in the order they wait for their turn" + "description": "an untaken head" }, - "description": "the merges waiting on a repository" + "description": "one repository on one watched branch" } - ], - "description": "which merge waits for which", - "history": 5 + ] } ], "defs": { @@ -913,122 +626,6 @@ "head" ] }, - "Act": { - "type": "object", - "description": "an act the gate said for a group, with its recorded outcome once the forge bridge said one", - "properties": { - "owed": { - "$ref": "#/defs/Owed" - }, - "outcome": { - "type": "string", - "enum": [ - "performed", - "refused", - "could not be performed", - "undecodable", - "dropped" - ], - "description": "the outcome the forge bridge said as owed.ended and the gate recorded; absent while unanswered" - }, - "words": { - "type": "string", - "description": "the forge's own words for a refusal, the error for an act that could not be performed, why one is undecodable or dropped" - }, - "at": { - "type": "string", - "format": "date-time", - "description": "when the outcome was recorded" - } - }, - "required": [ - "owed" - ] - }, - "Member": { - "type": "object", - "description": "one member of a group: a pull request", - "properties": { - "id": { - "type": "string", - "description": "the member's delivery id" - }, - "repository": { - "type": "string", - "description": "the repository, /" - }, - "number": { - "type": "integer", - "description": "the pull request's number" - }, - "head": { - "type": "string", - "description": "its head", - "pattern": "^[0-9a-f]{40}$" - }, - "base": { - "type": "string", - "description": "the branch it merges into" - }, - "state": { - "type": "string", - "description": "the member's delivery state" - }, - "open": { - "type": "boolean", - "description": "the pull request is open: not merged, closed or final" - } - }, - "required": [ - "id", - "repository", - "number", - "head", - "state" - ] - }, - "Group": { - "type": "object", - "description": "one delivery group: its members, its derived state and the acts the gate said for it", - "properties": { - "id": { - "type": "string", - "description": "the group's id, its branch" - }, - "state": { - "type": "string", - "description": "its state, derived from its members" - }, - "why": { - "type": "string", - "description": "why it is in that state" - }, - "check": { - "type": "string", - "description": "the group's check: its verdict, or asked as " - }, - "members": { - "type": "array", - "items": { - "$ref": "#/defs/Member" - }, - "description": "its members in merge order" - }, - "acts": { - "type": "array", - "items": { - "$ref": "#/defs/Act" - }, - "description": "the acts the gate said for it, each with its id and its recorded outcome; an id said and not answered is the forge bridge's to perform" - } - }, - "required": [ - "id", - "state", - "members", - "acts" - ] - }, "Fill": { "type": "object", "description": "the delivery records' ledger's fill against its cap", @@ -1060,104 +657,6 @@ "cap" ] }, - "Pins": { - "type": "object", - "description": "the graph revisions a delivery record starts or stops pointing at", - "properties": { - "record": { - "type": "string", - "description": "the record's id" - }, - "milestone": { - "type": "string", - "description": "the record's milestone" - }, - "catalog": { - "type": "array", - "items": { - "type": "object", - "description": "one catalog graph revision, named by its watched branch and its number on the seat mesh-catalog (revisions are numbered per branch)", - "properties": { - "branch": { - "type": "string", - "description": "the watched branch the revision belongs to" - }, - "revision": { - "type": "integer", - "description": "its number on that branch" - } - }, - "required": [ - "branch", - "revision" - ] - }, - "description": "catalog graph revisions, by watched branch and number on the seat mesh-catalog" - }, - "assignment": { - "type": "array", - "items": { - "type": "integer" - }, - "description": "assignment graph revisions, by their number on the seat mesh-wants" - }, - "why": { - "type": "string", - "description": "on freed: the record ended past its retention, or was removed by hand" - } - }, - "required": [ - "record", - "milestone" - ] - }, - "Ask": { - "type": "object", - "description": "the one Approve ask of a milestone (ADR 0493 \u00a79), said apart from each delivery's transition", - "properties": { - "milestone": { - "type": "string", - "description": "the milestone" - }, - "ask": { - "type": "string", - "description": "the ask's id" - }, - "group": { - "type": "string", - "description": "its delivery group" - }, - "heads": { - "type": "object", - "additionalProperties": { - "type": "string" - }, - "description": "repository to the head asked" - }, - "answer": { - "type": "string", - "description": "on answered: approve or decline" - }, - "by": { - "type": "string", - "description": "on answered: who answered" - }, - "why": { - "type": "string", - "description": "on withdrawn: why, such as a new head of a member" - }, - "at": { - "type": "string", - "format": "date-time", - "description": "when" - } - }, - "required": [ - "milestone", - "ask", - "group" - ] - }, "SourceHead": { "type": "object", "description": "one repository of the source revision: its trunk branch and that trunk's head", diff --git a/modules/mesh-delivery-contracts/ts/seats/meshdelivery/index.d.ts b/modules/mesh-delivery-contracts/ts/seats/meshdelivery/index.d.ts index 64cf716b..11e963b8 100644 --- a/modules/mesh-delivery-contracts/ts/seats/meshdelivery/index.d.ts +++ b/modules/mesh-delivery-contracts/ts/seats/meshdelivery/index.d.ts @@ -7,7 +7,6 @@ export declare const seat: "mesh-delivery"; export declare const verbs: { readonly deliveries: "deliveries"; readonly show: "show"; - readonly groups: "groups"; readonly source: "source"; readonly stalled: "stalled"; readonly recovery: "recovery"; @@ -15,9 +14,6 @@ export declare const verbs: { export declare const events: { readonly owed: "owed"; - readonly pinned: "pinned"; - readonly freed: "freed"; - readonly headsReplaced: "heads-replaced"; readonly recordOpened: "record-opened"; readonly recordEnded: "record-ended"; readonly filling: "filling"; @@ -25,8 +21,6 @@ export declare const events: { readonly room: "room"; readonly sourceMoved: "source-moved"; readonly recoveryMerged: "recovery-merged"; - readonly approvalCarried: "approval-carried"; - readonly pinsStated: "pins-stated"; }; export declare const family: { readonly name: "mesh-delivery.events"; readonly maxAgeDays: 7 }; @@ -37,13 +31,9 @@ export declare function owedSubject(repository: string, number: string): string; export declare const owedSubjectAll: "mesh.seat.mesh-delivery.event.owed.*.*"; -export declare const pinnedSubject: "mesh.seat.mesh-delivery.event.pinned"; +export declare function recordOpenedSubject(call: string): string; -export declare const freedSubject: "mesh.seat.mesh-delivery.event.freed"; - -export declare const headsReplacedSubject: "mesh.seat.mesh-delivery.event.heads-replaced"; - -export declare const recordOpenedSubject: "mesh.seat.mesh-delivery.event.record-opened"; +export declare const recordOpenedSubjectAll: "mesh.seat.mesh-delivery.event.record-opened.*"; export declare const recordEndedSubject: "mesh.seat.mesh-delivery.event.record-ended"; @@ -53,26 +43,18 @@ export declare const fullSubject: "mesh.seat.mesh-delivery.event.full"; export declare const roomSubject: "mesh.seat.mesh-delivery.event.room"; -export declare function sourceMovedSubject(branch: string): string; +export declare const sourceMovedStream: "SEAT_mesh-delivery_source-moved"; -export declare const sourceMovedSubjectAll: "mesh.seat.mesh-delivery.event.source-moved.*"; +export declare function sourceMovedSubject(branch: string, source: string): string; + +export declare const sourceMovedSubjectAll: "mesh.seat.mesh-delivery.event.source-moved.*.*"; export declare const recoveryMergedSubject: "mesh.seat.mesh-delivery.event.recovery-merged"; -export declare const approvalCarriedStream: "SEAT_mesh-delivery_approval-carried"; - -export declare function approvalCarriedSubject(repository: string, pull: string): string; - -export declare const approvalCarriedSubjectAll: "mesh.seat.mesh-delivery.event.approval-carried.*.*"; - -export declare const pinsStatedSubject: "mesh.seat.mesh-delivery.event.pins-stated"; - export declare const states: { readonly source: "source"; - readonly merges: "merges"; - readonly asks: "asks"; readonly owed: "owed"; - readonly turns: "turns"; + readonly heads: "heads"; }; /** The key of one value of the state source under the form "". */ @@ -81,60 +63,17 @@ export declare function sourceByBranchKey(branch: string): string; /** The parts of a key of the form "", or undefined for a key of another form. */ export declare function parseSourceByBranchKey(_key: string): { branch: string } | undefined; -/** The key of one value of the state merges under the form "". */ -export declare function mergesByGroupKey(group: string): string; - -/** The parts of a key of the form "", or undefined for a key of another form. */ -export declare function parseMergesByGroupKey(_key: string): { group: string } | undefined; - -/** The key of one value of the state asks under the form "merge..". */ -export declare function asksByMergeGroupHeadsKey(group: string, heads: string): string; - -/** The parts of a key of the form "merge..", or undefined for a key of another form. */ -export declare function parseAsksByMergeGroupHeadsKey(_key: string): { group: string; heads: string } | undefined; - /** The key of one value of the state owed under the form "...". */ export declare function owedByRepositoryNumberHeadActKey(repository: string, number: string, head: string, act: string): string; /** The parts of a key of the form "...", or undefined for a key of another form. */ export declare function parseOwedByRepositoryNumberHeadActKey(_key: string): { repository: string; number: string; head: string; act: string } | undefined; -/** The key of one value of the state turns under the form "". */ -export declare function turnsByRepositoryKey(repository: string): string; +/** The key of one value of the state heads under the form ".". */ +export declare function headsByRepositoryBranchKey(repository: string, branch: string): string; -/** The parts of a key of the form "", or undefined for a key of another form. */ -export declare function parseTurnsByRepositoryKey(_key: string): { repository: string } | undefined; - -/** an act the gate said for a group, with its recorded outcome once the forge bridge said one */ -export interface Act { - /** when the outcome was recorded */ - "at"?: string; - /** the outcome the forge bridge said as owed.ended and the gate recorded; absent while unanswered */ - "outcome"?: "performed" | "refused" | "could not be performed" | "undecodable" | "dropped"; - "owed": Owed; - /** the forge's own words for a refusal, the error for an act that could not be performed, why one is undecodable or dropped */ - "words"?: string; -} - -/** the one Approve ask of a milestone (ADR 0493 §9), said apart from each delivery's transition */ -export interface Ask { - /** on answered: approve or decline */ - "answer"?: string; - /** the ask's id */ - "ask": string; - /** when */ - "at"?: string; - /** on answered: who answered */ - "by"?: string; - /** its delivery group */ - "group": string; - /** repository to the head asked */ - "heads"?: Record; - /** the milestone */ - "milestone": string; - /** on withdrawn: why, such as a new head of a member */ - "why"?: string; -} +/** The parts of a key of the form ".", or undefined for a key of another form. */ +export declare function parseHeadsByRepositoryBranchKey(_key: string): { repository: string; branch: string } | undefined; /** the delivery records' ledger's fill against its cap */ export interface Fill { @@ -149,40 +88,6 @@ export interface Fill { "store": string; } -/** one delivery group: its members, its derived state and the acts the gate said for it */ -export interface Group { - /** the acts the gate said for it, each with its id and its recorded outcome; an id said and not answered is the forge bridge's to perform */ - "acts": Act[]; - /** the group's check: its verdict, or asked as */ - "check"?: string; - /** the group's id, its branch */ - "id": string; - /** its members in merge order */ - "members": Member[]; - /** its state, derived from its members */ - "state": string; - /** why it is in that state */ - "why"?: string; -} - -/** one member of a group: a pull request */ -export interface Member { - /** the branch it merges into */ - "base"?: string; - /** its head */ - "head": string; - /** the member's delivery id */ - "id": string; - /** the pull request's number */ - "number": number; - /** the pull request is open: not merged, closed or final */ - "open"?: boolean; - /** the repository, / */ - "repository": string; - /** the member's delivery state */ - "state": string; -} - /** one act the gate owes the forge, said once under its id and safe to repeat at the forge (design 47 *What the gate owes the forge*); the forge bridge performs it through the seat git's verb of the same act */ export interface Owed { /** the act: merge (the seat git's merge-pull), status, view, comment or note */ @@ -217,28 +122,6 @@ export interface Owed { "text"?: string; } -/** one catalog graph revision, named by its watched branch and its number on the seat mesh-catalog (revisions are numbered per branch) */ -export interface PinsCatalogItem { - /** the watched branch the revision belongs to */ - "branch": string; - /** its number on that branch */ - "revision": number; -} - -/** the graph revisions a delivery record starts or stops pointing at */ -export interface Pins { - /** assignment graph revisions, by their number on the seat mesh-wants */ - "assignment"?: number[]; - /** catalog graph revisions, by watched branch and number on the seat mesh-catalog */ - "catalog"?: PinsCatalogItem[]; - /** the record's milestone */ - "milestone": string; - /** the record's id */ - "record": string; - /** on freed: the record ended past its retention, or was removed by hand */ - "why"?: string; -} - /** one repository of the source revision: its trunk branch and that trunk's head */ export interface SourceHead { /** the trunk's head the source revision names */ @@ -273,21 +156,6 @@ export interface ShowInput { /** is what show answers. */ export type ShowAnswer = Record; -/** is what groups takes. */ -export interface GroupsInput { - /** "true": the groups that ended too */ - "all"?: "true" | "false"; - /** one group's id: that group alone, ended or not */ - "group"?: string; -} - -/** is what groups answers. */ -export interface GroupsAnswer { - /** why it could not answer at all; a group it does not know is answered with no groups, never an error */ - "error"?: string; - "groups"?: Group[]; -} - /** is what source takes. */ export interface SourceInput { /** the watched branch, escaped as a key name is; absent: the answer is the list of the branches the gate keeps a source revision of (design 47 G section 690) */ @@ -300,10 +168,10 @@ export interface SourceAnswer { "branch"?: string; /** given no branch: the branch name of each source. key the gate keeps, which every reader of the catalog half follows before the first registrations (design 47 G section 614, section 690) */ "branches"?: string[]; + /** the merge call that moved the source revision last; absent before the first */ + "call"?: string; /** why it could not be read */ "error"?: string; - /** the group that moved the source revision last; absent before the first */ - "group"?: string; /** every repository the source revision names, by name */ "repositories"?: SourceHead[]; /** the source revision's number on the bus; 0 before the first */ @@ -341,48 +209,20 @@ export interface RecoveryAnswer { /** is the body of the event owed. */ export type OwedEvent = Owed; -/** is the body of the event pinned. */ -export type PinnedEvent = Pins; - -/** is the body of the event freed. */ -export type FreedEvent = Pins; - -/** is the body of the event heads-replaced. */ -export interface HeadsReplacedEvent { - /** when */ - "at"?: string; - /** the pull request closed */ - "closed"?: boolean; - /** the group */ - "group": string; - /** its new head; absent when it closed */ - "head"?: string; - /** the candidate's heads, 12 hex digits, as its revisions are keyed */ - "heads": string; - /** its pull request's number */ - "number": number; - /** the member whose head moved or which closed */ - "repository": string; -} - /** is the body of the event record-opened. */ export interface RecordOpenedEvent { /** when */ "at"?: string; - /** for a forge-made record, the branch the merge moved */ - "branch"?: string; - /** for a forge-made record, the merge commit */ - "commit"?: string; - /** a merge made at the forge, with no Approve */ - "forge-made"?: boolean; - /** its milestone */ + /** the watched branch */ + "branch": string; + /** the merge call */ + "call": string; + /** its milestone, . */ "milestone": string; - /** for a forge-made record, the pull request's number */ - "pull"?: number; /** the record's id */ "record": string; - /** for a forge-made record, the repository, / */ - "repository"?: string; + /** the source revision */ + "source": number; } export interface RecordEndedEventAwayItem { @@ -398,12 +238,16 @@ export interface RecordEndedEvent { "at"?: string; /** the nodes away, each with since when; it ends without them */ "away"?: RecordEndedEventAwayItem[]; - /** a merge made at the forge, with no Approve */ - "forge-made"?: boolean; - /** its milestone */ + /** the watched branch */ + "branch": string; + /** the merge call */ + "call": string; + /** its milestone, . */ "milestone": string; /** the record's id */ "record": string; + /** the source revision */ + "source": number; } /** is the body of the event filling. */ @@ -415,14 +259,23 @@ export type FullEvent = Fill; /** is the body of the event room. */ export type RoomEvent = Fill; +export interface SourceMovedEventHeadsItem { + "commit": string; + "repository": string; +} + /** is the body of the event source-moved. */ export interface SourceMovedEvent { - "at"?: string; "branch": string; - /** the group that moved it, when one did */ - "group"?: string; - "revision": number; - "v"?: number; + /** the merge call that moved it */ + "call": string; + /** the repositories it moved */ + "heads": SourceMovedEventHeadsItem[]; + /** the source revision, numbered by the gate alone */ + "source": number; + /** true only for a branch's first revision (design 47 H §768) */ + "start": boolean; + "v": number; } /** is the body of the event recovery-merged. */ @@ -443,74 +296,14 @@ export interface RecoveryMergedEvent { "why": string; } -/** is the body of the event approval-carried. */ -export interface ApprovalCarriedEvent { - /** who approved: the operator */ - "approver": string; - /** when it was said, RFC 3339 */ - "at": string; - /** the head the Approve named */ - "commit": string; - /** the pull request's number */ - "pull": number; - /** the repository */ - "repository": string; -} - -/** is the body of the event pins-stated. */ -export interface PinsStatedEvent { - /** when it was said, RFC 3339 */ - "at": string; -} - /** is one value of the state source under the key . */ export interface SourceByBranchValue { - /** the group that moved it */ - "group": string; + /** the merge call that moved it; a call the newest revision already carries writes nothing (design 47 H §737, H-A-33) */ + "call": string; /** repository to the merged head, a full commit */ "heads": Record; - /** the layout version */ - "v"?: number; -} - -export interface MergesByGroupValuePullsItem { - "commit"?: string; - "head": string; - "number": number; - "repository": string; - /** merging, merged or refused */ - "state": string; - "words"?: string; -} - -/** is one value of the state merges under the key . */ -export interface MergesByGroupValue { - /** @ to the approved head */ - "approved"?: Record; - /** the ask key */ - "ask": string; - "group": string; - "pulls": MergesByGroupValuePullsItem[]; - /** the layout version */ - "v"?: number; -} - -export interface AsksByMergeGroupHeadsValueHeadsItem { - /** the full commit */ - "head": string; - "number": number; - /** / */ - "repository": string; -} - -/** is one value of the state asks under the key merge... */ -export interface AsksByMergeGroupHeadsValue { - /** the operator-channel ask as raised */ - "ask": unknown; - /** the number of times it was asked */ - "asking"?: number; - "group": string; - "heads": AsksByMergeGroupHeadsValueHeadsItem[]; + /** the branch's source revision, one above its newest */ + "source": number; /** the layout version */ "v"?: number; } @@ -528,25 +321,11 @@ export interface OwedByRepositoryNumberHeadActValue { "v"?: number; } -export interface TurnsByRepositoryValueWaitingItem { - /** when (RFC 3339 time) */ - "approved": string; - "ask"?: string; - "group": string; - "heads": string; - /** when (RFC 3339 time) */ +/** is one value of the state heads under the key .. */ +export interface HeadsByRepositoryBranchValue { + /** the head head-moved said */ + "head": string; + /** when it was first heard */ "since": string; - "step"?: string; - "waits-for"?: string; - /** when (RFC 3339 time) */ - "waits-since"?: string; -} - -/** is one value of the state turns under the key . */ -export interface TurnsByRepositoryValue { - "repository": string; - /** the layout version */ - "v"?: number; - "waiting": TurnsByRepositoryValueWaitingItem[]; } diff --git a/modules/mesh-delivery-contracts/ts/seats/meshdelivery/index.js b/modules/mesh-delivery-contracts/ts/seats/meshdelivery/index.js index 5416d647..d8e6bfe0 100644 --- a/modules/mesh-delivery-contracts/ts/seats/meshdelivery/index.js +++ b/modules/mesh-delivery-contracts/ts/seats/meshdelivery/index.js @@ -7,7 +7,6 @@ export const seat = "mesh-delivery"; export const verbs = { deliveries: "deliveries", show: "show", - groups: "groups", source: "source", stalled: "stalled", recovery: "recovery", @@ -15,9 +14,6 @@ export const verbs = { export const events = { owed: "owed", - pinned: "pinned", - freed: "freed", - headsReplaced: "heads-replaced", recordOpened: "record-opened", recordEnded: "record-ended", filling: "filling", @@ -25,8 +21,6 @@ export const events = { room: "room", sourceMoved: "source-moved", recoveryMerged: "recovery-merged", - approvalCarried: "approval-carried", - pinsStated: "pins-stated", }; export const family = { name: "mesh-delivery.events", maxAgeDays: 7 }; @@ -39,13 +33,11 @@ export function owedSubject(repository, number) { export const owedSubjectAll = "mesh.seat.mesh-delivery.event.owed.*.*"; -export const pinnedSubject = "mesh.seat.mesh-delivery.event.pinned"; +export function recordOpenedSubject(call) { + return "mesh.seat.mesh-delivery.event.record-opened." + call; +} -export const freedSubject = "mesh.seat.mesh-delivery.event.freed"; - -export const headsReplacedSubject = "mesh.seat.mesh-delivery.event.heads-replaced"; - -export const recordOpenedSubject = "mesh.seat.mesh-delivery.event.record-opened"; +export const recordOpenedSubjectAll = "mesh.seat.mesh-delivery.event.record-opened.*"; export const recordEndedSubject = "mesh.seat.mesh-delivery.event.record-ended"; @@ -55,30 +47,20 @@ export const fullSubject = "mesh.seat.mesh-delivery.event.full"; export const roomSubject = "mesh.seat.mesh-delivery.event.room"; -export function sourceMovedSubject(branch) { - return "mesh.seat.mesh-delivery.event.source-moved." + branch; +export const sourceMovedStream = "SEAT_mesh-delivery_source-moved"; + +export function sourceMovedSubject(branch, source) { + return "mesh.seat.mesh-delivery.event.source-moved." + branch + "." + source; } -export const sourceMovedSubjectAll = "mesh.seat.mesh-delivery.event.source-moved.*"; +export const sourceMovedSubjectAll = "mesh.seat.mesh-delivery.event.source-moved.*.*"; export const recoveryMergedSubject = "mesh.seat.mesh-delivery.event.recovery-merged"; -export const approvalCarriedStream = "SEAT_mesh-delivery_approval-carried"; - -export function approvalCarriedSubject(repository, pull) { - return "mesh.seat.mesh-delivery.event.approval-carried." + repository + "." + pull; -} - -export const approvalCarriedSubjectAll = "mesh.seat.mesh-delivery.event.approval-carried.*.*"; - -export const pinsStatedSubject = "mesh.seat.mesh-delivery.event.pins-stated"; - export const states = { source: "source", - merges: "merges", - asks: "asks", owed: "owed", - turns: "turns", + heads: "heads", }; /** The key of one value of the state source under the form "". */ @@ -96,42 +78,6 @@ export function parseSourceByBranchKey(_key) { return { branch }; } -/** The key of one value of the state merges under the form "". */ -export function mergesByGroupKey(group) { - return group; -} - -/** The parts of a key of the form "", or undefined for a key of another form. */ -export function parseMergesByGroupKey(_key) { - let _rest = _key; - if (_rest === "") return undefined; - const group = _rest; - _rest = ""; - if (_rest !== "") return undefined; - return { group }; -} - -/** The key of one value of the state asks under the form "merge..". */ -export function asksByMergeGroupHeadsKey(group, heads) { - return "merge." + group + "." + heads; -} - -/** The parts of a key of the form "merge..", or undefined for a key of another form. */ -export function parseAsksByMergeGroupHeadsKey(_key) { - let _rest = _key; - if (!_rest.startsWith("merge.")) return undefined; - _rest = _rest.slice(6); - const _at1 = _rest.indexOf("."); - if (_at1 <= 0) return undefined; - const group = _rest.slice(0, _at1); - _rest = _rest.slice(_at1 + 1); - if (_rest === "") return undefined; - const heads = _rest; - _rest = ""; - if (_rest !== "") return undefined; - return { group, heads }; -} - /** The key of one value of the state owed under the form "...". */ export function owedByRepositoryNumberHeadActKey(repository, number, head, act) { return repository + "." + number + "." + head + "." + act; @@ -159,18 +105,22 @@ export function parseOwedByRepositoryNumberHeadActKey(_key) { return { repository, number, head, act }; } -/** The key of one value of the state turns under the form "". */ -export function turnsByRepositoryKey(repository) { - return repository; +/** The key of one value of the state heads under the form ".". */ +export function headsByRepositoryBranchKey(repository, branch) { + return repository + "." + branch; } -/** The parts of a key of the form "", or undefined for a key of another form. */ -export function parseTurnsByRepositoryKey(_key) { +/** The parts of a key of the form ".", or undefined for a key of another form. */ +export function parseHeadsByRepositoryBranchKey(_key) { let _rest = _key; + const _at0 = _rest.indexOf("."); + if (_at0 <= 0) return undefined; + const repository = _rest.slice(0, _at0); + _rest = _rest.slice(_at0 + 1); if (_rest === "") return undefined; - const repository = _rest; + const branch = _rest; _rest = ""; if (_rest !== "") return undefined; - return { repository }; + return { repository, branch }; }