mesh/delivery merged: source.main moved to novox/mesh-sdk@7c015b652d36
mesh/delivery-group group feat/sdk1 merged: every member is merged
mesh/check failed: the composition: the composer at mesh-sdk f02f142af128b336c32a7f0059c5e1606bf9b1dc did not run: failed the composer git.novox.be/no…
The check of release sdk1 failed on TestStatePutWritesAKeyWhole: TestACallIsAskedAgainOnlyWhenItReachedNoOne left busretry's Bound at 50 ms, and on a loaded machine the state test's first pause overran it. Second failure of the kind "tests leave package-level state set". Quick fix: restore busretry's waits in the one test and lengthen the state test's bound. Thorough fix (chosen, the kind met twice): busretry.Waits sets the waits and returns their restore, used as t.Cleanup(busretry.Waits(...)) by every test that sets them, each with a bound of seconds where it waits to succeed; and servesAlone gives every test that serves its own runtime channel and Served, put back after it, instead of tests clearing the channel an earlier one left. A scan of every test assignment to a package-level variable found no other unrestored one. Claude-Session: https://claude.ai/code/session_01NcbgfJ9Gum47zkFKWRaovL
100 lines
3.7 KiB
Go
100 lines
3.7 KiB
Go
package stdio
|
|
|
|
import (
|
|
"bufio"
|
|
"encoding/json"
|
|
"errors"
|
|
"io"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
// novox/hq ADR 0259 §3: a bundle takes a seat's work and answers proofs through the runtime; a piece of
|
|
// work it fails is answered as an error, so the runtime offers it again, and a proof's error is said.
|
|
func TestABundleTakesWorkAndAnswersProofsThroughTheRuntime(t *testing.T) {
|
|
servesAlone(t)
|
|
t.Setenv(ServedAs, "router")
|
|
inR, inW := io.Pipe()
|
|
outR, outW := io.Pipe()
|
|
taken := make(chan string, 4)
|
|
go func() {
|
|
_ = ServeOn("", []Tool{{Name: "start", Run: func(map[string]any) (any, error) {
|
|
if err := SeatTake("SEAT_OPERATOR_CHANNEL_worker", func(w Work) error {
|
|
taken <- w.Subject
|
|
if string(w.Body) == `{"fail":true}` {
|
|
return errors.New("not recorded")
|
|
}
|
|
return nil
|
|
}); err != nil {
|
|
return nil, err
|
|
}
|
|
if err := SeatAnswer("mesh.seat.intake.proof.code.*", func(subject string, body json.RawMessage) (any, error) {
|
|
if subject != "mesh.seat.intake.proof.code.telegram" {
|
|
return nil, errors.New("no such kind")
|
|
}
|
|
return map[string]any{"accepted": true}, nil
|
|
}); err != nil {
|
|
return nil, err
|
|
}
|
|
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": "start"}})
|
|
asked := next()
|
|
if asked["method"] != "mesh/seat.take" || asked["params"].(map[string]any)["worker"] != "SEAT_OPERATOR_CHANNEL_worker" {
|
|
t.Fatalf("the take was not asked of the runtime: %v", asked)
|
|
}
|
|
send(map[string]any{"jsonrpc": "2.0", "id": asked["id"], "result": map[string]any{}})
|
|
asked = next()
|
|
if asked["method"] != "mesh/seat.answer" {
|
|
t.Fatalf("the answer was not asked of the runtime: %v", asked)
|
|
}
|
|
send(map[string]any{"jsonrpc": "2.0", "id": asked["id"], "result": map[string]any{}})
|
|
next() // the tool's answer
|
|
|
|
send(map[string]any{"jsonrpc": "2.0", "id": 2, "method": "mesh/work", "params": map[string]any{"work": map[string]any{
|
|
"worker": "SEAT_OPERATOR_CHANNEL_worker", "subject": "mesh.seat.operator-channel.accept.ask.x", "body": map[string]any{"fail": true}}}})
|
|
if got := next(); got["error"] == nil {
|
|
t.Errorf("work the handler failed was answered as taken: %v", got)
|
|
}
|
|
send(map[string]any{"jsonrpc": "2.0", "id": 3, "method": "mesh/work", "params": map[string]any{"work": map[string]any{
|
|
"worker": "SEAT_OPERATOR_CHANNEL_worker", "subject": "mesh.seat.operator-channel.accept.ask.x", "body": map[string]any{}}}})
|
|
if got := next(); got["error"] != nil {
|
|
t.Errorf("work the handler took was answered as an error: %v", got)
|
|
}
|
|
send(map[string]any{"jsonrpc": "2.0", "id": 4, "method": "mesh/proof", "params": map[string]any{
|
|
"subject": "mesh.seat.intake.proof.code.telegram", "body": map[string]any{"code": "1"}}})
|
|
if got := next(); got["result"].(map[string]any)["accepted"] != true {
|
|
t.Errorf("the proof was answered %v", got)
|
|
}
|
|
send(map[string]any{"jsonrpc": "2.0", "id": 5, "method": "mesh/proof", "params": map[string]any{
|
|
"subject": "mesh.seat.intake.proof.code.desktop", "body": map[string]any{}}})
|
|
if got := next(); got["error"] == nil {
|
|
t.Errorf("a proof the handler refused was answered as accepted: %v", got)
|
|
}
|
|
if len(taken) != 2 {
|
|
t.Errorf("the handler was handed %d pieces of work, want 2", len(taken))
|
|
}
|
|
_ = inW.Close()
|
|
}
|