Files
mesh-delivery/modules/mesh-grants/internal/grants/askstreams_test.go
T
jschoubben a559b0e7c9 D1b: the two seats' work queues carry their settings, derived once in mesh-sdk
mesh-builds' and mesh-wants' accepted kind step names max-age 24h, max-msgs
10,000, ack-wait 60s, in-progress 20s, max-ack-pending 1,000, max-deliveries 5
and a duplicates window of 2m; the grants part makes each seat's ask stream
through mesh-sdk's buscompose.SeatQueue and says a seat whose settings it
refuses, and its own copy of the derivation goes.

Builds: design 47 H2 §777; H-A-350 DMC-1, H-A-362
2026-11-21 23:23:04 +01:00

57 lines
2.5 KiB
Go

package grants
import (
"slices"
"strings"
"testing"
"time"
"github.com/nats-io/nats.go/jetstream"
"git.novox.be/novox/mesh-sdk/go/seatdef"
"mesh-grants/internal/buscompose"
)
type askCreator struct{ made []string }
func (c *askCreator) CreateDeclared(cfg jetstream.StreamConfig) error {
c.made = append(c.made, cfg.Name+" "+cfg.Subjects[0])
return nil
}
func (c *askCreator) AddSubjects(string, []string) error { return nil }
func (c *askCreator) RaiseMaxBytes(string, int64) (int64, bool, error) {
return 0, false, nil
}
func (c *askCreator) SourceFilter(string, string, string) (string, bool, error) {
return "", false, nil
}
// A seat whose queues came with G (mesh-builds) gets its work-queue ask stream from the seat list, as the controller made one for
// every seat before G; a seat that accepts nothing gets none, and a stream the bus holds is never made again (lead-47, 2026-11-15).
// The stream carries the settings the seat's accepted kinds name, derived by mesh-sdk's SeatQueue, and a seat whose settings it
// refuses is said (design 47 H2 §777; H-A-362).
func TestEachSeatThatAcceptsWorkHasItsAskStream(t *testing.T) {
defs := map[string]seatdef.Definition{
"mesh-builds": {Seat: "mesh-builds", Accepts: []seatdef.Message{{Name: "step", MaxAge: "24h", MaxMsgs: 10000, DuplicatesWindow: "2m"}}},
"mesh-wants": {Seat: "mesh-wants", Accepts: []seatdef.Message{{Name: "step"}}},
"git": {Seat: "git"},
"two-ways": {Seat: "two-ways", Accepts: []seatdef.Message{{Name: "a", MaxAge: "1h"}, {Name: "b", MaxAge: "2h"}}},
}
asks, refused := buscompose.AskStreamsOf(defs)
if len(asks) != 2 || asks[0].Name != "SEAT_MESH_BUILDS" || asks[0].Retention != jetstream.WorkQueuePolicy ||
!slices.Equal(asks[0].Subjects, []string{"mesh.seat.mesh-builds.accept.>"}) || asks[0].MaxAge != 24*time.Hour ||
asks[0].MaxMsgs != 10000 || asks[0].Duplicates != 2*time.Minute || asks[1].MaxAge != 7*24*time.Hour {
t.Fatalf("ask streams = %+v", asks)
}
if len(refused) != 1 || !strings.Contains(refused[0], "two-ways") {
t.Errorf("refused = %v, want the seat whose two kinds name two max-ages", refused)
}
c := &askCreator{}
made, notMade := createAskStreams(c, &creations{}, asks, map[string]Limits{"SEAT_MESH_WANTS": {}}, false)
if !slices.Equal(made, []string{"SEAT_MESH_BUILDS"}) || len(notMade) != 0 ||
!slices.Equal(c.made, []string{"SEAT_MESH_BUILDS mesh.seat.mesh-builds.accept.>"}) {
t.Errorf("made %v (not %v), created %v: want only the builds seat's, the wants seat's being held", made, notMade, c.made)
}
}