gunk-dev/the-valley

run.sh

source5c89ed8769dbmain's published tip history
79.3 KiB
1#!/usr/bin/env bash
2# The integrator, driven end to end over scratch repositories and throwaway
3# keys. It runs the real binaries: `attest` produces the evidence, the
4# `valley` deriver composes the policy, and the `integrator` judges and
5# lands. Only the nix evaluator is stood in for (integrator/e2e/nix), and
6# only because a nix build has no daemon to call.
7#
8# Each scenario below is one of the phase's exit criteria, observed rather
9# than asserted about. Nothing here touches a repository outside its own
10# scratch directory, and no ref is ever created anywhere but there.
11set -euo pipefail
12
13work="$(mktemp -d)"
14trap 'rm -rf "$work"' EXIT
15here="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
16
17export HOME="$work"
18export GIT_CONFIG_NOSYSTEM=1
19# Scratch goes where the run puts it, as it does under the unit, so what
20# a pass leaves behind is observable rather than scattered through /tmp.
21export TMPDIR="$work/tmp"
22mkdir -p "$TMPDIR"
23export VALLEY_FAKE_STORE="$work/store"
24export PATH="$here:$PATH" # the nix stand-ins, ahead of anything real
25
26git config --global user.name valley-check
27git config --global user.email valley-check@localhost
28git config --global init.defaultBranch main
29git config --global advice.detachedHead false
30
31say() { printf '\n=== %s\n' "$*"; }
32die() {
33 printf '\nintegrator-e2e: %s\n' "$*" >&2
34 exit 1
35}
36holds() { printf ' ok: %s\n' "$*"; }
37
38# ----------------------------------------------------------------------
39say "keys: a contributor, an integrator, and a stranger"
40
41for who in contributor integrator stranger; do
42 ssh-keygen -q -t ed25519 -N "" -C "$who" -f "$work/$who"
43done
44contributor=contributor.valley.invalid/attestations
45integrator_name=integrator.valley.invalid/attestations
46stranger=stranger.elsewhere.invalid/attestations
47
48# The known-signers file is the registry's interim compilation
49# (dcr-b87f6e8): the integrator accepts the contributor and nobody else.
50attest key --key "$work/contributor" --name "$contributor" > "$work/known_signers"
51# What a reader of a landed note holds: both parties to it.
52cat "$work/known_signers" > "$work/reader_keys"
53attest key --key "$work/integrator" --name "$integrator_name" >> "$work/reader_keys"
54attest key --key "$work/stranger" --name "$stranger" > "$work/stranger_key"
55# The key hash the integrator's own attestation refs are keyed by.
56ihash="$(attest key --key "$work/integrator" --name "$integrator_name" | cut -d+ -f2)"
57holds "the integrator holds one signer: $(cut -d+ -f1 < "$work/known_signers")"
58
59# ----------------------------------------------------------------------
60say "the served repository, and the instance policy layer"
61
62origin="$work/project.git"
63git init --quiet --bare "$origin"
64repo="$work/project"
65git init --quiet "$repo"
66cd "$repo"
67git remote add origin "$origin"
68
69mkdir -p docs src deploy checks policy/project
70echo "the readme" > docs/readme.md
71echo "the source" > src/main.txt
72echo "the deployment" > deploy/target.txt
73# What each check reads, which the nix stand-in turns into its closure.
74echo docs > checks/prose-format.inputs
75echo src > checks/code-build.inputs
76
77# The project layer: it declares its own classes and checks above the
78# floor, and declines nothing. It sits at policy/project, which is where the
79# integrator looks without being told (dcr-f41f718).
80cat > policy/project/policy.cue <<'EOF'
81package verification
82
83project: {
84 checks: {
85 "prose-format": {runner: "nix", attribute: "prose-format"}
86 "code-build": {runner: "nix", attribute: "code-build"}
87 // An effectful check, with the validity window dcr-439b771 calls
88 // Δ. Its observation transfers while nothing in the class that
89 // requires it has landed under it and it is younger than this.
90 reachable: {runner: "command", command: "true", validity: "1h"}
91 }
92 classes: {
93 prose: {paths: "docs/**": true, requires: "prose-format": true}
94 code: {paths: "src/**": true, requires: "code-build": true}
95 deploy: {paths: "deploy/**": true, requires: reachable: true}
96 }
97 unclassified: {}
98}
99EOF
100
101git add -A
102git commit --quiet -m "seed the project"
103git push --quiet origin main
104
105# The instance layer lives outside the project's tree, and the integrator
106# reads it from there: a change never supplies the policy that gates it. The
107# floor is the group's own repository's, read at the tip that has been
108# integrated (dcr-f41f718), and it sits at policy/instance in that tip.
109instance_repo="$work/instance.git"
110git init --quiet --bare "$instance_repo"
111floor="$work/instance-project"
112git init --quiet "$floor"
113mkdir -p "$floor/policy/instance"
114cat > "$floor/policy/instance/floor.cue" <<'EOF'
115package verification
116
117floor: {
118 checks: {}
119 classes: {}
120 unclassified: {}
121}
122EOF
123git -C "$floor" add -A
124git -C "$floor" commit --quiet -m "seed the floor"
125git -C "$floor" push --quiet "$instance_repo" main
126
127# The fallback source, for a host that serves no instance repository: the
128# same documents, materialized as a directory. One scenario below reads the
129# floor that way, and every other reads it from the repository.
130instance="$work/instance"
131mkdir -p "$instance"
132cp "$floor/policy/instance/floor.cue" "$instance/floor.cue"
133
134holds "the floor is policy/instance at $instance_repo's tip, and the project's layer is policy/project at its own"
135
136# ----------------------------------------------------------------------
137# Helpers.
138
139# attest_change <branch> <check spec…> — run the checks over the branch's
140# tip and publish the branch with its attestation ref, atomically.
141attest_change() {
142 local branch="$1" key="${2:-$work/contributor}" name="${3:-$contributor}"
143 shift 3
144 attest run --repo "$repo" --key "$key" --name "$name" \
145 --push origin --branch "$branch" "$@"
146}
147
148# request <change> <target> <commit> — the contributor files an integration
149# request by pushing one ref. That ref is the whole of the request.
150request() {
151 git push --quiet origin "$3:refs/the-valley/integration-requests/$2/$1"
152}
153
154# reconcile [flag…] — one pass. A flag given here overrides the one set
155# before it.
156reconcile() {
157 # Neither policy path is stated: both layers come from where the
158 # integrator defaults to looking, which is the whole of what a deployment
159 # following the convention says about policy.
160 integrator reconcile \
161 --repo "$origin" \
162 --key "$work/integrator" --name "$integrator_name" \
163 --known-signers "$work/known_signers" \
164 --instance-repo "$instance_repo" \
165 --schema "$SCHEMA_VERIFICATION" \
166 --attest-schema "$SCHEMA_ATTESTATION" \
167 --event-schema "$SCHEMA_EVENTS" \
168 ${VALLEY_E2E_NOW:+--now "$VALLEY_E2E_NOW"} \
169 "$@"
170}
171
172integrate() {
173 reconcile "$@" 2>&1 | tee "$work/last.out"
174 grep -q . "$work/last.out" || die "the integrator said nothing"
175}
176
177tip() { git -C "$origin" rev-parse refs/heads/main; }
178forget() { git -C "$origin" update-ref -d "refs/the-valley/integration-requests/main/$1"; }
179
180# ----------------------------------------------------------------------
181say "1. a change with valid transferring evidence lands"
182
183before="$(tip)"
184git checkout --quiet -b c1
185echo "a better readme" > docs/readme.md
186echo "a new target" > deploy/second.txt
187git add -A
188git commit --quiet -m "improve the readme and add a target"
189attest_change c1 "" "" --check prose-format --command reachable=true
190request c1 main "$(git rev-parse c1)"
191integrate
192
193grep -q "^c1 -> refs/heads/main .*: land$" "$work/last.out" || die "c1 did not land"
194grep -q "check prose-format .*transferred" "$work/last.out" || die "prose-format did not transfer"
195grep -q "check reachable .*transferred (untouched)" "$work/last.out" || die "the effectful check did not transfer"
196grep -q '"event":"integration-succeeded"' "$work/last.out" || die "no integration-succeeded event"
197# The landing's own ref-updated event, vetted against #RefUpdated like the rest.
198grep -qF "event ref-updated {\"event\":\"ref-updated\",\"repo\":" "$work/last.out" \
199 || die "no ref-updated event"
200[ "$(tip)" != "$before" ] || die "the protected ref did not move"
201[ "$(tip)" = "$(git rev-parse c1)" ] || die "main is not at the change's head"
202git -C "$origin" rev-parse --verify --quiet refs/the-valley/integration-requests/main/c1 > /dev/null \
203 && die "the request ref outlived the landing"
204holds "main moved $(git rev-parse --short "$before") -> $(git -C "$origin" rev-parse --short refs/heads/main)"
205
206# The decision is followed by one timing line: JSON after a fixed label,
207# naming the request and what was decided, with the time each stage took.
208# Every stage a landing reaches is there, as a whole number of
209# milliseconds, and the stages add up to no more than the whole.
210[ "$(grep -c '^ timing ' "$work/last.out")" = 1 ] || die "one decision did not print exactly one timing line"
211timing="$(sed -n 's/^ timing //p' "$work/last.out")"
212jq -e --arg head "$(git rev-parse c1)" --arg tip "$before" '
213 keys == ["change", "duration_ms", "head", "outcome", "project", "request", "stages_ms", "target", "time", "tip"]
214 and .request == "refs/the-valley/integration-requests/main/c1" and .change == "c1"
215 and .head == $head and .target == "refs/heads/main" and .tip == $tip and .outcome == "land"
216 and (.project | type == "string" and length > 0)
217 and (.time | type == "string" and test("^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}[.][0-9]{3}Z$"))
218 and (.duration_ms | type == "number" and . >= 0 and . == floor)
219 and (.stages_ms | type == "object"
220 and (keys - ["refusal", "checkout", "evidence", "policy", "apply", "closures", "sign", "land", "record", "publish"] == [])
221 and all(.refusal, .checkout, .evidence, .policy, .sign, .land, .record, .publish; type == "number")
222 and all(.[]; type == "number" and . >= 0 and . == floor))
223 and ([.stages_ms[]] | add) <= .duration_ms' <<< "$timing" > /dev/null \
224 || die "c1's timing line does not say what a landing's should: $timing"
225holds "the landing is timed: $timing"
226
227# The landed note carries both signatures, under one text, and verifies.
228# The integrator writes under its own key hash, so its ref never races the
229# contributor's over the same subject.
230landed="refs/the-valley/attestations/$(attest digest --repo "$repo" --rev c1 | cut -d: -f2)/$ihash"
231git -C "$origin" rev-parse --verify --quiet "$landed" > /dev/null \
232 || die "no attestation ref by the integrator for the landed tree"
233git -C "$origin" cat-file blob "$landed:prose-format/statement.note" > "$work/landed.note"
234siblings="$(grep -c '^— ' "$work/landed.note")"
235[ "$siblings" -eq 2 ] || die "the landed note carries $siblings signatures, not two"
236attest verify --note "$work/landed.note" --known-keys "$work/reader_keys" \
237 --schema "$SCHEMA_ATTESTATION" --repo "$repo" --rev c1 \
238 --signer "$contributor" --signer "$integrator_name" > "$work/landed.verify"
239grep -q 'matches the recorded subject digest' "$work/landed.verify" || die "the landed note does not bind to the tree"
240holds "the landed note carries contributor and integrator sibling signatures and verifies"
241
242# And the integrator's own transfer statement sits beside it.
243git -C "$origin" cat-file blob "$landed:transfer.note" > "$work/transfer.note"
244head -n1 "$work/transfer.note" | grep -qx 'the-valley/attestation/v1' || die "the transfer note is not a statement"
245grep -qx 'predicateType the-valley/integration/transfer/v1' "$work/transfer.note" || die "wrong predicate type"
246grep -qx 'predicate.change c1' "$work/transfer.note" || die "the transfer statement names no change"
247grep -q '^predicate.policy.sha256 ' "$work/transfer.note" || die "the transfer statement names no policy"
248attest verify --note "$work/transfer.note" --known-keys "$work/reader_keys" \
249 --schema "$SCHEMA_ATTESTATION" --signer "$integrator_name" > /dev/null
250holds "the transfer statement records the verdict and the policy it was derived under"
251
252# ----------------------------------------------------------------------
253say "2. an intervening landing invalidates one check's closure"
254
255git checkout --quiet main
256git pull --quiet --ff-only origin main
257
258# c2 is authored against the current tip and reads both classes.
259git checkout --quiet -b c2
260echo "a readme with more in it" > docs/readme.md
261echo "the source, revised" > src/main.txt
262git add -A
263git commit --quiet -m "revise the readme and the source"
264attest_change c2 "" "" --check prose-format --check code-build
265c2="$(git rev-parse c2)"
266
267# Meanwhile another change lands, touching only what code-build reads.
268git checkout --quiet main
269git checkout --quiet -b intervening
270echo "a second source file" > src/other.txt
271git add -A
272git commit --quiet -m "add a second source file"
273attest_change intervening "" "" --check code-build
274request intervening main "$(git rev-parse intervening)"
275integrate
276grep -q "^intervening -> refs/heads/main .*: land$" "$work/last.out" || die "the intervening change did not land"
277holds "the intervening change landed first; c2's base has moved"
278
279request c2 main "$c2"
280integrate
281grep -q "^c2 -> refs/heads/main .*: stale$" "$work/last.out" || die "c2 was not stale"
282grep -q "check prose-format .*transferred (closure)" "$work/last.out" \
283 || die "prose-format should have transferred by closure equality"
284grep -q "check code-build .*input closure changed" "$work/last.out" \
285 || die "code-build's closure should have moved"
286grep -q '"event":"request-stale"' "$work/last.out" || die "no request-stale event"
287grep -q '"checks":\["code-build"\]' "$work/last.out" || die "the event does not name exactly code-build"
288git -C "$origin" rev-parse --verify --quiet refs/the-valley/integration-requests/main/c2 > /dev/null \
289 || die "the request ref was dropped; there is nothing to approve again"
290holds "one request-stale naming exactly code-build; prose-format reported transferred"
291forget c2
292
293# ----------------------------------------------------------------------
294say "2b. evidence that survives the rebase lands on the moved tip"
295
296# The same shape as 2, with the intervening landing outside what the
297# change's checks read. The tree that lands is not the tree that was
298# attested, and the evidence stands anyway — which is the whole of what
299# content-addressed evidence buys.
300git checkout --quiet main
301git pull --quiet --ff-only origin main
302git checkout --quiet -b c2b
303echo "a readme revised again" > docs/readme.md
304git add -A
305git commit --quiet -m "revise the readme once more"
306attest_change c2b "" "" --check prose-format
307c2b="$(git rev-parse c2b)"
308attested="$(attest digest --repo "$repo" --rev c2b | cut -d: -f2)"
309
310git checkout --quiet main
311git checkout --quiet -b elsewhere
312echo "a third source file" > src/third.txt
313git add -A
314git commit --quiet -m "add a third source file"
315attest_change elsewhere "" "" --check code-build
316request elsewhere main "$(git rev-parse elsewhere)"
317integrate
318grep -q "^elsewhere -> refs/heads/main .*: land$" "$work/last.out" || die "the intervening change did not land"
319
320request c2b main "$c2b"
321integrate
322grep -q "^c2b -> refs/heads/main .*: land$" "$work/last.out" || die "c2b did not land"
323grep -q "check prose-format .*transferred (closure)" "$work/last.out" \
324 || die "the evidence did not transfer by closure equality"
325landedtree="$(git -C "$origin" rev-parse refs/heads/main^{tree})"
326[ "$(git -C "$origin" rev-parse "refs/heads/main^")" = "$(git rev-parse elsewhere)" ] \
327 || die "the landing is not a fast-forward from the tip it was judged against"
328[ "$(git -C "$origin" rev-parse refs/heads/main^{tree})" != "$(git rev-parse "$c2b^{tree}")" ] \
329 || die "the tree did not actually move; the scenario proves nothing"
330holds "the delta landed on a tree it was never attested over, and no check re-ran"
331
332# Two attestation refs now, because the two statements are about two
333# different trees: the contributor's is keyed by the tree it was made over,
334# and the integrator's transfer statement by the tree that landed.
335git fetch --quiet origin main
336landed_digest="$(attest digest --repo "$repo" --rev "$(git -C "$origin" rev-parse refs/heads/main)" | cut -d: -f2)"
337[ "$landed_digest" != "$attested" ] || die "the landed tree is the attested tree; the scenario proves nothing"
338git -C "$origin" cat-file blob \
339 "refs/the-valley/attestations/$attested/$ihash:prose-format/statement.note" > "$work/rebased.note"
340[ "$(grep -c '^— ' "$work/rebased.note")" -eq 2 ] \
341 || die "the countersigned note lost a sibling signature"
342grep -qx "subject.digest.valley-tree-v1 $attested" "$work/rebased.note" \
343 || die "the countersigned statement is not about the tree it was made over"
344git -C "$origin" cat-file blob \
345 "refs/the-valley/attestations/$landed_digest/$ihash:transfer.note" > "$work/rebased.transfer"
346grep -qx "subject.digest.valley-tree-v1 $landed_digest" "$work/rebased.transfer" \
347 || die "the transfer statement is not about the landed tree"
348grep -qx "predicate.base.valley-tree-v1 $attested" "$work/rebased.transfer" \
349 || die "the transfer statement does not cite the base the evidence was produced over"
350grep -qx "predicate.checks.0.rule closure" "$work/rebased.transfer" \
351 || die "the transfer statement does not record the rule that carried the evidence"
352holds "the contributor's statement stays about its own tree; the transfer statement names the landed one"
353
354# ----------------------------------------------------------------------
355say "2c. a re-parenting landing states its own committer, and needs none from the environment"
356
357# Re-parenting is the one landing that makes a commit of the integrator's
358# own, so it is the one that needs a committer. Under the unit there is
359# nothing to take one from: no git config the service can read, no GIT_* in
360# its environment, and a hostname git will not guess an address from. So the
361# integrator states both identities itself — the asker authored the change,
362# the integrator committed the commit that carries it onto the tip — and the
363# pass below runs with everything git could have fallen back to taken away.
364
365# A scrubbed environment: no global or system config, no GIT_* identity, and
366# auto-detection refused outright, so that a host whose own hostname does
367# resolve cannot hide a dependency on it.
368scrubbed() {
369 env -u GIT_AUTHOR_NAME -u GIT_AUTHOR_EMAIL -u GIT_AUTHOR_DATE \
370 -u GIT_COMMITTER_NAME -u GIT_COMMITTER_EMAIL -u GIT_COMMITTER_DATE -u EMAIL \
371 GIT_CONFIG_GLOBAL=/dev/null GIT_CONFIG_NOSYSTEM=1 \
372 GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=user.useConfigOnly GIT_CONFIG_VALUE_0=true \
373 "$@"
374}
375scrubbed git -C "$origin" var GIT_COMMITTER_IDENT > /dev/null 2>&1 \
376 && die "the scrub left an identity for git to find; the scenario proves nothing"
377
378git checkout --quiet main
379git pull --quiet --ff-only origin main
380git checkout --quiet -b c2c
381echo "a readme revised by a stated author" > docs/readme.md
382git add -A
383# A distinct author, so that what the landed commit carries over from the
384# head and what it states of its own are told apart by reading it.
385GIT_AUTHOR_NAME="a contributor" GIT_AUTHOR_EMAIL="contributor@valley.invalid" \
386 git commit --quiet -m "revise the readme under an author of its own"
387attest_change c2c "" "" --check prose-format
388c2c="$(git rev-parse c2c)"
389
390# The intervening landing, outside what prose-format reads, is what moves
391# c2c's base and makes the landing below a re-parent rather than a
392# fast-forward.
393git checkout --quiet main
394git checkout --quiet -b under-c2c
395echo "a fifth source file" > src/fifth.txt
396git add -A
397git commit --quiet -m "add a fifth source file"
398attest_change under-c2c "" "" --check code-build
399request under-c2c main "$(git rev-parse under-c2c)"
400integrate
401grep -q "^under-c2c -> refs/heads/main .*: land$" "$work/last.out" || die "the intervening change did not land"
402
403request c2c main "$c2c"
404scrubbed integrator reconcile \
405 --repo "$origin" \
406 --key "$work/integrator" --name "$integrator_name" \
407 --known-signers "$work/known_signers" \
408 --instance-repo "$instance_repo" \
409 --schema "$SCHEMA_VERIFICATION" \
410 --attest-schema "$SCHEMA_ATTESTATION" \
411 --event-schema "$SCHEMA_EVENTS" \
412 ${VALLEY_E2E_NOW:+--now "$VALLEY_E2E_NOW"} \
413 2>&1 | tee "$work/last.out"
414grep -q "^c2c -> refs/heads/main .*: land$" "$work/last.out" \
415 || die "a landing with no git identity in the environment did not land: $(cat "$work/last.out")"
416
417landed_commit="$(git -C "$origin" rev-parse refs/heads/main)"
418[ "$landed_commit" != "$c2c" ] || die "the landing was a fast-forward; the scenario proves nothing"
419[ "$(git -C "$origin" log -1 --format='%an <%ae>' "$landed_commit")" = "a contributor <contributor@valley.invalid>" ] \
420 || die "the landed commit is not authored by the asker: $(git -C "$origin" log -1 --format='%an <%ae>' "$landed_commit")"
421[ "$(git -C "$origin" log -1 --format='%cn <%ce>' "$landed_commit")" = "$integrator_name <integrator@the-valley.invalid>" ] \
422 || die "the landed commit is not committed by the integrator: $(git -C "$origin" log -1 --format='%cn <%ce>' "$landed_commit")"
423# The commit id is a function of what the pass decided from and nothing
424# else, so a pass that dies before the ref write recomputes this same
425# commit rather than leaving another behind.
426[ "$(git -C "$origin" log -1 --format=%aI "$landed_commit")" = "$(git -C "$origin" log -1 --format=%cI "$landed_commit")" ] \
427 || die "the committer date is not the author's, so the landed commit id is not reproducible"
428holds "the integrator committed under its own name with nothing in the environment to take one from"
429
430# ----------------------------------------------------------------------
431say "3. a conflicting delta is stale, and demands full re-attestation"
432
433git checkout --quiet main
434git pull --quiet --ff-only origin main
435git checkout --quiet -b c3
436echo "the readme, as c3 would have it" > docs/readme.md
437git add -A
438git commit --quiet -m "rewrite the readme one way"
439attest_change c3 "" "" --check prose-format
440c3="$(git rev-parse c3)"
441
442git checkout --quiet main
443git checkout --quiet -b conflicting
444echo "the readme, as the other change would have it" > docs/readme.md
445git add -A
446git commit --quiet -m "rewrite the readme another way"
447attest_change conflicting "" "" --check prose-format
448request conflicting main "$(git rev-parse conflicting)"
449integrate
450grep -q "^conflicting -> refs/heads/main .*: land$" "$work/last.out" || die "the conflicting change did not land"
451
452request c3 main "$c3"
453integrate
454grep -q "^c3 -> refs/heads/main .*: stale$" "$work/last.out" || die "c3 was not stale"
455grep -q 'resolving it is new authorship' "$work/last.out" || die "the conflict was not reported as new authorship"
456grep -q 'CONFLICT (content): Merge conflict in docs/readme.md' "$work/last.out" \
457 || die "the conflict does not name what could not be merged"
458grep -q '"reason":"conflict"' "$work/last.out" || die "the event does not say conflict"
459grep -q '"checks":\["prose-format"\]' "$work/last.out" || die "a conflict must re-demand every required check"
460holds "a conflict is stale, and every required check is re-demanded"
461forget c3
462
463# ----------------------------------------------------------------------
464say "4. an unknown signer's attestation does not transfer"
465
466git checkout --quiet main
467git pull --quiet --ff-only origin main
468git checkout --quiet -b c4
469echo "a readme signed by a stranger" > docs/readme.md
470git add -A
471git commit --quiet -m "a change a stranger attested"
472attest_change c4 "$work/stranger" "$stranger" --check prose-format
473request c4 main "$(git rev-parse c4)"
474integrate
475grep -q "^c4 -> refs/heads/main .*: stale$" "$work/last.out" || die "c4 was not stale"
476grep -q 'no signer the integrator holds' "$work/last.out" || die "the unknown signer was not reported"
477grep -q '"checks":\["prose-format"\]' "$work/last.out" || die "the event does not name prose-format"
478[ "$(tip)" = "$(git -C "$origin" rev-parse refs/heads/main)" ] || die "main moved"
479holds "evidence from a signer the integrator does not hold does not transfer"
480forget c4
481
482# ----------------------------------------------------------------------
483say "5. a tampered statement is rejected, not called stale"
484
485git checkout --quiet main
486git checkout --quiet -b c5
487echo "an honest readme" > docs/readme.md
488git add -A
489git commit --quiet -m "an honest change"
490attest_change c5 "" "" --check prose-format
491c5="$(git rev-parse c5)"
492c5digest="$(attest digest --repo "$repo" --rev c5 | cut -d: -f2)"
493
494# Edit one value in the signed text and store the result where the real
495# note was. Everything else about the note is untouched.
496c5ref="$(git -C "$origin" for-each-ref --format='%(refname)' \
497 "refs/the-valley/attestations/$c5digest" | head -n1)"
498git -C "$origin" cat-file blob "$c5ref:prose-format/statement.note" \
499 | sed 's/^predicate.result passed$/predicate.result failed/' > "$work/tampered.note"
500cmp -s "$work/tampered.note" <(git -C "$origin" cat-file blob "$c5ref:prose-format/statement.note") \
501 && die "the tamper changed nothing; the test proves nothing"
502blob="$(git -C "$origin" hash-object -w --stdin < "$work/tampered.note")"
503sub="$(printf '100644 blob %s\tstatement.note\n' "$blob" | git -C "$origin" mktree)"
504top="$(printf '040000 tree %s\tprose-format\n' "$sub" | git -C "$origin" mktree)"
505git -C "$origin" update-ref "$c5ref" "$top"
506
507request c5 main "$c5"
508integrate
509grep -q "^c5 -> refs/heads/main .*: reject$" "$work/last.out" || die "a tampered statement was not rejected"
510grep -q 'does not verify as the statement it claims to be' "$work/last.out" || die "the refusal was not reported"
511grep -q 'request-stale' "$work/last.out" && die "a forgery was announced as staleness"
512holds "a tampered statement is a rejection, and no outcome event claims otherwise"
513forget c5
514
515# ----------------------------------------------------------------------
516say "6. an attestation about a different tree is rejected"
517
518git checkout --quiet main
519git checkout --quiet -b c6
520echo "the tree that was actually attested" > docs/readme.md
521git add -A
522git commit --quiet -m "the attested change"
523attest_change c6 "" "" --check prose-format
524c6ref="$(git -C "$origin" for-each-ref --format='%(refname)' \
525 "refs/the-valley/attestations/$(attest digest --repo "$repo" --rev c6 | cut -d: -f2)" | head -n1)"
526
527# A second, different tree — with no attestation of its own — and the
528# first tree's valid, correctly signed note filed under its digest.
529git checkout --quiet -b c6-lifted
530echo "the tree that was not" > docs/readme.md
531git add -A
532git commit --quiet -m "the change the evidence was lifted onto"
533git push --quiet origin c6-lifted
534lifted="$(attest digest --repo "$repo" --rev c6-lifted | cut -d: -f2)"
535git -C "$origin" update-ref \
536 "refs/the-valley/attestations/$lifted/${c6ref##*/}" \
537 "$(git -C "$origin" rev-parse "$c6ref^{tree}")"
538
539request c6 main "$(git rev-parse c6-lifted)"
540integrate
541grep -q "^c6 -> refs/heads/main .*: reject$" "$work/last.out" || die "a lifted attestation was not rejected"
542grep -q 'tree digest mismatch' "$work/last.out" || die "the refusal does not name the tree digest"
543holds "a signature cannot be lifted onto a tree it was not made about"
544forget c6
545
546# ----------------------------------------------------------------------
547say "7. an attestation lying about its kind is rejected"
548
549# The policy runs prose-format with nix, so its evidence is content-
550# addressed. This attestation claims a notarization instead, and its class
551# was untouched by the intervening landing — so under the rule it nominated
552# for itself it would sail onto a base it was never produced over.
553git checkout --quiet main
554git pull --quiet --ff-only origin main
555git checkout --quiet -b c7
556echo "a readme attested as a notarization" > docs/readme.md
557git add -A
558git commit --quiet -m "a change whose attestation lies about its kind"
559attest_change c7 "" "" --command prose-format=true
560c7="$(git rev-parse c7)"
561
562git checkout --quiet main
563git checkout --quiet -b under-c7
564echo "a fourth source file" > src/fourth.txt
565git add -A
566git commit --quiet -m "add a fourth source file"
567attest_change under-c7 "" "" --check code-build
568request under-c7 main "$(git rev-parse under-c7)"
569integrate
570grep -q "^under-c7 -> refs/heads/main .*: land$" "$work/last.out" || die "the intervening change did not land"
571
572request c7 main "$c7"
573integrate
574grep -q "^c7 -> refs/heads/main .*: reject$" "$work/last.out" || die "a lie about the kind was not rejected"
575grep -q 'requires a pure check and the attestation claims an effectful check' "$work/last.out" \
576 || die "the refusal does not say the policy decides the rule"
577holds "the transfer rule follows the policy's runner, never the attestation's own claim"
578forget c7
579
580# ----------------------------------------------------------------------
581say "8. evidence pushed after a no-evidence verdict re-judges and lands"
582
583git checkout --quiet main
584git pull --quiet --ff-only origin main
585git checkout --quiet -b c8
586echo "a readme with no evidence yet" > docs/readme.md
587git add -A
588git commit --quiet -m "a change submitted before its checks ran"
589git push --quiet origin c8
590request c8 main "$(git rev-parse c8)"
591integrate
592grep -q "^c8 -> refs/heads/main .*: stale$" "$work/last.out" || die "a change with no evidence was not stale"
593grep -q 'no attestation for this check accompanies the change' "$work/last.out" \
594 || die "the absent attestation was not reported"
595
596# Nothing about the request or the tip moves; only the evidence arrives.
597attest_change c8 "" "" --check prose-format
598integrate
599grep -q "^c8 -> refs/heads/main .*: land$" "$work/last.out" \
600 || die "the request was not re-judged after its evidence arrived"
601[ "$(tip)" = "$(git rev-parse c8)" ] || die "main is not at the change's head"
602holds "a pass re-judges when evidence arrives, with the request and the tip unmoved"
603
604# ----------------------------------------------------------------------
605say "9. a ref that is not a request does not hold up one that is"
606
607git checkout --quiet main
608git pull --quiet --ff-only origin main
609git checkout --quiet -b c9
610echo "a readme beside a garbage ref" > docs/readme.md
611git add -A
612git commit --quiet -m "a change beside a malformed request"
613attest_change c9 "" "" --check prose-format
614# A name with no target segment at all, and one with a segment too many.
615# This repository is served with no pre-receive hook, so the namespace takes
616# whatever is pushed; on a host only a holder of the request grant writes
617# it, and a holder can still write a name that is not a request.
618git push --quiet origin "$(git rev-parse c9):refs/the-valley/integration-requests/garbage"
619git push --quiet origin "$(git rev-parse c9):refs/the-valley/integration-requests/main/too/deep"
620request c9 main "$(git rev-parse c9)"
621integrate
622grep -q 'refs/the-valley/integration-requests/garbage: not a request ref' "$work/last.out" \
623 || die "the malformed ref was not reported"
624grep -q 'refs/the-valley/integration-requests/main/too/deep: not a request ref' "$work/last.out" \
625 || die "the over-deep ref was not reported"
626grep -q "^c9 -> refs/heads/main .*: land$" "$work/last.out" \
627 || die "a malformed ref stopped the pass reaching a valid request"
628holds "malformed refs are reported and skipped; the valid request beside them landed"
629git -C "$origin" update-ref -d refs/the-valley/integration-requests/garbage
630git -C "$origin" update-ref -d refs/the-valley/integration-requests/main/too/deep
631
632# ----------------------------------------------------------------------
633say "10. a pass leaves no scratch behind, and a leaked worktree is swept"
634
635# Nine scenarios of real passes, landings and rejections alike, and the
636# scratch root is empty: every worktree a pass takes is given back on the
637# way out, on the failure path as much as the success one.
638leftover="$(find "$TMPDIR" -maxdepth 1 -name 'valley-integrator-wt*')"
639[ -z "$leftover" ] || die "nine passes left scratch behind: $leftover"
640[ "$(git -C "$origin" worktree list --porcelain | grep -c '^worktree ')" -eq 1 ] \
641 || die "nine passes left a worktree attached to the repository"
642holds "no pass left a worktree or a scratch directory behind"
643
644# What a crash leaves: the checkout and its administrative entry, both
645# still valid, so nothing prunes them. Beside it, a worktree of the kind
646# an operator might attach by hand, which is not the integrator's to
647# remove.
648leak="$TMPDIR/valley-integrator-wt-crashed"
649mine="$work/an-operators-own-worktree"
650git -C "$origin" worktree add --quiet --detach "$leak" refs/heads/main
651git -C "$origin" worktree add --quiet --detach "$mine" refs/heads/main
652timeout 5 integrator watch --interval 1s \
653 --repo "$origin" \
654 --key "$work/integrator" --name "$integrator_name" \
655 --known-signers "$work/known_signers" \
656 --instance "$instance" \
657 --schema "$SCHEMA_VERIFICATION" \
658 --attest-schema "$SCHEMA_ATTESTATION" \
659 --event-schema "$SCHEMA_EVENTS" \
660 ${VALLEY_E2E_NOW:+--now "$VALLEY_E2E_NOW"} \
661 > "$work/watch.out" 2>&1 || true
662[ ! -e "$leak" ] || die "a leaked scratch worktree survived the sweep"
663if git -C "$origin" worktree list --porcelain | grep -q "^worktree $leak$"; then
664 die "the leaked worktree is gone from disk and still registered"
665fi
666[ -e "$mine" ] || die "the sweep removed a worktree the integrator did not make"
667git -C "$origin" worktree remove --force "$mine"
668holds "a crash-leaked scratch worktree is swept at watch start; another hand's is not"
669
670# ----------------------------------------------------------------------
671say "11. a scratch root it may not write is reported as that, and nothing else"
672
673# The deployment failure this guards is a sandbox failure: the root TMPDIR
674# names is not writable. That is a statement about the unit, not about the
675# change being judged, and it has to arrive as one — with the path and where
676# the path came from — rather than as git complaining about the leading
677# directories of a .git file.
678refused="$work/refused"
679mkdir -p "$refused"
680chmod a-w "$refused"
681git checkout --quiet main
682git pull --quiet --ff-only origin main
683git checkout --quiet -b c10
684echo "a change that never gets a worktree" > docs/readme.md
685git add -A
686git commit --quiet -m "a change the integrator cannot make scratch for"
687attest_change c10 "" "" --check prose-format
688request c10 main "$(git rev-parse c10)"
689export TMPDIR="$refused"
690integrate || true
691export TMPDIR="$work/tmp"
692chmod u+w "$refused"
693grep -q "scratch directory under $refused, which TMPDIR names" "$work/last.out" \
694 || die "an unwritable scratch root was not reported as one: $(cat "$work/last.out")"
695forget c10
696holds "an unwritable scratch root names the path and where it came from"
697
698# ----------------------------------------------------------------------
699say "12. a floor the instance repository does not carry names the directory looked in"
700
701# The deployment failure this guards is a controller pointed at the wrong
702# directory: the floor is somewhere, and not where this controller looked.
703# The report has to name the repository, the directory and the ref, because
704# those three are what the operator compares against the repository in front
705# of them. A floor is either not there at all, or there under a name that
706# holds no documents, and both arrive that way.
707#
708# A missing floor is refused rather than read as requiring nothing, which is
709# the direction the other layer's absence defaults in (dcr-f41f718). The
710# refusal says why in its own sentence, because the operator reading it is
711# being told that the deployment is not one that can land anything.
712git checkout --quiet main
713git pull --quiet --ff-only origin main
714git checkout --quiet -b c11
715echo "a change judged under no floor" > docs/readme.md
716git add -A
717git commit --quiet -m "a change whose floor the controller cannot find"
718attest_change c11 "" "" --check prose-format
719request c11 main "$(git rev-parse c11)"
720
721# The sentence every refusal to find a floor ends with.
722unwritten="a valley without a written floor is not a valley whose changes land"
723
724floorless() {
725 integrator reconcile \
726 --repo "$origin" \
727 --key "$work/integrator" --name "$integrator_name" \
728 --known-signers "$work/known_signers" "$@" \
729 --schema "$SCHEMA_VERIFICATION" \
730 --attest-schema "$SCHEMA_ATTESTATION" \
731 --event-schema "$SCHEMA_EVENTS" \
732 ${VALLEY_E2E_NOW:+--now "$VALLEY_E2E_NOW"} \
733 2>&1 | tee "$work/last.out"
734}
735
736# The project's own repository carries policy/project and no policy/instance,
737# so the default directory is not there.
738floorless --instance-repo "$origin" || true
739grep -qF "no instance policy layer: $origin has no policy/instance/ at refs/heads/main: $unwritten" "$work/last.out" \
740 || die "a missing floor did not name the directory looked in, and why that is refused: $(cat "$work/last.out")"
741
742# And the flat layout, which is a directory that exists and holds no
743# documents of its own: policy/ has the two layers under it and no *.cue in
744# it. Said as that, rather than as an empty composition further on.
745#
746# Under a second request name, because the refusal above is now this
747# controller's recorded answer to c11 and it stands until the request, the
748# tip or the evidence moves — which is scenario 14's whole subject. A
749# request is what an answer is remembered against, so a second one asks the
750# question again.
751request c11-flat main "$(git rev-parse c11)"
752floorless --instance-repo "$origin" --instance-policy policy || true
753grep -qF "no instance policy layer: $origin holds no *.cue in policy/ at refs/heads/main: $unwritten" "$work/last.out" \
754 || die "a floor directory holding no documents did not say so: $(cat "$work/last.out")"
755
756# And the materialized layer, which is how a host that serves no instance
757# repository is given the floor. A directory with nothing in it is the same
758# absence and is refused the same way.
759request c11-bare main "$(git rev-parse c11)"
760nofloor="$work/no-floor-here"
761mkdir -p "$nofloor"
762floorless --instance "$nofloor" || true
763grep -qF "no instance policy layer: $nofloor holds no *.cue: $unwritten" "$work/last.out" \
764 || die "an empty materialized floor was not refused: $(cat "$work/last.out")"
765forget c11
766forget c11-flat
767forget c11-bare
768holds "a floor that is not where the controller looked names the repository, the directory and the ref"
769
770# ----------------------------------------------------------------------
771say "13. a change the policy requires no check of lands, and says so"
772
773# Requiring nothing is an ordinary outcome, not an edge: this project's
774# classes cover docs/, src/ and deploy/, and its `unclassified` set is
775# empty, so a path outside all three is answered with nothing required. The
776# landing still writes a transfer statement — a commit point that records
777# nothing is a landing nothing attests to — and that statement says the
778# required set was empty rather than carrying a list with nothing in it,
779# which has no written form at all.
780git checkout --quiet main
781git pull --quiet --ff-only origin main
782git checkout --quiet -b c12
783echo "outside every class this policy covers" > notes.txt
784git add -A
785git commit --quiet -m "a change no class covers"
786request c12 main "$(git rev-parse c12)"
787integrate
788grep -q '^c12 -> refs/heads/main .*: land$' "$work/last.out" \
789 || die "a change with nothing required did not land: $(cat "$work/last.out")"
790grep -q 'the policy requires no check of the paths this change touches' "$work/last.out" \
791 || die "the verdict did not say the policy required nothing"
792[ "$(tip)" = "$(git rev-parse c12)" ] || die "c12 did not land"
793git -C "$origin" rev-parse --verify --quiet "refs/the-valley/integration-requests/main/c12" > /dev/null \
794 && die "the request ref survived the landing"
795
796nothing="refs/the-valley/attestations/$(attest digest --repo "$repo" --rev c12 | cut -d: -f2)/$ihash"
797git -C "$origin" cat-file blob "$nothing:transfer.note" > "$work/nothing.note"
798grep -qx 'predicate.required none' "$work/nothing.note" \
799 || die "the transfer statement does not say the required set was empty: $(cat "$work/nothing.note")"
800grep -q '^predicate.checks' "$work/nothing.note" \
801 && die "the transfer statement carries a check list beside the empty-set line"
802attest verify --note "$work/nothing.note" --known-keys "$work/reader_keys" \
803 --repo "$repo" --rev c12 --signer "$integrator_name" > /dev/null \
804 || die "the transfer statement for a landing with nothing required does not verify"
805holds "a landing with no required checks is signed, stored, and consumed its request"
806
807# ----------------------------------------------------------------------
808say "14. a request the controller cannot judge is reported once, not every tick"
809
810# The failure this guards is the one that turns a broken deployment into a
811# broken deployment nobody can read: a pass that cannot act on its verdict,
812# retried at tick rate, filling the journal with one refusal per interval
813# forever. The same request, tip and evidence produce the same failure, so
814# repeating it says nothing new. It is reported once and then the answer
815# stands, exactly as an outcome stands.
816git checkout --quiet main
817git pull --quiet --ff-only origin main
818git checkout --quiet -b c13
819echo "a change judged under no floor, repeatedly" > docs/readme.md
820git add -A
821git commit --quiet -m "a change whose floor the controller cannot find, under watch"
822attest_change c13 "" "" --check prose-format
823request c13 main "$(git rev-parse c13)"
824
825# Five seconds at a one-second tick: five passes over one request the
826# controller cannot judge.
827timeout 5 integrator watch --interval 1s \
828 --repo "$origin" \
829 --key "$work/integrator" --name "$integrator_name" \
830 --known-signers "$work/known_signers" \
831 --instance-repo "$origin" --instance-policy policy \
832 --schema "$SCHEMA_VERIFICATION" \
833 --attest-schema "$SCHEMA_ATTESTATION" \
834 --event-schema "$SCHEMA_EVENTS" \
835 ${VALLEY_E2E_NOW:+--now "$VALLEY_E2E_NOW"} \
836 > "$work/repeat.out" 2>&1 || true
837reports="$(grep -c 'no instance policy layer' "$work/repeat.out" || true)"
838[ "$reports" -eq 1 ] \
839 || die "the same refusal was reported $reports times over five ticks: $(cat "$work/repeat.out")"
840forget c13
841holds "a failure a pass cannot get past is reported once and then backs off"
842
843# ----------------------------------------------------------------------
844say "14b. a failure is recorded before its timing line, which nobody has to read"
845
846# The timing line is printed after the outcome is recorded, and is dropped
847# when it cannot be written. A pass that cannot act on its verdict prints
848# nothing before its timing line, so with standard output a pipe whose
849# reader has gone, the timing line is the first write to fail. The failure
850# is recorded all the same. The line the integrator prints after it, naming
851# the failure, is its own output rather than timing, and may still end the
852# pass there.
853git checkout --quiet main
854git pull --quiet --ff-only origin main
855git checkout --quiet -b c14b
856echo "a change judged with nobody reading" > docs/readme.md
857git add -A
858git commit --quiet -m "a change judged with nobody reading the integrator"
859attest_change c14b "" "" --check prose-format
860request c14b main "$(git rev-parse c14b)"
861
862# A pipe with no reader. The FIFO is opened to read and write, so opening it
863# to write does not wait; closing the first leaves the writer alone.
864mkfifo "$work/unread"
865exec 3<> "$work/unread"
866exec 4> "$work/unread"
867exec 3<&-
868status=0
869timeout 120 integrator reconcile \
870 --repo "$origin" \
871 --key "$work/integrator" --name "$integrator_name" \
872 --known-signers "$work/known_signers" \
873 --instance-repo "$origin" --instance-policy policy \
874 --schema "$SCHEMA_VERIFICATION" \
875 --attest-schema "$SCHEMA_ATTESTATION" \
876 --event-schema "$SCHEMA_EVENTS" \
877 ${VALLEY_E2E_NOW:+--now "$VALLEY_E2E_NOW"} \
878 >&4 2> "$work/unread.err" || status=$?
879exec 4>&-
880[ "$status" != 124 ] || die "the pass did not finish with nobody reading its output"
881recorded="$(git -C "$origin" cat-file blob refs/the-valley/integration-outcomes/main/c14b 2> /dev/null || true)"
882[ "$(echo "$recorded" | cut -d' ' -f4)" = failed ] \
883 || die "with nobody reading its output, the pass did not record its failure (exit $status): ${recorded:-no record} $(cat "$work/unread.err")"
884forget c14b
885holds "with nobody reading its output, the pass recorded its failure before its timing line (exit $status)"
886
887# ----------------------------------------------------------------------
888say "15. a target that carries no project layer of its own is judged under the floor alone"
889
890# The bootstrap this guards is the first policy commit: a project that has
891# not written a layer yet cannot land the commit that writes one, because a
892# change never supplies the policy that gates it. The project layer only
893# ever adds (dcr-f41f718), so its absence adds nothing, and what is left is
894# the floor — which still governs, and is observed governing here.
895
896# The floor grows a requirement of its own first, so that what remains after
897# the project layer goes away is something rather than nothing.
898cat > "$floor/policy/instance/floor.cue" <<'EOF'
899package verification
900
901floor: {
902 checks: "prose-format": {runner: "nix", attribute: "prose-format"}
903 classes: prose: {paths: "docs/**": true, requires: "prose-format": true}
904 unclassified: {}
905}
906EOF
907git -C "$floor" commit --quiet -am "the floor requires prose-format of docs/"
908git -C "$floor" push --quiet "$instance_repo" main
909
910# The project stops carrying a layer. Nothing classifies policy/project
911# itself, so this lands with nothing required — which is how a project could
912# have arrived without one in the first place.
913git checkout --quiet main
914git pull --quiet --ff-only origin main
915git checkout --quiet -b c14
916git rm --quiet -r policy/project
917git commit --quiet -m "stop carrying a project policy layer"
918request c14 main "$(git rev-parse c14)"
919integrate
920grep -q "^c14 -> refs/heads/main .*: land$" "$work/last.out" \
921 || die "dropping the project layer did not land: $(cat "$work/last.out")"
922
923git checkout --quiet main
924git pull --quiet --ff-only origin main
925[ ! -e policy/project ] || die "the project layer is still at the tip; the scenario proves nothing"
926git checkout --quiet -b c15
927echo "a readme judged under the floor alone" > docs/readme.md
928git add -A
929git commit --quiet -m "a change to a project that declares no policy of its own"
930attest_change c15 "" "" --check prose-format
931request c15 main "$(git rev-parse c15)"
932integrate
933grep -q "^c15 -> refs/heads/main .*: land$" "$work/last.out" \
934 || die "a change to a project with no layer of its own did not land: $(cat "$work/last.out")"
935grep -qF "policy no project layer at policy/project; the floor alone" "$work/last.out" \
936 || die "the pass did not say it composed the floor alone"
937grep -q "check prose-format .*transferred" "$work/last.out" \
938 || die "the floor's own requirement did not govern a project with no layer"
939[ "$(tip)" = "$(git rev-parse c15)" ] || die "main is not at the change's head"
940holds "no project layer is no addition; the floor alone required prose-format and the change landed"
941
942# ----------------------------------------------------------------------
943say "16. a floor that requires nothing, written down, composes and judges"
944
945# Emptiness a floor states is not the same thing as a floor nobody wrote.
946# The document is there, somebody landed it, and what it composes to is a
947# policy that requires nothing — so a change under it lands requiring nothing,
948# rather than being refused the way scenario 12's missing floor is.
949cat > "$floor/policy/instance/floor.cue" <<'EOF'
950package verification
951
952floor: {
953 checks: {}
954 classes: {}
955 unclassified: {}
956}
957EOF
958git -C "$floor" commit --quiet -am "the floor requires nothing, and says so"
959git -C "$floor" push --quiet "$instance_repo" main
960
961git checkout --quiet main
962git pull --quiet --ff-only origin main
963git checkout --quiet -b c16
964echo "a readme under a floor that requires nothing" > docs/readme.md
965git add -A
966git commit --quiet -m "a change under an empty floor and no project layer"
967request c16 main "$(git rev-parse c16)"
968integrate
969grep -q "^c16 -> refs/heads/main .*: land$" "$work/last.out" \
970 || die "a change under an explicitly empty floor did not land: $(cat "$work/last.out")"
971grep -q 'the policy requires no check of the paths this change touches' "$work/last.out" \
972 || die "the verdict did not say the policy required nothing"
973grep -qF "policy no project layer at policy/project; the floor alone" "$work/last.out" \
974 || die "the pass did not say it composed the floor alone"
975[ "$(tip)" = "$(git rev-parse c16)" ] || die "main is not at the change's head"
976holds "a floor that states it requires nothing composes, judges, and lands the change requiring nothing"
977
978# ----------------------------------------------------------------------
979say "17. a planted replacement ref changes nothing the controller reads"
980
981# refs/replace/<id> makes git read another object wherever it looks <id> up.
982# Two are planted here, and each alone would land a change that requires
983# evidence and carries none. One swaps the floor's blob in the instance
984# repository for a floor that requires nothing. The other swaps the change's
985# head in the served repository for a commit that touches no class. Neither
986# moves a ref the controller watches. A controller that left replacement
987# refs on would read both and land the change; this one reads the objects
988# the refs actually name, and holds the change stale.
989cat > "$floor/policy/instance/floor.cue" <<'EOF'
990package verification
991
992floor: {
993 checks: "prose-format": {runner: "nix", attribute: "prose-format"}
994 classes: prose: {paths: "docs/**": true, requires: "prose-format": true}
995 unclassified: {}
996}
997EOF
998git -C "$floor" commit --quiet -am "the floor requires prose-format of docs/ again"
999git -C "$floor" push --quiet "$instance_repo" main
1000landed_floor="$(git -C "$instance_repo" rev-parse main:policy/instance/floor.cue)"
1001empty_floor="$(git -C "$instance_repo" rev-parse main~1:policy/instance/floor.cue)"
1002git -C "$instance_repo" update-ref "refs/replace/$landed_floor" "$empty_floor"
1003git -C "$instance_repo" show main:policy/instance/floor.cue | grep 'checks: {}' > /dev/null \
1004 || die "the floor's replacement did not take, so this scenario proves nothing"
1005
1006git checkout --quiet main
1007git pull --quiet --ff-only origin main
1008git checkout --quiet -b c17-decoy
1009echo "a note no class covers" > notes.txt
1010git commit --quiet -am "a decoy that touches no class"
1011git checkout --quiet main
1012git checkout --quiet -b c17
1013echo "a readme no evidence covers" > docs/readme.md
1014git commit --quiet -am "a change that requires prose-format and carries no evidence"
1015git push --quiet origin c17 c17-decoy
1016git -C "$origin" update-ref "refs/replace/$(git rev-parse c17)" "$(git rev-parse c17-decoy)"
1017git -C "$origin" diff --name-only main c17 | grep -x notes.txt > /dev/null \
1018 || die "the head's replacement did not take, so this scenario proves nothing"
1019request c17 main "$(git rev-parse c17)"
1020
1021# The environment asks for replacement refs too, and is not listened to.
1022before="$(tip)"
1023GIT_CONFIG_PARAMETERS="'core.usereplacerefs'='true'" integrate
1024grep -q "^c17 -> refs/heads/main .*: stale$" "$work/last.out" \
1025 || die "a planted replacement ref decided the verdict: $(cat "$work/last.out")"
1026grep -q "check prose-format" "$work/last.out" \
1027 || die "the landed floor's requirement was not what the controller read"
1028grep -q 'no attestation for this check accompanies the change' "$work/last.out" \
1029 || die "the missing evidence was not reported"
1030[ "$(tip)" = "$before" ] || die "main moved under a change that requires evidence"
1031git -C "$instance_repo" update-ref -d "refs/replace/$landed_floor"
1032git -C "$origin" update-ref -d "refs/replace/$(git rev-parse c17)"
1033forget c17
1034holds "the floor and the change were read as landed and as pushed, past both replacements"
1035
1036# ----------------------------------------------------------------------
1037say "18. a request approved again while its previous head lands stands for the next pass"
1038
1039# A second approval is leased against the request it read, and
1040# nothing stops it reading the head this pass is about to land. So the
1041# request can move between the pass reading it and the pass consuming it.
1042# The landing is still the old head's, and the request that moved is a new
1043# request: consuming it would drop a change nobody judged.
1044git checkout --quiet main
1045git pull --quiet --ff-only origin main
1046git checkout --quiet -b c18
1047echo "a readme requested once" > docs/readme.md
1048git commit --quiet -am "the first request"
1049attest_change c18 "" "" --check prose-format
1050request c18 main "$(git rev-parse c18)"
1051# main moves under the request, outside anything the check reads. The pass
1052# then recomputes the check's closure over the landed tree, and that
1053# evaluation is where the second approval happens.
1054git checkout --quiet main
1055echo "a note landed in between" > notes.txt
1056git commit --quiet -am "a note landed in between"
1057git push --quiet origin main
1058git checkout --quiet c18
1059git checkout --quiet -b c18-again
1060echo "a readme requested again" > docs/readme.md
1061git commit --quiet -am "the second request"
1062git push --quiet origin c18-again
1063again="$(git rev-parse c18-again)"
1064moving="refs/the-valley/integration-requests/main/c18"
1065before="$(tip)"
1066VALLEY_E2E_DURING_PASS="git -C '$origin' update-ref '$moving' '$again'" integrate
1067grep -q "^c18 -> refs/heads/main .*: land$" "$work/last.out" \
1068 || die "the first request did not land: $(cat "$work/last.out")"
1069[ "$(tip)" != "$before" ] || die "main did not move for the first request"
1070[ "$(git -C "$origin" rev-parse --verify --quiet "$moving")" = "$again" ] \
1071 || die "the request approved again was consumed with the landing of the one before it: $(git -C "$origin" for-each-ref refs/the-valley/integration-requests) $(cat "$work/last.out")"
1072grep -q "request $moving moved to .* while .* landed; it stands for the next pass" "$work/last.out" \
1073 || die "the moved request was not reported: $(cat "$work/last.out")"
1074forget c18
1075holds "a request that moved while its previous head landed was left standing, and said so"
1076
1077# ----------------------------------------------------------------------
1078say "19. a bus that never answers does not hold up a landing"
1079
1080# The landing's own record comes first: main moves, the move is queued for
1081# the mirrors, the evidence is stored and the request consumed. Only then
1082# does the integrator publish, and each publish is cut off at its deadline.
1083# The shipped wrapper puts the real nats first on the path, so the bare
1084# binary runs here, behind a nats that never exits.
1085mkdir "$work/hung-bus" "$work/queue"
1086cat > "$work/hung-bus/nats" <<EOF
1087#!$(command -v bash)
1088exec sleep 1000
1089EOF
1090chmod +x "$work/hung-bus/nats"
1091git checkout --quiet main
1092git pull --quiet --ff-only origin main
1093git checkout --quiet -b c19
1094echo "landed past a bus that never answers" > docs/bus.md
1095git add -A
1096git commit --quiet -m "past a hung bus"
1097attest_change c19 "" "" --check prose-format
1098request c19 main "$(git rev-parse c19)"
1099before="$(tip)"
1100started=$SECONDS
1101PATH="$work/hung-bus:$PATH" timeout 120 "$INTEGRATOR_UNWRAPPED" reconcile \
1102 --repo "$origin" \
1103 --key "$work/integrator" --name "$integrator_name" \
1104 --known-signers "$work/known_signers" \
1105 --instance-repo "$instance_repo" \
1106 --schema "$SCHEMA_VERIFICATION" \
1107 --attest-schema "$SCHEMA_ATTESTATION" \
1108 --event-schema "$SCHEMA_EVENTS" \
1109 --bus nats://127.0.0.1:1 \
1110 --publish-queue "$work/queue" \
1111 2>&1 | tee "$work/last.out" \
1112 || die "the pass did not finish with a bus that never answers: $(cat "$work/last.out")"
1113elapsed=$((SECONDS - started))
1114grep -q "^c19 -> refs/heads/main .*: land$" "$work/last.out" || die "c19 did not land: $(cat "$work/last.out")"
1115[ "$(tip)" = "$(git rev-parse c19)" ] || die "main is not at c19's head"
1116[ "$(cat "$work"/queue/*)" = "$before $(git rev-parse c19) refs/heads/main" ] \
1117 || die "the move was not queued for the mirrors: $(ls -A "$work/queue")"
1118git -C "$origin" rev-parse --verify --quiet refs/the-valley/integration-requests/main/c19 > /dev/null \
1119 && die "the request outlived the landing"
1120grep -q "^ evidence " "$work/last.out" || die "the evidence was not stored"
1121first_evidence="$(grep -n "^ evidence " "$work/last.out" | head -n1 | cut -d: -f1)"
1122first_bus="$(grep -n "^ bus " "$work/last.out" | head -n1 | cut -d: -f1)"
1123[ "$first_evidence" -lt "$first_bus" ] || die "the integrator asked the bus before it stored the evidence"
1124grep -q "bus publish of valley.git.project.ref-updated FAILED: no answer within 10s" "$work/last.out" \
1125 || die "the hung ref-updated publish was not cut off: $(cat "$work/last.out")"
1126grep -q "bus publish of valley.git.project.integration-succeeded FAILED: no answer within 10s" "$work/last.out" \
1127 || die "the hung integration-succeeded publish was not cut off"
1128[ "$elapsed" -lt 60 ] || die "the pass took ${elapsed}s behind a bus that never answers"
1129holds "c19 landed, queued and consumed its request before a hung bus was asked, and each publish gave up after 10s (${elapsed}s in all)"
1130
1131# ----------------------------------------------------------------------
1132say "20. a cue that never answers a payload's vet does not hold up a landing"
1133
1134# The payload is vetted before it is published, and the vet is bounded the
1135# same way. This cue hangs only when asked to vet against the event schema;
1136# every other use, judging included, goes to the real one.
1137real_cue="$(command -v cue)"
1138mkdir "$work/hung-cue" "$work/queue20"
1139cat > "$work/hung-cue/cue" <<EOF
1140#!$(command -v bash)
1141for arg; do [ "\$arg" = "$SCHEMA_EVENTS" ] && exec sleep 1000; done
1142exec "$real_cue" "\$@"
1143EOF
1144chmod +x "$work/hung-cue/cue"
1145git checkout --quiet main
1146git pull --quiet --ff-only origin main
1147git checkout --quiet -b c20
1148echo "landed past a cue that never answers" > docs/cue.md
1149git add -A
1150git commit --quiet -m "past a hung cue"
1151attest_change c20 "" "" --check prose-format
1152request c20 main "$(git rev-parse c20)"
1153before="$(tip)"
1154started=$SECONDS
1155PATH="$work/hung-cue:$PATH" timeout 120 "$INTEGRATOR_UNWRAPPED" reconcile \
1156 --repo "$origin" \
1157 --key "$work/integrator" --name "$integrator_name" \
1158 --known-signers "$work/known_signers" \
1159 --instance-repo "$instance_repo" \
1160 --schema "$SCHEMA_VERIFICATION" \
1161 --attest-schema "$SCHEMA_ATTESTATION" \
1162 --event-schema "$SCHEMA_EVENTS" \
1163 --publish-queue "$work/queue20" \
1164 2>&1 | tee "$work/last.out" \
1165 || die "the pass did not finish with a cue that never answers: $(cat "$work/last.out")"
1166elapsed=$((SECONDS - started))
1167grep -q "^c20 -> refs/heads/main .*: land$" "$work/last.out" || die "c20 did not land: $(cat "$work/last.out")"
1168[ "$(tip)" = "$(git rev-parse c20)" ] || die "main is not at c20's head"
1169[ "$(cat "$work"/queue20/*)" = "$before $(git rev-parse c20) refs/heads/main" ] \
1170 || die "the move was not queued for the mirrors: $(ls -A "$work/queue20")"
1171git -C "$origin" rev-parse --verify --quiet refs/the-valley/integration-requests/main/c20 > /dev/null \
1172 && die "the request outlived the landing"
1173grep -q "^ evidence " "$work/last.out" || die "the evidence was not stored"
1174grep -q "bus ref-updated not published: cue vet against #RefUpdated gave no answer within 10s" "$work/last.out" \
1175 || die "the hung vet of ref-updated was not cut off: $(cat "$work/last.out")"
1176grep -q "bus integration-succeeded not published: cue vet against #IntegrationSucceeded gave no answer within 10s" "$work/last.out" \
1177 || die "the hung vet of integration-succeeded was not cut off"
1178[ "$elapsed" -lt 60 ] || die "the pass took ${elapsed}s behind a cue that never answers"
1179holds "c20 landed, queued and consumed its request, and each hung vet gave up after 10s and skipped its publish (${elapsed}s in all)"
1180
1181# ----------------------------------------------------------------------
1182say "21. a request named for a change that is ready lands"
1183
1184# A change with a record is requested as c-<change ID>. The records are
1185# written by the valley command itself, as its owner would write them; this
1186# repository is served without the hook that guards them on a host. The
1187# integrator reads them only to refuse.
1188git config valley.principal contributor
1189# ready_change <branch>: the branch's head on origin readied as a new
1190# change, whose ID is left in $readied.
1191ready_change() {
1192 valley ready "$1" > "$work/ready.out" || die "valley ready $1 failed"
1193 readied="$(sed -n 's/^The change ID \([k-z]*\) is new\..*/\1/p' "$work/ready.out")"
1194 [ "${#readied}" = 32 ] || die "valley ready $1 made no change ID: $(cat "$work/ready.out")"
1195}
1196outcome_of() { git -C "$origin" cat-file blob "refs/the-valley/integration-outcomes/main/$1" | cut -d' ' -f4; }
1197
1198git checkout --quiet main
1199git pull --quiet --ff-only origin main
1200git checkout --quiet -b c21
1201echo "a change with a record" > docs/c21.md
1202git add -A
1203git commit --quiet -m "a change with a record"
1204attest_change c21 "" "" --check prose-format
1205ready_change c21
1206id21="$readied"
1207request "c-$id21" main "$(git rev-parse c21)"
1208integrate
1209grep -q "^c-$id21 -> refs/heads/main .*: land$" "$work/last.out" || die "c-$id21 did not land"
1210[ "$(tip)" = "$(git rev-parse c21)" ] || die "main is not at c21's head"
1211landed="refs/the-valley/attestations/$(attest digest --repo "$repo" --rev c21 | cut -d: -f2)/$ihash"
1212git -C "$origin" cat-file blob "$landed:transfer.note" | grep -qx "predicate.change c-$id21" \
1213 || die "the transfer statement does not name the request c-$id21"
1214holds "a ready change's request, named for its ID, landed, and its transfer statement names it so"
1215
1216# ----------------------------------------------------------------------
1217say "22. a change unreadied after its request was filed is refused, and lands once it is ready again"
1218
1219git checkout --quiet main
1220git pull --quiet --ff-only origin main
1221git checkout --quiet -b c22
1222echo "a change paused after it was approved" > docs/c22.md
1223git add -A
1224git commit --quiet -m "a change paused after it was approved"
1225attest_change c22 "" "" --check prose-format
1226ready_change c22
1227id22="$readied"
1228request "c-$id22" main "$(git rev-parse c22)"
1229valley unready "$id22" > /dev/null 2>&1 || die "valley unready failed"
1230before="$(tip)"
1231integrate
1232grep -q "^c-$id22 -> refs/heads/main .*: refused-not-ready$" "$work/last.out" \
1233 || die "a draft's request was not refused: $(cat "$work/last.out")"
1234grep -q "change $id22 is draft, not ready" "$work/last.out" || die "the refusal did not say the change is a draft"
1235[ "$(tip)" = "$before" ] || die "a draft's request moved main"
1236git -C "$origin" rev-parse --verify --quiet "refs/the-valley/integration-requests/main/c-$id22" > /dev/null \
1237 || die "the refused request was dropped"
1238[ "$(outcome_of "c-$id22")" = refused-not-ready ] || die "the outcome record does not say refused-not-ready"
1239
1240# The refusal is decided again on every pass, and said once.
1241timeout 4 integrator watch --interval 1s \
1242 --repo "$origin" \
1243 --key "$work/integrator" --name "$integrator_name" \
1244 --known-signers "$work/known_signers" \
1245 --instance-repo "$instance_repo" \
1246 --schema "$SCHEMA_VERIFICATION" \
1247 --attest-schema "$SCHEMA_ATTESTATION" \
1248 --event-schema "$SCHEMA_EVENTS" \
1249 > "$work/repeat.out" 2>&1 || true
1250[ "$(grep -c "c-$id22 .*refused-not-ready" "$work/repeat.out" || true)" -eq 0 ] \
1251 || die "a standing refusal was reported again: $(cat "$work/repeat.out")"
1252[ "$(tip)" = "$before" ] || die "a draft's request moved main under watch"
1253
1254# Readied again at the same head, the same request lands on the next pass.
1255valley ready --change "$id22" c22 > /dev/null 2>&1 || die "valley ready --change $id22 failed"
1256integrate
1257grep -q "^c-$id22 -> refs/heads/main .*: land$" "$work/last.out" \
1258 || die "the change readied again did not land: $(cat "$work/last.out")"
1259[ "$(tip)" = "$(git rev-parse c22)" ] || die "main is not at c22's head"
1260holds "unready stopped a filed request, the refusal was said once, and ready let the same request land"
1261
1262# ----------------------------------------------------------------------
1263say "23. a request named for a branch, at a draft's head, is refused"
1264
1265# Whatever a request is named, a head that is a version of a change that
1266# is not ready does not land.
1267git checkout --quiet main
1268git pull --quiet --ff-only origin main
1269git checkout --quiet -b c23
1270echo "a draft requested under its branch's name" > docs/c23.md
1271git add -A
1272git commit --quiet -m "a draft requested under its branch's name"
1273attest_change c23 "" "" --check prose-format
1274ready_change c23
1275id23="$readied"
1276valley unready "$id23" > /dev/null 2>&1 || die "valley unready failed"
1277request c23 main "$(git rev-parse c23)"
1278before="$(tip)"
1279integrate
1280grep -q "^c23 -> refs/heads/main .*: refused-not-ready$" "$work/last.out" \
1281 || die "a branch-named request at a draft's head was not refused: $(cat "$work/last.out")"
1282grep -q "is v1 of change $id23, which is draft, not ready" "$work/last.out" \
1283 || die "the refusal did not name the draft"
1284[ "$(tip)" = "$before" ] || die "a draft's head landed under its branch's name"
1285[ "$(outcome_of c23)" = refused-not-ready ] || die "the outcome record does not say refused-not-ready"
1286forget c23
1287holds "a draft's head was refused under a branch's name too"
1288
1289# ----------------------------------------------------------------------
1290say "24. a request whose commits hold a merge is refused"
1291
1292# A merge can make other work look landed by ancestry, so the integrator
1293# lands a line of commits and nothing else.
1294git checkout --quiet main
1295git pull --quiet --ff-only origin main
1296git checkout --quiet -b c24-side
1297echo "a side line" > docs/c24-side.md
1298git add -A
1299git commit --quiet -m "a side line"
1300git checkout --quiet main
1301git checkout --quiet -b c24
1302echo "a line with a merge in it" > docs/c24.md
1303git add -A
1304git commit --quiet -m "a line with a merge in it"
1305git merge --quiet --no-ff --no-edit c24-side
1306git push --quiet origin c24
1307request c24 main "$(git rev-parse c24)"
1308before="$(tip)"
1309integrate
1310grep -q "^c24 -> refs/heads/main .*: refused-merge$" "$work/last.out" \
1311 || die "a request holding a merge was not refused: $(cat "$work/last.out")"
1312grep -q "include the merge $(git rev-parse c24 | cut -c1-12)" "$work/last.out" || die "the refusal did not name the merge"
1313[ "$(tip)" = "$before" ] || die "a request holding a merge moved main"
1314[ "$(outcome_of c24)" = refused-merge ] || die "the outcome record does not say refused-merge"
1315forget c24
1316holds "a request holding a merge was refused, and main did not move"
1317
1318# ----------------------------------------------------------------------
1319say "25. a line of commits above a draft's head is refused, naming the draft"
1320
1321# A request brings every commit from its merge base to its head. So a child
1322# of a draft's head, approved under another name, would land the draft too.
1323git checkout --quiet main
1324git pull --quiet --ff-only origin main
1325git checkout --quiet -b c25-draft
1326echo "a draft below another change" > docs/c25-draft.md
1327git add -A
1328git commit --quiet -m "a draft below another change"
1329git push --quiet origin c25-draft
1330ready_change c25-draft
1331id25="$readied"
1332valley unready "$id25" > /dev/null 2>&1 || die "valley unready failed"
1333git checkout --quiet -b c25
1334echo "a change above a draft" > docs/c25.md
1335git add -A
1336git commit --quiet -m "a change above a draft"
1337git push --quiet origin c25
1338request c25 main "$(git rev-parse c25)"
1339before="$(tip)"
1340integrate
1341grep -q "^c25 -> refs/heads/main .*: refused-not-ready$" "$work/last.out" \
1342 || die "a child of a draft's head was not refused: $(cat "$work/last.out")"
1343grep -q "the commit $(git rev-parse c25-draft | cut -c1-12) it brings is v1 of change $id25, which is draft, not ready" \
1344 "$work/last.out" || die "the refusal did not name the draft"
1345[ "$(tip)" = "$before" ] || die "a child of a draft's head moved main"
1346forget c25
1347holds "a line above a draft's head was refused, and the refusal named the draft"
1348
1349# ----------------------------------------------------------------------
1350say "26. withdrawing a change voids its request, and readying it again needs a fresh approval"
1351
1352# integrate_quiet: a pass that may have nothing to say.
1353integrate_quiet() {
1354 integrator reconcile \
1355 --repo "$origin" \
1356 --key "$work/integrator" --name "$integrator_name" \
1357 --known-signers "$work/known_signers" \
1358 --instance-repo "$instance_repo" \
1359 --schema "$SCHEMA_VERIFICATION" \
1360 --attest-schema "$SCHEMA_ATTESTATION" \
1361 --event-schema "$SCHEMA_EVENTS" \
1362 2>&1 | tee "$work/last.out"
1363}
1364git checkout --quiet main
1365git pull --quiet --ff-only origin main
1366git checkout --quiet -b c26
1367echo "a change withdrawn after it was approved" > docs/c26.md
1368git add -A
1369git commit --quiet -m "a change withdrawn after it was approved"
1370attest_change c26 "" "" --check prose-format
1371ready_change c26
1372id26="$readied"
1373request "c-$id26" main "$(git rev-parse c26)"
1374valley withdraw "$id26" > /dev/null 2>&1 || die "valley withdraw failed"
1375before="$(tip)"
1376integrate
1377grep -q "^c-$id26 -> refs/heads/main .*: voided-withdrawn$" "$work/last.out" \
1378 || die "a withdrawn change's request was not voided: $(cat "$work/last.out")"
1379git -C "$origin" rev-parse --verify --quiet "refs/the-valley/integration-requests/main/c-$id26" > /dev/null \
1380 && die "the voided request is still there"
1381[ "$(outcome_of "c-$id26")" = voided-withdrawn ] || die "the outcome record does not say voided-withdrawn"
1382[ "$(tip)" = "$before" ] || die "a withdrawn change moved main"
1383
1384# Readied again at the same head, the change has no request: the old
1385# approval is gone, and nothing lands.
1386valley ready --change "$id26" c26 > /dev/null 2>&1 || die "valley ready --change $id26 failed"
1387integrate_quiet
1388git -C "$origin" rev-parse --verify --quiet "refs/the-valley/integration-requests/main/c-$id26" > /dev/null \
1389 && die "the old request came back"
1390[ "$(tip)" = "$before" ] || die "a change readied again landed with no fresh approval"
1391
1392# A fresh approval at the same head lands.
1393request "c-$id26" main "$(git rev-parse c26)"
1394integrate
1395grep -q "^c-$id26 -> refs/heads/main .*: land$" "$work/last.out" \
1396 || die "the fresh approval did not land: $(cat "$work/last.out")"
1397[ "$(tip)" = "$(git rev-parse c26)" ] || die "main is not at c26's head"
1398holds "withdraw voided the request on the next pass; readied again, the change landed only on a fresh approval"
1399
1400# ----------------------------------------------------------------------
1401say "27. a stack is rebased whole, a landed change under it drops out, and approving its top lands every layer"
1402
1403# approve reads the floor where the integrator does: the owning valley,
1404# which policy/valley names at main's tip.
1405git checkout --quiet main
1406git pull --quiet --ff-only origin main
1407mkdir -p policy
1408echo "$instance_repo" > policy/valley
1409git add policy/valley
1410git commit --quiet -m "name the owning valley"
1411git push --quiet origin main
1412
1413# A change of two commits, a plain branch on it, and two changes on that.
1414git checkout --quiet -b c27-a
1415echo "the first half of a" > docs/c27-a1.md
1416git add -A
1417git commit --quiet -m "c27: the first half of a"
1418echo "the second half of a" > docs/c27-a2.md
1419git add -A
1420git commit --quiet -m "c27: the second half of a"
1421attest_change c27-a "" "" --check prose-format
1422ready_change c27-a
1423id27a="$readied"
1424for layer in p b c; do
1425 git checkout --quiet -b "c27-$layer"
1426 echo "layer $layer" > "docs/c27-$layer.md"
1427 git add -A
1428 git commit --quiet -m "c27: layer $layer"
1429 git push --quiet origin "c27-$layer"
1430done
1431ready_change c27-b
1432id27b="$readied"
1433ready_change c27-c
1434id27c="$readied"
1435a="$(git rev-parse c27-a)" p="$(git rev-parse c27-p)" b="$(git rev-parse c27-b)" c="$(git rev-parse c27-c)"
1436
1437# main moves under the stack, outside what prose-format reads, and then a
1438# lands through an integrator merge: one new commit, not its own two.
1439git checkout --quiet main
1440git checkout --quiet -b c27-x
1441mkdir -p notes
1442echo "main moves on" > notes/c27-x.txt
1443git add -A
1444git commit --quiet -m "c27: main moves on"
1445git push --quiet origin c27-x
1446request c27-x main "$(git rev-parse c27-x)"
1447integrate
1448grep -q "^c27-x -> refs/heads/main .*: land$" "$work/last.out" || die "c27-x did not land"
1449request "c-$id27a" main "$a"
1450integrate
1451grep -q "^c-$id27a -> refs/heads/main .*: land$" "$work/last.out" || die "c-$id27a did not land"
1452main27="$(tip)"
1453git -C "$origin" merge-base --is-ancestor "$a" "$main27" && die "a landed by fast-forward; the scenario proves nothing"
1454
1455# The rebase reads a's landing from its transfer statement, so a is no
1456# layer, and its two commits under the plain branch drop out. Each layer
1457# keeps its own diff, on the rebased layer below.
1458export VALLEY_KNOWN_SIGNERS="$work/reader_keys" VALLEY_INTEGRATOR_SIGNER="$integrator_name"
1459valley status --json "$id27a" | grep -q '"landing": *"landed-recorded"' || die "a's landing was not read as recorded"
1460valley rebase "$id27c" > "$work/rebase.out" 2>&1 || die "the rebase failed: $(cat "$work/rebase.out")"
1461git fetch --quiet origin
1462np="$(git rev-parse origin/c27-p)" nb="$(git rev-parse origin/c27-b)" nc="$(git rev-parse origin/c27-c)"
1463git merge-base --is-ancestor "$main27" "$np" || die "the bottom is not on main"
1464git merge-base --is-ancestor "$np" "$nb" || die "b is not on the rebased plain branch"
1465git merge-base --is-ancestor "$nb" "$nc" || die "c is not on b"
1466[ "$(git rev-list --count "$main27..$np")" = 1 ] || die "a's commits did not drop out from under the plain branch"
1467[ "$(git diff "$a" "$p")" = "$(git diff "$main27" "$np")" ] || die "the plain branch's diff changed"
1468[ "$(git diff "$p" "$b")" = "$(git diff "$np" "$nb")" ] || die "b's diff changed"
1469[ "$(git diff "$b" "$c")" = "$(git diff "$nb" "$nc")" ] || die "c's diff changed"
1470grep -q "^ c27-p .* origin/c27-p pushed$" "$work/rebase.out" || die "the manifest did not list the plain branch: $(cat "$work/rebase.out")"
1471holds "the stack moved whole onto main, and the landed change's commits dropped out from under it"
1472
1473# Approving the rebased top, and landing it, lands every layer.
1474VALLEY_ATTEST_KEY="$work/contributor" VALLEY_ATTEST_NAME="$contributor" \
1475 valley approve --head "$nc" "$id27c" > "$work/approve.out" 2>&1 \
1476 || die "approving the rebased top failed: $(cat "$work/approve.out")"
1477integrate
1478grep -q "^c-$id27c -> refs/heads/main .*: land$" "$work/last.out" || die "c-$id27c did not land"
1479[ "$(tip)" = "$nc" ] || die "main is not at the top's rebased head"
1480for id in "$id27b" "$id27c"; do
1481 valley status --json "$id" | grep -q '"landing": *"landed"' || die "change $id does not read landed"
1482done
1483git -C "$origin" merge-base --is-ancestor "$np" "$(tip)" || die "the plain branch did not land"
1484unset VALLEY_KNOWN_SIGNERS VALLEY_INTEGRATOR_SIGNER
1485holds "the rebased stack landed as one fast-forward, and every layer reads landed"
1486
1487# ----------------------------------------------------------------------
1488say "28. a signer restricted to some projects counts in those, and is unknown in every other"
1489
1490# A check worker's key is in the known-signers file, as it is for every
1491# controller that shares the file, and so is the integrator's, as a host's
1492# registry holds it. The signer projects file lets the worker count in this
1493# project alone. A controller takes the project from the repository it
1494# serves, so this one's is "project".
1495ssh-keygen -q -t ed25519 -N "" -C worker -f "$work/worker"
1496worker=worker.valley.invalid/attestations
1497cat "$work/known_signers" > "$work/worker_signers"
1498attest key --key "$work/worker" --name "$worker" >> "$work/worker_signers"
1499attest key --key "$work/integrator" --name "$integrator_name" >> "$work/worker_signers"
1500printf '# the check worker builds for this project alone\n%s project\n' "$worker" > "$work/signer_projects"
1501restricted=(--known-signers "$work/worker_signers" --signer-projects "$work/signer_projects")
1502# The second project's controller signs under a name and key of its own,
1503# as a controller on another host sharing the registry does, and holds the
1504# same known-signers file, the first controller's key included. Nothing in
1505# a note marks the first controller's signature as a countersignature, so
1506# this host declares it: its signer projects file names the first
1507# controller with no project, and the worker with this project alone.
1508ssh-keygen -q -t ed25519 -N "" -C second-integrator -f "$work/second_integrator"
1509second_integrator=second-integrator.valley.invalid/attestations
1510printf '%s project\n%s\n' "$worker" "$integrator_name" > "$work/second_signer_projects"
1511second=(--repo "$work/elsewhere.git" --key "$work/second_integrator" --name "$second_integrator"
1512 --known-signers "$work/worker_signers" --signer-projects "$work/second_signer_projects")
1513
1514git checkout --quiet main
1515git pull --quiet --ff-only origin main
1516git checkout --quiet -b c28
1517echo "a readme a check worker built" > docs/c28.md
1518git add -A
1519git commit --quiet -m "a change a check worker attested"
1520attest_change c28 "$work/worker" "$worker" --check prose-format
1521c28="$(git rev-parse c28)"
1522c28digest="$(attest digest --repo "$repo" --rev c28 | cut -d: -f2)"
1523c28ref="refs/the-valley/attestations/$c28digest/$(attest key --key "$work/worker" --name "$worker" | cut -d+ -f2)"
1524request c28 main "$c28"
1525
1526# A second project, served the same way, holds the same commits, the same
1527# note and the same request. Its controller's project is "elsewhere".
1528elsewhere="$work/elsewhere.git"
1529git init --quiet --bare "$elsewhere"
1530git -C "$origin" push --quiet "$elsewhere" main c28 "$c28ref" refs/the-valley/integration-requests/main/c28
1531[ "$(git -C "$elsewhere" rev-parse "$c28ref")" = "$(git -C "$origin" rev-parse "$c28ref")" ] \
1532 || die "the second project does not hold the same note"
1533integrate "${second[@]}"
1534grep -q "^c28 -> refs/heads/main .*: stale$" "$work/last.out" \
1535 || die "the worker's evidence counted in a project not listed for it"
1536grep -q "check prose-format .*signed by no signer the integrator holds" "$work/last.out" \
1537 || die "the worker's note was not reported as an unknown signer's"
1538[ "$(git -C "$elsewhere" rev-parse main)" != "$c28" ] || die "main moved in the second project"
1539holds "in a project not listed for it, the worker's note is classified as a stranger's"
1540
1541# A signer projects file the controller cannot read stops it before it
1542# judges anything: one that names a signer twice, one that names a
1543# verifier key line rather than a signer, one whose projects are joined by
1544# a no-break space rather than a space, and one that is not there. So does
1545# one that restricts the integrator's own name, under which a worker would
1546# also sign transfer statements.
1547printf '%s project\n%s elsewhere\n' "$worker" "$worker" > "$work/named_twice"
1548attest key --key "$work/worker" --name "$worker" > "$work/key_line"
1549printf '%s project\302\240elsewhere\n' "$worker" > "$work/no_break_space"
1550printf '%s project\n' "$integrator_name" > "$work/names_the_integrator"
1551for list in named_twice key_line no_break_space missing names_the_integrator; do
1552 if reconcile "${restricted[@]}" --signer-projects "$work/$list" > "$work/$list.out" 2>&1; then
1553 die "a controller given the $list signer projects file ran: $(cat "$work/$list.out")"
1554 fi
1555 grep -q "signer projects file" "$work/$list.out" \
1556 || die "the $list signer projects file was not named as the reason: $(cat "$work/$list.out")"
1557 grep -q "^c28 " "$work/$list.out" && die "a controller given the $list signer projects file judged c28"
1558 [ "$(tip)" != "$c28" ] || die "main moved under the $list signer projects file"
1559done
1560grep -qF "names $integrator_name, the name the integrator signs under" "$work/names_the_integrator.out" \
1561 || die "the integrator's own name was not the reason: $(cat "$work/names_the_integrator.out")"
1562holds "a signer projects file that does not read, or restricts the integrator's name, stops the controller, and nothing lands"
1563
1564# In the project listed for it, the same note lands the change.
1565integrate "${restricted[@]}"
1566grep -q "^c28 -> refs/heads/main .*: land$" "$work/last.out" \
1567 || die "the worker's evidence did not count in the project listed for it"
1568grep -q "check prose-format .*transferred" "$work/last.out" || die "prose-format did not transfer"
1569[ "$(tip)" = "$c28" ] || die "main is not at c28's head"
1570holds "in the project listed for it, the same note lands c28"
1571
1572# Landing countersigned the worker's note: the first controller stored it,
1573# with its own signature added, under its own key hash. Copied into the
1574# second project, the countersigned note still counts only through the
1575# worker, who does not count there: the second controller holds the first
1576# one's key, and its signer projects file lets that signature count
1577# nowhere.
1578countersigned="refs/the-valley/attestations/$c28digest/$ihash"
1579git -C "$origin" cat-file blob "$countersigned:prose-format/statement.note" | grep -qF " $integrator_name " \
1580 || die "the landing did not countersign the worker's note"
1581git -C "$origin" push --quiet "$elsewhere" "$countersigned"
1582integrate "${second[@]}"
1583grep -q "^c28 -> refs/heads/main .*: stale$" "$work/last.out" \
1584 || die "another controller's countersignature made the worker's note count in a project not listed for it"
1585[ "$(git -C "$elsewhere" rev-parse main)" != "$c28" ] || die "main moved in the second project"
1586holds "another controller's countersignature does not stand in for the worker"
1587
1588# A signer the file does not name still counts in the second project. The
1589# contributor's note for the same tree arrives there, and replaces the
1590# worker's as the evidence.
1591attest run --repo "$repo" --key "$work/contributor" --name "$contributor" --check prose-format > /dev/null
1592git push --quiet "$elsewhere" "refs/the-valley/attestations/$c28digest/$(cut -d+ -f2 < "$work/known_signers")"
1593integrate "${second[@]}"
1594grep -q "^c28 -> refs/heads/main .*: land$" "$work/last.out" \
1595 || die "an unrestricted signer's evidence did not count in the second project"
1596[ "$(git -C "$elsewhere" rev-parse main)" = "$c28" ] || die "main in the second project is not at c28's head"
1597holds "a signer the file does not name counts in every project, as before"
1598
1599printf '\nintegrator-e2e: every scenario held\n'