A test step takes the level's text out of its test answers (their member output) and keeps it in the holder's outputs objects as <node>.<ask id>, a header of its size and the failing tests with their words from the level's results beside the text; a check ask's answer keeps none. The verb output at the part's form 2 takes the ask and answers the text's last 64 KB, its size and the failing tests from the header; no-longer-kept only when this node's steps key shows the ask ended more than the max-age (7 days) ago, an ask never run here refused naming it. Builds: design 47 H2 §791, §820; H-A-367 (1), H-A-412 (1) and its second and third addenda
108 lines
5.7 KiB
Go
108 lines
5.7 KiB
Go
package steprun
|
|
|
|
import (
|
|
"encoding/base64"
|
|
"errors"
|
|
"time"
|
|
|
|
sdkstep "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/buildstep"
|
|
stdio "git.novox.be/novox/mesh-sdk/go"
|
|
)
|
|
|
|
// SeatTools are a build seat's verbs on one node, as its holder serves them (novox/hq ADR 0525 §10; mesh-sdk catalogue
|
|
// buildSeatVerbs): `<seat>.current` (what the node runs, its capacity, whether it is paused), `<seat>.pause` and
|
|
// `<seat>.resume`, the pause kept on the node's pause key by the puller. what names the asks in the descriptions ("Go").
|
|
func SeatTools(seat, what string, p *Puller) []stdio.Tool {
|
|
verb := func(name, description string, run func() (any, error)) stdio.Tool {
|
|
return stdio.Tool{Name: seat + "." + name, Description: description,
|
|
Input: map[string]any{"type": "object", "properties": map[string]any{}},
|
|
Run: func(map[string]any) (any, error) { return run() }}
|
|
}
|
|
current := func() (any, error) {
|
|
// The part's current at form 2 (design 47 H2 §801, H-A-367 (2)): whether it takes asks, why not since when, its
|
|
// capacity and every ask it runs, whoever asked it.
|
|
c := p.CapacityDetail()
|
|
why := p.whyNot(c)
|
|
out := map[string]any{"node": p.Node, "takes": why == "", "since": p.takesSince(why), "capacity": c.Effective, "asks": p.Running()}
|
|
if why != "" {
|
|
out["why-not"] = why
|
|
}
|
|
return out, nil
|
|
}
|
|
drop := stdio.Tool{Name: seat + ".drop", Description: "End an " + what + " ask its caller no longer waits for: it is kept as dropped on this node " +
|
|
"(so a bus that gives it again has it refused), and a step running here for it is ended, written refused naming who dropped it and why.",
|
|
Input: map[string]any{"type": "object", "required": []string{"id", "why"}, "properties": map[string]any{
|
|
"id": map[string]any{"type": "string", "description": "the ask's id"},
|
|
"by": map[string]any{"type": "string", "description": "who drops it"},
|
|
"why": map[string]any{"type": "string", "description": "why the caller no longer waits"}}},
|
|
Run: func(args map[string]any) (any, error) {
|
|
str := func(k string) string { s, _ := args[k].(string); return s }
|
|
if err := p.Drop(str("id"), str("by"), str("why")); err != nil {
|
|
return nil, err
|
|
}
|
|
return map[string]any{}, nil
|
|
}}
|
|
return []stdio.Tool{drop,
|
|
verb("current", "Whether this node takes "+what+" asks now and why not (paused, capacity 0, unhealthy) since when, its build capacity, "+
|
|
"and every ask it runs (its id, kind, module, when it started and who asked it), whoever asked it.", current),
|
|
verb("pause", "Take no new "+what+" ask on this node until resumed; an ask running here ends in its place. Kept "+
|
|
"across a restart (the node's pause key).", func() (any, error) {
|
|
if err := p.Pause("the seat's pause verb"); err != nil {
|
|
return nil, err
|
|
}
|
|
return current()
|
|
}),
|
|
verb("resume", "Take "+what+" asks again on this node.", func() (any, error) {
|
|
if err := p.Resume("the seat's resume verb"); err != nil {
|
|
return nil, err
|
|
}
|
|
return current()
|
|
}),
|
|
}
|
|
}
|
|
|
|
// AnswerTool serves `<seat>.answer` (design 47 G A-254, A-257; H2 H-A-412 addendum): a step's end over what its key or
|
|
// step-ended carries, by its ask, as the object the holder keeps it in (sdkstep.AnswerObjectName), read with read, which
|
|
// answers nil for none. The verb's answer is marked chunks: the bundle answers the whole end as the member `file` (base64)
|
|
// and the tool runner sends it in chunks and answers their count; an ask whose end this node does not keep answers no chunks.
|
|
func AnswerTool(seat string, read func(object string) ([]byte, error)) stdio.Tool {
|
|
return stdio.Tool{Name: seat + "." + sdkstep.AnswerVerb,
|
|
Description: "A step's answer by its ask, when its step key or step-ended named it as an answer-object: the kept end's bytes in chunks, of any size.",
|
|
Input: map[string]any{"type": "object", "required": []string{"ask", "call"}, "properties": map[string]any{
|
|
"ask": map[string]any{"type": "string", "description": "the ask's id"},
|
|
"call": map[string]any{"type": "string", "description": "the subject token of this send's chunks"}}},
|
|
Run: func(args map[string]any) (any, error) {
|
|
ask, _ := args["ask"].(string)
|
|
if ask == "" {
|
|
return nil, errors.New("the verb answer is asked for no ask")
|
|
}
|
|
body, err := read(sdkstep.AnswerObjectName(ask))
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if body == nil {
|
|
return map[string]any{"ask": ask, "chunks": 0}, nil
|
|
}
|
|
return map[string]any{"ask": ask, "file": base64.StdEncoding.EncodeToString(body)}, nil
|
|
}}
|
|
}
|
|
|
|
// OutputTool serves `<seat>.output` at the part's form 2 (design 47 H2 §791, H-A-367 (1), H-A-412): a run's test output by
|
|
// its ask, from the object `<node>.<ask>` in the outputs objects o: its last 64 KB, its size and the failing tests with their
|
|
// words; no-longer-kept once ended (EndedHere over the holder's steps state) shows the ask ended on node more than the
|
|
// objects' max-age ago; an ask never run here is refused, naming it.
|
|
func OutputTool(seat, node string, o OutputObjects, ended func(ask string) (time.Time, bool, error)) stdio.Tool {
|
|
return stdio.Tool{Name: seat + "." + sdkstep.OutputVerb,
|
|
Description: "A run's test output by its ask: the output's last 64 KB, its size and the failing tests with their words, " +
|
|
"or no longer kept once past the outputs objects' max-age (7 days). An ask that never ran on this node is refused.",
|
|
Input: map[string]any{"type": "object", "required": []string{"ask"}, "properties": map[string]any{
|
|
"ask": map[string]any{"type": "string", "description": "the ask's id"}}},
|
|
Run: func(args map[string]any) (any, error) {
|
|
ask, _ := args["ask"].(string)
|
|
if ask == "" {
|
|
return nil, errors.New("the verb output is asked for no ask")
|
|
}
|
|
return readOutput(o, node, ask, ended)
|
|
}}
|
|
}
|