72 lines
3.4 KiB
Go
72 lines
3.4 KiB
Go
// Command mesh-delivery-checker-tools serves the checker's read tools (novox/hq ADR 0484 clause 13, issue 1686): the runtime
|
|
// launches it for a call, it reads the checker's verdicts and kept states and the indexer's candidates through the checker's
|
|
// state and reads, and writes nothing. The checker is the other program: it serves no tool (ADR 0437 §4).
|
|
package main
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"os"
|
|
|
|
stdio "git.novox.be/novox/mesh-sdk/go"
|
|
|
|
"mesh-delivery-checker/internal/check"
|
|
)
|
|
|
|
func read(s stdio.KeptState) check.StateRead {
|
|
return check.StateRead{Keys: s.Keys, Get: func(key string) (json.RawMessage, error) {
|
|
e, err := s.Get(key)
|
|
if err != nil || e == nil {
|
|
return nil, err
|
|
}
|
|
return e.Value, nil
|
|
}}
|
|
}
|
|
|
|
// Tools are the read tools over the checker's states.
|
|
func Tools(r check.Reader) []stdio.Tool {
|
|
return []stdio.Tool{
|
|
{Name: check.VerdictsReadTool,
|
|
Description: "The verdicts the checker holds, each as stored under verdicts.<group>.<heads>: its state, what failed first, the tests run, kept and skipped per level, the time of each part, the trunk heads it judged against and the composition, with the full " +
|
|
"report of the status each pull request carries (the line the forge shows is cut at 140 characters, this is not). With a group, that group's only. Read-only.",
|
|
Input: map[string]any{"type": "object", "properties": map[string]any{
|
|
"group": map[string]any{"type": "string", "description": "the delivery group's branch name"}}},
|
|
Run: func(args map[string]any) (any, error) {
|
|
group, _ := args["group"].(string)
|
|
vs, err := r.Verdicts(group)
|
|
return map[string]any{"verdicts": vs}, err
|
|
}},
|
|
{Name: check.PullReadTool,
|
|
Description: "The verdict that judges one pull request and the full report of its status mesh/check; for an hq pull request, that hq is judged by " +
|
|
"merge-check.sh until issue 1296. Read-only.",
|
|
Input: map[string]any{"type": "object", "required": []string{"repository", "number"}, "properties": map[string]any{
|
|
"repository": map[string]any{"type": "string", "description": "<owner>/<name>"},
|
|
"number": map[string]any{"type": "integer", "description": "the pull request's number"}}},
|
|
Run: func(args map[string]any) (any, error) {
|
|
repository, _ := args["repository"].(string)
|
|
n, _ := args["number"].(float64)
|
|
return r.Pull(repository, int(n))
|
|
}},
|
|
{Name: check.KeptReadTool,
|
|
Description: "The kept verdicts of passing packages, each as stored under kept.<level>.<digest>: the package, its tests, the time they took, the toolchain " +
|
|
"and when it was kept. With a level, that level's; with a level and a digest, that one. Read-only.",
|
|
Input: map[string]any{"type": "object", "properties": map[string]any{
|
|
"level": map[string]any{"type": "string", "enum": []string{"unit", "integration"}, "description": "the level"},
|
|
"digest": map[string]any{"type": "string", "description": "the package's digest, with a level"}}},
|
|
Run: func(args map[string]any) (any, error) {
|
|
level, _ := args["level"].(string)
|
|
digest, _ := args["digest"].(string)
|
|
kept, err := r.Kept(level, digest)
|
|
return map[string]any{"kept": kept}, err
|
|
}},
|
|
}
|
|
}
|
|
|
|
func main() {
|
|
r := check.Reader{VerdictState: read(stdio.State("verdicts")), KeptState: read(stdio.State("kept")), CandidateState: read(stdio.State("mesh-delivery-indexer.candidates"))}
|
|
if err := stdio.Serve("", Tools(r)); err != nil {
|
|
fmt.Fprintf(os.Stderr, "[mesh-delivery-checker-tools] %v\n", err)
|
|
os.Exit(1)
|
|
}
|
|
}
|