From d557c0c2aff19c394f56c07924ef5b4620310b9c Mon Sep 17 00:00:00 2001 From: jochen Date: Sun, 22 Nov 2026 11:41:25 +0100 Subject: [PATCH] View: a pipelines list not read is a page shown unreadable, not a refusal The socket answered a refusal and a list it could not read with the same field, so the terminal view's -follow ended at a list not read yet (the runner not answering at the view's start) instead of showing it unreadable and reading it again at the runner's next event. A refusal now has its own field; a list's page is handed on whatever it holds. The unit tests' waits for a change are bounded, so a change never said fails instead of hanging. Issue 1983, review round 1 finding 1. Builds: design 47 H2 H-A-467 (1), (2) --- .../internal/view/pipelines_test.go | 55 ++++++++++++++++++- .../mesh-delivery-view/internal/view/serve.go | 21 ++++--- 2 files changed, 66 insertions(+), 10 deletions(-) diff --git a/modules/mesh-delivery-view/internal/view/pipelines_test.go b/modules/mesh-delivery-view/internal/view/pipelines_test.go index 05cfdeba1..5653849b5 100644 --- a/modules/mesh-delivery-view/internal/view/pipelines_test.go +++ b/modules/mesh-delivery-view/internal/view/pipelines_test.go @@ -11,6 +11,7 @@ import ( "strings" "sync" "testing" + "time" seat "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshpipelinerunner" ) @@ -56,6 +57,13 @@ func (f *fakeRunner) setRows(branch string, rows ...seat.PipelineRow) { f.rows[branch] = rows } +// changedWithin is p.Changed bounded, so a change never said fails the test instead of hanging it. +func changedWithin(ctx context.Context, p *Pipelines, what string, since uint64) bool { + ctx, cancel := context.WithTimeout(ctx, 30*time.Second) + defer cancel() + return p.Changed(ctx, what, since) +} + // Design 47 H2 H-A-467: the pipelines page reads the runner's list and show, refreshes on its events, never on a timer, // and links each delivery to its pipeline by its source revision. func TestThePipelinesPage(t *testing.T) { @@ -79,7 +87,7 @@ func TestThePipelinesPage(t *testing.T) { ctx, cancel := context.WithCancel(context.Background()) defer cancel() go p.Run(ctx) - if !p.Changed(ctx, "", 0) { // the first reading at the start + if !changedWithin(ctx, p, "", 0) { // the first reading at the start t.Fatal("the lists were never read") } web := func(path string) string { @@ -151,7 +159,7 @@ func TestThePipelinesPage(t *testing.T) { t.Fatalf("the stream starts %q", line) } shown := make(chan bool, 1) - go func() { shown <- p.Changed(ctx, "main.13", v) }() + go func() { shown <- changedWithin(ctx, p, "main.13", v) }() runner.mu.Lock() before := runner.lists runner.mu.Unlock() @@ -213,4 +221,47 @@ func TestThePipelinesPage(t *testing.T) { t.Fatalf("a pipeline the runner does not hold = %v", err) } }) + + t.Run("a list not read is shown unreadable and followed on, read again at the next event", func(t *testing.T) { + var mu sync.Mutex + away := true // the runner not answering yet, as the bus says when no holder listens + call := func(key string, body any) (json.RawMessage, error) { + mu.Lock() + defer mu.Unlock() + if away { + return nil, fmt.Errorf("nats: no responders available for request") + } + return runner.call(key, body) + } + up := NewPipelines(call, nil, nil) + upCtx, upCancel := context.WithCancel(ctx) + defer upCancel() + go up.Run(upCtx) + if !changedWithin(upCtx, up, "", 0) { + t.Fatal("the lists were never read") + } + path, sm := served(t) + sm.SetPipelines(up) + var seen []PipelinesPage + err := AskPipelines(path, "", "", "", "", true, func(page PipelinesPage, _ *seat.ShowAnswer) bool { + seen = append(seen, page) + if len(seen) == 1 { + mu.Lock() + away = false + mu.Unlock() + if err := up.Hear([]byte(`{"pipeline":"main.14"}`)); err != nil { + t.Error(err) + } + } + return page.Error != "" || len(page.Rows) == 0 + }) + if err != nil || len(seen) < 2 || !strings.Contains(seen[0].Error, "no responders") || seen[len(seen)-1].Rows[0].Pipeline != "main.14" { + t.Fatalf("followed %+v, %v; want the unreadable list, then main.14 after the event", seen, err) + } + var b bytes.Buffer + PipelinesTable(&b, seen[0]) + if !strings.Contains(b.String(), "unreadable: ") { + t.Errorf("the terminal view of an unreadable list = %q", b.String()) + } + }) } diff --git a/modules/mesh-delivery-view/internal/view/serve.go b/modules/mesh-delivery-view/internal/view/serve.go index 0f199991a..4f0c197f3 100644 --- a/modules/mesh-delivery-view/internal/view/serve.go +++ b/modules/mesh-delivery-view/internal/view/serve.go @@ -547,11 +547,11 @@ func answerPipelines(c net.Conn, m *Model, a ask) { p := m.Pipelines() enc := json.NewEncoder(c) if p == nil { - enc.Encode(map[string]string{"error": "the view reads no pipelines yet"}) + enc.Encode(pipelinesRefusal{Refused: "the view reads no pipelines yet"}) return } if a.Ask == "pipeline" && a.Pipeline == "" { - enc.Encode(map[string]string{"error": "name a pipeline"}) + enc.Encode(pipelinesRefusal{Refused: "name a pipeline"}) return } what := "" @@ -573,7 +573,7 @@ func answerPipelines(c net.Conn, m *Model, a ask) { if a.Ask == "pipelines" { err = enc.Encode(p.Page(a.Branch)) } else if sa, serr := p.Show(a.Pipeline, a.Mover, a.Next); serr != nil { - err = enc.Encode(map[string]string{"error": serr.Error()}) + err = enc.Encode(pipelinesRefusal{Refused: serr.Error()}) } else { err = enc.Encode(sa) } @@ -583,6 +583,13 @@ func answerPipelines(c net.Conn, m *Model, a ask) { } } +// pipelinesRefusal is the socket's answer to a pipelines ask it cannot answer: no reader, no pipeline named, or a pipeline +// show could not read. A list that could not be read is no refusal: it is a page whose Error says why, handed on, and a +// following reads it again at the runner's next event (design 47 H2 H-A-467). +type pipelinesRefusal struct { + Refused string `json:"refused"` +} + // AskPipelines asks the socket at path for one branch's pipelines, or with pipeline set for that pipeline (of mover when // named); with follow, each answers again at each change, handed to each until it answers false or the view leaves. func AskPipelines(path, branch, pipeline, mover, next string, follow bool, each func(PipelinesPage, *seat.ShowAnswer) bool) error { @@ -611,11 +618,9 @@ func AskPipelines(path, branch, pipeline, mover, next string, follow bool, each } return fmt.Errorf("the view's answer is not pipelines: %w", err) } - var refused struct { - Error string `json:"error"` - } - if json.Unmarshal(raw, &refused) == nil && refused.Error != "" { - return errors.New(refused.Error) + var refused pipelinesRefusal + if json.Unmarshal(raw, &refused) == nil && refused.Refused != "" { + return errors.New(refused.Refused) } var page PipelinesPage var show *seat.ShowAnswer