gunk-dev/the-valley

run.sh

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