Add the checking program: it answers the verdict of a check's facts (issue 1921)
mesh-checking-program -verdict reads the facts from the file the build seat's run step names, judges them with the rules package and answers one versioned line; facts of a version it does not read are refused, naming it, because the running checker of B0 runs G's programs (milestone 47/B0, ADR 0644, ADR 0656). Claude-Session: https://claude.ai/code/session_01NcbgfFSnn24M3GcqttoU7i
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
// Command mesh-checking-program is the checker's checking program (novox/hq ADR 0644, ADR 0656; design 47's bootstrap
|
||||
// delivery): built from a check's heads and run in the build seat's sandbox through the seat node-build-go's ask run,
|
||||
// with no network and no bus account, it reads the check's facts from the file MESH_RUN_INPUT names and answers the
|
||||
// verdict the judging rules give them, as one JSON line on its standard output (rules.Answer).
|
||||
//
|
||||
// mesh-checking-program -verdict
|
||||
//
|
||||
// It refuses facts of a version it does not read, naming it, with exit 2.
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"flag"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
|
||||
"git.novox.be/novox/mesh-sdk/go/delivery"
|
||||
"mesh-delivery-checker/rules"
|
||||
)
|
||||
|
||||
func main() {
|
||||
os.Exit(run(os.Args[1:], os.Getenv, os.Stdout, os.Stderr))
|
||||
}
|
||||
|
||||
// run is the command over its arguments, environment and outputs, answering its exit.
|
||||
func run(args []string, getenv func(string) string, stdout, stderr io.Writer) int {
|
||||
fs := flag.NewFlagSet("mesh-checking-program", flag.ContinueOnError)
|
||||
fs.SetOutput(stderr)
|
||||
verdict := fs.Bool("verdict", false, "answer the verdict of the facts in the input")
|
||||
if err := fs.Parse(args); err != nil {
|
||||
return 2
|
||||
}
|
||||
refuse := func(format string, a ...any) int {
|
||||
fmt.Fprintf(stderr, "mesh-checking-program: "+format+"\n", a...)
|
||||
return 2
|
||||
}
|
||||
if !*verdict {
|
||||
return refuse("nothing asked: give -verdict")
|
||||
}
|
||||
file := getenv(delivery.RunInputEnv)
|
||||
if file == "" {
|
||||
return refuse("no input: %s names no file", delivery.RunInputEnv)
|
||||
}
|
||||
data, err := os.ReadFile(file)
|
||||
if err != nil {
|
||||
return refuse("the input cannot be read: %v", err)
|
||||
}
|
||||
facts, err := rules.DecodeFacts(data)
|
||||
if err != nil {
|
||||
return refuse("%v", err)
|
||||
}
|
||||
line, err := json.Marshal(rules.Answer{V: rules.AnswerVersion, Verdict: rules.Judge(facts)})
|
||||
if err != nil {
|
||||
return refuse("the verdict cannot be written: %v", err)
|
||||
}
|
||||
fmt.Fprintf(stdout, "%s\n", line)
|
||||
return 0
|
||||
}
|
||||
Reference in New Issue
Block a user