gunk-dev/the-valley

run.sh

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