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 by8afc3ebin #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 headf30dee54only 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 atf30dee54) Claude-Session: https://claude.ai/code/session_01NcbgfGKaxw984XyAPfLm4h
This commit is contained in:
@@ -153,6 +153,18 @@ func TestABundleSubscribesAndAsksThroughTheRuntime(t *testing.T) {
|
||||
if !TopicMatches("a.#", "a.b.c") || TopicMatches("a.*", "a.b.c") || !TopicMatches("#", "x") {
|
||||
t.Error("topic matching differs from the TypeScript SDK's")
|
||||
}
|
||||
// Design 47 G A-101: the bus's `>` is one or more tokens at the end, and only there.
|
||||
for pattern, want := range map[string]map[string]bool{
|
||||
"s.rev.>": {"s.rev.a": true, "s.rev.a.b": true, "s.rev": false, "s.other.a": false},
|
||||
"s.>.x": {"s.a.x": false},
|
||||
">": {"a": true, "a.b": true},
|
||||
} {
|
||||
for key, ok := range want {
|
||||
if TopicMatches(pattern, key) != ok {
|
||||
t.Errorf("TopicMatches(%q, %q) = %v, want %v", pattern, key, !ok, ok)
|
||||
}
|
||||
}
|
||||
}
|
||||
// Issue 774 notes 84-87: a malformed key is refused before the runtime is asked.
|
||||
for _, key := range []string{"seat:node-service-manager.stop@novox@g14", "seat:a.*", "postgres.list@", "postgres.list@a.b"} {
|
||||
if _, err := Ask(key, nil); err == nil || strings.Contains(err.Error(), "Serve") {
|
||||
@@ -343,3 +355,61 @@ func servesAlone(t *testing.T) {
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// Design 47 G §559: a bundle's acknowledged publish asks `ack: true` and fails on the runtime's `{error}`; its
|
||||
// subscription for new messages asks `deliver: new`.
|
||||
func subABundleAsksAnAcknowledgedPublishAndASubscriptionForNewMessages(t *testing.T) {
|
||||
servesAlone(t)
|
||||
t.Setenv(ServedAs, "keeper")
|
||||
inR, inW := io.Pipe()
|
||||
outR, outW := io.Pipe()
|
||||
errs := make(chan error, 2)
|
||||
go func() {
|
||||
_ = ServeOn("", []Tool{{Name: "go", Run: func(map[string]any) (any, error) {
|
||||
go func() { errs <- SubscribeNew("mesh-conditions.findings-asked", func(Envelope) error { return nil }) }()
|
||||
errs <- Emit("finding-written", map[string]any{}, EmitOptions{Ack: true})
|
||||
return map[string]any{}, nil
|
||||
}}}, inR, outW)
|
||||
}()
|
||||
lines := bufio.NewScanner(outR)
|
||||
next := func() map[string]any {
|
||||
done := make(chan map[string]any, 1)
|
||||
go func() {
|
||||
if lines.Scan() {
|
||||
var m map[string]any
|
||||
_ = json.Unmarshal(lines.Bytes(), &m)
|
||||
done <- m
|
||||
}
|
||||
}()
|
||||
select {
|
||||
case m := <-done:
|
||||
return m
|
||||
case <-time.After(3 * time.Second):
|
||||
t.Fatal("the bundle said nothing")
|
||||
return nil
|
||||
}
|
||||
}
|
||||
send := func(m map[string]any) { b, _ := json.Marshal(m); _, _ = inW.Write(append(b, '\n')) }
|
||||
send(map[string]any{"jsonrpc": "2.0", "id": 1, "method": "tools/call", "params": map[string]any{"name": "go"}})
|
||||
asked := map[string]map[string]any{}
|
||||
for len(asked) < 2 {
|
||||
m := next()
|
||||
asked[m["method"].(string)] = m
|
||||
}
|
||||
sub, pub := asked["mesh/subscribe"]["params"].(map[string]any), asked["mesh/publish"]["params"].(map[string]any)
|
||||
if sub["deliver"] != "new" || pub["ack"] != true {
|
||||
t.Fatalf("asked subscribe %v, publish %v", sub, pub)
|
||||
}
|
||||
send(map[string]any{"jsonrpc": "2.0", "id": asked["mesh/subscribe"]["id"], "result": map[string]any{}})
|
||||
send(map[string]any{"jsonrpc": "2.0", "id": asked["mesh/publish"]["id"], "result": map[string]any{"error": "no stream"}})
|
||||
var failed bool
|
||||
for range 2 {
|
||||
if err := <-errs; err != nil {
|
||||
failed = failed || strings.Contains(err.Error(), "did not acknowledge finding-written: no stream")
|
||||
}
|
||||
}
|
||||
if !failed {
|
||||
t.Errorf("an {error} answer to an acknowledged publish was not returned as an error")
|
||||
}
|
||||
_ = inW.Close()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user