| 1 | # shellcheck shell=bash |
| 2 | # The plan graph's two validators, held to agreeing: the Go one (knot/), |
| 3 | # which is the authority for refs/the-valley/knots, and the CUE schema |
| 4 | # with the knowledge lint, which read the archived graph. Both are run |
| 5 | # over the same graphs, the shared fixtures and graphs generated from a |
| 6 | # fixed seed, and the check fails on any graph where either verdict is not |
| 7 | # the one the case states. Every rejected case names the rule it breaks, |
| 8 | # and that rule must be one the two share. |
| 9 | # Paths and fixtures come from the derivation environment. |
| 10 | # shellcheck disable=SC2154 |
| 11 | set -euo pipefail |
| 12 | |
| 13 | w="$TMPDIR/knot-agree" |
| 14 | mkdir -p "$w" |
| 15 | |
| 16 | fail() { |
| 17 | printf 'knot-agree: %s\n' "$*" >&2 |
| 18 | exit 1 |
| 19 | } |
| 20 | |
| 21 | # The constants the lint restates must be the contract's. |
| 22 | knotcheck contract > "$w/contract.json" |
| 23 | cutoff="$(sed -n 's/.*"cutoff":"\([^"]*\)".*/\1/p' "$w/contract.json")" |
| 24 | grep -qx "ID_RULE_CUTOFF = \"$cutoff\"" "$lint" \ |
| 25 | || fail "the lint's ID_RULE_CUTOFF is not the contract's $cutoff" |
| 26 | cue export -e '#Directories' "$nodeSchema" --out json | tr -d ' \n' > "$w/cue-dirs" |
| 27 | sed -n 's/.*"directories":\({[^}]*}\).*/\1/p' "$w/contract.json" > "$w/go-dirs" |
| 28 | python3 -c 'import json,sys; a,b=(json.load(open(p)) for p in sys.argv[1:]); sys.exit(a!=b)' \ |
| 29 | "$w/cue-dirs" "$w/go-dirs" || fail "the type directories differ: $(cat "$w/cue-dirs") against $(cat "$w/go-dirs")" |
| 30 | |
| 31 | knotcheck rules > "$w/shared" |
| 32 | knotcheck fixtures "$w/fixtures" |
| 33 | knotcheck generate "$w/generated" 40 20261015 |
| 34 | |
| 35 | checked=0 |
| 36 | for set in fixtures generated; do |
| 37 | while IFS=$'\t' read -r case verdict rule; do |
| 38 | dir="$w/$set/$case" |
| 39 | if [ "$verdict" = reject ] && ! grep -qx -- "$rule" "$w/shared"; then |
| 40 | fail "$case breaks $rule, which is no rule the validators share" |
| 41 | fi |
| 42 | by_go="accept" |
| 43 | knotcheck validate "$dir/graph" > "$dir/go.out" || by_go="reject" |
| 44 | by_lint="accept" |
| 45 | mkdir -p "$dir/work" |
| 46 | python3 "$lint" --tree "$dir/tree" --root knots --schema "$nodeSchema" \ |
| 47 | --work "$dir/work" > "$dir/lint.out" 2>&1 || by_lint="reject" |
| 48 | if [ "$by_go" != "$verdict" ] || [ "$by_lint" != "$verdict" ]; then |
| 49 | echo "knot-agree: $set/$case should be $verdict${rule:+ ($rule)}; Go says $by_go, the lint says $by_lint" >&2 |
| 50 | cat "$dir/go.out" "$dir/lint.out" >&2 |
| 51 | find "$dir/graph" -type f -print -exec cat {} \; >&2 |
| 52 | exit 1 |
| 53 | fi |
| 54 | checked=$((checked + 1)) |
| 55 | done < "$w/$set/cases.tsv" |
| 56 | done |
| 57 | [ "$checked" -gt 60 ] || fail "only $checked graphs were checked" |
| 58 | echo "knot-agree: $checked graphs, the validators agree on each" |
| 59 | touch "$out" |