package main import ( "encoding/json" "strings" "testing" "time" "git.novox.be/novox/mesh-contracts/health-and-repair/go/clients/meshhandactsclient" "mesh-delivery-builder/internal/build" "mesh-delivery-builder/internal/versions" ) // Design 47 G §276, §672: builder_waits lists the held entries; builder_release records the hand act first and asks the // builder through reasks, whose refusal is the tool's error. func TestWaitsToolsListTheWaitsAndReleaseAfterTheHandAct(t *testing.T) { wait, _ := json.Marshal(build.ToolchainWait{Module: "m", Fingerprint: "src2:" + strings.Repeat("1", 64), Language: "go", Version: "go1.26.0", Since: time.Now()}) rr := versions.Reader{Keys: func() ([]string, error) { return []string{"m.k"}, nil }, Get: func(string) (json.RawMessage, bool, error) { return wait, true, nil }} var asked []build.ReAsk answer := func(key string, value []byte) (json.RawMessage, error) { a, _ := build.DecodeReAsk(value) asked = append(asked, a) a.Answered, a.Answer = time.Now(), "released: built" return json.Marshal(a) } recorded := 0 acts := meshhandactsclient.Recorder{Ask: func(string, any) (json.RawMessage, error) { recorded++; return json.RawMessage(`{}`), nil }} tools := waitsTools(rr, answer, time.Now, acts) byName := map[string]func(map[string]any) (any, error){} for _, tl := range tools { byName[tl.Name] = tl.Run } got, err := byName[build.WaitsTool](nil) if rows := got.(map[string]any)["waits"].([]build.ToolchainWait); err != nil || len(rows) != 1 || rows[0].On() != "toolchain:go@go1.26.0" { t.Fatalf("waits = %v, %v", got, err) } if _, err := byName[build.ReleaseTool](map[string]any{"module": "m", "fp": "src2:" + strings.Repeat("1", 64), "why": ""}); err == nil || recorded != 0 { t.Fatalf("a release with no why was taken: %v, %d recorded", err, recorded) } if _, err := byName[build.ReleaseTool](map[string]any{"module": "m", "fp": "src2:" + strings.Repeat("1", 64), "why": "the build module runs"}); err != nil || recorded != 1 || len(asked) != 1 || asked[0].Mode != build.ModeRelease || asked[0].Module != "m" { t.Fatalf("release: %v, %d recorded, asked %+v", err, recorded, asked) } }