Asked -seats, it reads every seat definition the heads carry, resolves the parts it includes and answers the list with what it left out and why, so the running checker hands the manifest validator and the composer a list it does not read itself (ADR 0636 §4, ADR 0644 §1). Claude-Session: https://claude.ai/code/session_01NcbgfFSnn24M3GcqttoU7i
77 lines
2.3 KiB
Go
77 lines
2.3 KiB
Go
// 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")
|
|
seats := fs.Bool("seats", false, "answer the seat list of the heads laid for it")
|
|
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 *seats {
|
|
dir := getenv(delivery.RunHeadsEnv)
|
|
if dir == "" {
|
|
return refuse("no heads: %s names no directory", delivery.RunHeadsEnv)
|
|
}
|
|
answer, err := rules.SeatsOf(os.DirFS(dir))
|
|
if err != nil {
|
|
return refuse("%v", err)
|
|
}
|
|
line, err := json.Marshal(answer)
|
|
if err != nil {
|
|
return refuse("the seat list cannot be written: %v", err)
|
|
}
|
|
fmt.Fprintf(stdout, "%s\n", line)
|
|
return 0
|
|
}
|
|
if !*verdict {
|
|
return refuse("nothing asked: give -verdict or -seats")
|
|
}
|
|
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
|
|
}
|