Files
mesh-delivery/modules/mesh-delivery-indexer/internal/index/held_test.go
T
jschoubben 4611f263f3 H-A-48: the takeins ask keeps no field of the earlier take-in
The pending wait, the abandon, the merge by hand with its repository and sequence, and their
ask builders go; an ask naming only one of them is refused as naming no hand act.

Builds: design 47 H §744, §764 (the indexer); H-A-48

Claude-Session: https://claude.ai/code/session_01JG73KHUnBze48rdua8u2sy
2026-11-20 04:56:27 +01:00

74 lines
3.1 KiB
Go

package index
import (
"encoding/json"
"testing"
"time"
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshdelivery"
stdio "git.novox.be/novox/mesh-sdk/go"
)
// Design 47 H §744, §765, H-A-97, H-A-57: the hand tools of the held take-in and the pin drop write asks the indexer reads
// back, each recorded in the hand-act log before it is asked where it is a hand act.
func TestTheHeldAndPinToolsAskWhatTheIndexerReads(t *testing.T) {
var asked []TakeInAsk
var recorded []string
ask := func(_ string, value []byte) (TakeInAsk, error) {
a, err := DecodeTakeIn(value)
if err != nil {
t.Errorf("the indexer cannot read the ask %s: %v", value, err)
}
asked = append(asked, a)
return a, nil
}
record := func(what, _ string) error { recorded = append(recorded, what); return nil }
tools := map[string]stdio.Tool{}
for _, tl := range append(HeldTools(newMem(), ask, time.Now, record), PinsTools(newMem(), newMemObjects(0), ask, time.Now, record)...) {
tools[tl.Name] = tl
}
for _, c := range []struct {
tool string
args map[string]any
want func(TakeInAsk) bool
}{
{TakeInPendingTool, map[string]any{"branch": "main"}, func(a TakeInAsk) bool { return a.Held == "main" && !a.Skip }},
{TakeInSkipTool, map[string]any{"branch": "main", "source": float64(4), "why": "stale"}, func(a TakeInAsk) bool { return a.Held == "main" && a.HeldSource == 4 && a.Skip }},
{PinDropTool, map[string]any{"key": "main.7", "why": "no pipeline"}, func(a TakeInAsk) bool { return a.PinDrop == "main.7" }},
} {
asked = nil
if _, err := tools[c.tool].Run(c.args); err != nil || len(asked) != 1 || !c.want(asked[0]) {
t.Errorf("%s asked %+v (%v)", c.tool, asked, err)
}
}
if len(recorded) != 2 {
t.Errorf("recorded %v, want the skip and the pin drop", recorded)
}
// Design 47 H §744, §764 (H-A-48): an ask of the earlier take-in (a pending wait, a merge by hand) names no hand act the
// indexer serves, and is refused, not acted on.
for _, old := range []string{`{"v":1,"pending":"m.12","drop":true,"why":"x"}`, `{"v":1,"merge":"` + "0123456789012345678901234567890123456789" + `","sequence":3}`} {
if _, err := DecodeTakeIn([]byte(old)); err == nil {
t.Errorf("the earlier ask %s is read as a hand act", old)
}
}
held := newMem()
ix := &Indexer{Held: held}
ix.hold(t.Context(), meshdelivery.SourceMovedEvent{Branch: "main", Source: 4, Call: "0123456789abcdef"}, "the catalog store is full")
got, err := HeldTools(held, ask, time.Now, record)[0].Run(map[string]any{})
data, _ := json.Marshal(got)
var answer struct {
Held []struct {
Branch string `json:"branch"`
Source int64 `json:"source"`
Why string `json:"why"`
Since string `json:"since"`
} `json:"held"`
}
if err != nil || json.Unmarshal(data, &answer) != nil || len(answer.Held) != 1 || answer.Held[0].Branch != "main" || answer.Held[0].Source != 4 || answer.Held[0].Why == "" {
t.Fatalf("indexer_pending answered %s (%v), want {held: [main 4 and why]}", data, err)
}
if _, err := time.Parse(time.RFC3339, answer.Held[0].Since); err != nil {
t.Errorf("since %q is not RFC 3339: %v", answer.Held[0].Since, err)
}
}