| 1 | # shellcheck shell=bash |
| 2 | # Paths and fixtures come from the derivation environment. |
| 3 | # shellcheck disable=SC2154 |
| 4 | cue vet -c "$schema" "$example" |
| 5 | cue export "$schema" "$example" > example.json |
| 6 | grep -q 'gunk-dev/the-valley' example.json |
| 7 | grep -q 'restic-sftp' example.json |
| 8 | |
| 9 | # A declaration with no optional field set must stay valid — |
| 10 | # consumers written before backup or protection existed keep |
| 11 | # vetting. |
| 12 | cue vet -c "$schema" "$hosts/no-backup.cue" |
| 13 | |
| 14 | # What the installer renders a hook from. A project that |
| 15 | # leaves the set out gets the default, a project that names |
| 16 | # patterns gets them in order, and a project that declares no |
| 17 | # protection exports none at all — which is how the installer |
| 18 | # tells a protected project from an open one. |
| 19 | protected=("$schema" "$hosts/protected.cue") |
| 20 | [ "$(cue export -e 'projects.guarded.protection.refs[0]' "${protected[@]}")" \ |
| 21 | = '"refs/heads/main"' ] |
| 22 | cue export -e 'projects.released.protection.refs' "${protected[@]}" > released.json |
| 23 | grep -q '"refs/heads/release/\*"' released.json |
| 24 | if cue export -e 'projects.open.protection' "${protected[@]}" > open.err 2>&1; then |
| 25 | echo "cue-vet: a project declaring no protection exported one" >&2 |
| 26 | exit 1 |
| 27 | fi |
| 28 | |
| 29 | # The event schema accepts what the publisher hook emits … |
| 30 | cue vet -d '#RefUpdated' "$eventSchema" "$events/ref-updated.json" |
| 31 | # … and stays closed: a field outside the git-derivable |
| 32 | # identity — wall-clock time, a hostname — must be rejected, |
| 33 | # or replay determinism silently dies. An abbreviated object |
| 34 | # id is rejected for the same reason. |
| 35 | for bad in "$events"/rejected/*.json; do |
| 36 | if cue vet -d '#RefUpdated' "$eventSchema" "$bad"; then |
| 37 | echo "cue-vet: expected $(basename "$bad") to be rejected" >&2 |
| 38 | exit 1 |
| 39 | fi |
| 40 | done |
| 41 | |
| 42 | # The rejected declarations, and the words each rejection must name. |
| 43 | while IFS=$'\t' read -r name names; do |
| 44 | case "$name" in ''|'#'*) continue ;; esac |
| 45 | if cue vet -c "$schema" "$hosts/rejected/$name.cue" > "$name.err" 2>&1; then |
| 46 | echo "cue-vet: expected invalid declaration '$name' to be rejected" >&2 |
| 47 | exit 1 |
| 48 | fi |
| 49 | if [ -n "$names" ] && ! grep -qF -- "$names" "$name.err"; then |
| 50 | echo "cue-vet: '$name' was rejected without naming $names" >&2 |
| 51 | cat "$name.err" >&2 |
| 52 | exit 1 |
| 53 | fi |
| 54 | done < "$rejectedCases" |
| 55 | touch "$out" |