package grants import ( "slices" "testing" "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 } // 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). func TestEachSeatThatAcceptsWorkHasItsAskStream(t *testing.T) { defs := map[string]seatdef.Definition{ "mesh-builds": {Seat: "mesh-builds", Accepts: []seatdef.Message{{Name: "step"}}}, "mesh-wants": {Seat: "mesh-wants", Accepts: []seatdef.Message{{Name: "step"}}}, "git": {Seat: "git"}, } asks := 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 == 0 { t.Fatalf("ask streams = %+v", asks) } 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) } }