gunk-dev/the-valley

attest-schema.sh

sourcefefe7833f700main's published tip history
2.1 KiB
1# shellcheck shell=bash
2# Paths and fixtures come from the derivation environment.
3# shellcheck disable=SC2154
4cue vet -c "$schema" "$statements/pure.json"
5cue vet -c "$schema" "$statements/effectful.json"
6
7# Each rejected statement is a pure, effectful or transfer statement with a
8# single thing wrong; the file name says which.
9for bad in "$statements"/rejected/*.json; do
10 name="$(basename "$bad" .json)"
11 if cue vet -c "$schema" "$bad" > "$name.err" 2>&1; then
12 echo "attest-schema: expected invalid statement '$name' to be rejected" >&2
13 exit 1
14 fi
15done
16
17# A map whose keys come from a caller is written as
18# #SegmentKeyed. A field's name is written into the key that
19# names its line, so a name holding the dot that separates
20# segments, the space that separates key from value, or
21# anything a line cannot carry is a statement with no written
22# form. It fails vet rather than reaching a signer.
23cue vet -d '#SegmentKeyed' "$schema" "$statements/segment-keys.json"
24for bad in "$statements"/rejected-keys/*.json; do
25 name="$(basename "$bad" .json)"
26 if cue vet -d '#SegmentKeyed' "$schema" "$bad" > "$name.err" 2>&1; then
27 echo "attest-schema: expected the key in '$name' to be rejected" >&2
28 exit 1
29 fi
30 grep -q 'field not allowed' "$name.err"
31done
32
33# A rejection that does not name the field leaves the reader
34# to find the breakage themselves.
35grep -q 'signature: conflicting values' signature-in-statement.err
36grep -q 'subject.digest."valley-tree-v1"' no-content-addressed-subject.err
37grep -q 'predicate.environment: field not allowed' effectful-claiming-pure.err
38grep -q 'predicate.check.command' command-over-two-lines.err
39# A transfer statement says what the policy required exactly one
40# way: a check list with something in it, or `required: "none"`.
41# An empty list is the shape that vets and cannot be signed —
42# it has no lines, so it has no written form — so it has to fail
43# here, where a composer meets it, rather than in the renderer
44# after a ref has moved.
45grep -q 'predicate.checks' transfer-with-an-empty-check-list.err
46grep -q 'predicate.checks' transfer-both-required-and-checks.err
47touch "$out"