gunk-dev/the-valley

run.sh

sourceca98fdc29fbfmain's published tip history
137.5 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)"
14# A scenario's controllers run in the background, and end with the run.
15trap 'kill $(jobs -p) 2> /dev/null || true; wait || true; rm -rf "$work"' EXIT
16here="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
17
18export HOME="$work"
19export GIT_CONFIG_NOSYSTEM=1
20# Scratch goes where the run puts it, as it does under the unit, so what
21# a pass leaves behind is observable rather than scattered through /tmp.
22export TMPDIR="$work/tmp"
23mkdir -p "$TMPDIR"
24export VALLEY_FAKE_STORE="$work/store"
25export PATH="$here:$PATH" # the nix stand-ins, ahead of anything real
26# What the nix stand-in was asked to do, one line per call (integrator/e2e/nix).
27export VALLEY_E2E_NIX_LOG="$work/nix.log"
28
29git config --global user.name valley-check
30git config --global user.email valley-check@localhost
31git config --global init.defaultBranch main
32git config --global advice.detachedHead false
33
34say() { printf '\n=== %s\n' "$*"; }
35die() {
36 printf '\nintegrator-e2e: %s\n' "$*" >&2
37 exit 1
38}
39holds() { printf ' ok: %s\n' "$*"; }
40
41# ----------------------------------------------------------------------
42say "keys: a contributor, an integrator, and a stranger"
43
44for who in contributor integrator stranger; do
45 ssh-keygen -q -t ed25519 -N "" -C "$who" -f "$work/$who"
46done
47contributor=contributor.valley.invalid/attestations
48integrator_name=integrator.valley.invalid/attestations
49stranger=stranger.elsewhere.invalid/attestations
50
51# The known-signers file is the registry's interim compilation
52# (dcr-b87f6e8): the integrator accepts the contributor and nobody else.
53attest key --key "$work/contributor" --name "$contributor" > "$work/known_signers"
54# What a reader of a landed note holds: both parties to it.
55cat "$work/known_signers" > "$work/reader_keys"
56attest key --key "$work/integrator" --name "$integrator_name" >> "$work/reader_keys"
57attest key --key "$work/stranger" --name "$stranger" > "$work/stranger_key"
58# The key hash the integrator's own attestation refs are keyed by.
59ihash="$(attest key --key "$work/integrator" --name "$integrator_name" | cut -d+ -f2)"
60holds "the integrator holds one signer: $(cut -d+ -f1 < "$work/known_signers")"
61
62# ----------------------------------------------------------------------
63say "the served repository, and the instance policy layer"
64
65origin="$work/project.git"
66git init --quiet --bare "$origin"
67repo="$work/project"
68git init --quiet "$repo"
69cd "$repo"
70git remote add origin "$origin"
71
72mkdir -p docs src deploy checks policy/project
73echo "the readme" > docs/readme.md
74echo "the source" > src/main.txt
75echo "the deployment" > deploy/target.txt
76# What each check reads, which the nix stand-in turns into its closure.
77echo docs > checks/prose-format.inputs
78echo src > checks/code-build.inputs
79
80# The project layer: it declares its own classes and checks above the
81# floor, and declines nothing. It sits at policy/project, which is where the
82# integrator looks without being told (dcr-f41f718).
83cat > policy/project/policy.cue <<'EOF'
84package verification
85
86project: {
87 checks: {
88 "prose-format": {runner: "nix", attribute: "prose-format"}
89 "code-build": {runner: "nix", attribute: "code-build"}
90 // An effectful check, with the validity window dcr-439b771 calls
91 // Δ. Its observation transfers while nothing in the class that
92 // requires it has landed under it and it is younger than this.
93 reachable: {runner: "command", command: "true", validity: "1h"}
94 }
95 classes: {
96 prose: {paths: "docs/**": true, requires: "prose-format": true}
97 code: {paths: "src/**": true, requires: "code-build": true}
98 deploy: {paths: "deploy/**": true, requires: reachable: true}
99 }
100 unclassified: {}
101}
102EOF
103
104git add -A
105git commit --quiet -m "seed the project"
106git push --quiet origin main
107
108# The instance layer lives outside the project's tree, and the integrator
109# reads it from there: a change never supplies the policy that gates it. The
110# floor is the group's own repository's, read at the tip that has been
111# integrated (dcr-f41f718), and it sits at policy/instance in that tip.
112instance_repo="$work/instance.git"
113git init --quiet --bare "$instance_repo"
114floor="$work/instance-project"
115git init --quiet "$floor"
116mkdir -p "$floor/policy/instance"
117cat > "$floor/policy/instance/floor.cue" <<'EOF'
118package verification
119
120floor: {
121 checks: {}
122 classes: {}
123 unclassified: {}
124}
125EOF
126git -C "$floor" add -A
127git -C "$floor" commit --quiet -m "seed the floor"
128git -C "$floor" push --quiet "$instance_repo" main
129
130# The fallback source, for a host that serves no instance repository: the
131# same documents, materialized as a directory. One scenario below reads the
132# floor that way, and every other reads it from the repository.
133instance="$work/instance"
134mkdir -p "$instance"
135cp "$floor/policy/instance/floor.cue" "$instance/floor.cue"
136
137holds "the floor is policy/instance at $instance_repo's tip, and the project's layer is policy/project at its own"
138
139# ----------------------------------------------------------------------
140# Helpers.
141
142# attest_change <branch> <check spec…> — run the checks over the branch's
143# tip and publish the branch with its attestation ref, atomically.
144attest_change() {
145 local branch="$1" key="${2:-$work/contributor}" name="${3:-$contributor}"
146 shift 3
147 attest run --repo "$repo" --key "$key" --name "$name" \
148 --push origin --branch "$branch" "$@"
149}
150
151# request <change> <target> <commit> — the contributor files an integration
152# request by pushing one ref. That ref is the whole of the request.
153request() {
154 git push --quiet origin "$3:refs/the-valley/integration-requests/$2/$1"
155}
156
157# reconcile [flag…] — one pass. A flag given here overrides the one set
158# before it.
159reconcile() {
160 # Neither policy path is stated: both layers come from where the
161 # integrator defaults to looking, which is the whole of what a deployment
162 # following the convention says about policy.
163 integrator reconcile \
164 --repo "$origin" \
165 --key "$work/integrator" --name "$integrator_name" \
166 --known-signers "$work/known_signers" \
167 --instance-repo "$instance_repo" \
168 --schema "$SCHEMA_VERIFICATION" \
169 --attest-schema "$SCHEMA_ATTESTATION" \
170 --event-schema "$SCHEMA_EVENTS" \
171 ${VALLEY_E2E_NOW:+--now "$VALLEY_E2E_NOW"} \
172 "$@"
173}
174
175# integrate [flag…] — one pass, its output kept in last.out and what it
176# asked of the nix stand-in in last.nix. pre is main's tip on origin before
177# the pass.
178integrate() {
179 pre="$(tip)"
180 : > "$VALLEY_E2E_NIX_LOG"
181 reconcile "$@" 2>&1 | tee "$work/last.out"
182 cp "$VALLEY_E2E_NIX_LOG" "$work/last.nix"
183 grep -q . "$work/last.out" || die "the integrator said nothing"
184}
185
186# asked_nix LINE… — the last pass asked the nix stand-in for exactly these
187# calls, in this order, and for nothing else.
188asked_nix() {
189 [ "$(cat "$work/last.nix")" = "$(if [ $# -gt 0 ]; then printf '%s\n' "$@"; fi)" ] \
190 || die "the pass asked nix for $(paste -sd, "$work/last.nix"), not $(IFS=,; echo "$*")"
191}
192
193tip() { git -C "$origin" rev-parse refs/heads/main; }
194# landed_as HEAD BEFORE [REPO [NAME]] — main in REPO, origin by default,
195# is the one commit the integrator signing as NAME made for the change
196# whose head is HEAD, on BEFORE, the tip main was at before the pass:
197# HEAD's tree, the integrator as committer, BEFORE as its one parent, and
198# main one commit ahead of BEFORE. So none of HEAD's own commits reached
199# main in the pass.
200landed_as() {
201 local in="${3:-$origin}" name="${4:-$integrator_name}" main
202 main="$(git -C "$in" rev-parse refs/heads/main)"
203 [ "$main" != "$1" ] || die "main is at $1 itself, not a commit the integrator made"
204 [ "$(git -C "$in" rev-parse "$main^{tree}")" = "$(git -C "$in" rev-parse "$1^{tree}")" ] \
205 || die "main does not hold the tree of $1"
206 [ "$(git -C "$in" rev-list --no-walk --parents "$main")" = "$main $2" ] \
207 || die "main's tip is not one commit whose one parent is $2, the tip before the pass"
208 [ "$(git -C "$in" rev-list --count "$2..$main")" = 1 ] \
209 || die "main gained more than one commit in the pass"
210 [ "$(git -C "$in" log -1 --format=%cn "$main")" = "$name" ] \
211 || die "main's tip was not committed by the integrator"
212}
213# transfer_path COMMIT — where an attestation ref holds the transfer
214# statement for a landing as COMMIT (change.TransferPath).
215transfer_path() { printf 'transfer.d/%s/%s/%s.note' "${1:0:2}" "${1:2:2}" "${1:4}"; }
216forget() { git -C "$origin" update-ref -d "refs/the-valley/integration-requests/main/$1"; }
217
218# ----------------------------------------------------------------------
219say "1. a change with valid transferring evidence lands"
220
221before="$(tip)"
222git checkout --quiet -b c1
223echo "a better readme" > docs/readme.md
224echo "a new target" > deploy/second.txt
225git add -A
226git commit --quiet -m "improve the readme and add a target"
227attest_change c1 "" "" --check prose-format --command reachable=true
228request c1 main "$(git rev-parse c1)"
229integrate
230
231grep -q "^c1 -> refs/heads/main .*: land$" "$work/last.out" || die "c1 did not land"
232grep -q "check prose-format .*transferred" "$work/last.out" || die "prose-format did not transfer"
233grep -q "check reachable .*transferred (untouched)" "$work/last.out" || die "the effectful check did not transfer"
234grep -q '"event":"integration-succeeded"' "$work/last.out" || die "no integration-succeeded event"
235# The landing's own ref-updated event, vetted against #RefUpdated like the rest.
236grep -qF "event ref-updated {\"event\":\"ref-updated\",\"repo\":" "$work/last.out" \
237 || die "no ref-updated event"
238[ "$(tip)" != "$before" ] || die "the protected ref did not move"
239landed_as "$(git rev-parse c1)" "$pre"
240asked_nix
241holds "the tree that landed is the tree attested, so nothing was evaluated"
242git -C "$origin" rev-parse --verify --quiet refs/the-valley/integration-requests/main/c1 > /dev/null \
243 && die "the request ref outlived the landing"
244holds "main moved $(git rev-parse --short "$before") -> $(git -C "$origin" rev-parse --short refs/heads/main)"
245
246# The landing is recorded per head: a commit with no parent, holding one
247# file that names the landed commit, the request and the head. The outcome
248# record, written in the same transaction, says land.
249record="refs/the-valley/integration-landings/main/$(git rev-parse c1)"
250[ "$(git -C "$origin" cat-file blob "$record:landing")" = "$(printf 'landed %s\nrequest c1\nhead %s' "$(tip)" "$(git rev-parse c1)")" ] \
251 || die "the landing record does not name the landing: $(git -C "$origin" cat-file blob "$record:landing" 2>&1)"
252[ "$(git -C "$origin" rev-list --no-walk --parents "$record" | wc -w)" = 1 ] || die "the landing record's commit has a parent"
253[ "$(git -C "$origin" cat-file blob refs/the-valley/integration-outcomes/main/c1 | cut -d' ' -f1,2,4)" = "$(git rev-parse c1) $before land" ] \
254 || die "the outcome record does not say land at c1 on the tip it was judged against"
255grep -qx " record $record" "$work/last.out" || die "the landing record was not reported"
256holds "the landing record and the outcome record name the landing"
257
258# The decision is followed by one timing line: JSON after a fixed label,
259# naming the request and what was decided, with the time each stage took.
260# Every stage a landing reaches is there, as a whole number of
261# milliseconds, and the stages add up to no more than the whole. A pass
262# run by hand is its process's only pass, which first saw the request.
263[ "$(grep -c '^ timing ' "$work/last.out")" = 1 ] || die "one decision did not print exactly one timing line"
264timing="$(sed -n 's/^ timing //p' "$work/last.out")"
265jq -e --arg head "$(git rev-parse c1)" --arg tip "$before" '
266 keys == ["change", "duration_ms", "first_seen", "first_seen_at_start", "first_seen_pass", "head", "listed_to_began_ms",
267 "outcome", "pass", "pass_listed", "pass_reason", "process", "project", "request", "seen_to_began_ms", "stages_ms",
268 "target", "time", "tip"]
269 and .pass == 1 and .pass_reason == "reconcile" and .first_seen_pass == 1 and .first_seen_at_start == true
270 and .first_seen == .pass_listed and .first_seen <= .time and .seen_to_began_ms == .listed_to_began_ms
271 and .seen_to_began_ms >= 0 and (.process | type == "string" and length > 0)
272 and .request == "refs/the-valley/integration-requests/main/c1" and .change == "c1"
273 and .head == $head and .target == "refs/heads/main" and .tip == $tip and .outcome == "land"
274 and (.project | type == "string" and length > 0)
275 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$"))
276 and (.duration_ms | type == "number" and . >= 0 and . == floor)
277 and (.stages_ms | type == "object"
278 and (keys - ["refusal", "checkout", "evidence", "policy", "apply", "closures", "sign", "land", "record", "publish"] == [])
279 and all(.refusal, .checkout, .evidence, .policy, .sign, .land, .record, .publish; type == "number")
280 and all(.[]; type == "number" and . >= 0 and . == floor))
281 and ([.stages_ms[]] | add) <= .duration_ms' <<< "$timing" > /dev/null \
282 || die "c1's timing line does not say what a landing's should: $timing"
283holds "the landing is timed: $timing"
284
285# The landed note carries both signatures, under one text, and verifies.
286# The integrator writes under its own key hash, so its ref never races the
287# contributor's over the same subject.
288landed="refs/the-valley/attestations/$(attest digest --repo "$repo" --rev c1 | cut -d: -f2)/$ihash"
289git -C "$origin" rev-parse --verify --quiet "$landed" > /dev/null \
290 || die "no attestation ref by the integrator for the landed tree"
291git -C "$origin" cat-file blob "$landed:prose-format/statement.note" > "$work/landed.note"
292siblings="$(grep -c '^— ' "$work/landed.note")"
293[ "$siblings" -eq 2 ] || die "the landed note carries $siblings signatures, not two"
294attest verify --note "$work/landed.note" --known-keys "$work/reader_keys" \
295 --schema "$SCHEMA_ATTESTATION" --repo "$repo" --rev c1 \
296 --signer "$contributor" --signer "$integrator_name" > "$work/landed.verify"
297grep -q 'matches the recorded subject digest' "$work/landed.verify" || die "the landed note does not bind to the tree"
298holds "the landed note carries contributor and integrator sibling signatures and verifies"
299
300# And the integrator's own transfer statement sits beside it.
301git -C "$origin" cat-file blob "$landed:$(transfer_path "$(tip)")" > "$work/transfer.note"
302head -n1 "$work/transfer.note" | grep -qx 'the-valley/attestation/v1' || die "the transfer note is not a statement"
303grep -qx 'predicateType the-valley/integration/transfer/v1' "$work/transfer.note" || die "wrong predicate type"
304grep -qx 'predicate.change c1' "$work/transfer.note" || die "the transfer statement names no change"
305grep -q '^predicate.policy.sha256 ' "$work/transfer.note" || die "the transfer statement names no policy"
306attest verify --note "$work/transfer.note" --known-keys "$work/reader_keys" \
307 --schema "$SCHEMA_ATTESTATION" --signer "$integrator_name" > /dev/null
308holds "the transfer statement records the verdict and the policy it was derived under"
309
310# ----------------------------------------------------------------------
311say "2. an intervening landing invalidates one check's closure"
312
313git checkout --quiet main
314git pull --quiet --ff-only origin main
315
316# c2 is authored against the current tip and reads both classes.
317git checkout --quiet -b c2
318echo "a readme with more in it" > docs/readme.md
319echo "the source, revised" > src/main.txt
320git add -A
321git commit --quiet -m "revise the readme and the source"
322attest_change c2 "" "" --check prose-format --check code-build
323c2="$(git rev-parse c2)"
324
325# Meanwhile another change lands, touching only what code-build reads.
326git checkout --quiet main
327git checkout --quiet -b intervening
328echo "a second source file" > src/other.txt
329git add -A
330git commit --quiet -m "add a second source file"
331attest_change intervening "" "" --check code-build
332request intervening main "$(git rev-parse intervening)"
333integrate
334grep -q "^intervening -> refs/heads/main .*: land$" "$work/last.out" || die "the intervening change did not land"
335holds "the intervening change landed first; c2's base has moved"
336
337request c2 main "$c2"
338integrate
339grep -q "^c2 -> refs/heads/main .*: stale$" "$work/last.out" || die "c2 was not stale"
340grep -q "check prose-format .*transferred (closure)" "$work/last.out" \
341 || die "prose-format should have transferred by closure equality"
342grep -q "check code-build .*input closure changed" "$work/last.out" \
343 || die "code-build's closure should have moved"
344grep -q '"event":"request-stale"' "$work/last.out" || die "no request-stale event"
345grep -q '"checks":\["code-build"\]' "$work/last.out" || die "the event does not name exactly code-build"
346git -C "$origin" rev-parse --verify --quiet refs/the-valley/integration-requests/main/c2 > /dev/null \
347 || die "the request ref was dropped; there is nothing to approve again"
348holds "one request-stale naming exactly code-build; prose-format reported transferred"
349asked_nix "eval shared code-build prose-format"
350holds "both checks were evaluated together on the moved tree, in one evaluation, and nothing was built"
351forget c2
352
353# ----------------------------------------------------------------------
354say "2b. evidence that survives the rebase lands on the moved tip"
355
356# The same shape as 2, with the intervening landing outside what the
357# change's checks read. The tree that lands is not the tree that was
358# attested, and the evidence stands anyway — which is the whole of what
359# content-addressed evidence buys.
360git checkout --quiet main
361git pull --quiet --ff-only origin main
362git checkout --quiet -b c2b
363echo "a readme revised again" > docs/readme.md
364git add -A
365git commit --quiet -m "revise the readme once more"
366attest_change c2b "" "" --check prose-format
367c2b="$(git rev-parse c2b)"
368attested="$(attest digest --repo "$repo" --rev c2b | cut -d: -f2)"
369
370git checkout --quiet main
371git checkout --quiet -b elsewhere
372echo "a third source file" > src/third.txt
373git add -A
374git commit --quiet -m "add a third source file"
375attest_change elsewhere "" "" --check code-build
376request elsewhere main "$(git rev-parse elsewhere)"
377integrate
378grep -q "^elsewhere -> refs/heads/main .*: land$" "$work/last.out" || die "the intervening change did not land"
379intervened="$(tip)"
380
381request c2b main "$c2b"
382integrate
383grep -q "^c2b -> refs/heads/main .*: land$" "$work/last.out" || die "c2b did not land"
384grep -q "check prose-format .*transferred (closure)" "$work/last.out" \
385 || die "the evidence did not transfer by closure equality"
386landedtree="$(git -C "$origin" rev-parse refs/heads/main^{tree})"
387[ "$(git -C "$origin" rev-parse "refs/heads/main^")" = "$intervened" ] \
388 || die "the landing is not a fast-forward from the tip it was judged against"
389[ "$(git -C "$origin" rev-parse refs/heads/main^{tree})" != "$(git rev-parse "$c2b^{tree}")" ] \
390 || die "the tree did not actually move; the scenario proves nothing"
391holds "the delta landed on a tree it was never attested over, and no check re-ran"
392asked_nix "eval prose-format"
393holds "the one check was evaluated once, alone"
394
395# Two attestation refs now, because the two statements are about two
396# different trees: the contributor's is keyed by the tree it was made over,
397# and the integrator's transfer statement by the tree that landed.
398git fetch --quiet origin main
399landed_digest="$(attest digest --repo "$repo" --rev "$(git -C "$origin" rev-parse refs/heads/main)" | cut -d: -f2)"
400[ "$landed_digest" != "$attested" ] || die "the landed tree is the attested tree; the scenario proves nothing"
401git -C "$origin" cat-file blob \
402 "refs/the-valley/attestations/$attested/$ihash:prose-format/statement.note" > "$work/rebased.note"
403[ "$(grep -c '^— ' "$work/rebased.note")" -eq 2 ] \
404 || die "the countersigned note lost a sibling signature"
405grep -qx "subject.digest.valley-tree-v1 $attested" "$work/rebased.note" \
406 || die "the countersigned statement is not about the tree it was made over"
407git -C "$origin" cat-file blob \
408 "refs/the-valley/attestations/$landed_digest/$ihash:$(transfer_path "$(tip)")" > "$work/rebased.transfer"
409grep -qx "subject.digest.valley-tree-v1 $landed_digest" "$work/rebased.transfer" \
410 || die "the transfer statement is not about the landed tree"
411grep -qx "predicate.base.valley-tree-v1 $attested" "$work/rebased.transfer" \
412 || die "the transfer statement does not cite the base the evidence was produced over"
413grep -qx "predicate.checks.0.rule closure" "$work/rebased.transfer" \
414 || die "the transfer statement does not record the rule that carried the evidence"
415holds "the contributor's statement stays about its own tree; the transfer statement names the landed one"
416
417# ----------------------------------------------------------------------
418say "2c. a re-parenting landing states its own committer, and needs none from the environment"
419
420# Re-parenting is the one landing that makes a commit of the integrator's
421# own, so it is the one that needs a committer. Under the unit there is
422# nothing to take one from: no git config the service can read, no GIT_* in
423# its environment, and a hostname git will not guess an address from. So the
424# integrator states both identities itself — the asker authored the change,
425# the integrator committed the commit that carries it onto the tip — and the
426# pass below runs with everything git could have fallen back to taken away.
427
428# A scrubbed environment: no global or system config, no GIT_* identity, and
429# auto-detection refused outright, so that a host whose own hostname does
430# resolve cannot hide a dependency on it.
431scrubbed() {
432 env -u GIT_AUTHOR_NAME -u GIT_AUTHOR_EMAIL -u GIT_AUTHOR_DATE \
433 -u GIT_COMMITTER_NAME -u GIT_COMMITTER_EMAIL -u GIT_COMMITTER_DATE -u EMAIL \
434 GIT_CONFIG_GLOBAL=/dev/null GIT_CONFIG_NOSYSTEM=1 \
435 GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=user.useConfigOnly GIT_CONFIG_VALUE_0=true \
436 "$@"
437}
438scrubbed git -C "$origin" var GIT_COMMITTER_IDENT > /dev/null 2>&1 \
439 && die "the scrub left an identity for git to find; the scenario proves nothing"
440
441git checkout --quiet main
442git pull --quiet --ff-only origin main
443git checkout --quiet -b c2c
444echo "a readme revised by a stated author" > docs/readme.md
445git add -A
446# A distinct author, so that what the landed commit carries over from the
447# head and what it states of its own are told apart by reading it.
448GIT_AUTHOR_NAME="a contributor" GIT_AUTHOR_EMAIL="contributor@valley.invalid" \
449 git commit --quiet -m "revise the readme under an author of its own"
450attest_change c2c "" "" --check prose-format
451c2c="$(git rev-parse c2c)"
452
453# The intervening landing, outside what prose-format reads, is what moves
454# c2c's base and makes the landing below a re-parent rather than a
455# fast-forward.
456git checkout --quiet main
457git checkout --quiet -b under-c2c
458echo "a fifth source file" > src/fifth.txt
459git add -A
460git commit --quiet -m "add a fifth source file"
461attest_change under-c2c "" "" --check code-build
462request under-c2c main "$(git rev-parse under-c2c)"
463integrate
464grep -q "^under-c2c -> refs/heads/main .*: land$" "$work/last.out" || die "the intervening change did not land"
465
466request c2c main "$c2c"
467pre="$(tip)"
468scrubbed integrator reconcile \
469 --repo "$origin" \
470 --key "$work/integrator" --name "$integrator_name" \
471 --known-signers "$work/known_signers" \
472 --instance-repo "$instance_repo" \
473 --schema "$SCHEMA_VERIFICATION" \
474 --attest-schema "$SCHEMA_ATTESTATION" \
475 --event-schema "$SCHEMA_EVENTS" \
476 ${VALLEY_E2E_NOW:+--now "$VALLEY_E2E_NOW"} \
477 2>&1 | tee "$work/last.out"
478grep -q "^c2c -> refs/heads/main .*: land$" "$work/last.out" \
479 || die "a landing with no git identity in the environment did not land: $(cat "$work/last.out")"
480
481landed_commit="$(git -C "$origin" rev-parse refs/heads/main)"
482[ "$(git -C "$origin" merge-base "$c2c" "$pre")" != "$pre" ] \
483 || die "c2c's base is the tip it landed on, so main did not move under it; the scenario proves nothing"
484[ "$(git -C "$origin" rev-list --no-walk --parents "$landed_commit")" = "$landed_commit $pre" ] \
485 || die "c2c did not land as one commit on the tip before the pass"
486[ "$(git -C "$origin" log -1 --format='%an <%ae>' "$landed_commit")" = "a contributor <contributor@valley.invalid>" ] \
487 || die "the landed commit is not authored by the asker: $(git -C "$origin" log -1 --format='%an <%ae>' "$landed_commit")"
488[ "$(git -C "$origin" log -1 --format='%cn <%ce>' "$landed_commit")" = "$integrator_name <integrator@the-valley.invalid>" ] \
489 || die "the landed commit is not committed by the integrator: $(git -C "$origin" log -1 --format='%cn <%ce>' "$landed_commit")"
490# The commit id is a function of what the pass decided from and nothing
491# else, so a pass that dies before the ref write recomputes this same
492# commit rather than leaving another behind.
493[ "$(git -C "$origin" log -1 --format=%aI "$landed_commit")" = "$(git -C "$origin" log -1 --format=%cI "$landed_commit")" ] \
494 || die "the committer date is not the author's, so the landed commit id is not reproducible"
495holds "the integrator committed under its own name with nothing in the environment to take one from"
496
497# ----------------------------------------------------------------------
498say "2d. a check that does not evaluate on the moved tree is stale alone"
499
500# c2d reads both classes. Landings under it then keep code-build from
501# evaluating on the tree that would land, while prose-format still
502# evaluates there: first with an error no evaluation can catch, which ends
503# the shared evaluation of both, then by taking the check out of the tree.
504# Each time the two checks together fail, each is evaluated alone, so
505# prose-format still transfers and code-build alone is stale.
506git checkout --quiet main
507git pull --quiet --ff-only origin main
508git checkout --quiet -b c2d
509echo "a readme revised beside the source" > docs/readme.md
510echo "the source, revised beside the readme" > src/main.txt
511git add -A
512git commit --quiet -m "revise the readme and the source together"
513attest_change c2d "" "" --check prose-format --check code-build
514c2d="$(git rev-parse c2d)"
515
516# land_unclassified BRANCH MESSAGE — commit what is staged, on BRANCH off
517# main, and land it. It touches only checks/, which no class covers, so it
518# requires no check.
519land_unclassified() {
520 git commit --quiet -m "$2"
521 request "$1" main "$(git rev-parse "$1")"
522 integrate
523 grep -q "^$1 -> refs/heads/main .*: land$" "$work/last.out" || die "$1 did not land"
524 git checkout --quiet main
525 git pull --quiet --ff-only origin main
526}
527
528# c2d_is_stale_alone WHY — c2d, requested now, is stale, prose-format
529# transfers, and code-build alone could not be recomputed, for WHY.
530c2d_is_stale_alone() {
531 request c2d main "$c2d"
532 integrate
533 grep -q "^c2d -> refs/heads/main .*: stale$" "$work/last.out" || die "c2d was not stale"
534 grep -q "check prose-format .*transferred (closure)" "$work/last.out" \
535 || die "prose-format did not transfer beside the check that does not evaluate"
536 grep -q "check code-build .*could not be recomputed on the landed tree: attest: evaluating .*$1" "$work/last.out" \
537 || die "code-build is not reported as not evaluating: $(grep 'check code-build' "$work/last.out")"
538 grep -q '"checks":\["code-build"\]' "$work/last.out" || die "the event does not name exactly code-build"
539 forget c2d
540}
541
542git checkout --quiet main
543git checkout --quiet -b uncaught
544echo "error: code-build does not evaluate, and nothing can catch it" > checks/code-build.uncaught
545git add -A
546land_unclassified uncaught "break code-build beyond catching"
547c2d_is_stale_alone "nothing can catch it"
548# Together, then in the shared evaluation's place each alone, then each in
549# a call of its own: 2N+1 evaluations of N checks, where it is N alone.
550asked_nix "eval shared code-build prose-format" "eval code-build" "eval prose-format" \
551 "eval code-build" "eval prose-format"
552holds "an error that ends the shared evaluation leaves prose-format transferred and code-build alone stale"
553
554git checkout --quiet -b missing
555git rm --quiet checks/code-build.uncaught checks/code-build.inputs
556land_unclassified missing "take code-build out of the tree"
557c2d_is_stale_alone "declares no check code-build"
558asked_nix "eval shared code-build prose-format" "eval code-build" "eval code-build" "eval prose-format"
559holds "a check missing from the tree leaves prose-format transferred and code-build alone stale"
560
561git checkout --quiet -b restored
562echo src > checks/code-build.inputs
563git add -A
564land_unclassified restored "put code-build back"
565
566# ----------------------------------------------------------------------
567say "3. a conflicting delta is stale, and demands full re-attestation"
568
569git checkout --quiet main
570git pull --quiet --ff-only origin main
571git checkout --quiet -b c3
572echo "the readme, as c3 would have it" > docs/readme.md
573git add -A
574git commit --quiet -m "rewrite the readme one way"
575attest_change c3 "" "" --check prose-format
576c3="$(git rev-parse c3)"
577
578git checkout --quiet main
579git checkout --quiet -b conflicting
580echo "the readme, as the other change would have it" > docs/readme.md
581git add -A
582git commit --quiet -m "rewrite the readme another way"
583attest_change conflicting "" "" --check prose-format
584request conflicting main "$(git rev-parse conflicting)"
585integrate
586grep -q "^conflicting -> refs/heads/main .*: land$" "$work/last.out" || die "the conflicting change did not land"
587
588request c3 main "$c3"
589integrate
590grep -q "^c3 -> refs/heads/main .*: stale$" "$work/last.out" || die "c3 was not stale"
591grep -q 'resolving it is new authorship' "$work/last.out" || die "the conflict was not reported as new authorship"
592grep -q 'CONFLICT (content): Merge conflict in docs/readme.md' "$work/last.out" \
593 || die "the conflict does not name what could not be merged"
594grep -q '"reason":"conflict"' "$work/last.out" || die "the event does not say conflict"
595grep -q '"checks":\["prose-format"\]' "$work/last.out" || die "a conflict must re-demand every required check"
596holds "a conflict is stale, and every required check is re-demanded"
597forget c3
598
599# ----------------------------------------------------------------------
600say "4. an unknown signer's attestation does not transfer"
601
602git checkout --quiet main
603git pull --quiet --ff-only origin main
604git checkout --quiet -b c4
605echo "a readme signed by a stranger" > docs/readme.md
606git add -A
607git commit --quiet -m "a change a stranger attested"
608attest_change c4 "$work/stranger" "$stranger" --check prose-format
609request c4 main "$(git rev-parse c4)"
610integrate
611grep -q "^c4 -> refs/heads/main .*: stale$" "$work/last.out" || die "c4 was not stale"
612grep -q 'no signer the integrator holds' "$work/last.out" || die "the unknown signer was not reported"
613grep -q '"checks":\["prose-format"\]' "$work/last.out" || die "the event does not name prose-format"
614[ "$(tip)" = "$(git -C "$origin" rev-parse refs/heads/main)" ] || die "main moved"
615holds "evidence from a signer the integrator does not hold does not transfer"
616forget c4
617
618# ----------------------------------------------------------------------
619say "5. a tampered statement is rejected, not called stale"
620
621git checkout --quiet main
622git checkout --quiet -b c5
623echo "an honest readme" > docs/readme.md
624git add -A
625git commit --quiet -m "an honest change"
626attest_change c5 "" "" --check prose-format
627c5="$(git rev-parse c5)"
628c5digest="$(attest digest --repo "$repo" --rev c5 | cut -d: -f2)"
629
630# Edit one value in the signed text and store the result where the real
631# note was. Everything else about the note is untouched.
632c5ref="$(git -C "$origin" for-each-ref --format='%(refname)' \
633 "refs/the-valley/attestations/$c5digest" | head -n1)"
634git -C "$origin" cat-file blob "$c5ref:prose-format/statement.note" \
635 | sed 's/^predicate.result passed$/predicate.result failed/' > "$work/tampered.note"
636cmp -s "$work/tampered.note" <(git -C "$origin" cat-file blob "$c5ref:prose-format/statement.note") \
637 && die "the tamper changed nothing; the test proves nothing"
638blob="$(git -C "$origin" hash-object -w --stdin < "$work/tampered.note")"
639sub="$(printf '100644 blob %s\tstatement.note\n' "$blob" | git -C "$origin" mktree)"
640top="$(printf '040000 tree %s\tprose-format\n' "$sub" | git -C "$origin" mktree)"
641git -C "$origin" update-ref "$c5ref" "$top"
642
643request c5 main "$c5"
644integrate
645grep -q "^c5 -> refs/heads/main .*: reject$" "$work/last.out" || die "a tampered statement was not rejected"
646grep -q 'does not verify as the statement it claims to be' "$work/last.out" || die "the refusal was not reported"
647grep -q 'request-stale' "$work/last.out" && die "a forgery was announced as staleness"
648holds "a tampered statement is a rejection, and no outcome event claims otherwise"
649forget c5
650
651# ----------------------------------------------------------------------
652say "6. an attestation about a different tree is rejected"
653
654git checkout --quiet main
655git checkout --quiet -b c6
656echo "the tree that was actually attested" > docs/readme.md
657git add -A
658git commit --quiet -m "the attested change"
659attest_change c6 "" "" --check prose-format
660c6ref="$(git -C "$origin" for-each-ref --format='%(refname)' \
661 "refs/the-valley/attestations/$(attest digest --repo "$repo" --rev c6 | cut -d: -f2)" | head -n1)"
662
663# A second, different tree — with no attestation of its own — and the
664# first tree's valid, correctly signed note filed under its digest.
665git checkout --quiet -b c6-lifted
666echo "the tree that was not" > docs/readme.md
667git add -A
668git commit --quiet -m "the change the evidence was lifted onto"
669git push --quiet origin c6-lifted
670lifted="$(attest digest --repo "$repo" --rev c6-lifted | cut -d: -f2)"
671git -C "$origin" update-ref \
672 "refs/the-valley/attestations/$lifted/${c6ref##*/}" \
673 "$(git -C "$origin" rev-parse "$c6ref^{tree}")"
674
675request c6 main "$(git rev-parse c6-lifted)"
676integrate
677grep -q "^c6 -> refs/heads/main .*: reject$" "$work/last.out" || die "a lifted attestation was not rejected"
678grep -q 'tree digest mismatch' "$work/last.out" || die "the refusal does not name the tree digest"
679holds "a signature cannot be lifted onto a tree it was not made about"
680forget c6
681
682# ----------------------------------------------------------------------
683say "7. an attestation of the wrong kind is no evidence"
684
685# The policy runs prose-format with nix, so its evidence is content-
686# addressed. This attestation is for a notarization instead, and its class
687# was untouched by the intervening landing — so under the rule it nominated
688# for itself it would sail onto a base it was never produced over. The
689# integrator counts a note of the wrong kind as no evidence, so the request
690# is stale.
691git checkout --quiet main
692git pull --quiet --ff-only origin main
693git checkout --quiet -b c7
694echo "a readme attested as a notarization" > docs/readme.md
695git add -A
696git commit --quiet -m "a change whose attestation lies about its kind"
697attest_change c7 "" "" --command prose-format=true
698c7="$(git rev-parse c7)"
699
700git checkout --quiet main
701git checkout --quiet -b under-c7
702echo "a fourth source file" > src/fourth.txt
703git add -A
704git commit --quiet -m "add a fourth source file"
705attest_change under-c7 "" "" --check code-build
706request under-c7 main "$(git rev-parse under-c7)"
707integrate
708grep -q "^under-c7 -> refs/heads/main .*: land$" "$work/last.out" || die "the intervening change did not land"
709
710request c7 main "$c7"
711integrate
712grep -q "^c7 -> refs/heads/main .*: stale$" "$work/last.out" || die "a note of the wrong kind was not treated as no evidence"
713grep -q 'requires a pure check and the attestation is for an effectful check' "$work/last.out" \
714 || die "the verdict does not say the policy decides the rule"
715holds "the transfer rule follows the policy's runner, never the attestation's own claim"
716forget c7
717
718# ----------------------------------------------------------------------
719say "8. evidence pushed after a no-evidence verdict re-judges and lands"
720
721git checkout --quiet main
722git pull --quiet --ff-only origin main
723git checkout --quiet -b c8
724echo "a readme with no evidence yet" > docs/readme.md
725git add -A
726git commit --quiet -m "a change submitted before its checks ran"
727git push --quiet origin c8
728request c8 main "$(git rev-parse c8)"
729integrate
730grep -q "^c8 -> refs/heads/main .*: stale$" "$work/last.out" || die "a change with no evidence was not stale"
731grep -q 'no attestation for this check accompanies the change' "$work/last.out" \
732 || die "the absent attestation was not reported"
733
734# Nothing about the request or the tip moves; only the evidence arrives.
735attest_change c8 "" "" --check prose-format
736integrate
737grep -q "^c8 -> refs/heads/main .*: land$" "$work/last.out" \
738 || die "the request was not re-judged after its evidence arrived"
739landed_as "$(git rev-parse c8)" "$pre"
740holds "a pass re-judges when evidence arrives, with the request and the tip unmoved"
741
742# ----------------------------------------------------------------------
743say "9. a ref that is not a request does not hold up one that is"
744
745git checkout --quiet main
746git pull --quiet --ff-only origin main
747git checkout --quiet -b c9
748echo "a readme beside a garbage ref" > docs/readme.md
749git add -A
750git commit --quiet -m "a change beside a malformed request"
751attest_change c9 "" "" --check prose-format
752# A name with no target segment at all, and one with a segment too many.
753# This repository is served with no pre-receive hook, so the namespace takes
754# whatever is pushed; on a host only a holder of the request grant writes
755# it, and a holder can still write a name that is not a request.
756git push --quiet origin "$(git rev-parse c9):refs/the-valley/integration-requests/garbage"
757git push --quiet origin "$(git rev-parse c9):refs/the-valley/integration-requests/main/too/deep"
758request c9 main "$(git rev-parse c9)"
759integrate
760grep -q 'refs/the-valley/integration-requests/garbage: not a request ref' "$work/last.out" \
761 || die "the malformed ref was not reported"
762grep -q 'refs/the-valley/integration-requests/main/too/deep: not a request ref' "$work/last.out" \
763 || die "the over-deep ref was not reported"
764grep -q "^c9 -> refs/heads/main .*: land$" "$work/last.out" \
765 || die "a malformed ref stopped the pass reaching a valid request"
766holds "malformed refs are reported and skipped; the valid request beside them landed"
767git -C "$origin" update-ref -d refs/the-valley/integration-requests/garbage
768git -C "$origin" update-ref -d refs/the-valley/integration-requests/main/too/deep
769
770# ----------------------------------------------------------------------
771say "10. a pass leaves no scratch behind, and a leaked worktree is swept"
772
773# Nine scenarios of real passes, landings and rejections alike, and the
774# scratch root is empty: every worktree a pass takes is given back on the
775# way out, on the failure path as much as the success one.
776leftover="$(find "$TMPDIR" -maxdepth 1 -name 'valley-integrator-wt*')"
777[ -z "$leftover" ] || die "nine passes left scratch behind: $leftover"
778[ "$(git -C "$origin" worktree list --porcelain | grep -c '^worktree ')" -eq 1 ] \
779 || die "nine passes left a worktree attached to the repository"
780holds "no pass left a worktree or a scratch directory behind"
781
782# What a crash leaves: the checkout and its administrative entry, both
783# still valid, so nothing prunes them. Beside it, a worktree of the kind
784# an operator might attach by hand, which is not the integrator's to
785# remove.
786leak="$TMPDIR/valley-integrator-wt-crashed"
787mine="$work/an-operators-own-worktree"
788git -C "$origin" worktree add --quiet --detach "$leak" refs/heads/main
789git -C "$origin" worktree add --quiet --detach "$mine" refs/heads/main
790timeout 5 integrator watch --interval 1s \
791 --repo "$origin" \
792 --key "$work/integrator" --name "$integrator_name" \
793 --known-signers "$work/known_signers" \
794 --instance "$instance" \
795 --schema "$SCHEMA_VERIFICATION" \
796 --attest-schema "$SCHEMA_ATTESTATION" \
797 --event-schema "$SCHEMA_EVENTS" \
798 ${VALLEY_E2E_NOW:+--now "$VALLEY_E2E_NOW"} \
799 > "$work/watch.out" 2>&1 || true
800[ ! -e "$leak" ] || die "a leaked scratch worktree survived the sweep"
801if git -C "$origin" worktree list --porcelain | grep -q "^worktree $leak$"; then
802 die "the leaked worktree is gone from disk and still registered"
803fi
804[ -e "$mine" ] || die "the sweep removed a worktree the integrator did not make"
805git -C "$origin" worktree remove --force "$mine"
806holds "a crash-leaked scratch worktree is swept at watch start; another hand's is not"
807
808# ----------------------------------------------------------------------
809say "11. a scratch root it may not write is reported as that, and nothing else"
810
811# The deployment failure this guards is a sandbox failure: the root TMPDIR
812# names is not writable. That is a statement about the unit, not about the
813# change being judged, and it has to arrive as one — with the path and where
814# the path came from — rather than as git complaining about the leading
815# directories of a .git file.
816refused="$work/refused"
817mkdir -p "$refused"
818chmod a-w "$refused"
819git checkout --quiet main
820git pull --quiet --ff-only origin main
821git checkout --quiet -b c10
822echo "a change that never gets a worktree" > docs/readme.md
823git add -A
824git commit --quiet -m "a change the integrator cannot make scratch for"
825attest_change c10 "" "" --check prose-format
826request c10 main "$(git rev-parse c10)"
827export TMPDIR="$refused"
828integrate || true
829export TMPDIR="$work/tmp"
830chmod u+w "$refused"
831grep -q "scratch directory under $refused, which TMPDIR names" "$work/last.out" \
832 || die "an unwritable scratch root was not reported as one: $(cat "$work/last.out")"
833forget c10
834holds "an unwritable scratch root names the path and where it came from"
835
836# ----------------------------------------------------------------------
837say "12. a floor the instance repository does not carry names the directory looked in"
838
839# The deployment failure this guards is a controller pointed at the wrong
840# directory: the floor is somewhere, and not where this controller looked.
841# The report has to name the repository, the directory and the ref, because
842# those three are what the operator compares against the repository in front
843# of them. A floor is either not there at all, or there under a name that
844# holds no documents, and both arrive that way.
845#
846# A missing floor is refused rather than read as requiring nothing, which is
847# the direction the other layer's absence defaults in (dcr-f41f718). The
848# refusal says why in its own sentence, because the operator reading it is
849# being told that the deployment is not one that can land anything.
850git checkout --quiet main
851git pull --quiet --ff-only origin main
852git checkout --quiet -b c11
853echo "a change judged under no floor" > docs/readme.md
854git add -A
855git commit --quiet -m "a change whose floor the controller cannot find"
856attest_change c11 "" "" --check prose-format
857request c11 main "$(git rev-parse c11)"
858
859# The sentence every refusal to find a floor ends with.
860unwritten="a valley without a written floor is not a valley whose changes land"
861
862floorless() {
863 integrator reconcile \
864 --repo "$origin" \
865 --key "$work/integrator" --name "$integrator_name" \
866 --known-signers "$work/known_signers" "$@" \
867 --schema "$SCHEMA_VERIFICATION" \
868 --attest-schema "$SCHEMA_ATTESTATION" \
869 --event-schema "$SCHEMA_EVENTS" \
870 ${VALLEY_E2E_NOW:+--now "$VALLEY_E2E_NOW"} \
871 2>&1 | tee "$work/last.out"
872}
873
874# The project's own repository carries policy/project and no policy/instance,
875# so the default directory is not there.
876floorless --instance-repo "$origin" || true
877grep -qF "no instance policy layer: $origin has no policy/instance/ at refs/heads/main: $unwritten" "$work/last.out" \
878 || die "a missing floor did not name the directory looked in, and why that is refused: $(cat "$work/last.out")"
879
880# And the flat layout, which is a directory that exists and holds no
881# documents of its own: policy/ has the two layers under it and no *.cue in
882# it. Said as that, rather than as an empty composition further on.
883#
884# Under a second request name, because the refusal above is now this
885# controller's recorded answer to c11 and it stands until the request, the
886# tip, the evidence or the inputs move — which is scenario 14's whole
887# subject. A request is what an answer is remembered against, so a second
888# one asks the question again.
889request c11-flat main "$(git rev-parse c11)"
890floorless --instance-repo "$origin" --instance-policy policy || true
891grep -qF "no instance policy layer: $origin holds no *.cue in policy/ at refs/heads/main: $unwritten" "$work/last.out" \
892 || die "a floor directory holding no documents did not say so: $(cat "$work/last.out")"
893
894# And the materialized layer, which is how a host that serves no instance
895# repository is given the floor. A directory with nothing in it is the same
896# absence and is refused the same way.
897request c11-bare main "$(git rev-parse c11)"
898nofloor="$work/no-floor-here"
899mkdir -p "$nofloor"
900floorless --instance "$nofloor" || true
901grep -qF "no instance policy layer: $nofloor holds no *.cue: $unwritten" "$work/last.out" \
902 || die "an empty materialized floor was not refused: $(cat "$work/last.out")"
903forget c11
904forget c11-flat
905forget c11-bare
906holds "a floor that is not where the controller looked names the repository, the directory and the ref"
907
908# ----------------------------------------------------------------------
909say "13. a change the policy requires no check of lands, and says so"
910
911# Requiring nothing is an ordinary outcome, not an edge: this project's
912# classes cover docs/, src/ and deploy/, and its `unclassified` set is
913# empty, so a path outside all three is answered with nothing required. The
914# landing still writes a transfer statement — a commit point that records
915# nothing is a landing nothing attests to — and that statement says the
916# required set was empty rather than carrying a list with nothing in it,
917# which has no written form at all.
918git checkout --quiet main
919git pull --quiet --ff-only origin main
920git checkout --quiet -b c12
921echo "outside every class this policy covers" > notes.txt
922git add -A
923git commit --quiet -m "a change no class covers"
924request c12 main "$(git rev-parse c12)"
925integrate
926grep -q '^c12 -> refs/heads/main .*: land$' "$work/last.out" \
927 || die "a change with nothing required did not land: $(cat "$work/last.out")"
928grep -q 'the policy requires no check of the paths this change touches' "$work/last.out" \
929 || die "the verdict did not say the policy required nothing"
930landed_as "$(git rev-parse c12)" "$pre"
931git -C "$origin" rev-parse --verify --quiet "refs/the-valley/integration-requests/main/c12" > /dev/null \
932 && die "the request ref survived the landing"
933
934nothing="refs/the-valley/attestations/$(attest digest --repo "$repo" --rev c12 | cut -d: -f2)/$ihash"
935git -C "$origin" cat-file blob "$nothing:$(transfer_path "$(tip)")" > "$work/nothing.note"
936grep -qx 'predicate.required none' "$work/nothing.note" \
937 || die "the transfer statement does not say the required set was empty: $(cat "$work/nothing.note")"
938grep -q '^predicate.checks' "$work/nothing.note" \
939 && die "the transfer statement carries a check list beside the empty-set line"
940attest verify --note "$work/nothing.note" --known-keys "$work/reader_keys" \
941 --repo "$repo" --rev c12 --signer "$integrator_name" > /dev/null \
942 || die "the transfer statement for a landing with nothing required does not verify"
943holds "a landing with no required checks is signed, stored, and consumed its request"
944
945# ----------------------------------------------------------------------
946say "14. a request the controller cannot judge is reported once, not every tick"
947
948# The failure this guards is the one that turns a broken deployment into a
949# broken deployment nobody can read: a pass that cannot act on its verdict,
950# retried at tick rate, filling the journal with one refusal per interval
951# forever. The same request, tip and evidence produce the same failure, so
952# repeating it says nothing new. It is reported once and then the answer
953# stands, exactly as an outcome stands.
954git checkout --quiet main
955git pull --quiet --ff-only origin main
956git checkout --quiet -b c13
957echo "a change judged under no floor, repeatedly" > docs/readme.md
958git add -A
959git commit --quiet -m "a change whose floor the controller cannot find, under watch"
960attest_change c13 "" "" --check prose-format
961request c13 main "$(git rev-parse c13)"
962
963# Five seconds at a one-second tick: five passes over one request the
964# controller cannot judge.
965timeout 5 integrator watch --interval 1s \
966 --repo "$origin" \
967 --key "$work/integrator" --name "$integrator_name" \
968 --known-signers "$work/known_signers" \
969 --instance-repo "$origin" --instance-policy policy \
970 --schema "$SCHEMA_VERIFICATION" \
971 --attest-schema "$SCHEMA_ATTESTATION" \
972 --event-schema "$SCHEMA_EVENTS" \
973 ${VALLEY_E2E_NOW:+--now "$VALLEY_E2E_NOW"} \
974 > "$work/repeat.out" 2>&1 || true
975reports="$(grep -c 'no instance policy layer' "$work/repeat.out" || true)"
976[ "$reports" -eq 1 ] \
977 || die "the same refusal was reported $reports times over five ticks: $(cat "$work/repeat.out")"
978forget c13
979holds "a failure a pass cannot get past is reported once and then backs off"
980
981# ----------------------------------------------------------------------
982say "14b. a failure is recorded before its timing line, which nobody has to read"
983
984# The timing line is printed after the outcome is recorded, and is dropped
985# when it cannot be written. A pass that cannot act on its verdict prints
986# nothing before its timing line, so with standard output a pipe whose
987# reader has gone, the timing line is the first write to fail. The failure
988# is recorded all the same. The line the integrator prints after it, naming
989# the failure, is its own output rather than timing, and may still end the
990# pass there.
991git checkout --quiet main
992git pull --quiet --ff-only origin main
993git checkout --quiet -b c14b
994echo "a change judged with nobody reading" > docs/readme.md
995git add -A
996git commit --quiet -m "a change judged with nobody reading the integrator"
997attest_change c14b "" "" --check prose-format
998request c14b main "$(git rev-parse c14b)"
999
1000# A pipe with no reader. The FIFO is opened to read and write, so opening it
1001# to write does not wait; closing the first leaves the writer alone.
1002mkfifo "$work/unread"
1003exec 3<> "$work/unread"
1004exec 4> "$work/unread"
1005exec 3<&-
1006status=0
1007timeout 120 integrator reconcile \
1008 --repo "$origin" \
1009 --key "$work/integrator" --name "$integrator_name" \
1010 --known-signers "$work/known_signers" \
1011 --instance-repo "$origin" --instance-policy policy \
1012 --schema "$SCHEMA_VERIFICATION" \
1013 --attest-schema "$SCHEMA_ATTESTATION" \
1014 --event-schema "$SCHEMA_EVENTS" \
1015 ${VALLEY_E2E_NOW:+--now "$VALLEY_E2E_NOW"} \
1016 >&4 2> "$work/unread.err" || status=$?
1017exec 4>&-
1018[ "$status" != 124 ] || die "the pass did not finish with nobody reading its output"
1019recorded="$(git -C "$origin" cat-file blob refs/the-valley/integration-outcomes/main/c14b 2> /dev/null || true)"
1020[ "$(echo "$recorded" | cut -d' ' -f4)" = failed ] \
1021 || die "with nobody reading its output, the pass did not record its failure (exit $status): ${recorded:-no record} $(cat "$work/unread.err")"
1022forget c14b
1023holds "with nobody reading its output, the pass recorded its failure before its timing line (exit $status)"
1024
1025# ----------------------------------------------------------------------
1026say "15. a target that carries no project layer of its own is judged under the floor alone"
1027
1028# The bootstrap this guards is the first policy commit: a project that has
1029# not written a layer yet cannot land the commit that writes one, because a
1030# change never supplies the policy that gates it. The project layer only
1031# ever adds (dcr-f41f718), so its absence adds nothing, and what is left is
1032# the floor — which still governs, and is observed governing here.
1033
1034# The floor grows a requirement of its own first, so that what remains after
1035# the project layer goes away is something rather than nothing.
1036cat > "$floor/policy/instance/floor.cue" <<'EOF'
1037package verification
1038
1039floor: {
1040 checks: "prose-format": {runner: "nix", attribute: "prose-format"}
1041 classes: prose: {paths: "docs/**": true, requires: "prose-format": true}
1042 unclassified: {}
1043}
1044EOF
1045git -C "$floor" commit --quiet -am "the floor requires prose-format of docs/"
1046git -C "$floor" push --quiet "$instance_repo" main
1047
1048# The project stops carrying a layer. Nothing classifies policy/project
1049# itself, so this lands with nothing required — which is how a project could
1050# have arrived without one in the first place.
1051git checkout --quiet main
1052git pull --quiet --ff-only origin main
1053git checkout --quiet -b c14
1054git rm --quiet -r policy/project
1055git commit --quiet -m "stop carrying a project policy layer"
1056request c14 main "$(git rev-parse c14)"
1057integrate
1058grep -q "^c14 -> refs/heads/main .*: land$" "$work/last.out" \
1059 || die "dropping the project layer did not land: $(cat "$work/last.out")"
1060
1061git checkout --quiet main
1062git pull --quiet --ff-only origin main
1063[ ! -e policy/project ] || die "the project layer is still at the tip; the scenario proves nothing"
1064git checkout --quiet -b c15
1065echo "a readme judged under the floor alone" > docs/readme.md
1066git add -A
1067git commit --quiet -m "a change to a project that declares no policy of its own"
1068attest_change c15 "" "" --check prose-format
1069request c15 main "$(git rev-parse c15)"
1070integrate
1071grep -q "^c15 -> refs/heads/main .*: land$" "$work/last.out" \
1072 || die "a change to a project with no layer of its own did not land: $(cat "$work/last.out")"
1073grep -qF "policy no project layer at policy/project; the floor alone" "$work/last.out" \
1074 || die "the pass did not say it composed the floor alone"
1075grep -q "check prose-format .*transferred" "$work/last.out" \
1076 || die "the floor's own requirement did not govern a project with no layer"
1077landed_as "$(git rev-parse c15)" "$pre"
1078holds "no project layer is no addition; the floor alone required prose-format and the change landed"
1079
1080# ----------------------------------------------------------------------
1081say "16. a floor that requires nothing, written down, composes and judges"
1082
1083# Emptiness a floor states is not the same thing as a floor nobody wrote.
1084# The document is there, somebody landed it, and what it composes to is a
1085# policy that requires nothing — so a change under it lands requiring nothing,
1086# rather than being refused the way scenario 12's missing floor is.
1087cat > "$floor/policy/instance/floor.cue" <<'EOF'
1088package verification
1089
1090floor: {
1091 checks: {}
1092 classes: {}
1093 unclassified: {}
1094}
1095EOF
1096git -C "$floor" commit --quiet -am "the floor requires nothing, and says so"
1097git -C "$floor" push --quiet "$instance_repo" main
1098
1099git checkout --quiet main
1100git pull --quiet --ff-only origin main
1101git checkout --quiet -b c16
1102echo "a readme under a floor that requires nothing" > docs/readme.md
1103git add -A
1104git commit --quiet -m "a change under an empty floor and no project layer"
1105request c16 main "$(git rev-parse c16)"
1106integrate
1107grep -q "^c16 -> refs/heads/main .*: land$" "$work/last.out" \
1108 || die "a change under an explicitly empty floor did not land: $(cat "$work/last.out")"
1109grep -q 'the policy requires no check of the paths this change touches' "$work/last.out" \
1110 || die "the verdict did not say the policy required nothing"
1111grep -qF "policy no project layer at policy/project; the floor alone" "$work/last.out" \
1112 || die "the pass did not say it composed the floor alone"
1113landed_as "$(git rev-parse c16)" "$pre"
1114holds "a floor that states it requires nothing composes, judges, and lands the change requiring nothing"
1115
1116# ----------------------------------------------------------------------
1117say "17. a planted replacement ref changes nothing the controller reads"
1118
1119# refs/replace/<id> makes git read another object wherever it looks <id> up.
1120# Two are planted here, and each alone would land a change that requires
1121# evidence and carries none. One swaps the floor's blob in the instance
1122# repository for a floor that requires nothing. The other swaps the change's
1123# head in the served repository for a commit that touches no class. Neither
1124# moves a ref the controller watches. A controller that left replacement
1125# refs on would read both and land the change; this one reads the objects
1126# the refs actually name, and holds the change stale.
1127cat > "$floor/policy/instance/floor.cue" <<'EOF'
1128package verification
1129
1130floor: {
1131 checks: "prose-format": {runner: "nix", attribute: "prose-format"}
1132 classes: prose: {paths: "docs/**": true, requires: "prose-format": true}
1133 unclassified: {}
1134}
1135EOF
1136git -C "$floor" commit --quiet -am "the floor requires prose-format of docs/ again"
1137git -C "$floor" push --quiet "$instance_repo" main
1138landed_floor="$(git -C "$instance_repo" rev-parse main:policy/instance/floor.cue)"
1139empty_floor="$(git -C "$instance_repo" rev-parse main~1:policy/instance/floor.cue)"
1140git -C "$instance_repo" update-ref "refs/replace/$landed_floor" "$empty_floor"
1141git -C "$instance_repo" show main:policy/instance/floor.cue | grep 'checks: {}' > /dev/null \
1142 || die "the floor's replacement did not take, so this scenario proves nothing"
1143
1144git checkout --quiet main
1145git pull --quiet --ff-only origin main
1146git checkout --quiet -b c17-decoy
1147echo "a note no class covers" > notes.txt
1148git commit --quiet -am "a decoy that touches no class"
1149git checkout --quiet main
1150git checkout --quiet -b c17
1151echo "a readme no evidence covers" > docs/readme.md
1152git commit --quiet -am "a change that requires prose-format and carries no evidence"
1153git push --quiet origin c17 c17-decoy
1154git -C "$origin" update-ref "refs/replace/$(git rev-parse c17)" "$(git rev-parse c17-decoy)"
1155git -C "$origin" diff --name-only main c17 | grep -x notes.txt > /dev/null \
1156 || die "the head's replacement did not take, so this scenario proves nothing"
1157request c17 main "$(git rev-parse c17)"
1158
1159# The environment asks for replacement refs too, and is not listened to.
1160before="$(tip)"
1161GIT_CONFIG_PARAMETERS="'core.usereplacerefs'='true'" integrate
1162grep -q "^c17 -> refs/heads/main .*: stale$" "$work/last.out" \
1163 || die "a planted replacement ref decided the verdict: $(cat "$work/last.out")"
1164grep -q "check prose-format" "$work/last.out" \
1165 || die "the landed floor's requirement was not what the controller read"
1166grep -q 'no attestation for this check accompanies the change' "$work/last.out" \
1167 || die "the missing evidence was not reported"
1168[ "$(tip)" = "$before" ] || die "main moved under a change that requires evidence"
1169git -C "$instance_repo" update-ref -d "refs/replace/$landed_floor"
1170git -C "$origin" update-ref -d "refs/replace/$(git rev-parse c17)"
1171forget c17
1172holds "the floor and the change were read as landed and as pushed, past both replacements"
1173
1174# ----------------------------------------------------------------------
1175say "18. a request approved again while its previous head lands stands for the next pass"
1176
1177# A second approval is leased against the request it read, and
1178# nothing stops it reading the head this pass is about to land. So the
1179# request can move between the pass reading it and the pass consuming it.
1180# The landing is still the old head's, and the request that moved is a new
1181# request: consuming it would drop a change nobody judged.
1182git checkout --quiet main
1183git pull --quiet --ff-only origin main
1184git checkout --quiet -b c18
1185echo "a readme requested once" > docs/readme.md
1186git commit --quiet -am "the first request"
1187attest_change c18 "" "" --check prose-format
1188request c18 main "$(git rev-parse c18)"
1189# main moves under the request, outside anything the check reads. The pass
1190# then recomputes the check's closure over the landed tree, and that
1191# evaluation is where the second approval happens.
1192git checkout --quiet main
1193echo "a note landed in between" > notes.txt
1194git commit --quiet -am "a note landed in between"
1195git push --quiet origin main
1196git checkout --quiet c18
1197git checkout --quiet -b c18-again
1198echo "a readme requested again" > docs/readme.md
1199git commit --quiet -am "the second request"
1200git push --quiet origin c18-again
1201again="$(git rev-parse c18-again)"
1202moving="refs/the-valley/integration-requests/main/c18"
1203before="$(tip)"
1204VALLEY_E2E_DURING_PASS="git -C '$origin' update-ref '$moving' '$again'" integrate
1205grep -q "^c18 -> refs/heads/main .*: land$" "$work/last.out" \
1206 || die "the first request did not land: $(cat "$work/last.out")"
1207[ "$(tip)" != "$before" ] || die "main did not move for the first request"
1208[ "$(git -C "$origin" rev-parse --verify --quiet "$moving")" = "$again" ] \
1209 || 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")"
1210grep -q "request $moving moved to .* while .* landed; it stands for the next pass" "$work/last.out" \
1211 || die "the moved request was not reported: $(cat "$work/last.out")"
1212forget c18
1213holds "a request that moved while its previous head landed was left standing, and said so"
1214
1215# ----------------------------------------------------------------------
1216say "19. a bus that never answers does not hold up a landing"
1217
1218# The landing's own record comes first: main moves, the move is queued for
1219# the mirrors, the evidence is stored and the request consumed. Only then
1220# does the integrator publish, and each publish is cut off at its deadline.
1221# The shipped wrapper puts the real nats first on the path, so the bare
1222# binary runs here, behind a nats that never exits.
1223mkdir "$work/hung-bus" "$work/queue" "$work/wake"
1224cat > "$work/hung-bus/nats" <<EOF
1225#!$(command -v bash)
1226exec sleep 1000
1227EOF
1228chmod +x "$work/hung-bus/nats"
1229git checkout --quiet main
1230git pull --quiet --ff-only origin main
1231git checkout --quiet -b c19
1232echo "landed past a bus that never answers" > docs/bus.md
1233git add -A
1234git commit --quiet -m "past a hung bus"
1235attest_change c19 "" "" --check prose-format
1236request c19 main "$(git rev-parse c19)"
1237before="$(tip)"
1238started=$SECONDS
1239PATH="$work/hung-bus:$PATH" timeout 120 "$INTEGRATOR_UNWRAPPED" reconcile \
1240 --repo "$origin" \
1241 --key "$work/integrator" --name "$integrator_name" \
1242 --known-signers "$work/known_signers" \
1243 --instance-repo "$instance_repo" \
1244 --schema "$SCHEMA_VERIFICATION" \
1245 --attest-schema "$SCHEMA_ATTESTATION" \
1246 --event-schema "$SCHEMA_EVENTS" \
1247 --bus nats://127.0.0.1:1 \
1248 --publish-queue "$work/queue" \
1249 --wake "$work/wake" \
1250 2>&1 | tee "$work/last.out" \
1251 || die "the pass did not finish with a bus that never answers: $(cat "$work/last.out")"
1252elapsed=$((SECONDS - started))
1253grep -q "^c19 -> refs/heads/main .*: land$" "$work/last.out" || die "c19 did not land: $(cat "$work/last.out")"
1254landed_as "$(git rev-parse c19)" "$before"
1255[ "$(cat "$work"/queue/*)" = "$before $(tip) refs/heads/main" ] \
1256 || die "the move was not queued for the mirrors: $(ls -A "$work/queue")"
1257git -C "$origin" rev-parse --verify --quiet refs/the-valley/integration-requests/main/c19 > /dev/null \
1258 && die "the request outlived the landing"
1259grep -q "^ evidence " "$work/last.out" || die "the evidence was not stored"
1260first_evidence="$(grep -n "^ evidence " "$work/last.out" | head -n1 | cut -d: -f1)"
1261first_bus="$(grep -n "^ bus " "$work/last.out" | head -n1 | cut -d: -f1)"
1262[ "$first_evidence" -lt "$first_bus" ] || die "the integrator asked the bus before it stored the evidence"
1263grep -q "bus publish of valley.git.project.ref-updated FAILED: no answer within 10s" "$work/last.out" \
1264 || die "the hung ref-updated publish was not cut off: $(cat "$work/last.out")"
1265grep -q "bus publish of valley.git.project.integration-succeeded FAILED: no answer within 10s" "$work/last.out" \
1266 || die "the hung integration-succeeded publish was not cut off"
1267[ "$elapsed" -lt 60 ] || die "the pass took ${elapsed}s behind a bus that never answers"
1268# The check worker is marked due by the landing, before the mirror queue
1269# and the bus, and the wake directory holds the one empty file.
1270[ "$(ls -A "$work/wake")" = due ] && [ ! -s "$work/wake/due" ] \
1271 || die "the landing did not leave one empty due: $(ls -A "$work/wake")"
1272first_wake="$(grep -n "^ wake the check worker is due$" "$work/last.out" | head -n1 | cut -d: -f1)"
1273first_queue="$(grep -n "^ publish " "$work/last.out" | head -n1 | cut -d: -f1)"
1274[ -n "$first_wake" ] && [ "$first_wake" -lt "$first_queue" ] && [ "$first_wake" -lt "$first_bus" ] \
1275 || die "the worker was not marked due before the mirror queue and the bus: $(cat "$work/last.out")"
1276holds "c19 marked the check worker due before its mirror queue and its hung bus"
1277holds "c19 landed, queued and consumed its request before a hung bus was asked, and each publish gave up after 10s (${elapsed}s in all)"
1278
1279# ----------------------------------------------------------------------
1280say "20. a cue that never answers a payload's vet does not hold up a landing"
1281
1282# The payload is vetted before it is published, and the vet is bounded the
1283# same way. This cue hangs only when asked to vet against the event schema;
1284# every other use, judging included, goes to the real one.
1285real_cue="$(command -v cue)"
1286mkdir "$work/hung-cue" "$work/queue20"
1287cat > "$work/hung-cue/cue" <<EOF
1288#!$(command -v bash)
1289for arg; do [ "\$arg" = "$SCHEMA_EVENTS" ] && exec sleep 1000; done
1290exec "$real_cue" "\$@"
1291EOF
1292chmod +x "$work/hung-cue/cue"
1293git checkout --quiet main
1294git pull --quiet --ff-only origin main
1295git checkout --quiet -b c20
1296echo "landed past a cue that never answers" > docs/cue.md
1297git add -A
1298git commit --quiet -m "past a hung cue"
1299attest_change c20 "" "" --check prose-format
1300request c20 main "$(git rev-parse c20)"
1301before="$(tip)"
1302started=$SECONDS
1303PATH="$work/hung-cue:$PATH" timeout 120 "$INTEGRATOR_UNWRAPPED" reconcile \
1304 --repo "$origin" \
1305 --key "$work/integrator" --name "$integrator_name" \
1306 --known-signers "$work/known_signers" \
1307 --instance-repo "$instance_repo" \
1308 --schema "$SCHEMA_VERIFICATION" \
1309 --attest-schema "$SCHEMA_ATTESTATION" \
1310 --event-schema "$SCHEMA_EVENTS" \
1311 --publish-queue "$work/queue20" \
1312 2>&1 | tee "$work/last.out" \
1313 || die "the pass did not finish with a cue that never answers: $(cat "$work/last.out")"
1314elapsed=$((SECONDS - started))
1315grep -q "^c20 -> refs/heads/main .*: land$" "$work/last.out" || die "c20 did not land: $(cat "$work/last.out")"
1316landed_as "$(git rev-parse c20)" "$before"
1317[ "$(cat "$work"/queue20/*)" = "$before $(tip) refs/heads/main" ] \
1318 || die "the move was not queued for the mirrors: $(ls -A "$work/queue20")"
1319git -C "$origin" rev-parse --verify --quiet refs/the-valley/integration-requests/main/c20 > /dev/null \
1320 && die "the request outlived the landing"
1321grep -q "^ evidence " "$work/last.out" || die "the evidence was not stored"
1322grep -q "bus ref-updated not published: cue vet against #RefUpdated gave no answer within 10s" "$work/last.out" \
1323 || die "the hung vet of ref-updated was not cut off: $(cat "$work/last.out")"
1324grep -q "bus integration-succeeded not published: cue vet against #IntegrationSucceeded gave no answer within 10s" "$work/last.out" \
1325 || die "the hung vet of integration-succeeded was not cut off"
1326[ "$elapsed" -lt 60 ] || die "the pass took ${elapsed}s behind a cue that never answers"
1327holds "c20 landed, queued and consumed its request, and each hung vet gave up after 10s and skipped its publish (${elapsed}s in all)"
1328
1329# ----------------------------------------------------------------------
1330say "21. a request named for a change that is ready lands"
1331
1332# A change with a record is requested as c-<change ID>. The records are
1333# written by the valley command itself, as its owner would write them; this
1334# repository is served without the hook that guards them on a host. The
1335# integrator reads them only to refuse.
1336git config valley.principal contributor
1337# ready_change <branch>: the branch's head on origin readied as a new
1338# change, whose ID is left in $readied.
1339ready_change() {
1340 valley ready "$1" > "$work/ready.out" || die "valley ready $1 failed"
1341 readied="$(sed -n 's/^The change ID \([k-z]*\) is new\..*/\1/p' "$work/ready.out")"
1342 [ "${#readied}" = 32 ] || die "valley ready $1 made no change ID: $(cat "$work/ready.out")"
1343}
1344outcome_of() { git -C "$origin" cat-file blob "refs/the-valley/integration-outcomes/main/$1" | cut -d' ' -f4; }
1345
1346git checkout --quiet main
1347git pull --quiet --ff-only origin main
1348git checkout --quiet -b c21
1349echo "a change with a record" > docs/c21.md
1350git add -A
1351git commit --quiet -m "a change with a record"
1352attest_change c21 "" "" --check prose-format
1353ready_change c21
1354id21="$readied"
1355request "c-$id21" main "$(git rev-parse c21)"
1356integrate
1357grep -q "^c-$id21 -> refs/heads/main .*: land$" "$work/last.out" || die "c-$id21 did not land"
1358landed_as "$(git rev-parse c21)" "$pre"
1359landed="refs/the-valley/attestations/$(attest digest --repo "$repo" --rev c21 | cut -d: -f2)/$ihash"
1360git -C "$origin" cat-file blob "$landed:$(transfer_path "$(tip)")" | grep -qx "predicate.change c-$id21" \
1361 || die "the transfer statement does not name the request c-$id21"
1362holds "a ready change's request, named for its ID, landed, and its transfer statement names it so"
1363
1364# ----------------------------------------------------------------------
1365say "22. a change unreadied after its request was filed is refused, and lands once it is ready again"
1366
1367git checkout --quiet main
1368git pull --quiet --ff-only origin main
1369git checkout --quiet -b c22
1370echo "a change paused after it was approved" > docs/c22.md
1371git add -A
1372git commit --quiet -m "a change paused after it was approved"
1373attest_change c22 "" "" --check prose-format
1374ready_change c22
1375id22="$readied"
1376request "c-$id22" main "$(git rev-parse c22)"
1377valley unready "$id22" > /dev/null 2>&1 || die "valley unready failed"
1378before="$(tip)"
1379integrate
1380grep -q "^c-$id22 -> refs/heads/main .*: refused-not-ready$" "$work/last.out" \
1381 || die "a draft's request was not refused: $(cat "$work/last.out")"
1382grep -q "change $id22 is draft, not ready" "$work/last.out" || die "the refusal did not say the change is a draft"
1383[ "$(tip)" = "$before" ] || die "a draft's request moved main"
1384git -C "$origin" rev-parse --verify --quiet "refs/the-valley/integration-requests/main/c-$id22" > /dev/null \
1385 || die "the refused request was dropped"
1386[ "$(outcome_of "c-$id22")" = refused-not-ready ] || die "the outcome record does not say refused-not-ready"
1387
1388# The refusal is decided again on every pass, and said once.
1389timeout 4 integrator watch --interval 1s \
1390 --repo "$origin" \
1391 --key "$work/integrator" --name "$integrator_name" \
1392 --known-signers "$work/known_signers" \
1393 --instance-repo "$instance_repo" \
1394 --schema "$SCHEMA_VERIFICATION" \
1395 --attest-schema "$SCHEMA_ATTESTATION" \
1396 --event-schema "$SCHEMA_EVENTS" \
1397 > "$work/repeat.out" 2>&1 || true
1398[ "$(grep -c "c-$id22 .*refused-not-ready" "$work/repeat.out" || true)" -eq 0 ] \
1399 || die "a standing refusal was reported again: $(cat "$work/repeat.out")"
1400[ "$(tip)" = "$before" ] || die "a draft's request moved main under watch"
1401
1402# Readied again at the same head, the same request lands on the next pass.
1403valley ready --change "$id22" c22 > /dev/null 2>&1 || die "valley ready --change $id22 failed"
1404integrate
1405grep -q "^c-$id22 -> refs/heads/main .*: land$" "$work/last.out" \
1406 || die "the change readied again did not land: $(cat "$work/last.out")"
1407landed_as "$(git rev-parse c22)" "$pre"
1408holds "unready stopped a filed request, the refusal was said once, and ready let the same request land"
1409
1410# ----------------------------------------------------------------------
1411say "23. a request named for a branch, at a draft's head, is refused"
1412
1413# Whatever a request is named, a head that is a version of a change that
1414# is not ready does not land.
1415git checkout --quiet main
1416git pull --quiet --ff-only origin main
1417git checkout --quiet -b c23
1418echo "a draft requested under its branch's name" > docs/c23.md
1419git add -A
1420git commit --quiet -m "a draft requested under its branch's name"
1421attest_change c23 "" "" --check prose-format
1422ready_change c23
1423id23="$readied"
1424valley unready "$id23" > /dev/null 2>&1 || die "valley unready failed"
1425request c23 main "$(git rev-parse c23)"
1426before="$(tip)"
1427integrate
1428grep -q "^c23 -> refs/heads/main .*: refused-not-ready$" "$work/last.out" \
1429 || die "a branch-named request at a draft's head was not refused: $(cat "$work/last.out")"
1430grep -q "is v1 of change $id23, which is draft, not ready" "$work/last.out" \
1431 || die "the refusal did not name the draft"
1432[ "$(tip)" = "$before" ] || die "a draft's head landed under its branch's name"
1433[ "$(outcome_of c23)" = refused-not-ready ] || die "the outcome record does not say refused-not-ready"
1434forget c23
1435holds "a draft's head was refused under a branch's name too"
1436
1437# ----------------------------------------------------------------------
1438say "24. a request whose commits hold a merge is refused"
1439
1440# A merge can make other work look landed by ancestry, so the integrator
1441# lands a line of commits and nothing else.
1442git checkout --quiet main
1443git pull --quiet --ff-only origin main
1444git checkout --quiet -b c24-side
1445echo "a side line" > docs/c24-side.md
1446git add -A
1447git commit --quiet -m "a side line"
1448git checkout --quiet main
1449git checkout --quiet -b c24
1450echo "a line with a merge in it" > docs/c24.md
1451git add -A
1452git commit --quiet -m "a line with a merge in it"
1453git merge --quiet --no-ff --no-edit c24-side
1454git push --quiet origin c24
1455request c24 main "$(git rev-parse c24)"
1456before="$(tip)"
1457integrate
1458grep -q "^c24 -> refs/heads/main .*: refused-merge$" "$work/last.out" \
1459 || die "a request holding a merge was not refused: $(cat "$work/last.out")"
1460grep -q "include the merge $(git rev-parse c24 | cut -c1-12)" "$work/last.out" || die "the refusal did not name the merge"
1461[ "$(tip)" = "$before" ] || die "a request holding a merge moved main"
1462[ "$(outcome_of c24)" = refused-merge ] || die "the outcome record does not say refused-merge"
1463forget c24
1464holds "a request holding a merge was refused, and main did not move"
1465
1466# ----------------------------------------------------------------------
1467say "25. a line of commits above a draft's head is refused, naming the draft"
1468
1469# A request brings every commit from its merge base to its head. So a child
1470# of a draft's head, approved under another name, would land the draft too.
1471git checkout --quiet main
1472git pull --quiet --ff-only origin main
1473git checkout --quiet -b c25-draft
1474echo "a draft below another change" > docs/c25-draft.md
1475git add -A
1476git commit --quiet -m "a draft below another change"
1477git push --quiet origin c25-draft
1478ready_change c25-draft
1479id25="$readied"
1480valley unready "$id25" > /dev/null 2>&1 || die "valley unready failed"
1481git checkout --quiet -b c25
1482echo "a change above a draft" > docs/c25.md
1483git add -A
1484git commit --quiet -m "a change above a draft"
1485git push --quiet origin c25
1486request c25 main "$(git rev-parse c25)"
1487before="$(tip)"
1488integrate
1489grep -q "^c25 -> refs/heads/main .*: refused-not-ready$" "$work/last.out" \
1490 || die "a child of a draft's head was not refused: $(cat "$work/last.out")"
1491grep -q "the commit $(git rev-parse c25-draft | cut -c1-12) it brings is v1 of change $id25, which is draft, not ready" \
1492 "$work/last.out" || die "the refusal did not name the draft"
1493[ "$(tip)" = "$before" ] || die "a child of a draft's head moved main"
1494forget c25
1495holds "a line above a draft's head was refused, and the refusal named the draft"
1496
1497# ----------------------------------------------------------------------
1498say "26. withdrawing a change voids its request, and readying it again needs a fresh approval"
1499
1500# integrate_quiet: a pass that may have nothing to say.
1501integrate_quiet() {
1502 integrator reconcile \
1503 --repo "$origin" \
1504 --key "$work/integrator" --name "$integrator_name" \
1505 --known-signers "$work/known_signers" \
1506 --instance-repo "$instance_repo" \
1507 --schema "$SCHEMA_VERIFICATION" \
1508 --attest-schema "$SCHEMA_ATTESTATION" \
1509 --event-schema "$SCHEMA_EVENTS" \
1510 2>&1 | tee "$work/last.out"
1511}
1512git checkout --quiet main
1513git pull --quiet --ff-only origin main
1514git checkout --quiet -b c26
1515echo "a change withdrawn after it was approved" > docs/c26.md
1516git add -A
1517git commit --quiet -m "a change withdrawn after it was approved"
1518attest_change c26 "" "" --check prose-format
1519ready_change c26
1520id26="$readied"
1521request "c-$id26" main "$(git rev-parse c26)"
1522valley withdraw "$id26" > /dev/null 2>&1 || die "valley withdraw failed"
1523before="$(tip)"
1524integrate
1525grep -q "^c-$id26 -> refs/heads/main .*: voided-withdrawn$" "$work/last.out" \
1526 || die "a withdrawn change's request was not voided: $(cat "$work/last.out")"
1527git -C "$origin" rev-parse --verify --quiet "refs/the-valley/integration-requests/main/c-$id26" > /dev/null \
1528 && die "the voided request is still there"
1529[ "$(outcome_of "c-$id26")" = voided-withdrawn ] || die "the outcome record does not say voided-withdrawn"
1530[ "$(tip)" = "$before" ] || die "a withdrawn change moved main"
1531
1532# Readied again at the same head, the change has no request: the old
1533# approval is gone, and nothing lands.
1534valley ready --change "$id26" c26 > /dev/null 2>&1 || die "valley ready --change $id26 failed"
1535integrate_quiet
1536git -C "$origin" rev-parse --verify --quiet "refs/the-valley/integration-requests/main/c-$id26" > /dev/null \
1537 && die "the old request came back"
1538[ "$(tip)" = "$before" ] || die "a change readied again landed with no fresh approval"
1539
1540# A fresh approval at the same head lands.
1541request "c-$id26" main "$(git rev-parse c26)"
1542integrate
1543grep -q "^c-$id26 -> refs/heads/main .*: land$" "$work/last.out" \
1544 || die "the fresh approval did not land: $(cat "$work/last.out")"
1545landed_as "$(git rev-parse c26)" "$pre"
1546holds "withdraw voided the request on the next pass; readied again, the change landed only on a fresh approval"
1547
1548# ----------------------------------------------------------------------
1549say "27. a stack is rebased whole, a landed change under it drops out, and approving its top lands it as one commit"
1550
1551# approve reads the floor where the integrator does: the owning valley,
1552# which policy/valley names at main's tip.
1553git checkout --quiet main
1554git pull --quiet --ff-only origin main
1555mkdir -p policy
1556echo "$instance_repo" > policy/valley
1557git add policy/valley
1558git commit --quiet -m "name the owning valley"
1559git push --quiet origin main
1560
1561# A change of two commits, a plain branch on it, and two changes on that.
1562git checkout --quiet -b c27-a
1563echo "the first half of a" > docs/c27-a1.md
1564git add -A
1565git commit --quiet -m "c27: the first half of a"
1566echo "the second half of a" > docs/c27-a2.md
1567git add -A
1568git commit --quiet -m "c27: the second half of a"
1569attest_change c27-a "" "" --check prose-format
1570ready_change c27-a
1571id27a="$readied"
1572for layer in p b c; do
1573 git checkout --quiet -b "c27-$layer"
1574 echo "layer $layer" > "docs/c27-$layer.md"
1575 git add -A
1576 git commit --quiet -m "c27: layer $layer"
1577 git push --quiet origin "c27-$layer"
1578done
1579ready_change c27-b
1580id27b="$readied"
1581ready_change c27-c
1582id27c="$readied"
1583a="$(git rev-parse c27-a)" p="$(git rev-parse c27-p)" b="$(git rev-parse c27-b)" c="$(git rev-parse c27-c)"
1584
1585# main moves under the stack, outside what prose-format reads, and then a
1586# lands through an integrator merge: one new commit, not its own two.
1587git checkout --quiet main
1588git checkout --quiet -b c27-x
1589mkdir -p notes
1590echo "main moves on" > notes/c27-x.txt
1591git add -A
1592git commit --quiet -m "c27: main moves on"
1593git push --quiet origin c27-x
1594request c27-x main "$(git rev-parse c27-x)"
1595integrate
1596grep -q "^c27-x -> refs/heads/main .*: land$" "$work/last.out" || die "c27-x did not land"
1597request "c-$id27a" main "$a"
1598integrate
1599grep -q "^c-$id27a -> refs/heads/main .*: land$" "$work/last.out" || die "c-$id27a did not land"
1600[ "$(git -C "$origin" merge-base "$a" "$pre")" != "$pre" ] \
1601 || die "a's base is the tip it landed on, so main did not move under it; the scenario proves nothing"
1602main27="$(tip)"
1603[ "$(git -C "$origin" rev-list --no-walk --parents "$main27")" = "$main27 $pre" ] \
1604 || die "a did not land as one commit on the tip before the pass"
1605
1606# The rebase reads a's landing from its transfer statement, so a is no
1607# layer, and its two commits under the plain branch drop out. Each layer
1608# keeps its own diff, on the rebased layer below.
1609export VALLEY_KNOWN_SIGNERS="$work/reader_keys" VALLEY_INTEGRATOR_SIGNER="$integrator_name"
1610valley status --json "$id27a" | grep -q '"landing": *"landed-recorded"' || die "a's landing was not read as recorded"
1611valley rebase "$id27c" > "$work/rebase.out" 2>&1 || die "the rebase failed: $(cat "$work/rebase.out")"
1612git fetch --quiet origin
1613np="$(git rev-parse origin/c27-p)" nb="$(git rev-parse origin/c27-b)" nc="$(git rev-parse origin/c27-c)"
1614git merge-base --is-ancestor "$main27" "$np" || die "the bottom is not on main"
1615git merge-base --is-ancestor "$np" "$nb" || die "b is not on the rebased plain branch"
1616git merge-base --is-ancestor "$nb" "$nc" || die "c is not on b"
1617[ "$(git rev-list --count "$main27..$np")" = 1 ] || die "a's commits did not drop out from under the plain branch"
1618[ "$(git diff "$a" "$p")" = "$(git diff "$main27" "$np")" ] || die "the plain branch's diff changed"
1619[ "$(git diff "$p" "$b")" = "$(git diff "$np" "$nb")" ] || die "b's diff changed"
1620[ "$(git diff "$b" "$c")" = "$(git diff "$nb" "$nc")" ] || die "c's diff changed"
1621grep -q "^ c27-p .* origin/c27-p pushed$" "$work/rebase.out" || die "the manifest did not list the plain branch: $(cat "$work/rebase.out")"
1622holds "the stack moved whole onto main, and the landed change's commits dropped out from under it"
1623
1624# Approving the rebased top, and landing it, lands the whole stack as one
1625# commit the integrator makes, with landing evidence for the top alone. A
1626# lower layer's landing evidence comes with per-layer landing, which lands
1627# a stack as one commit per layer.
1628VALLEY_ATTEST_KEY="$work/contributor" VALLEY_ATTEST_NAME="$contributor" \
1629 valley approve --build-here --head "$nc" "$id27c" > "$work/approve.out" 2>&1 \
1630 || die "approving the rebased top failed: $(cat "$work/approve.out")"
1631integrate
1632grep -q "^c-$id27c -> refs/heads/main .*: land$" "$work/last.out" || die "c-$id27c did not land"
1633landed_as "$nc" "$pre"
1634[ "$(git -C "$origin" rev-parse "$(tip)^")" = "$main27" ] || die "the stack did not land as one commit on the tip"
1635for commit in "$np" "$nb" "$nc"; do
1636 git -C "$origin" merge-base --is-ancestor "$commit" "$(tip)" && die "the stack's own commit $commit is on main"
1637done
1638valley status --json "$id27c" | grep -q '"landing": *"landed-recorded"' || die "the top's landing was not read as recorded"
1639unset VALLEY_KNOWN_SIGNERS VALLEY_INTEGRATOR_SIGNER
1640holds "the rebased stack landed as one commit, none of its own commits is on main, and the top reads landed-recorded"
1641
1642# ----------------------------------------------------------------------
1643say "28. a signer restricted to some projects counts in those, and is unknown in every other"
1644
1645# A check worker's key is in the known-signers file, as it is for every
1646# controller that shares the file, and so is the integrator's, as a host's
1647# registry holds it. The signer projects file lets the worker count in this
1648# project alone. A controller takes the project from the repository it
1649# serves, so this one's is "project".
1650ssh-keygen -q -t ed25519 -N "" -C worker -f "$work/worker"
1651worker=worker.valley.invalid/attestations
1652cat "$work/known_signers" > "$work/worker_signers"
1653attest key --key "$work/worker" --name "$worker" >> "$work/worker_signers"
1654attest key --key "$work/integrator" --name "$integrator_name" >> "$work/worker_signers"
1655printf '# the check worker builds for this project alone\n%s project\n' "$worker" > "$work/signer_projects"
1656restricted=(--known-signers "$work/worker_signers" --signer-projects "$work/signer_projects")
1657# The second project's controller signs under a name and key of its own,
1658# as a controller on another host sharing the registry does, and holds the
1659# same known-signers file, the first controller's key included. Nothing in
1660# a note marks the first controller's signature as a countersignature, so
1661# this host declares it: its signer projects file names the first
1662# controller with no project, and the worker with this project alone.
1663ssh-keygen -q -t ed25519 -N "" -C second-integrator -f "$work/second_integrator"
1664second_integrator=second-integrator.valley.invalid/attestations
1665printf '%s project\n%s\n' "$worker" "$integrator_name" > "$work/second_signer_projects"
1666second=(--repo "$work/elsewhere.git" --key "$work/second_integrator" --name "$second_integrator"
1667 --known-signers "$work/worker_signers" --signer-projects "$work/second_signer_projects")
1668
1669git checkout --quiet main
1670git pull --quiet --ff-only origin main
1671git checkout --quiet -b c28
1672echo "a readme a check worker built" > docs/c28.md
1673git add -A
1674git commit --quiet -m "a change a check worker attested"
1675attest_change c28 "$work/worker" "$worker" --check prose-format
1676c28="$(git rev-parse c28)"
1677c28digest="$(attest digest --repo "$repo" --rev c28 | cut -d: -f2)"
1678c28ref="refs/the-valley/attestations/$c28digest/$(attest key --key "$work/worker" --name "$worker" | cut -d+ -f2)"
1679request c28 main "$c28"
1680
1681# A second project, served the same way, holds the same commits, the same
1682# note and the same request. Its controller's project is "elsewhere".
1683elsewhere="$work/elsewhere.git"
1684git init --quiet --bare "$elsewhere"
1685git -C "$origin" push --quiet "$elsewhere" main c28 "$c28ref" refs/the-valley/integration-requests/main/c28
1686[ "$(git -C "$elsewhere" rev-parse "$c28ref")" = "$(git -C "$origin" rev-parse "$c28ref")" ] \
1687 || die "the second project does not hold the same note"
1688before28="$(git -C "$elsewhere" rev-parse main)" before="$(tip)"
1689integrate "${second[@]}"
1690grep -q "^c28 -> refs/heads/main .*: stale$" "$work/last.out" \
1691 || die "the worker's evidence counted in a project not listed for it"
1692grep -q "check prose-format .*signed by no signer the integrator holds" "$work/last.out" \
1693 || die "the worker's note was not reported as an unknown signer's"
1694[ "$(git -C "$elsewhere" rev-parse main)" = "$before28" ] || die "main moved in the second project"
1695holds "in a project not listed for it, the worker's note is classified as a stranger's"
1696
1697# A signer projects file the controller cannot read stops it before it
1698# judges anything: one that names a signer twice, one that names a
1699# verifier key line rather than a signer, one whose projects are joined by
1700# a no-break space rather than a space, and one that is not there. So does
1701# one that restricts the integrator's own name, under which a worker would
1702# also sign transfer statements.
1703printf '%s project\n%s elsewhere\n' "$worker" "$worker" > "$work/named_twice"
1704attest key --key "$work/worker" --name "$worker" > "$work/key_line"
1705printf '%s project\302\240elsewhere\n' "$worker" > "$work/no_break_space"
1706printf '%s project\n' "$integrator_name" > "$work/names_the_integrator"
1707for list in named_twice key_line no_break_space missing names_the_integrator; do
1708 if reconcile "${restricted[@]}" --signer-projects "$work/$list" > "$work/$list.out" 2>&1; then
1709 die "a controller given the $list signer projects file ran: $(cat "$work/$list.out")"
1710 fi
1711 grep -q "signer projects file" "$work/$list.out" \
1712 || die "the $list signer projects file was not named as the reason: $(cat "$work/$list.out")"
1713 grep -q "^c28 " "$work/$list.out" && die "a controller given the $list signer projects file judged c28"
1714 [ "$(tip)" = "$before" ] || die "main moved under the $list signer projects file"
1715done
1716grep -qF "names $integrator_name, the name the integrator signs under" "$work/names_the_integrator.out" \
1717 || die "the integrator's own name was not the reason: $(cat "$work/names_the_integrator.out")"
1718holds "a signer projects file that does not read, or restricts the integrator's name, stops the controller, and nothing lands"
1719
1720# In the project listed for it, the same note lands the change.
1721integrate "${restricted[@]}"
1722grep -q "^c28 -> refs/heads/main .*: land$" "$work/last.out" \
1723 || die "the worker's evidence did not count in the project listed for it"
1724grep -q "check prose-format .*transferred" "$work/last.out" || die "prose-format did not transfer"
1725landed_as "$c28" "$pre"
1726holds "in the project listed for it, the same note lands c28"
1727
1728# Landing countersigned the worker's note: the first controller stored it,
1729# with its own signature added, under its own key hash. Copied into the
1730# second project, the countersigned note still counts only through the
1731# worker, who does not count there: the second controller holds the first
1732# one's key, and its signer projects file lets that signature count
1733# nowhere.
1734countersigned="refs/the-valley/attestations/$c28digest/$ihash"
1735git -C "$origin" cat-file blob "$countersigned:prose-format/statement.note" | grep -qF " $integrator_name " \
1736 || die "the landing did not countersign the worker's note"
1737git -C "$origin" push --quiet "$elsewhere" "$countersigned"
1738integrate "${second[@]}"
1739grep -q "^c28 -> refs/heads/main .*: stale$" "$work/last.out" \
1740 || die "another controller's countersignature made the worker's note count in a project not listed for it"
1741[ "$(git -C "$elsewhere" rev-parse main)" = "$before28" ] || die "main moved in the second project"
1742holds "another controller's countersignature does not stand in for the worker"
1743
1744# A signer the file does not name still counts in the second project. The
1745# contributor's note for the same tree arrives there, and replaces the
1746# worker's as the evidence.
1747attest run --repo "$repo" --key "$work/contributor" --name "$contributor" --check prose-format > /dev/null
1748git push --quiet "$elsewhere" "refs/the-valley/attestations/$c28digest/$(cut -d+ -f2 < "$work/known_signers")"
1749integrate "${second[@]}"
1750grep -q "^c28 -> refs/heads/main .*: land$" "$work/last.out" \
1751 || die "an unrestricted signer's evidence did not count in the second project"
1752landed_as "$c28" "$before28" "$elsewhere" "$second_integrator"
1753holds "a signer the file does not name counts in every project, as before"
1754
1755# ----------------------------------------------------------------------
1756say "29. a change lands as one commit on the tip, and a tree that lands twice keeps both proofs"
1757
1758# A change of three commits on the tip. The middle one adds a build output
1759# and the last removes it, so no diff review shows holds it. The change
1760# lands as one commit the integrator makes, and the build output is in no
1761# commit on main.
1762export VALLEY_KNOWN_SIGNERS="$work/reader_keys" VALLEY_INTEGRATOR_SIGNER="$integrator_name"
1763git fetch --quiet origin
1764git checkout --quiet -B c29-a origin/main
1765echo "the first text" > docs/c29.md
1766git add -A
1767git commit --quiet -m "c29: a document"
1768mkdir -p build
1769echo "a build output" > build/output.bin
1770git add -A
1771git commit --quiet -m "c29: a build output"
1772git rm --quiet -r build
1773git commit --quiet -m "c29: no build output"
1774attest_change c29-a "" "" --check prose-format
1775ready_change c29-a
1776id29a="$readied"
1777request "c-$id29a" main "$(git rev-parse c29-a)"
1778integrate
1779grep -q "^c-$id29a -> refs/heads/main .*: land$" "$work/last.out" || die "c-$id29a did not land"
1780landed_as "$(git rev-parse c29-a)" "$pre"
1781land29a="$(tip)"
1782[ -z "$(git -C "$origin" log --format=%H refs/heads/main -- build)" ] || die "the build output is on main"
1783valley status --json "$id29a" | grep -q '"landing": *"landed-recorded"' || die "c-$id29a's landing was not read as recorded"
1784holds "three commits on the tip landed as one commit, and the build output one of them held is nowhere on main"
1785
1786# Two single-commit changes: one changes the document, and the next puts
1787# back the first text, so the tree c29-a landed lands again. Each landing
1788# keeps its own transfer statement under that tree's ref, and both read
1789# landed-recorded.
1790git fetch --quiet origin
1791git checkout --quiet -B c29-b origin/main
1792echo "the second text" > docs/c29.md
1793git commit --quiet -am "c29: the second text"
1794attest_change c29-b "" "" --check prose-format
1795ready_change c29-b
1796request "c-$readied" main "$(git rev-parse c29-b)"
1797integrate
1798grep -q "^c-$readied -> refs/heads/main .*: land$" "$work/last.out" || die "c-$readied did not land"
1799landed_as "$(git rev-parse c29-b)" "$pre"
1800git fetch --quiet origin
1801git checkout --quiet -B c29-c origin/main
1802echo "the first text" > docs/c29.md
1803git commit --quiet -am "c29: the first text again"
1804[ "$(git rev-parse "c29-c^{tree}")" = "$(git -C "$origin" rev-parse "$land29a^{tree}")" ] \
1805 || die "c29-c does not hold the tree c29-a landed; the scenario proves nothing"
1806git push --quiet origin c29-c
1807ready_change c29-c
1808id29c="$readied"
1809request "c-$id29c" main "$(git rev-parse c29-c)"
1810integrate
1811grep -q "^c-$id29c -> refs/heads/main .*: land$" "$work/last.out" || die "c-$id29c did not land"
1812landed_as "$(git rev-parse c29-c)" "$pre"
1813land29c="$(tip)"
1814landed="refs/the-valley/attestations/$(attest digest --repo "$repo" --rev c29-c | cut -d: -f2)/$ihash"
1815for commit in "$land29a" "$land29c"; do
1816 git -C "$origin" cat-file blob "$landed:$(transfer_path "$commit")" > "$work/twice.note" \
1817 || die "no transfer statement for the landing as $commit"
1818 grep -qx "subject.digest.git-sha1 $commit" "$work/twice.note" || die "the statement in $commit's slot is about another commit"
1819done
1820for id in "$id29a" "$id29c"; do
1821 valley status --json "$id" | grep -q '"landing": *"landed-recorded"' || die "change $id does not read landed-recorded"
1822done
1823unset VALLEY_KNOWN_SIGNERS VALLEY_INTEGRATOR_SIGNER
1824holds "one tree landed twice, each landing kept its own statement, and both read landed-recorded"
1825
1826# ----------------------------------------------------------------------
1827say "30. a change's next version lands under the same name, and the version before stays landed-recorded"
1828
1829# Version 1 lands under c-<ID>. Version 2, rebased onto the landing, lands
1830# under the same name, and its outcome record replaces version 1's. Each
1831# version's landing record still binds its own head to its own landing.
1832export VALLEY_KNOWN_SIGNERS="$work/reader_keys" VALLEY_INTEGRATOR_SIGNER="$integrator_name"
1833git fetch --quiet origin
1834git checkout --quiet -B c30 origin/main
1835echo "the first version" > docs/c30.md
1836git add -A
1837git commit --quiet -m "c30: the first version"
1838attest_change c30 "" "" --check prose-format
1839ready_change c30
1840id30="$readied" v1="$(git rev-parse c30)"
1841request "c-$id30" main "$v1"
1842integrate
1843grep -q "^c-$id30 -> refs/heads/main .*: land$" "$work/last.out" || die "version 1 of c-$id30 did not land"
1844landed_as "$v1" "$pre"
1845land30v1="$(tip)"
1846git fetch --quiet origin
1847git checkout --quiet -B c30-again origin/main
1848echo "the second version" > docs/c30-again.md
1849git add -A
1850git commit --quiet -m "c30: the second version"
1851attest_change c30-again "" "" --check prose-format
1852valley ready --change "$id30" c30-again > /dev/null 2>&1 || die "valley ready --change $id30 c30-again failed"
1853v2="$(git rev-parse c30-again)"
1854# v2 is made on the main v1 landed on, so it is the change's next round.
1855valley status --json "$id30" | jq -e '.version == 2 and .landing == "not-landed" and .landed_version == null' > /dev/null \
1856 || die "v2, made on v1's landing, does not read as work left to land: $(valley status --json "$id30")"
1857request "c-$id30" main "$v2"
1858integrate
1859grep -q "^c-$id30 -> refs/heads/main .*: land$" "$work/last.out" || die "version 2 of c-$id30 did not land"
1860landed_as "$v2" "$pre"
1861land30v2="$(tip)"
1862[ "$(git -C "$origin" cat-file blob "refs/the-valley/integration-outcomes/main/c-$id30" | cut -d' ' -f1)" = "$v2" ] \
1863 || die "the outcome record under c-$id30 does not name version 2; the scenario proves nothing"
1864valley changes --json > "$work/changes30.json"
1865jq -e --arg id "$id30" --arg l1 "$land30v1" --arg l2 "$land30v2" '
1866 [.repos[].changes[] | select(.change_id == $id) | .versions[] | [.landing, .landed_commit]]
1867 == [["landed-recorded", $l1], ["landed-recorded", $l2]]' "$work/changes30.json" > /dev/null \
1868 || 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")"
1869holds "version 2 replaced the outcome record, and version 1's landing record kept it landed-recorded"
1870
1871# ----------------------------------------------------------------------
1872say "30b. approving the version shown lands it under a restacked active version, and the change reads landed as it"
1873
1874# v1 is what the reviewer read. main moves, and the change is restacked
1875# onto it as v2 while the review is open. Approving v1, the head shown,
1876# lands it, and from then on the change reads landed as v1 though v2 is
1877# active: it is no work left to land, so nothing restacks it, and no
1878# request for it is judged when main moves again.
1879git fetch --quiet origin
1880git checkout --quiet -B c30b origin/main
1881echo "the version the reviewer read" > docs/c30b.md
1882git add -A
1883git commit --quiet -m "c30b: the version the reviewer read"
1884git push --quiet origin c30b
1885ready_change c30b
1886id30b="$readied" v1="$(git rev-parse c30b)"
1887git checkout --quiet -B c30b-x origin/main
1888echo "main moves under the review" > notes/c30b-x.txt
1889git add -A
1890git commit --quiet -m "c30b: main moves under the review"
1891git push --quiet origin c30b-x
1892request c30b-x main "$(git rev-parse c30b-x)"
1893integrate
1894grep -q "^c30b-x -> refs/heads/main .*: land$" "$work/last.out" || die "c30b-x did not land"
1895valley rebase "$id30b" > "$work/rebase30b.out" 2>&1 || die "the restack of c30b failed: $(cat "$work/rebase30b.out")"
1896valley status --json "$id30b" | jq -e '.version == 2 and .landing == "not-landed"' > /dev/null \
1897 || die "the restack did not make v2 the active version: $(valley status --json "$id30b")"
1898VALLEY_ATTEST_KEY="$work/contributor" VALLEY_ATTEST_NAME="$contributor" \
1899 valley approve --build-here --head "$v1" "$id30b" > "$work/approve30b.out" 2>&1 \
1900 || die "approving v1 under an active v2 failed: $(cat "$work/approve30b.out")"
1901integrate
1902grep -q "^c-$id30b -> refs/heads/main .*: land$" "$work/last.out" || die "v1 of c-$id30b did not land"
1903[ "$(git -C "$origin" rev-parse "$(tip)^")" = "$pre" ] \
1904 && [ "$(git -C "$origin" diff "$pre" "$(tip)")" = "$(git -C "$origin" diff "$v1^" "$v1")" ] \
1905 || die "v1 did not land as its own delta, one commit on the tip"
1906land30b="$(tip)"
1907valley status --json "$id30b" | jq -e --arg v1 "$v1" '.version == 2 and .landing == "landed-recorded" and .landed_version == 1 and .head == $v1 and .state == "integrated-recorded"' > /dev/null \
1908 || die "the change does not read landed as v1: $(valley status --json "$id30b")"
1909valley pending --json | jq -e --arg id "$id30b" '[.. | objects | select(.change_id? == $id)] == []' > /dev/null \
1910 || die "valley pending lists c-$id30b, which landed as v1"
1911valley changes --json | jq -e --arg id "$id30b" --arg l "$land30b" '[.repos[].changes[] | select(.change_id == $id) | [.active, .landed_version, .landed_commit]] == [[2, 1, $l]]' > /dev/null \
1912 || die "valley changes does not list c-$id30b as landed as v1: $(valley changes --json)"
1913valley rebase "$id30b" > "$work/rebase30b-again.out" 2>&1 || true # a landed change is no layer to restack
1914git fetch --quiet origin
1915valley status --json "$id30b" | jq -e '.version == 2' > /dev/null \
1916 || die "c-$id30b was restacked again after it landed as v1: $(cat "$work/rebase30b-again.out")"
1917git checkout --quiet -B c30b-y origin/main
1918echo "main moves after the landing" > notes/c30b-y.txt
1919git add -A
1920git commit --quiet -m "c30b: main moves after the landing"
1921git push --quiet origin c30b-y
1922request c30b-y main "$(git rev-parse c30b-y)"
1923integrate
1924grep -q "^c30b-y -> refs/heads/main .*: land$" "$work/last.out" || die "c30b-y did not land"
1925[ "$(git -C "$origin" rev-parse "$(tip)^")" = "$land30b" ] || die "main did not move past the landing; the scenario proves nothing"
1926grep -q "c-$id30b\|c-c30b " "$work/last.out" && die "a request for c-$id30b was judged after it landed: $(cat "$work/last.out")"
1927holds "v1 landed under an active v2, the change reads landed as v1, and nothing restacks or judges it after"
1928
1929# ----------------------------------------------------------------------
1930say "31. a branch below a landed change is no layer, and the change above it is measured from the landing"
1931
1932# main -> p -> a -> b, with p a plain branch, and a and b changes. a lands
1933# as one new commit, so main reaches neither a's commits nor p, though
1934# both are on main in content. p is listed nowhere and is no layer of b's
1935# stack, and b counts its own commit alone.
1936git fetch --quiet origin
1937git checkout --quiet -B c31-p origin/main
1938echo "the plain branch" > docs/c31-p.md
1939git add -A
1940git commit --quiet -m "c31: a plain branch"
1941git push --quiet origin c31-p
1942git checkout --quiet -B c31-a
1943echo "change a" > docs/c31-a.md
1944git add -A
1945git commit --quiet -m "c31: change a"
1946attest_change c31-a "" "" --check prose-format
1947ready_change c31-a
1948id31a="$readied"
1949git checkout --quiet -B c31-b
1950echo "change b" > docs/c31-b.md
1951git add -A
1952git commit --quiet -m "c31: change b"
1953git push --quiet origin c31-b
1954ready_change c31-b
1955id31b="$readied"
1956p31="$(git rev-parse c31-p)" a31="$(git rev-parse c31-a)" b31="$(git rev-parse c31-b)"
1957request "c-$id31a" main "$a31"
1958integrate
1959grep -q "^c-$id31a -> refs/heads/main .*: land$" "$work/last.out" || die "c-$id31a did not land"
1960landed_as "$a31" "$pre"
1961main31="$(tip)"
1962git -C "$origin" merge-base --is-ancestor "$p31" "$main31" && die "main reaches the plain branch; the scenario proves nothing"
1963
1964valley changes --json > "$work/changes31.json"
1965jq -e --arg p "$p31" '[.repos[].branches[] | select(.head == $p)] == []' "$work/changes31.json" > /dev/null \
1966 || die "valley changes lists the plain branch below the landed change"
1967valley pending --json > "$work/pending31.json"
1968jq -e --arg p "$p31" '[.repos[].branches[] | select(.head == $p)] == []' "$work/pending31.json" > /dev/null \
1969 || die "valley pending --json lists the plain branch below the landed change"
1970h31b="$(jq -r --arg id "$id31b" '.repos[].changes[] | select(.change_id == $id) | .handle' "$work/pending31.json")"
1971[ -n "$h31b" ] || die "valley pending does not list c-$id31b"
1972valley pending -v --branches > "$work/pending31.out"
1973grep -q "c31-p" "$work/pending31.out" && die "valley pending lists the plain branch below the landed change: $(cat "$work/pending31.out")"
1974grep -E -A2 "^ [0-9]+ $h31b v1( |$)" "$work/pending31.out" | tail -n1 | grep -qx ' 1 commit · 1 file +1 −0' \
1975 || die "valley pending does not measure b from a's landing: $(grep -E -A3 "^ [0-9]+ $h31b v1" "$work/pending31.out")"
1976holds "valley changes and valley pending leave out the plain branch, and pending counts b's own commit alone"
1977
1978valley rebase "$id31b" > "$work/rebase31.out" 2>&1 || die "the rebase of b failed: $(cat "$work/rebase31.out")"
1979git fetch --quiet origin
1980nb31="$(git rev-parse origin/c31-b)"
1981[ "$(git rev-parse "$nb31^")" = "$main31" ] || die "b was not rebased as one commit onto main"
1982[ "$(git diff "$a31" "$b31")" = "$(git diff "$main31" "$nb31")" ] || die "b's diff changed in the rebase"
1983[ "$(git rev-parse origin/c31-p)" = "$p31" ] || die "the rebase moved the plain branch below the landed change"
1984holds "b rebased alone onto main: the plain branch and a's commits dropped out from under it"
1985unset VALLEY_KNOWN_SIGNERS VALLEY_INTEGRATOR_SIGNER
1986
1987# ----------------------------------------------------------------------
1988say "32. a standing answer is judged again when the accepted signers or the floor change, and only then"
1989
1990# A verdict reads more than the request, the target and the attestation
1991# refs. It reads which signers count, and the floor. Each case below holds
1992# the head, main and every attestation ref where they are, changes only the
1993# one input, and expects the request to be judged again.
1994inputs_of() { git -C "$origin" cat-file blob "refs/the-valley/integration-inputs/main/$1"; }
1995# quiet32 [flag…] — a pass that may have nothing to say, its output in last.out.
1996quiet32() { reconcile "$@" > "$work/last.out" 2>&1 || die "the pass failed: $(cat "$work/last.out")"; }
1997fixed() { printf '%s %s %s' "$(git -C "$origin" rev-parse "refs/the-valley/integration-requests/main/$1")" "$(tip)" \
1998 "$(git -C "$origin" for-each-ref --format='%(refname) %(objectname)' refs/the-valley/attestations/ | sha256sum)"; }
1999
2000git checkout --quiet main
2001git pull --quiet --ff-only origin main
2002
2003# A signer the known-signers file does not hold yet attests a change.
2004ssh-keygen -q -t ed25519 -N "" -C late -f "$work/late"
2005late=late.valley.invalid/attestations
2006cp "$work/known_signers" "$work/late_signers"
2007git checkout --quiet -b c32s
2008echo "a readme a late signer attested" > docs/c32s.md
2009git add -A
2010git commit --quiet -m "a change attested by a signer not yet accepted"
2011attest_change c32s "$work/late" "$late" --check prose-format
2012request c32s main "$(git rev-parse c32s)"
2013integrate --known-signers "$work/late_signers"
2014grep -q "^c32s -> refs/heads/main .*: stale$" "$work/last.out" || die "an unaccepted signer's evidence did not leave c32s stale"
2015grep -q "check prose-format .*signed by no signer the integrator holds" "$work/last.out" \
2016 || die "the late signer's note was not reported as an unknown signer's"
2017grep -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) \
2018 || die "the outcome record is not in the format its readers parse"
2019fixed32="$(fixed c32s)"
2020
2021# Nothing moved, so nothing is judged again.
2022quiet32 --known-signers "$work/late_signers"
2023grep -q "^c32s " "$work/last.out" && die "an unchanged c32s was judged again: $(cat "$work/last.out")"
2024
2025# A record written before inputs were remembered has an outcome and no
2026# inputs record. It is judged once more, and then stands.
2027git -C "$origin" update-ref -d refs/the-valley/integration-inputs/main/c32s
2028integrate --known-signers "$work/late_signers"
2029grep -q "^c32s -> refs/heads/main .*: stale$" "$work/last.out" || die "an outcome with no inputs record was not judged again"
2030inputs_of c32s > /dev/null || die "judging c32s again did not record its inputs"
2031quiet32 --known-signers "$work/late_signers"
2032grep -q "^c32s " "$work/last.out" && die "c32s was judged again after its inputs were recorded: $(cat "$work/last.out")"
2033
2034# The registry accepts the late signer. Only the known-signers file moves.
2035attest key --key "$work/late" --name "$late" >> "$work/late_signers"
2036[ "$(fixed c32s)" = "$fixed32" ] || die "the head, main or an attestation ref moved; the case proves nothing"
2037integrate --known-signers "$work/late_signers"
2038grep -q "^c32s -> refs/heads/main .*: land$" "$work/last.out" \
2039 || die "accepting the signer did not judge c32s again: $(cat "$work/last.out")"
2040landed_as "$(git rev-parse c32s)" "$pre"
2041holds "a stale answer stands while nothing moves, and accepting the signer alone lands the change"
2042
2043# The signer projects file is read once, when the controller starts, and
2044# the host restarts the controller when the list changes. So a start under
2045# a changed list at the same path must judge again what an earlier start
2046# answered.
2047git checkout --quiet main
2048git pull --quiet --ff-only origin main
2049git checkout --quiet -b c32p
2050echo "a readme a restricted signer attested" > docs/c32p.md
2051git add -A
2052git commit --quiet -m "a change attested by a signer restricted elsewhere"
2053attest_change c32p "$work/late" "$late" --check prose-format
2054request c32p main "$(git rev-parse c32p)"
2055printf '%s elsewhere\n' "$late" > "$work/late_projects"
2056integrate --known-signers "$work/late_signers" --signer-projects "$work/late_projects"
2057grep -q "^c32p -> refs/heads/main .*: stale$" "$work/last.out" || die "a signer restricted elsewhere counted in this project"
2058fixed32="$(fixed c32p)"
2059quiet32 --known-signers "$work/late_signers" --signer-projects "$work/late_projects"
2060grep -q "^c32p " "$work/last.out" && die "an unchanged c32p was judged again: $(cat "$work/last.out")"
2061printf '%s project\n' "$late" > "$work/late_projects"
2062[ "$(fixed c32p)" = "$fixed32" ] || die "the head, main or an attestation ref moved; the case proves nothing"
2063integrate --known-signers "$work/late_signers" --signer-projects "$work/late_projects"
2064grep -q "^c32p -> refs/heads/main .*: land$" "$work/last.out" \
2065 || die "a start under a changed signer projects file did not judge c32p again: $(cat "$work/last.out")"
2066landed_as "$(git rev-parse c32p)" "$pre"
2067holds "a controller started under a changed signer projects file judges the standing answer again"
2068
2069# The floor requires a check the change carries no evidence for.
2070cp "$floor/policy/instance/floor.cue" "$work/floor32.cue"
2071cat > "$floor/policy/instance/floor.cue" <<'EOF'
2072package verification
2073
2074floor: {
2075 checks: {
2076 "prose-format": {runner: "nix", attribute: "prose-format"}
2077 "floor-review": {runner: "command", command: "true"}
2078 }
2079 classes: prose: {paths: "docs/**": true, requires: {"prose-format": true, "floor-review": true}}
2080 unclassified: {}
2081}
2082EOF
2083git -C "$floor" commit --quiet -am "the floor requires floor-review of docs/"
2084git -C "$floor" push --quiet "$instance_repo" main
2085git checkout --quiet main
2086git pull --quiet --ff-only origin main
2087git checkout --quiet -b c32f
2088echo "a readme the floor holds back" > docs/c32f.md
2089git add -A
2090git commit --quiet -m "a change the floor holds back"
2091attest_change c32f "" "" --check prose-format
2092request c32f main "$(git rev-parse c32f)"
2093integrate
2094grep -q "^c32f -> refs/heads/main .*: stale$" "$work/last.out" || die "the floor's own requirement did not hold c32f back: $(cat "$work/last.out")"
2095grep -q "floor-review" "$work/last.out" || die "the missing floor-review evidence was not named"
2096fixed32="$(fixed c32f)"
2097quiet32
2098grep -q "^c32f " "$work/last.out" && die "an unchanged c32f was judged again: $(cat "$work/last.out")"
2099
2100# An input that does not read fails the request closed, and the failure
2101# stands for its window. Restored, the input is judged again at once.
2102before="$(tip)"
2103integrate --known-signers "$work/nowhere"
2104grep -q "^c32f: .*known-signers" "$work/last.out" || die "an unreadable known-signers file was not the reason c32f failed: $(cat "$work/last.out")"
2105[ "$(outcome_of c32f)" = failed ] || die "the unreadable input did not record a failure"
2106[ "$(tip)" = "$before" ] || die "main moved while an input did not read"
2107quiet32 --known-signers "$work/nowhere"
2108grep -q "^c32f" "$work/last.out" && die "the failure did not stand for its window: $(cat "$work/last.out")"
2109integrate
2110grep -q "^c32f -> refs/heads/main .*: stale$" "$work/last.out" || die "c32f was not judged again once the input read: $(cat "$work/last.out")"
2111holds "an input that does not read fails closed, and the request is judged again once it reads"
2112
2113# The floor drops the requirement. Only the instance repository moves.
2114cp "$work/floor32.cue" "$floor/policy/instance/floor.cue"
2115git -C "$floor" commit --quiet -am "the floor no longer requires floor-review"
2116git -C "$floor" push --quiet "$instance_repo" main
2117[ "$(fixed c32f)" = "$fixed32" ] || die "the head, main or an attestation ref moved; the case proves nothing"
2118integrate
2119grep -q "^c32f -> refs/heads/main .*: land$" "$work/last.out" \
2120 || die "changing the floor did not judge c32f again: $(cat "$work/last.out")"
2121landed_as "$(git rev-parse c32f)" "$pre"
2122holds "a stale answer the floor gave is judged again when only the floor changes, and the change lands"
2123
2124# ----------------------------------------------------------------------
2125say "33. a controller woken by its wake directory decides at once, follows a landing, and recovers what it missed"
2126
2127# Every controller here passes on a one-hour interval unless a case says
2128# otherwise, so a pass that comes within seconds came from a mark, a
2129# landing or a start, never the timer. The served repositories carry a
2130# post-receive hook in the shape the host installs: each push creates the
2131# empty file due in the controller's wake directory with O_EXCL, and a due
2132# that is already there is a mark already made.
2133wake="$work/wake33"
2134iwake="$work/wake33-instance"
2135other="$work/wake33-other" # a controller that reads nothing here
2136mkdir -m 0770 "$wake" "$iwake" "$other"
2137hook33() {
2138 printf '#!%s\nset -C\n{ : > "%s/due"; } 2>/dev/null || true\n' "$(command -v bash)" "$2" > "$1/hooks/post-receive"
2139 chmod +x "$1/hooks/post-receive"
2140}
2141hook33 "$origin" "$wake"
2142hook33 "$instance_repo" "$iwake"
2143
2144# Each line a controller prints is stamped with the time it was read, so a
2145# case measures from a stamp taken before a push to a line.
2146stamp() { while IFS= read -r line; do printf '%s %s\n' "$EPOCHREALTIME" "$line"; done; }
2147# watch33 LOG REPO DIR [flag…] — a controller for REPO, woken by DIR, in the
2148# background, its pid in watch_pid. A case that leaves an executable
2149# $work/during33 has it run once, from the middle of a pass.
2150watch33() {
2151 local log="$1" served="$2" dir="$3"
2152 shift 3
2153 VALLEY_E2E_DURING_PASS="f=$work/during33; if [ -x \$f ]; then mv \$f \$f.ran && \$f.ran; fi" \
2154 VALLEY_TELEMETRY_DIR="$stream33" \
2155 integrator watch \
2156 --repo "$served" \
2157 --key "$work/integrator" --name "$integrator_name" \
2158 --known-signers "$work/known_signers" \
2159 --instance-repo "$instance_repo" \
2160 --schema "$SCHEMA_VERIFICATION" \
2161 --attest-schema "$SCHEMA_ATTESTATION" \
2162 --event-schema "$SCHEMA_EVENTS" \
2163 --woken-by "$dir" --interval 1h "$@" > >(stamp >> "$log") 2>&1 &
2164 watch_pid=$!
2165}
2166# when33 LOG AFTER PATTERN [SECONDS] — the stamp of the first line of LOG
2167# stamped no earlier than AFTER that matches PATTERN, waiting for it.
2168when33() {
2169 local log="$1" after="$2" pattern="$3" limit="${4:-30}" i at
2170 for ((i = 0; i < limit * 20; i++)); do
2171 at="$(awk -v a="$after" -v p="$pattern" \
2172 '$1 >= a { line = $0; sub(/^[^ ]* /, "", line); if (line ~ p) { print $1; exit } }' "$log" 2> /dev/null)"
2173 if [ -n "$at" ]; then
2174 echo "$at"
2175 return 0
2176 fi
2177 sleep 0.05
2178 done
2179 return 1
2180}
2181ms() { awk -v a="$1" -v b="$2" 'BEGIN { printf "%d", (b - a) * 1000 }'; }
2182# The controllers store their decision records in one telemetry stream,
2183# which the checks below read as any reader of the stream would.
2184stream33="$work/telemetry33"
2185# decision33 CHANGE OUTCOME — the first decision record about CHANGE
2186# with OUTCOME in the stream, waiting for it.
2187decision33() {
2188 local i rec
2189 for ((i = 0; i < 100; i++)); do
2190 rec="$(cat "$stream33"/seg-*.jsonl 2> /dev/null \
2191 | jq -c --arg c "$1" --arg o "$2" 'select(.type == "decision" and .change == $c and .data.outcome == $o)' | head -n 1)"
2192 if [ -n "$rec" ]; then
2193 echo "$rec"
2194 return 0
2195 fi
2196 sleep 0.05
2197 done
2198 return 1
2199}
2200passes33() { awk -v a="$2" '$1 >= a && $2 == "pass:"' "$1" | wc -l; }
2201# restart33 [flag…] — the project's controller, stopped and started again;
2202# t is the stamp before the start.
2203restart33() {
2204 kill "$watch_pid" 2> /dev/null || true
2205 wait "$watch_pid" 2> /dev/null || true
2206 t="$EPOCHREALTIME"
2207 watch33 "$log" "$origin" "$wake" "$@"
2208 when33 "$log" "$t" "^pass: startup$" > /dev/null || die "the controller did not start: $(cat "$log")"
2209}
2210log="$work/watch33.log"
2211ilog="$work/inst33.log"
2212# change33 NAME — a change to docs/, which prose-format reads, off main.
2213change33() {
2214 git checkout --quiet main
2215 git pull --quiet --ff-only origin main
2216 git checkout --quiet -b "$1"
2217 echo "$1" > "docs/$1.md"
2218 git add -A
2219 git commit --quiet -m "$1"
2220}
2221# lands33 NAME AFTER WHAT — NAME lands after AFTER. Says how long it took
2222# from AFTER to the start of the pass that decided it, and to its landing.
2223lands33() {
2224 local decided landed started
2225 decided="$(when33 "$log" "$2" "^$1 -> refs/heads/main .*: land$")" || die "$1 did not land within 30s: $(cat "$log")"
2226 landed="$(when33 "$log" "$decided" "^ landed refs/heads/main ")" || die "$1 decided to land, and did not"
2227 started="$(awk -v a="$2" -v d="$decided" '$1 >= a && $1 <= d && $2 == "pass:" { s = $1 } END { print s }' "$log")"
2228 [ -n "$started" ] || die "no pass started between $2 and deciding $1"
2229 printf ' measured: %s: to decision start %sms, to landing %sms\n' "$3" "$(ms "$2" "$started")" "$(ms "$2" "$landed")"
2230}
2231
2232git checkout --quiet main
2233git pull --quiet --ff-only origin main
2234watch33 "$log" "$origin" "$wake"
2235when33 "$log" 0 "^pass: startup$" > /dev/null || die "the controller did not start: $(cat "$log")"
2236holds "a controller started on a one-hour interval passes once, at its start"
2237
2238# Request arrival, idle. The evidence is published first, and its push
2239# starts a pass that finds no request. The request's push starts the pass
2240# that lands it. The first decision this process makes is the cold case;
2241# the ones after it are warm.
2242for c in c33a c33b c33c; do
2243 change33 "$c"
2244 t="$EPOCHREALTIME"
2245 attest_change "$c" "" "" --check prose-format
2246 when33 "$log" "$t" "^pass: due$" > /dev/null || die "the evidence push did not wake the controller"
2247 sleep 0.5
2248 t="$EPOCHREALTIME"
2249 request "$c" main "$(git rev-parse "$c")"
2250 pushed="$EPOCHREALTIME"
2251 [ "$c" = c33a ] && what="request publication, cold" || what="request publication, warm"
2252 lands33 "$c" "$t" "$what (the push returned at $(ms "$t" "$pushed")ms)"
2253done
2254holds "a request pushed to an idle controller lands within seconds on a one-hour interval"
2255
2256# Evidence arrival. The request is judged stale for want of evidence, and
2257# the evidence's own push wakes the controller, which lands it.
2258change33 c33e
2259git push --quiet origin c33e
2260request c33e main "$(git rev-parse c33e)"
2261when33 "$log" 0 "^c33e -> refs/heads/main .*: stale$" > /dev/null || die "c33e was not judged stale without evidence"
2262sleep 0.5
2263t="$EPOCHREALTIME"
2264attest_change c33e "" "" --check prose-format
2265lands33 c33e "$t" "evidence publication, warm"
2266holds "evidence pushed for a stale request wakes the controller, which lands it"
2267# The first two decisions about c33e say when this process first saw the request
2268# at its head, which was before the stale one began. The landing began
2269# in a later pass, the one c33e's evidence woke, at least the half second
2270# the evidence waited after that sighting.
2271stale="$(decision33 c33e stale)" || die "no stale decision about c33e in the stream"
2272landed="$(decision33 c33e land)" || die "no landing decision about c33e in the stream"
2273jq -e -s '.[0].data as $s | .[1].data as $l
2274 | $s.process == $l.process and $s.first_seen == $l.first_seen and $s.first_seen_pass == $l.first_seen_pass
2275 and $s.first_seen_at_start == false and $s.first_seen_pass == $s.pass and $s.seen_to_began_ms >= 0
2276 and $l.pass > $l.first_seen_pass and $l.pass_reason == "due" and $l.seen_to_began_ms >= 500
2277 and $l.seen_to_began_ms >= $l.listed_to_began_ms' <<< "$stale$landed" > /dev/null \
2278 || die "c33e's decision records do not say when it was first seen: $stale $landed"
2279holds "a request's decisions say when this process first saw it, and the landing began in a later pass"
2280
2281# Busy. A request is pushed while a pass works on another, after that pass
2282# listed the requests. Its mark survives the pass, and the next pass starts
2283# as soon as the busy one ends, and lands it. The busy pass judges c33f,
2284# whose evidence is over a tree c33h has since moved what prose-format
2285# reads under, so it evaluates the check, and the request it pushes then
2286# is pushed from the middle of the pass. c33f stays stale, so nothing lands
2287# and no follow-up comes: only the mark starts the next pass.
2288change33 c33f
2289attest_change c33f "" "" --check prose-format
2290change33 c33h
2291attest_change c33h "" "" --check prose-format
2292t="$EPOCHREALTIME"
2293request c33h main "$(git rev-parse c33h)"
2294lands33 c33h "$t" "request publication, warm"
2295change33 c33g
2296t="$EPOCHREALTIME"
2297attest_change c33g "" "" --check prose-format
2298when33 "$log" "$t" "^pass: due$" > /dev/null || die "c33g's evidence did not wake the controller"
2299cat > "$work/during33" <<EOF
2300#!$(command -v bash)
2301echo "\$EPOCHREALTIME" > "$work/during33.at"
2302git -C "$repo" push --quiet origin "$(git rev-parse c33g):refs/the-valley/integration-requests/main/c33g"
2303sleep 2
2304EOF
2305chmod +x "$work/during33"
2306# c33i is requested with c33f, without evidence, so the busy pass lists
2307# both and judges c33i once c33f is done. The 2s c33f's evaluation sleeps
2308# fall between c33i's sighting and its decision.
2309change33 c33i
2310sleep 0.5
2311git push --quiet origin \
2312 "$(git rev-parse c33f):refs/the-valley/integration-requests/main/c33f" \
2313 "$(git rev-parse c33i):refs/the-valley/integration-requests/main/c33i"
2314busy="$(when33 "$log" 0 "^c33f -> refs/heads/main .*: stale$")" || die "c33f was not judged"
2315[ -e "$work/during33.ran" ] || die "the busy pass did not push c33g's request"
2316t="$(cat "$work/during33.at")"
2317lands33 c33g "$t" "request publication while busy"
2318reason="$(awk -v a="$busy" '$1 >= a && $2 == "pass:" { print $3; exit }' "$log")"
2319[ "$reason" = due ] || die "the pass after the busy one started for $reason, not due"
2320holds "a request pushed while a pass works is landed by the pass right after it"
2321rec="$(decision33 c33i stale)" || die "no decision about c33i in the stream"
2322jq -e '.data | .first_seen == .pass_listed and .first_seen_pass == .pass
2323 and .listed_to_began_ms >= 2000 and .seen_to_began_ms == .listed_to_began_ms' <<< "$rec" > /dev/null \
2324 || die "c33i's decision does not say it waited behind c33f: $rec"
2325printf ' measured: c33i: first seen to decision start %sms, behind c33f in the same pass\n' "$(jq -r .data.seen_to_began_ms <<< "$rec")"
2326holds "a request judged behind a slow one in the same pass says how long it waited after it was first seen"
2327git -C "$origin" update-ref -d refs/the-valley/integration-requests/main/c33i
2328
2329# A landing is followed by another pass at once. c33-dep-a sorts first, so
2330# it is judged against the tip before c33-dep-b lands, and it conflicts
2331# there: the tip and it change one line differently. c33-dep-b reverts the
2332# tip's change, and on the tip it lands the two no longer conflict.
2333git checkout --quiet main
2334git pull --quiet --ff-only origin main
2335git checkout --quiet -b c33s
2336echo base > checks/dep33.txt
2337git add -A
2338git commit --quiet -m "the line both sides change"
2339t="$EPOCHREALTIME"
2340request c33s main "$(git rev-parse c33s)"
2341lands33 c33s "$t" "unclassified request publication, warm"
2342git checkout --quiet main
2343git pull --quiet --ff-only origin main
2344git checkout --quiet -b c33-dep-a
2345echo a > checks/dep33.txt
2346git commit --quiet -am "a changes the line"
2347git checkout --quiet main
2348git checkout --quiet -b c33x
2349echo x > checks/dep33.txt
2350git commit --quiet -am "the tip changes it otherwise"
2351t="$EPOCHREALTIME"
2352request c33x main "$(git rev-parse c33x)"
2353lands33 c33x "$t" "unclassified request publication, warm"
2354git checkout --quiet main
2355git pull --quiet --ff-only origin main
2356git checkout --quiet -b c33-dep-b
2357echo base > checks/dep33.txt
2358git commit --quiet -am "b reverts the tip's change"
2359t="$EPOCHREALTIME"
2360git push --quiet origin \
2361 "$(git rev-parse c33-dep-a):refs/the-valley/integration-requests/main/c33-dep-a" \
2362 "$(git rev-parse c33-dep-b):refs/the-valley/integration-requests/main/c33-dep-b"
2363stale="$(when33 "$log" "$t" "^c33-dep-a -> refs/heads/main .*: stale$")" || die "c33-dep-a did not conflict with the tip before c33-dep-b"
2364when33 "$log" "$stale" "^c33-dep-b -> refs/heads/main .*: land$" > /dev/null || die "c33-dep-b did not land"
2365follow="$(when33 "$log" "$stale" "^pass: follow-up$")" || die "no follow-up pass after c33-dep-b landed"
2366lands33 c33-dep-a "$follow" "dependent request, from the follow-up's start"
2367lands33 c33-dep-a "$t" "dependent request, from the publication of both"
2368[ "$(git -C "$origin" show refs/heads/main:checks/dep33.txt)" = a ] || die "c33-dep-a's line is not on main"
2369holds "a request that conflicted with the tip before a landing lands in the pass that follows it at once"
2370
2371# A burst of evidence. Six requests are stale for want of it, and each
2372# change's evidence is pushed in turn, as fast as attest publishes. While a
2373# pass works, the marks wait as one due. Each change adds to docs/, which
2374# prose-format reads, so once one lands the others' evidence no longer
2375# transfers to the tip, and they are judged stale again. What is measured
2376# is the work: every request judged after its evidence, how many passes
2377# and decisions that took, and that the controller then goes quiet.
2378burst=(c33b1 c33b2 c33b3 c33b4 c33b5 c33b6)
2379for c in "${burst[@]}"; do
2380 change33 "$c"
2381 git push --quiet origin "$c"
2382 request "$c" main "$(git rev-parse "$c")"
2383 when33 "$log" 0 "^$c -> refs/heads/main .*: stale$" > /dev/null || die "$c was not judged stale"
2384done
2385sleep 0.5
2386t="$EPOCHREALTIME"
2387before="$(grep -c ' -> refs/heads/main ' "$log")"
2388for c in "${burst[@]}"; do
2389 git checkout --quiet "$c"
2390 pushed="$EPOCHREALTIME"
2391 attest_change "$c" "" "" --check prose-format
2392 when33 "$log" "$pushed" "^$c -> refs/heads/main " 60 > /dev/null || die "$c was not judged after its evidence: $(cat "$log")"
2393done
2394published="$EPOCHREALTIME"
2395n=-1
2396while [ "$n" != "$(passes33 "$log" "$t")" ]; do
2397 n="$(passes33 "$log" "$t")"
2398 sleep 2
2399done
2400last="$(awk -v a="$t" '$1 >= a && / -> refs\/heads\/main / { l = $1 } END { print l }' "$log")"
2401decisions=$(($(grep -c ' -> refs/heads/main ' "$log") - before))
2402landings="$(awk -v a="$t" '$1 >= a && $2 == "landed"' "$log" | wc -l)"
2403printf ' measured: evidence burst of %d pushes over %sms: %d passes, %d decisions, %d landing, last decision %sms after the first push began\n' \
2404 "${#burst[@]}" "$(ms "$t" "$published")" "$n" "$decisions" "$landings" "$(ms "$t" "$last")"
2405[ "$landings" -ge 1 ] || die "nothing landed after the burst"
2406[ "$n" -le $((2 * ${#burst[@]} + 1)) ] || die "a burst of ${#burst[@]} evidence pushes ran $n passes"
2407for c in "${burst[@]}"; do forget "$c"; done
2408holds "a burst of evidence is judged in $n passes, and the controller goes quiet"
2409
2410# Idle, the controller does nothing: no mark, no landing, no pass.
2411t="$EPOCHREALTIME"
2412sleep 2
2413[ "$(passes33 "$log" "$t")" = 0 ] || die "an idle controller passed: $(awk -v a="$t" '$1 >= a' "$log")"
2414[ -z "$(ls -A "$wake")" ] || die "the idle wake directory holds $(ls -A "$wake")"
2415holds "an idle controller on a one-hour interval passes no more, and its directory holds nothing"
2416
2417# A second controller over the same repository stops at its start, before
2418# it sweeps or passes, whatever happened to the wake directory. Here the
2419# first controller's wake directory is replaced, as anyone who may write
2420# its parent could, and a scratch worktree stands where a pass in progress
2421# would keep one. The second controller is refused the repository, sweeps
2422# nothing, and judges nothing. The first goes on serving it.
2423leak33="$TMPDIR/valley-integrator-wt-in-progress"
2424git -C "$origin" worktree add --quiet --detach "$leak33" refs/heads/main
2425mv "$wake" "$wake.replaced"
2426mkdir -m 0770 "$wake"
2427t="$EPOCHREALTIME"
2428if out="$(timeout 20 integrator watch --repo "$origin" --key "$work/integrator" --name "$integrator_name" \
2429 --known-signers "$work/known_signers" --instance-repo "$instance_repo" --schema "$SCHEMA_VERIFICATION" \
2430 --attest-schema "$SCHEMA_ATTESTATION" --woken-by "$wake" --interval 1h 2>&1)"; then
2431 die "a second controller over one repository ran: $out"
2432fi
2433grep -q "$origin: another controller holds its lock; one controller serves a repository" <<< "$out" \
2434 || die "the second controller said: $out"
2435grep -q "^pass: " <<< "$out" && die "the refused controller passed: $out"
2436[ -e "$leak33" ] || die "the refused controller swept the first one's worktree"
2437git -C "$origin" worktree remove --force "$leak33"
2438rm -r "$wake.replaced"
2439when33 "$log" "$t" "watching $wake again" 20 > /dev/null || die "the first controller did not watch the new directory: $(cat "$log")"
2440t="$EPOCHREALTIME"
2441change33 c33r
2442attest_change c33r "" "" --check prose-format
2443request c33r main "$(git rev-parse c33r)"
2444lands33 c33r "$t" "the first controller, after its wake directory was replaced"
2445reconcile --woken-by "$wake" > "$work/last.out" 2>&1 && die "reconcile took a wake directory"
2446grep -q "reconcile reads no wake directory" "$work/last.out" || die "reconcile said: $(cat "$work/last.out")"
2447holds "one controller serves a repository, a refused one sweeps and judges nothing, and reconcile never takes a wake directory"
2448
2449# A crash. The controller is killed, a request is pushed while nothing
2450# consumes its mark, and the next start lands it.
2451kill -9 "$watch_pid"
2452wait "$watch_pid" 2> /dev/null || true
2453change33 c33k
2454attest_change c33k "" "" --check prose-format
2455request c33k main "$(git rev-parse c33k)"
2456[ -e "$wake/due" ] || die "the push while the controller was down left no mark"
2457restart33
2458lands33 c33k "$t" "restart after a crash, from the start"
2459holds "a request pushed while the controller was down lands at its next start"
2460
2461# A dropped mark and a newly accepted signer start no pass on a one-hour
2462# interval. The interval is what reads them. The request is written with
2463# update-ref, which runs no hook, as a mark that never came.
2464grep -v "^$late+" "$work/late_signers" > "$work/signers33"
2465change33 c33l
2466attest_change c33l "$work/late" "$late" --check prose-format
2467request c33l main "$(git rev-parse c33l)"
2468# c33m touches only checks/, which no class covers, so c33l landing first
2469# leaves it nothing to be stale for.
2470git checkout --quiet main
2471git checkout --quiet -b c33m
2472echo c33m > checks/c33m.txt
2473git add -A
2474git commit --quiet -m c33m
2475git push --quiet origin c33m
2476restart33 --known-signers "$work/signers33"
2477when33 "$log" "$t" "^c33l -> refs/heads/main .*: stale$" > /dev/null || die "c33l counted a signer not yet accepted"
2478sleep 0.5
2479t="$EPOCHREALTIME"
2480cp "$work/late_signers" "$work/signers33"
2481git -C "$origin" update-ref refs/the-valley/integration-requests/main/c33m "$(git rev-parse c33m)"
2482sleep 2
2483[ "$(passes33 "$log" "$t")" = 0 ] || die "a changed signers file or a dropped mark started a pass on a one-hour interval"
2484holds "on a one-hour interval, a changed signers file and a dropped mark start no pass"
2485
2486grep -v "^$late+" "$work/late_signers" > "$work/signers33"
2487git -C "$origin" update-ref -d refs/the-valley/integration-requests/main/c33m
2488restart33 --known-signers "$work/signers33" --interval 3s
2489sleep 0.5
2490t="$EPOCHREALTIME"
2491cp "$work/late_signers" "$work/signers33"
2492git -C "$origin" update-ref refs/the-valley/integration-requests/main/c33m "$(git rev-parse c33m)"
2493lands33 c33l "$t" "accepted signer, on a 3s interval"
2494lands33 c33m "$t" "dropped mark, on a 3s interval"
2495reason="$(awk -v a="$t" '$1 >= a && $2 == "pass:" { print $3; exit }' "$log")"
2496[ "$reason" = timer ] || die "the changed signers file and the dropped mark were read by a $reason pass, not the timer"
2497holds "the interval's timer pass lands what a changed signers file and a dropped mark left waiting"
2498# The restarted controller first saw c33l in its first pass, and says so:
2499# it knows nothing of the stale decision the controller before it made.
2500# It first saw c33m, filed after it started, in a later pass.
2501stale="$(decision33 c33l stale)" || die "no stale decision about c33l in the stream"
2502landed="$(decision33 c33l land)" || die "no landing decision about c33l in the stream"
2503jq -e -s '.[0].data as $s | .[1].data as $l
2504 | $s.process != $l.process and $l.first_seen_at_start == true and $l.first_seen_pass == 1
2505 and $l.pass > 1 and $l.pass_reason == "timer" and $l.first_seen > $s.first_seen' <<< "$stale$landed" > /dev/null \
2506 || die "c33l's landing does not say a restarted controller first saw it at its start: $stale $landed"
2507rec="$(decision33 c33m land)" || die "no landing decision about c33m in the stream"
2508jq -e --argjson p "$(jq .data.process <<< "$landed")" '.data
2509 | .process == $p and .first_seen_at_start == false and .first_seen_pass > 1' <<< "$rec" > /dev/null \
2510 || die "c33m's landing does not say the controller saw it after its start: $rec"
2511holds "after a restart, a decision says its request was first seen at the start, and nothing from before it"
2512
2513# A due the controller cannot remove starts the pass it is found at, and
2514# then none until the interval, however often it is marked.
2515restart33
2516t="$EPOCHREALTIME"
2517mkdir -p "$wake/due/held"
2518when33 "$log" "$t" "could not remove the due in $wake" > /dev/null || die "the stuck due was not said"
2519change33 c33q
2520attest_change c33q "" "" --check prose-format
2521sleep 2
2522[ "$(passes33 "$log" "$t")" = 1 ] || die "a due that cannot be removed started $(passes33 "$log" "$t") passes"
2523rm -r "$wake/due"
2524holds "a due that cannot be removed starts one pass, and the controller does not spin on it"
2525
2526# The floor's move wakes the controllers that read it, and only those. The
2527# instance repository's controller lands a floor change, and marks the
2528# project's directory once it has. Its own push woke only it.
2529restart33
2530sleep 1
2531watch33 "$ilog" "$instance_repo" "$iwake" --wake-floor-reader "$wake"
2532when33 "$ilog" 0 "^pass: startup$" > /dev/null || die "the instance's controller did not start: $(cat "$ilog")"
2533cat > "$floor/policy/instance/floor.cue" <<'EOF'
2534package verification
2535
2536floor: {
2537 checks: {
2538 "prose-format": {runner: "nix", attribute: "prose-format"}
2539 "floor-review": {runner: "command", command: "true"}
2540 }
2541 classes: prose: {paths: "docs/**": true, requires: {"prose-format": true, "floor-review": true}}
2542 unclassified: {}
2543}
2544EOF
2545git -C "$floor" commit --quiet -am "the floor requires floor-review of docs/"
2546git -C "$floor" push --quiet "$instance_repo" main
2547change33 c33o
2548attest_change c33o "" "" --check prose-format
2549request c33o main "$(git rev-parse c33o)"
2550when33 "$log" 0 "^c33o -> refs/heads/main .*: stale$" > /dev/null || die "the floor did not hold c33o back: $(cat "$log")"
2551cp "$work/floor32.cue" "$floor/policy/instance/floor.cue"
2552git -C "$floor" commit --quiet -am "the floor no longer requires floor-review"
2553sleep 0.5
2554t="$EPOCHREALTIME"
2555git -C "$floor" push --quiet "$instance_repo" "HEAD:refs/the-valley/integration-requests/main/floor33"
2556when33 "$ilog" "$t" "^ wake the floor reader at $wake is due$" > /dev/null || die "the floor landing did not mark the project: $(cat "$ilog")"
2557lands33 c33o "$t" "floor request publication, to the project's landing"
2558[ -z "$(ls -A "$other")" ] || die "a controller that reads nothing here was marked"
2559holds "a floor landed by the instance's controller wakes the project's, which lands what the floor held back"
2560holds "the directory of a controller the floor does not concern stayed empty"
2561reconcile --wake-floor-reader "$other" > "$work/last.out" 2>&1 \
2562 && die "a controller that does not serve the instance repository took --wake-floor-reader"
2563grep -q "is for the controller that lands the floor" "$work/last.out" || die "the refusal said: $(cat "$work/last.out")"
2564holds "only the controller serving the instance repository marks the floor's readers"
2565
2566# ----------------------------------------------------------------------
2567say "34. evidence for the tree that would land stands where the change's own cannot transfer"
2568
2569# A note counts for a check only when it ran the computation the policy
2570# requires. c34u's note is a known signer's passing note for check
2571# prose-format, built from the code-build attribute, on the tip. The tree
2572# has not moved, and the note is still no evidence for prose-format.
2573change33 c34u
2574attest_change c34u "" "" --check prose-format=code-build
2575ready_change c34u
2576before34="$(tip)"
2577t="$EPOCHREALTIME"
2578request "c-$readied" main "$(git rev-parse c34u)"
2579when33 "$log" "$t" "^c-$readied -> refs/heads/main .*: stale$" > /dev/null \
2580 || die "c34u was not stale on a note for another attribute: $(cat "$log")"
2581when33 "$log" "$t" "check prose-format .*attestation is for runner \"nix\", attribute \"code-build\", and the policy requires runner \"nix\", attribute \"prose-format\"" > /dev/null \
2582 || die "the verdict did not name the attribute it refused: $(cat "$log")"
2583[ "$(tip)" = "$before34" ] || die "main moved on a note for another attribute"
2584holds "a passing note for the right check and another attribute is no evidence on an unmoved tree"
2585
2586# c34 is attested on the tip. Then a change lands that touches what
2587# prose-format reads, so c34's evidence no longer transfers to the tree its
2588# delta would land as. The controller of 33 is still watching.
2589change33 c34
2590attest_change c34 "" "" --check prose-format
2591ready_change c34
2592id34="$readied" x34="$(git rev-parse c34)"
2593change33 c34-main
2594attest_change c34-main "" "" --check prose-format
2595t="$EPOCHREALTIME"
2596request c34-main main "$(git rev-parse c34-main)"
2597lands33 c34-main "$t" "the change that moves c34's inputs"
2598before34="$(tip)"
2599
2600# c34-rebased is the version the restacker would make: c34's delta on the
2601# new tip. Its tree is the tree c34 would land as. A stranger attests it
2602# first, which the integrator does not accept.
2603git fetch --quiet origin
2604git checkout --quiet -B c34-rebased origin/main
2605git cherry-pick "$x34" > /dev/null
2606attest_change c34-rebased "$work/stranger" "$stranger" --check prose-format
2607landing34="$(attest digest --repo "$repo" --rev c34-rebased | cut -d: -f2)"
2608[ "$landing34" != "$(attest digest --repo "$repo" --rev "$x34" | cut -d: -f2)" ] \
2609 || die "c34's tree is the landing tree; the scenario proves nothing"
2610sleep 0.5
2611t="$EPOCHREALTIME"
2612request "c-$id34" main "$x34"
2613when33 "$log" "$t" "^c-$id34 -> refs/heads/main .*: stale$" > /dev/null \
2614 || die "c-$id34 was not stale with a stranger's evidence for its landing tree: $(cat "$log")"
2615when33 "$log" "$t" "check prose-format .*input closure changed.*tree that would land.*no signer the integrator holds" > /dev/null \
2616 || die "the verdict did not report both sources refused: $(cat "$log")"
2617[ "$(tip)" = "$before34" ] || die "main moved on a stranger's evidence"
2618# The pass prints its verdict before it writes the outcome record, which
2619# keeps the four fields every reader parses.
2620for ((i = 0; i < 100; i++)); do
2621 record34="$(git -C "$origin" cat-file blob "refs/the-valley/integration-outcomes/main/c-$id34" 2> /dev/null)" && break
2622 sleep 0.05
2623done
2624grep -Eqx "$x34 [0-9a-f]{40} [0-9a-f]{16} stale" <<< "$record34" \
2625 || die "the outcome record is not in the format its readers parse: $record34"
2626holds "a stranger's evidence for the landing tree lands nothing"
2627
2628# A known signer's passing note for the landing tree, built from another
2629# attribute, is no evidence for prose-format either.
2630sleep 0.5
2631t="$EPOCHREALTIME"
2632attest_change c34-rebased "" "" --check prose-format=code-build
2633when33 "$log" "$t" "^pass: due$" > /dev/null || die "the landing tree's evidence did not wake the controller"
2634when33 "$log" "$t" "check prose-format .*tree that would land.*attestation is for runner \"nix\", attribute \"code-build\"" > /dev/null \
2635 || die "the verdict did not refuse the landing tree's note for another attribute: $(cat "$log")"
2636[ "$(tip)" = "$before34" ] || die "main moved on a note for another attribute"
2637holds "a passing note for the landing tree and another attribute is no evidence on a moved landing"
2638
2639# The host's worker then attests the landing tree under a known key, for
2640# the attribute the policy names. Its ref replaces the one before it. The
2641# push wakes the controller, which lands c34's delta on that evidence and
2642# countersigns it under the landing tree.
2643known34="refs/the-valley/attestations/$landing34/$(attest key --key "$work/contributor" --name "$contributor" | cut -d+ -f2)"
2644git -C "$origin" update-ref -d "$known34"
2645git update-ref -d "$known34"
2646sleep 0.5
2647t="$EPOCHREALTIME"
2648attest_change c34-rebased "" "" --check prose-format
2649when33 "$log" "$t" "^pass: due$" > /dev/null || die "the landing tree's evidence did not wake the controller"
2650lands33 "c-$id34" "$t" "landing-tree evidence publication"
2651[ "$(passes33 "$log" "$t")" -eq "$(awk -v a="$t" '$1 >= a && $2 == "pass:" && $3 == "due"' "$log" | wc -l)" ] \
2652 || die "a pass other than a woken one ran: $(cat "$log")"
2653when33 "$log" "$t" "check prose-format .*transferred .unmoved, the landing tree's own evidence." > /dev/null \
2654 || die "prose-format did not stand on the landing tree's evidence: $(cat "$log")"
2655landed_as c34-rebased "$before34"
2656note34="$(git -C "$origin" cat-file blob "refs/the-valley/attestations/$landing34/$ihash:prose-format/statement.note")" \
2657 || die "the landing tree's evidence was not countersigned under the landing tree"
2658grep -qx "subject.digest.valley-tree-v1 $landing34" <<< "$note34" || die "the countersigned note is not about the landing tree"
2659grep -qF " $integrator_name " <<< "$note34" || die "the note under the landing tree carries no countersignature"
2660git -C "$origin" cat-file blob \
2661 "refs/the-valley/attestations/$landing34/$ihash:$(transfer_path "$(tip)")" > "$work/c34.transfer"
2662grep -qx "predicate.checks.0.rule unmoved" "$work/c34.transfer" \
2663 || die "the transfer statement does not record the landing tree's evidence as unmoved"
2664grep -qx "predicate.checks.0.evidence.sha256 $(sed '/^$/,$d' <<< "$note34" | sha256sum | cut -d' ' -f1)" "$work/c34.transfer" \
2665 || die "the transfer statement does not cite the landing tree's note"
2666holds "a stale-for-evidence request lands when its landing tree's evidence arrives, woken by the push"
2667holds "the landing countersigns that evidence and its transfer statement cites it"
2668
2669kill $(jobs -p) 2> /dev/null || true
2670wait 2> /dev/null || true
2671rm -f "$origin/hooks/post-receive" "$instance_repo/hooks/post-receive"
2672
2673printf '\nintegrator-e2e: every scenario held\n'