S4 page by cursor: a state page continues from an opaque cursor in sequence order

The runtime's mesh/state.page takes the cursor the page before answered as
next, so a state is read once however many pages it takes; a key written
again since an earlier page comes marked seen-again.

Builds: design 47 H2 §779
This commit is contained in:
2026-11-21 23:56:07 +01:00
parent 6d290eb46b
commit 92cb6a8d6d
4 changed files with 45 additions and 18 deletions
+17
View File
@@ -59,6 +59,9 @@ func TestABundleKeepsAndWatchesStateThroughTheRuntime(t *testing.T) {
{Name: "take", Run: func(a map[string]any) (any, error) {
return State("servers").TakeOnce(a["seat"].(string), a["ask"].(string), 10*time.Minute)
}},
{Name: "page", Run: func(a map[string]any) (any, error) {
return State("servers").Page(a["cursor"].(string), 1000, time.Second)
}},
}, inR, outW)
}()
lines := bufio.NewScanner(outR)
@@ -247,6 +250,20 @@ func TestABundleKeepsAndWatchesStateThroughTheRuntime(t *testing.T) {
if r := next(); r["id"] != float64(42) || !strings.Contains(fmt.Sprint(r), "is not an ask id") {
t.Fatalf("a take with no ask id answered %v", r)
}
// Design 47 H2 §779: a page read hands the runtime the opaque cursor and answers the cursor that continues it, and a
// key written again since an earlier page comes marked seen-again.
send(map[string]any{"jsonrpc": "2.0", "id": 43, "method": "tools/call", "params": map[string]any{"name": "page",
"arguments": map[string]any{"cursor": "c.17"}}})
if asked := next(); asked["method"] != "mesh/state.page" || asked["params"].(map[string]any)["cursor"] != "c.17" || asked["params"].(map[string]any)["after"] != nil {
t.Fatalf("asked %v", asked)
} else {
send(map[string]any{"jsonrpc": "2.0", "id": asked["id"], "result": map[string]any{"next": "c.19", "entries": []any{
map[string]any{"key": "a", "value": 1, "revision": 18}, map[string]any{"key": "b", "value": 2, "revision": 19, "seen-again": true}}}})
}
if r := next(); r["id"] != float64(43) || !strings.Contains(fmt.Sprint(r), `"next":"c.19"`) || !strings.Contains(fmt.Sprint(r), `"revision":19,"seen-again":true`) ||
strings.Count(fmt.Sprint(r), "seen-again") != 1 {
t.Fatalf("the page answered %v", r)
}
if !errors.Is(&refused{code: CodeChanged, message: "x"}, ErrChanged) {
t.Fatal("a refusal coded -32010 is not ErrChanged")
}