mesh-delivery-forge-bridge: read the open groups, and one group by its id, never every ended group in one answer
The merged message and the catch-up asked the seat's groups with all=true, whose answer outgrew one bus message (2888983 bytes, live 02:06), so no take-in answered. Read asks the open groups, MergedOf the one group its branch names (group=<id>); the list a person asks (bridge_groups) keeps ReadAll. Builds: lead: principle 7, live 02:06 Claude-Session: https://claude.ai/code/session_01NcbgfGKaxw984XyAPfLm4h
This commit is contained in:
@@ -123,7 +123,7 @@ func Tools(ask asker, now func() time.Time, groupsRead func() ([]groups.Row, []s
|
||||
// number, branch and head through the seat git's verb pull (by number when given, else by the merge commit; a merge made
|
||||
// on the forge is read the same way), the rest from the forge through trees and files (bridge.MergedMessage), and, for a
|
||||
// member of a delivery group the seat mesh-delivery names (of), the group and its members as the process sets them.
|
||||
func MergedOf(of []seat.Group, repository, merge string, number int, trees bridge.Trees, files bridge.Files, forge bridge.Caller) (json.RawMessage, error) {
|
||||
func MergedOf(groupOf func(id string) ([]seat.Group, error), repository, merge string, number int, trees bridge.Trees, files bridge.Files, forge bridge.Caller) (json.RawMessage, error) {
|
||||
owner, repo, ok := strings.Cut(repository, "/")
|
||||
if !ok || owner == "" || repo == "" {
|
||||
return nil, fmt.Errorf("%q is not owner/name", repository)
|
||||
@@ -140,6 +140,10 @@ func MergedOf(of []seat.Group, repository, merge string, number int, trees bridg
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
of, err := groupOf(f.Branch) // the one group the pull request's branch names, never the whole list
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if g, ok := groups.Named(of, f.Branch, f.Repository, f.Number); ok {
|
||||
f.Group, f.Members = g.ID, groups.MembersOf(g)
|
||||
}
|
||||
@@ -251,7 +255,7 @@ func main() {
|
||||
performed, asks := stdio.State(groups.PerformedState), stdio.State(groups.EndAsksState)
|
||||
tools := Tools(askEnd(asks, served, 25*time.Second), time.Now,
|
||||
func() ([]groups.Row, []string, error) {
|
||||
of, err := groups.Read(context.Background(), askCaller)
|
||||
of, err := groups.ReadAll(context.Background(), askCaller)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
@@ -259,11 +263,7 @@ func main() {
|
||||
},
|
||||
func(repository, merge string, number int) (json.RawMessage, error) {
|
||||
ctx := context.Background()
|
||||
of, err := groups.Read(ctx, askCaller)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return MergedOf(of, repository, merge, number, bridge.TreesVia(ctx, askCaller), bridge.FilesVia(ctx, askCaller), askCaller)
|
||||
return MergedOf(func(id string) ([]seat.Group, error) { return groups.ReadGroup(ctx, askCaller, id) }, repository, merge, number, bridge.TreesVia(ctx, askCaller), bridge.FilesVia(ctx, askCaller), askCaller)
|
||||
}, askCaller)
|
||||
owedAsks := stdio.State(groups.OwedAsksState)
|
||||
recorder := meshhandactsclient.Recorder{Ask: stdio.Ask}
|
||||
|
||||
+2
-2
@@ -199,7 +199,7 @@ func TestTheBridgeToolsReadTheGroupsAndAskTheEndAgain(t *testing.T) {
|
||||
}, fail: "the forge is down"},
|
||||
} {
|
||||
t.Run(c.name, func(t *testing.T) {
|
||||
raw, err := MergedOf(c.of, c.repository, c.merge, c.number, trees, files, c.api)
|
||||
raw, err := MergedOf(func(string) ([]seat.Group, error) { return c.of, nil }, c.repository, c.merge, c.number, trees, files, c.api)
|
||||
if c.fail != "" {
|
||||
if err == nil || !strings.Contains(err.Error(), c.fail) {
|
||||
t.Fatalf("err %v, want %q", err, c.fail)
|
||||
@@ -212,7 +212,7 @@ func TestTheBridgeToolsReadTheGroupsAndAskTheEndAgain(t *testing.T) {
|
||||
}
|
||||
})
|
||||
}
|
||||
if _, err := MergedOf(nil, "novox/a", c2, 9, func(string, string, string) (string, map[string]string, error) {
|
||||
if _, err := MergedOf(func(string) ([]seat.Group, error) { return nil, nil }, "novox/a", c2, 9, func(string, string, string) (string, map[string]string, error) {
|
||||
return "", nil, errors.New("the forge does not answer")
|
||||
}, files, forgeAnswers(t, 9, "", "merged", "fix/x", h2, c2, "main")); err == nil || !strings.Contains(err.Error(), "does not answer") {
|
||||
t.Errorf("a forge that does not answer: %v", err)
|
||||
|
||||
@@ -255,12 +255,28 @@ func Named(of []seat.Group, id, repository string, number int) (seat.Group, bool
|
||||
return seat.Group{}, false
|
||||
}
|
||||
|
||||
// Read is every delivery group the seat mesh-delivery's verb groups answers, the ended ones too (all), called through call
|
||||
// by the verb's manifest key: the bridge reads a group from the seat, never from the gate's state (design 47 *A group's
|
||||
// merges are taken in together*). An answer saying an error, or one the contract cannot type, is an error: a failed read
|
||||
// is never read as no group.
|
||||
// Read is the open delivery groups the seat mesh-delivery's verb groups answers by default, called through call by the
|
||||
// verb's manifest key: the bridge reads a group from the seat, never from the gate's state (design 47 *A group's merges are
|
||||
// taken in together*). The ended ones are never asked whole: their list outgrows one bus message (lead: principle 7, live
|
||||
// 02:06); one is read by its id with ReadGroup. An answer saying an error, or one the contract cannot type, is an error: a
|
||||
// failed read is never read as no group.
|
||||
func Read(ctx context.Context, call func(ctx context.Context, key string, body any) (json.RawMessage, error)) ([]seat.Group, error) {
|
||||
raw, err := call(ctx, "seat:"+seat.Seat+"."+seat.VerbGroups, seat.GroupsInput{All: seat.GroupsInputAllTrue})
|
||||
return ask(ctx, call, seat.GroupsInput{})
|
||||
}
|
||||
|
||||
// ReadAll is every delivery group, the ended ones too (all). Its answer grows with every group that ended, so only a
|
||||
// tool a person asks reads it, never the take-in or the catch-up.
|
||||
func ReadAll(ctx context.Context, call func(ctx context.Context, key string, body any) (json.RawMessage, error)) ([]seat.Group, error) {
|
||||
return ask(ctx, call, seat.GroupsInput{All: seat.GroupsInputAllTrue})
|
||||
}
|
||||
|
||||
// ReadGroup is the one group id names, ended or not, as the verb answers with its group: none for a group it does not know.
|
||||
func ReadGroup(ctx context.Context, call func(ctx context.Context, key string, body any) (json.RawMessage, error), id string) ([]seat.Group, error) {
|
||||
return ask(ctx, call, seat.GroupsInput{Group: id})
|
||||
}
|
||||
|
||||
func ask(ctx context.Context, call func(ctx context.Context, key string, body any) (json.RawMessage, error), in seat.GroupsInput) ([]seat.Group, error) {
|
||||
raw, err := call(ctx, "seat:"+seat.Seat+"."+seat.VerbGroups, in)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("the seat %s did not answer %s: %w", seat.Seat, seat.VerbGroups, err)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
package groups
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
seat "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshdelivery"
|
||||
)
|
||||
|
||||
// The seat answers the whole list of groups with more than one bus message carries once many have ended (live 02:06);
|
||||
// a read of the open ones, or of one by its id, is answered; Read never asks for all (lead: principle 7).
|
||||
func TestReadsNeverAskTheEndedGroupsWhole(t *testing.T) {
|
||||
const bus = 1 << 20
|
||||
seatOf := func(_ context.Context, _ string, body any) (json.RawMessage, error) {
|
||||
in := body.(seat.GroupsInput)
|
||||
groups := []seat.Group{{ID: "feat/open", State: "gathering"}}
|
||||
switch {
|
||||
case in.Group != "":
|
||||
groups = []seat.Group{{ID: in.Group}}
|
||||
case in.All == seat.GroupsInputAllTrue:
|
||||
for i := 0; i < 3000; i++ {
|
||||
groups = append(groups, seat.Group{ID: "ended", Why: strings.Repeat("x", 500)})
|
||||
}
|
||||
}
|
||||
raw, _ := json.Marshal(seat.GroupsAnswer{Groups: groups})
|
||||
if len(raw) > bus {
|
||||
return nil, errors.New("the answer is more than the bus carries in one message")
|
||||
}
|
||||
return raw, nil
|
||||
}
|
||||
if got, err := Read(context.Background(), seatOf); err != nil || len(got) != 1 || got[0].ID != "feat/open" {
|
||||
t.Errorf("Read: %v %v; want the open group alone", got, err)
|
||||
}
|
||||
if got, err := ReadGroup(context.Background(), seatOf, "feat/ended"); err != nil || len(got) != 1 || got[0].ID != "feat/ended" {
|
||||
t.Errorf("ReadGroup: %v %v; want the group by its id", got, err)
|
||||
}
|
||||
if _, err := ReadAll(context.Background(), seatOf); err == nil {
|
||||
t.Errorf("ReadAll: want the seat's refusal to be an error, never read as no group")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user