mesh-issues: the runner's show is read to its last page before a pipeline row is written

G20 issues-read-show-pages.

Builds: design 47 H2 H-A-709 (2)
This commit is contained in:
2026-11-25 17:11:26 +01:00
parent 5a82d93ccb
commit 9c8ce82151
2 changed files with 80 additions and 5 deletions
@@ -2,6 +2,7 @@ package main
import (
"encoding/json"
"fmt"
"strings"
"testing"
"time"
@@ -471,6 +472,42 @@ func TestTheReviewEndsAtTheFirstPassedReviewStepOfTheRunner(t *testing.T) {
}
}
// H-A-709 (2): the runner's `show` is read to its last page; the steps of every page are the row's; a page that fails writes no row.
func TestTheRunnersShowIsReadToItsLastPage(t *testing.T) {
page := func(next, step, outcome, ended string) json.RawMessage {
e := ""
if ended != "" {
e = `,"ended":"` + ended + `"`
}
return json.RawMessage(`{"pipeline":{"pipeline":"b.1.m","module":"m","outcome":"passed","steps":[{"step":"` + step + `","outcome":"` + outcome + `"` + e + `}]},"capped":` +
fmt.Sprint(next != "") + `,"next":"` + next + `"}`)
}
pages := map[string]json.RawMessage{"": page("c1", "lint", "passed", ""), "c1": page("c2", "unit", "passed", ""),
"c2": page("", "review", "passed", "2026-10-12T09:05:00Z")}
var asked []string
row, err := readPipeline(func(a map[string]any) (json.RawMessage, error) {
next, _ := a["next"].(string)
asked = append(asked, next)
return pages[next], nil
}, "b.1.m", "r#1")
if err != nil || len(row.Steps) != 3 || row.reviewed.IsZero() || fmt.Sprint(asked) != "[ c1 c2]" {
t.Fatalf("row %+v, asked %q, %v: every page's steps are the row's, the last page's review among them", row, asked, err)
}
// A page that fails: no row, the error names the page.
if row, err := readPipeline(func(a map[string]any) (json.RawMessage, error) {
if a["next"] == "c1" {
return nil, errFake("the runner is away")
}
return pages[""], nil
}, "b.1.m", "r#1"); err == nil || !strings.Contains(err.Error(), "page 2") || row.Module != "" {
t.Fatalf("row %+v, error %v", row, err)
}
// A cursor answered again is no endless read.
if _, err := readPipeline(func(map[string]any) (json.RawMessage, error) { return page("c1", "lint", "passed", ""), nil }, "b.1.m", "r#1"); err == nil {
t.Fatal("a cursor repeated was read on")
}
}
type errFake string
func (e errFake) Error() string { return string(e) }
@@ -88,6 +88,46 @@ func parsePipelineRow(raw json.RawMessage, pr string) (PipelineRow, error) {
return row, nil
}
// readPipeline reads one pipeline through `show`, page after page: each page's `next` is asked until none is left, the steps of
// every page are the row's (design 47 H2 H-A-709 (2): the runner answers within a bound). A page that fails fails the read,
// so no row is written from the pages before it.
func readPipeline(ask func(args map[string]any) (json.RawMessage, error), key, pr string) (PipelineRow, error) {
var row PipelineRow
next, seen := "", map[string]bool{}
for page := 1; ; page++ {
args := map[string]any{"pipeline": key}
if next != "" {
args["next"] = next
}
raw, err := ask(args)
if err != nil {
return PipelineRow{}, fmt.Errorf("page %d of %s: %w", page, key, err)
}
got, err := parsePipelineRow(raw, pr)
if err != nil {
return PipelineRow{}, fmt.Errorf("page %d of %s: %w", page, key, err)
}
if page == 1 {
row = got
} else {
row.Steps = append(row.Steps, got.Steps...)
if !got.reviewed.IsZero() && (row.reviewed.IsZero() || got.reviewed.Before(row.reviewed)) {
row.reviewed = got.reviewed
}
}
m, _ := answerOf(raw, "mesh-pipeline-runner.show")
next = ""
_ = json.Unmarshal(m["next"], &next)
if next == "" {
return row, nil
}
if seen[next] {
return PipelineRow{}, fmt.Errorf("page %d of %s: the runner answered the cursor %q again", page, key, next)
}
seen[next] = true
}
}
// busPipelines reads a pull request's head from the seat `git`, then its pipelines from the runner: `list` given the head
// commit, `show` of each.
func busPipelines(owner string) Pipelines {
@@ -110,11 +150,9 @@ func busPipelines(owner string) Pipelines {
}
var rows []PipelineRow
for _, k := range keys {
raw, err := stdio.Ask("seat:mesh-pipeline-runner.show", map[string]any{"pipeline": k})
if err != nil {
return nil, err
}
row, err := parsePipelineRow(raw, pr)
row, err := readPipeline(func(args map[string]any) (json.RawMessage, error) {
return stdio.Ask("seat:mesh-pipeline-runner.show", args)
}, k, pr)
if err != nil {
return nil, err
}