From 8db99b0205d406b28e01aa399c572a276284dc2f Mon Sep 17 00:00:00 2001 From: jochen Date: Wed, 25 Nov 2026 22:47:03 +0100 Subject: [PATCH] mesh-build-go: build_go_step finds an ask's step under its asker's key MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Builds: design 47 G §481; issue 1984 note 52 --- .../mesh-build-go/cmd/mesh-build-go/read.go | 41 +++++++++++++++---- .../cmd/mesh-build-go/read_test.go | 10 +++++ 2 files changed, 43 insertions(+), 8 deletions(-) diff --git a/modules/mesh-build-go/cmd/mesh-build-go/read.go b/modules/mesh-build-go/cmd/mesh-build-go/read.go index b036c8b3b..22f44e252 100644 --- a/modules/mesh-build-go/cmd/mesh-build-go/read.go +++ b/modules/mesh-build-go/cmd/mesh-build-go/read.go @@ -89,19 +89,26 @@ func readValues(keys []string, get func(string) (json.RawMessage, error)) ([]jso return out, fail } -// stepKey is the key of a step of this node: the id alone, or the whole key . as a step tool answered it. +// stepKey is the key of a step of this node: the id alone, or a whole key as a step tool answered it, `.` or an +// ask's `..` (design 47 G §481); the node of the key is this module's. func (m *Module) stepKey(id string) (string, error) { id = strings.TrimSpace(id) - if node, rest, ok := strings.Cut(id, "."); ok { - if node != m.Node { - return "", fmt.Errorf("the step %q is of node %q, this module runs on %q", id, node, m.Node) - } - id = rest + if !strings.Contains(id, ".") { + return sdkstep.StepKey(m.Node, id) } - return sdkstep.StepKey(m.Node, id) + _, node, _, err := sdkstep.ParseStepKey(id) + if err != nil { + return "", err + } + if node != m.Node { + return "", fmt.Errorf("the step %q is of node %q, this module runs on %q", id, node, m.Node) + } + return id, nil } -// ReadStep is the stored value of this node's step id (state, reason, result). +// ReadStep is the stored value of this node's step id (state, reason, result). A step is stored under `.`, or +// under its asker for an ask (`..`, design 47 G §481): when the key as given holds none, the keys of the +// state are searched for this node's step of that id under either form, as the verb output's read does (EndedHere). func (m *Module) ReadStep(id string) (sdkstep.Step, error) { key, err := m.stepKey(id) if err != nil { @@ -114,6 +121,24 @@ func (m *Module) ReadStep(id string) (sdkstep.Step, error) { if err != nil { return sdkstep.Step{}, err } + if len(raw) == 0 && m.ReadSteps.Keys != nil { + _, _, want, _ := sdkstep.ParseStepKey(key) + keys, err := m.ReadSteps.Keys() + if err != nil { + return sdkstep.Step{}, err + } + for _, k := range keys { + if _, node, id, err := sdkstep.ParseStepKey(k); err != nil || node != m.Node || id != want { + continue + } + if raw, err = m.ReadSteps.Get(k); err != nil { + return sdkstep.Step{}, err + } + if len(raw) > 0 { + break + } + } + } if len(raw) == 0 { return sdkstep.Step{}, fmt.Errorf("no step %s in the steps state", key) } diff --git a/modules/mesh-build-go/cmd/mesh-build-go/read_test.go b/modules/mesh-build-go/cmd/mesh-build-go/read_test.go index 8b5d2776a..e4ea8115d 100644 --- a/modules/mesh-build-go/cmd/mesh-build-go/read_test.go +++ b/modules/mesh-build-go/cmd/mesh-build-go/read_test.go @@ -74,6 +74,16 @@ func TestStepToolAnswersTheStoredStep(t *testing.T) { t.Errorf("id %s: step = %+v", id, st) } } + // An ask's step is stored under its asker (design 47 G §481, issue 1984 note 52): found by its id, or by its whole key. + asked, _ := sdkstep.AskStepKey("pipeline", "ace", "mwwmppk5788534") + b, _ := sdkstep.EncodeStep(sdkstep.Step{ID: "mwwmppk5788534", Tool: "build_go_test", Node: "ace", State: sdkstep.StepPassed, Started: t0, Ended: t0.Add(time.Second)}) + steps[asked] = b + for _, id := range []string{"mwwmppk5788534", "ace.mwwmppk5788534", asked} { + out, err := tool(t, m, StepReadTool)(map[string]any{"id": id}) + if err != nil || out.(sdkstep.Step).ID != "mwwmppk5788534" { + t.Errorf("the ask's step by %q = %v, %v", id, out, err) + } + } out, _ := tool(t, m, StepReadTool)(map[string]any{"id": "abc2"}) if st := out.(sdkstep.Step); st.State != sdkstep.StepRefused || st.Reason != "go cannot be run" { t.Errorf("refused step = %+v", st)