gunk-dev/the-valley

identity-e2e.sh

source6e46ef4e1f41main's published tip history
4.8 KiB
1# shellcheck shell=bash
2# Paths and fixtures come from the derivation environment.
3# shellcheck disable=SC2154
4export HOME="$TMPDIR"
5export GIT_CONFIG_NOSYSTEM=1
6git config --global user.name valley-check
7git config --global user.email valley-check@localhost
8git config --global init.defaultBranch main
9cd "$TMPDIR" || exit 1
10
11# A bare instance repository, holding one registry at its tip โ€” what a host
12# serves and what the compiler reads.
13serve() {
14 local name="$1" source="$2"
15 rm -rf work "$name.git"
16 git init --quiet --bare "$name.git"
17 git init --quiet work
18 mkdir -p work/identity
19 cp "$source"/*.cue work/identity/
20 chmod u+w work/identity/*.cue
21 git -C work add -A
22 git -C work commit --quiet -m "$name"
23 git -C work push --quiet "$TMPDIR/$name.git" main
24}
25
26compile() {
27 identity compile --repo "$TMPDIR/instance.git" \
28 --known-signers "$TMPDIR/signers" --authorized-keys "$TMPDIR/keys" "$@"
29}
30
31# The worked registry compiles to exactly the artifacts checked in beside
32# it. This is the whole claim of the compiler, and the artifacts it replaces
33# were written by hand โ€” so the comparison is byte for byte.
34serve instance "$registry"
35compile --now 2026-08-09 2> first.log || exit 1
36diff -u "$compiled/known-signers" "$TMPDIR/signers" || exit 1
37diff -u "$compiled/authorized_keys" "$TMPDIR/keys" || exit 1
38
39# Level-triggered: compiling again converges on the same bytes and touches
40# nothing.
41compile --now 2026-08-09 2> second.log || exit 1
42if ! grep -q "unchanged" second.log; then
43 echo "identity-e2e: a second compilation of an unchanged registry rewrote its artifacts" >&2
44 cat second.log >&2
45 exit 1
46fi
47
48# The registry is read from the integrated tip and from nowhere else, which
49# is the whole of the forcing: an edit on a branch governs nothing.
50git -C work checkout --quiet -b topic
51cp "$expired"/*.cue work/identity/registry.cue
52git -C work commit --quiet -am topic
53git -C work push --quiet "$TMPDIR/instance.git" topic
54compile --now 2026-08-09 || exit 1
55diff -u "$compiled/known-signers" "$TMPDIR/signers" || exit 1
56
57# The compiled verifier line is the one attest writes. The published keys
58# above pin the format against a fixed vector; this pins it against the
59# implementation that reads it, over a key generated here.
60ssh-keygen -q -t ed25519 -N "" -C valley-check -f "$TMPDIR/scratch"
61mkdir -p scratch-registry
62{
63 echo 'package identity'
64 echo 'boundaries: "registry": kind: "registry"'
65 echo 'genesis: "someone"'
66 echo 'principals: "someone": {'
67 echo ' kind: "human"'
68 echo ' keys: [{'
69 echo ' class: "ssh-ed25519"'
70 echo ' bound: "hardware"'
71 printf '\t\tpublic: "%s"\n' "$(cut -d' ' -f1,2 < "$TMPDIR/scratch.pub")"
72 echo ' signs: "someone/attestations"'
73 echo ' }]'
74 echo ' grants: govern: boundary: "registry"'
75 echo '}'
76} > scratch-registry/registry.cue
77serve instance scratch-registry
78compile --now 2026-08-09 || exit 1
79attest key --key "$TMPDIR/scratch" --name "someone/attestations" > expected-line
80if ! grep -qxFf expected-line "$TMPDIR/signers"; then
81 echo "identity-e2e: the compiled verifier key is not the line attest writes" >&2
82 cat expected-line "$TMPDIR/signers" >&2
83 exit 1
84fi
85
86# An entry past its expiry leaves both artifacts, says so, and costs the
87# rest of the registry nothing. The day before, it is still there โ€” the
88# declared day is the first day the entry no longer counts.
89serve instance "$expired"
90compile --now 2026-09-30 || exit 1
91grep -q "stoned-flynn/attestations" "$TMPDIR/signers" || {
92 echo "identity-e2e: an unexpired entry was omitted" >&2
93 exit 1
94}
95compile --now 2026-11-01 2> expired.log || exit 1
96if grep -q "stoned-flynn" "$TMPDIR/signers" "$TMPDIR/keys"; then
97 echo "identity-e2e: an expired entry stayed in the compiled artifacts" >&2
98 cat "$TMPDIR/signers" "$TMPDIR/keys" >&2
99 exit 1
100fi
101if ! grep -q "stoned-flynn expired 2026-10-01" expired.log; then
102 echo "identity-e2e: an expired entry was dropped without saying so" >&2
103 cat expired.log >&2
104 exit 1
105fi
106grep -q "patrick" "$TMPDIR/keys" || {
107 echo "identity-e2e: one expired entry took the rest of the registry with it" >&2
108 exit 1
109}
110
111# The fail-safe. An invalid registry must cost the compilation and nothing
112# else: the last good artifacts are what the gates keep reading, because a
113# compiler bug that emptied them would lock the git user out of the host.
114cp "$TMPDIR/signers" last-good-signers
115cp "$TMPDIR/keys" last-good-keys
116mkdir -p invalid-registry
117cp "$invalid" invalid-registry/registry.cue
118serve instance invalid-registry
119if compile --now 2026-08-09 2> refused.log; then
120 echo "identity-e2e: an invalid registry compiled" >&2
121 exit 1
122fi
123if ! grep -q "externalGovernance" refused.log; then
124 echo "identity-e2e: the refusal did not name the field that failed" >&2
125 cat refused.log >&2
126 exit 1
127fi
128diff -u last-good-signers "$TMPDIR/signers" || exit 1
129diff -u last-good-keys "$TMPDIR/keys" || exit 1
130
131touch "$out"