mesh-build-go: build_go_step finds an ask's step under its asker's key
Builds: design 47 G §481; issue 1984 note 52
This commit is contained in:
@@ -89,19 +89,26 @@ func readValues(keys []string, get func(string) (json.RawMessage, error)) ([]jso
|
|||||||
return out, fail
|
return out, fail
|
||||||
}
|
}
|
||||||
|
|
||||||
// stepKey is the key of a step of this node: the id alone, or the whole key <node>.<id> 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, `<node>.<id>` or an
|
||||||
|
// ask's `<asker>.<node>.<id>` (design 47 G §481); the node of the key is this module's.
|
||||||
func (m *Module) stepKey(id string) (string, error) {
|
func (m *Module) stepKey(id string) (string, error) {
|
||||||
id = strings.TrimSpace(id)
|
id = strings.TrimSpace(id)
|
||||||
if node, rest, ok := strings.Cut(id, "."); ok {
|
if !strings.Contains(id, ".") {
|
||||||
if node != m.Node {
|
return sdkstep.StepKey(m.Node, id)
|
||||||
return "", fmt.Errorf("the step %q is of node %q, this module runs on %q", id, node, m.Node)
|
|
||||||
}
|
|
||||||
id = rest
|
|
||||||
}
|
}
|
||||||
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 `<node>.<id>`, or
|
||||||
|
// under its asker for an ask (`<asker>.<node>.<id>`, 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) {
|
func (m *Module) ReadStep(id string) (sdkstep.Step, error) {
|
||||||
key, err := m.stepKey(id)
|
key, err := m.stepKey(id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -114,6 +121,24 @@ func (m *Module) ReadStep(id string) (sdkstep.Step, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return sdkstep.Step{}, err
|
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 {
|
if len(raw) == 0 {
|
||||||
return sdkstep.Step{}, fmt.Errorf("no step %s in the steps state", key)
|
return sdkstep.Step{}, fmt.Errorf("no step %s in the steps state", key)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -74,6 +74,16 @@ func TestStepToolAnswersTheStoredStep(t *testing.T) {
|
|||||||
t.Errorf("id %s: step = %+v", id, st)
|
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"})
|
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" {
|
if st := out.(sdkstep.Step); st.State != sdkstep.StepRefused || st.Reason != "go cannot be run" {
|
||||||
t.Errorf("refused step = %+v", st)
|
t.Errorf("refused step = %+v", st)
|
||||||
|
|||||||
Reference in New Issue
Block a user