A page reads the bucket bound once and stops at its time budget, one value at least; an unknown verb is told by its code (issue 1966)
Claude-Session: https://claude.ai/code/session_01NcbgfFSnn24M3GcqttoU7i
This commit is contained in:
@@ -1024,8 +1024,15 @@ type stateAsked struct {
|
||||
// After and MaxBytes are a `page`'s start key and its size in keys and values (zero is a megabyte).
|
||||
After string `json:"after"`
|
||||
MaxBytes int `json:"max_bytes"`
|
||||
// BudgetMS is the time a `page` may spend reading, in milliseconds (zero is the runtime's own, well under 30 s).
|
||||
BudgetMS int `json:"budget_ms"`
|
||||
}
|
||||
|
||||
// unknownVerb is an answer with the JSON-RPC code of a method not found, which a bundle tells by its code.
|
||||
type unknownVerb struct{ error }
|
||||
|
||||
func (unknownVerb) ErrorCode() int { return -32601 }
|
||||
|
||||
// State answers a bundle's `get`, `put`, `delete`, `keys`, `page`, `create`, `update`, `history` and `info` on its
|
||||
// module's state (ADR 0201, ADR 0259, ADR 0307); `create` and `put` take `ttl_seconds`, a key's own time to live,
|
||||
// whose end every watch hears as an `expire` (issue 1952). The runtime refuses, with the reason, a state the module was not issued and a write to one it only reads.
|
||||
@@ -1051,7 +1058,7 @@ func (b *moduleBus) State(verb string, params json.RawMessage) (json.RawMessage,
|
||||
if asked.MaxBytes <= 0 {
|
||||
asked.MaxBytes = 1 << 20
|
||||
}
|
||||
page, err := conn.StatePage(b.module, asked.State, asked.After, asked.MaxBytes)
|
||||
page, err := conn.StatePage(b.module, asked.State, asked.After, asked.MaxBytes, time.Duration(asked.BudgetMS)*time.Millisecond)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -1118,7 +1125,7 @@ func (b *moduleBus) State(verb string, params json.RawMessage) (json.RawMessage,
|
||||
}
|
||||
answer = map[string]any{"revision": revision}
|
||||
default:
|
||||
return nil, fmt.Errorf("the runtime answers no mesh/state.%s", verb)
|
||||
return nil, unknownVerb{fmt.Errorf("the runtime answers no mesh/state.%s", verb)}
|
||||
}
|
||||
return json.Marshal(answer)
|
||||
}
|
||||
|
||||
@@ -132,8 +132,9 @@ func TestAKeysHistoryIsEveryValueKeptOldestFirst(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// A module the bucket was not issued to is refused its history with the reason, as it is a get.
|
||||
func TestAKeysHistoryIsRefusedToAModuleNotIssuedTheState(t *testing.T) {
|
||||
// A module the bucket was not issued to is refused its history, and a page, with the reason, as it is a get; the
|
||||
// owner and a reader are served a page.
|
||||
func TestAKeysHistoryAndAPageOfAStateAreServedToOwnerAndReaderAndRefusedToAModuleNotIssuedIt(t *testing.T) {
|
||||
owner, reader, other := historyBuses(t)
|
||||
if _, err := ask(owner, "put", map[string]any{"state": "issues", "key": "1", "value": 1}); err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -179,6 +180,15 @@ func TestAKeysHistoryIsRefusedToAModuleNotIssuedTheState(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
// A page stops when its time budget is spent, after one value at least, and says where it goes on.
|
||||
step := time.Time{}
|
||||
bus.PageClock = func() time.Time { step = step.Add(11 * time.Second); return step }
|
||||
defer func() { bus.PageClock = time.Now }()
|
||||
raw, err := ask(owner, "page", map[string]any{"state": "issues", "max_bytes": 1 << 20, "budget_ms": 10000})
|
||||
var cut page
|
||||
if err != nil || json.Unmarshal(raw, &cut) != nil || len(cut.Entries) != 1 || cut.Next != "1" {
|
||||
t.Fatalf("a page past its budget = %s, %v", raw, err)
|
||||
}
|
||||
if _, err := ask(other, "page", map[string]any{"state": "issues.issues"}); err == nil {
|
||||
t.Errorf("a page given to a module not issued the state")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user