// 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.Judged(facts)) if err != nil { return refuse("the verdict cannot be written: %v", err) } fmt.Fprintf(stdout, "%s\n", line) return 0 }