Files
mesh-delivery/modules/mesh-delivery-teller/cmd/mesh-delivery-teller-tools/main_test.go
T
jschoubben a489c738b3 TL1: the teller tells a pipeline's widening on every channel, once per commit
The teller hears pipeline-ended, tells each end that carries widens through the seat operator-channel's notify with every-channel,
one line per entry, and keeps the last commit said per module and watched branch in its state widens-said (read by
teller_widens_said); registration-changed drops the branches no longer watched.

Builds: design 47 G §71, §335, §514, §522
Claude-Session: https://claude.ai/code/session_01NcbgfGKaxw984XyAPfLm4h
2026-11-12 05:34:43 +01:00

67 lines
2.2 KiB
Go

package main
import (
"encoding/json"
"fmt"
"testing"
stdio "git.novox.be/novox/mesh-sdk/go"
)
type fakeAnswers map[string]string
func (f fakeAnswers) Get(key string) (*stdio.StateEntry, error) {
v, ok := f[key]
if !ok {
return nil, nil
}
return &stdio.StateEntry{Key: key, Value: json.RawMessage(v)}, nil
}
func (f fakeAnswers) Keys() ([]string, error) {
var out []string
for k := range f {
out = append(out, k)
}
return out, nil
}
// teller_answers reads the teller's answers: one by the ask's key, an ask with none said as not found, every answer when no key
// is named (ADR 0596 §3: the gate asks this tool, never the bucket).
func TestTellerAnswersReadsOneAnswerOrEveryAnswer(t *testing.T) {
tool := AnswerTools(fakeAnswers{"k1": `{"option":"approve"}`, "k2": `{"option":"decline"}`})[0]
if tool.Name != "teller_answers" {
t.Fatalf("the tool is %s", tool.Name)
}
out, err := tool.Run(map[string]any{"key": "k1"})
if err != nil || fmt.Sprint(out) != `map[answer:{"option":"approve"} found:true key:k1]` {
t.Errorf("one answer: %v, %v", out, err)
}
out, err = tool.Run(map[string]any{"key": "gone"})
if err != nil || fmt.Sprint(out) != `map[found:false key:gone]` {
t.Errorf("no answer: %v, %v", out, err)
}
out, err = tool.Run(map[string]any{})
raw, _ := json.Marshal(out)
if err != nil || string(raw) != `{"answers":[{"answer":{"option":"approve"},"key":"k1"},{"answer":{"option":"decline"},"key":"k2"}]}` {
t.Errorf("every answer: %s, %v", raw, err)
}
}
// teller_widens_said reads the state widens-said: the commit last said for one module and branch, or every one.
func TestTellerWidensSaidReadsOneKeyOrEveryKey(t *testing.T) {
tool := WidensSaidTools(fakeAnswers{"nats.main": `"c1"`, "nats.next": `"c2"`})[0]
if tool.Name != "teller_widens_said" {
t.Fatalf("the tool is %s", tool.Name)
}
out, err := tool.Run(map[string]any{"key": "nats.main"})
if err != nil || fmt.Sprint(out) != `map[commit:"c1" found:true key:nats.main]` {
t.Errorf("one key: %v, %v", out, err)
}
out, err = tool.Run(map[string]any{})
raw, _ := json.Marshal(out)
if err != nil || string(raw) != `{"said":[{"commit":"c1","key":"nats.main"},{"commit":"c2","key":"nats.next"}]}` {
t.Errorf("every key: %s, %v", raw, err)
}
}