Revert the revert of G's mesh-sdk merge (#191): G's sdk stands again over reader release 3

Main reverted G's half merge (#189, reverted by 8afc3eb in #191) and then took the reader release's S1-S5, which
copied G's code. G's form holds where they differ (process_bus.go, seats.go, state.go and their tests); the
release's kept names stay so main's callers keep building: SeatViewPrefix beside SeatReadPrefix, and QueueInvoke's
empty strings on not-ok (with its test TestQueueInvoke). The tree differs from G's head f30dee54 only by those and
the release's two tests (objects cap option, seat states and stream kinds).

Builds: design 47 G (the milestone's sdk part, as at f30dee54)

Claude-Session: https://claude.ai/code/session_01NcbgfGKaxw984XyAPfLm4h
This commit is contained in:
2026-11-13 12:49:56 +01:00
parent 93e0a7b50d
commit 5fa64be894
211 changed files with 32027 additions and 2484 deletions
@@ -0,0 +1,98 @@
//go:build integration
package stateobjects
import (
"bytes"
"context"
"strings"
"testing"
"time"
"github.com/nats-io/nats.go"
"github.com/nats-io/nats.go/jetstream"
"git.novox.be/novox/mesh-sdk/go/testbus"
"git.novox.be/novox/mesh-sdk/go/views"
)
// ADR 0666 §16, §25 against the real bus: a process's values of 1x, 10x and 100x the limit, replaced and deleted, and a
// body over the per-message limit sent and received, each read back whole.
func TestStateObjectsWholeAgainstTheBus(t *testing.T) {
nc, err := nats.Connect(testbus.URL(t))
if err != nil {
t.Fatal(err)
}
defer nc.Close()
js, err := jetstream.New(nc)
if err != nil {
t.Fatal(err)
}
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
defer cancel()
kv, err := js.CreateKeyValue(ctx, jetstream.KeyValueConfig{Bucket: "m_views", MaxValueSize: 256 * 1024, Storage: jetstream.MemoryStorage})
if err != nil {
t.Fatal(err)
}
store, err := js.CreateObjectStore(ctx, jetstream.ObjectStoreConfig{Bucket: "m_views-objects", Storage: jetstream.MemoryStorage})
if err != nil {
t.Fatal(err)
}
sent, err := js.CreateObjectStore(ctx, jetstream.ObjectStoreConfig{Bucket: "m_sent-objects", Storage: jetstream.MemoryStorage, TTL: 7 * 24 * time.Hour})
if err != nil {
t.Fatal(err)
}
t.Run("a reply and an event over the message limit", func(t *testing.T) {
s := Sender{Objects: BusObjects{Store: sent}, Store: "m_sent-objects", Limit: int(nc.MaxPayload())}
for _, label := range []string{"reply.list", "event.done"} {
body := []byte(`{"text":"` + strings.Repeat("y", 3<<20) + `"}`)
wire, err := s.Send(label, body)
if err != nil || len(wire) > int(nc.MaxPayload()) {
t.Fatalf("%s: sent %d bytes, %v", label, len(wire), err)
}
got, err := Receive(wire, ProcessFetch(BusObjects{Store: sent}))
if err != nil || !bytes.Equal(got, body) {
t.Fatalf("%s: received %d bytes, %v", label, len(got), err)
}
}
})
// G §477: a send past a fixture's cap fails its reply or event, naming the store.
t.Run("a send past the sent store's cap names the store", func(t *testing.T) {
small, err := js.CreateObjectStore(ctx, jetstream.ObjectStoreConfig{Bucket: "n_sent-objects", Storage: jetstream.MemoryStorage, MaxBytes: 1 << 20})
if err != nil {
t.Fatal(err)
}
s := Sender{Objects: BusObjects{Store: small}, Store: "n_sent-objects", Limit: int(nc.MaxPayload())}
if _, err := s.Send("reply.list", []byte(`{"text":"`+strings.Repeat("y", 2<<20)+`"}`)); err == nil || !strings.Contains(err.Error(), "n_sent-objects") {
t.Fatalf("a send past the cap: %v, want it refused naming n_sent-objects", err)
}
})
t.Run("values of 1x, 10x and 100x the limit", func(t *testing.T) { valueRows(t, OverBus(kv, store, "m_views-objects"), 1, 10, 100) })
t.Run("the tools read and drop what a deleted key left", func(t *testing.T) {
v := OverBus(kv, store, "m_views-objects")
if err := v.Put("tool-key", big(2*256*1024)); err != nil {
t.Fatal(err)
}
if err := v.Delete("tool-key"); err != nil {
t.Fatal(err)
}
tools := Tools("m", []State{{Name: "views", Values: v}}, nil, handActs{}, time.Now)
read, err := tools[0].Run(map[string]any{})
if err != nil || read.(map[string]any)["key-gone"].(int) < 1 {
t.Fatalf("the reading tool: %v, %v", read, err)
}
if _, err := tools[1].Run(map[string]any{"by": "a@b", "why": "test"}); err != nil {
t.Fatal(err)
}
kept, _ := v.Kept()
for _, k := range kept {
if k.KeyGone {
t.Fatalf("%s is still key-gone after the drop", k.Name)
}
}
})
}
type handActs struct{}
func (handActs) RecordHandAct(views.HandAct) error { return nil }