gunk-dev/the-valley

restack-e2e.sh

source5c91b2faf25bmain's published tip history
22.4 KiB
1# shellcheck shell=bash
2# valley-restacker once --report-only, end to end over a real bare
3# repository wired with the fixture host's rendered pre-receive hook.
4# Every change is readied with the repository's own valley as its owner.
5# The hook grants request and restack to the principal requester, which
6# files the requests, and restack alone to the principal restacker, which
7# is the principal the restacker counts.
8#
9# In the planner's scenarios, outcome records are injected on the server
10# side with update-ref, because no push may write one: only the
11# integrator writes them. Each injection is marked where it is made. The
12# fixtures after them run the real integrator.
13# Paths and fixtures come from the derivation environment.
14# shellcheck disable=SC2154
15set -euo pipefail
16
17w="$TMPDIR/restack-e2e"
18mkdir -p "$w"
19export HOME="$w"
20export GIT_CONFIG_NOSYSTEM=1
21git config --global user.name restack-e2e
22git config --global user.email restack-e2e@localhost
23git config --global init.defaultBranch main
24git config --global advice.detachedHead false
25
26fail() {
27 printf 'restack-e2e: %s\n' "$*" >&2
28 for f in "$w"/out "$w"/err; do
29 if [ -s "$f" ]; then cat "$f" >&2; fi
30 done
31 exit 1
32}
33
34origin="$w/project.git"
35hook="$(grep -o '/nix/store/[^ ]*-valley-protect-open' "$initScriptPath" | head -n1)"
36test -x "$hook"
37git init --quiet --bare "$origin"
38cp "$hook" "$origin/hooks/pre-receive"
39chmod +x "$origin/hooks/pre-receive"
40
41repo="$w/project"
42git init --quiet "$repo"
43cd "$repo"
44git remote add origin "$origin"
45# The project layer caps the restacker at two automatic versions a change.
46mkdir -p policy/project
47printf 'package verification\n\nproject: restack: maxAutomaticVersions: 2\n' > policy/project/policy.cue
48echo base > readme
49git add readme policy
50git commit --quiet -m base
51env -u VALLEY_PRINCIPAL git push --quiet origin main
52
53as() {
54 local who="$1"
55 shift
56 git config valley.principal "$who"
57 VALLEY_PRINCIPAL="$who" "$@"
58}
59ok() { "$@" > "$w/out" 2> "$w/err" || fail "$* failed"; }
60
61# change <owner> <branch> <base>: a commit on base, pushed and readied by
62# its owner; prints the change ID.
63change() {
64 local who="$1" branch="$2" base="$3"
65 git checkout --quiet -B "$branch" "$base"
66 echo "$branch" > "$branch"
67 git add "$branch"
68 git commit --quiet -m "$branch"
69 as "$who" git push --quiet --force origin "$branch"
70 ok as "$who" valley ready
71 sed -n 's/^The change ID \([k-z]*\) is new\..*/\1/p' "$w/out"
72}
73# branch <name> <base>: a plain branch, which no record is on.
74branch() {
75 git checkout --quiet -B "$1" "$2"
76 echo "$1" > "$1"
77 git add "$1"
78 git commit --quiet -m "$1"
79 as alice git push --quiet origin "$1"
80}
81
82base="$(git rev-parse main)"
83a="$(change alice a "$base")"
84b1="$(change bob b1 "$base")"
85b2="$(change bob b2 b1)"
86c1="$(change alice c1 "$base")"
87c2="$(change alice c2 c1)"
88c3="$(change bob c3 c1)"
89d="$(change alice d "$base")"
90ok as alice valley unready "$d"
91wd="$(change bob wd "$base")"
92ok as bob valley withdraw "$wd"
93branch plain "$base"
94e="$(change alice e "$base")"
95branch e-plain e
96g1="$(change alice g1 "$base")"
97g2="$(change alice g2 g1)"
98ok as alice valley unready "$g1"
99u="$(change bob u "$base")"
100# k gains two versions from the restacker principal. A version the restack
101# grant adds keeps the active version's title, so each commit's subject is
102# k's title; one under any other title is refused, and its branch is put
103# back.
104k="$(change alice k "$base")"
105git checkout --quiet k
106for n in 2 3; do
107 echo "$n" >> k
108 git commit --quiet -am k
109 as restacker git push --quiet origin k
110 ok as restacker valley ready --change "$k" k
111done
112echo forged >> k
113git commit --quiet -am 'a title of its own'
114as restacker git push --quiet origin k
115if as restacker valley ready --change "$k" k > "$w/out" 2> "$w/err"; then
116 fail 'the restacker readied a version under a title of its own'
117fi
118grep -q 'under the title of the active one' "$w/err" || fail 'the refusal does not name the title'
119git reset --quiet --hard HEAD~1
120as restacker git push --quiet --force origin k
121# s lands by fast-forward before main moves, so it is submitted.
122s="$(change alice s "$base")"
123env -u VALLEY_PRINCIPAL git push --quiet origin s:main
124git checkout --quiet main
125git reset --quiet --hard origin/main
126echo moved > moved
127git add moved
128git commit --quiet -m moved
129env -u VALLEY_PRINCIPAL git push --quiet origin main
130tip="$(git rev-parse main)"
131
132# Server-side injection of an outcome record under a request name.
133evidence() {
134 git -C "$origin" for-each-ref --format='%(refname) %(objectname)' refs/the-valley/attestations/ \
135 | LC_ALL=C sort | sha256sum | cut -c1-16
136}
137inject() {
138 local name="$1" line="$2" blob
139 blob="$(printf '%s\n' "$line" | git -C "$origin" hash-object -w --stdin)"
140 git -C "$origin" update-ref "refs/the-valley/integration-outcomes/main/$name" "$blob"
141}
142# u's request was judged failed, and no request is left: its landing is
143# uncertain.
144inject "c-$u" "$(git rev-parse u) $base $(evidence) failed 2026-10-18T00:00:00Z"
145
146# request <name> <head>: requester files an integration request.
147request() { as requester git push --quiet origin "$2:refs/the-valley/integration-requests/main/$1"; }
148
149refs() { git -C "$origin" for-each-ref --format='%(refname) %(objectname)' | LC_ALL=C sort; }
150plan() {
151 local before
152 before="$(refs)"
153 valley-restacker once --report-only --json --repo "$origin" --state "$w/state" \
154 --principal restacker --instance "$smokePolicy/instance" "$@" > "$w/plan.json" 2> "$w/err" \
155 || fail "the planner failed"
156 [ "$(refs)" = "$before" ] || fail 'a --report-only pass changed a ref on origin'
157}
158# family <id>: the family plan a change is a layer of.
159family() { jq -c --arg id "$1" '.families[] | select(any(.layers[]; .id == $id))' "$w/plan.json"; }
160action() {
161 local got
162 got="$(family "$1" | jq -r .action)"
163 [ "$got" = "$2" ] || fail "the family of $1 is $got, not $2: $(family "$1")"
164}
165says() { family "$1" | jq -e --arg s "$2" 'any(.reasons[], .notes[]; contains($s))' > /dev/null \
166 || fail "the family of $1 does not say: $2: $(family "$1")"; }
167
168# ----------------------------------------------------------------------
169# Selection and families.
170plan
171jq -e --arg t "$tip" '.tip == $t and .maxAutomaticVersions == 2' "$w/plan.json" > /dev/null \
172 || fail "the plan does not read main's tip or the project's cap"
173action "$a" restack
174action "$b1" restack
175[ "$(family "$b1" | jq -c '[.layers[].id]')" = "[\"$b1\",\"$b2\"]" ] || fail 'b1 and b2 are not one family'
176[ "$(family "$c1" | jq '.layers | length')" = 3 ] || fail 'c1, c2 and c3 are not one family'
177[ "$(family "$c2" | jq -r '.layers[0].id')" = "$c1" ] || fail 'the shared lower layer is not the bottom'
178action "$c3" restack
179action "$d" leave
180action "$wd" leave
181action "$u" leave
182action "$e" hold
183says "$e" 'e-plain is a plain branch'
184action "$g2" hold
185says "$g2" 'is a draft'
186[ -z "$(family "$s")" ] || fail 'a submitted change was planned'
187jq -e '[.families[].layers[] | select(.name == "plain")] | length == 0' "$w/plan.json" > /dev/null \
188 || fail 'a lone plain branch was planned'
189
190# Capacity: k has two versions uploaded by the restacker principal, and a
191# third is over the project's cap of 2.
192action "$k" hold
193says "$k" 'over the cap of 2'
194family "$k" | jq -e '.layers[0].capacity.uploads == 3' > /dev/null || fail 'k does not count three uploads'
195
196# ----------------------------------------------------------------------
197# Request holds. A request by name with no outcome holds.
198request a a
199plan
200action "$a" hold
201says "$a" 'no outcome yet'
202family "$a" | jq -e '.requests[0].by == ["name", "head"]' > /dev/null || fail 'request a was not related by name'
203# A current stale releases.
204inject a "$(git rev-parse a) $tip $(evidence) stale"
205plan
206action "$a" restack
207# A mismatched head, tip or fingerprint holds.
208inject a "$base $tip $(evidence) stale"
209plan
210action "$a" hold
211says "$a" 'is about head'
212inject a "$(git rev-parse a) $base $(evidence) stale"
213plan
214says "$a" 'judged on main at'
215inject a "$(git rev-parse a) $tip 0000000000000000 stale"
216plan
217says "$a" 'judged on evidence'
218# A malformed outcome holds.
219inject a "not an outcome"
220plan
221says "$a" 'does not read'
222# A current reject releases, with a note.
223inject a "$(git rev-parse a) $tip $(evidence) reject"
224plan
225action "$a" restack
226says "$a" 'was rejected'
227
228# By an exact head, under a name nothing else relates.
229request zz-head "$(git rev-parse b2)"
230# By range: a commit on c2 no branch holds, so only the request names it
231# and the planner has to fetch it before reading its ancestry.
232git checkout --quiet -B scratch c2
233echo over > over
234git add over
235git commit --quiet -m over
236request zz-range "$(git rev-parse HEAD)"
237git checkout --quiet main
238git branch --quiet -D scratch
239plan
240action "$b1" hold
241family "$b1" | jq -e '.requests[] | select(.name == "zz-head") | .by == ["head"]' > /dev/null \
242 || fail 'zz-head was not related by head'
243action "$c1" hold
244family "$c1" | jq -e '.requests[] | select(.name == "zz-range") | .by == ["range"]' > /dev/null \
245 || fail 'zz-range was not related by range'
246action "$c3" hold
247
248# A request whose head is no commit cannot be related or not, so every
249# family it might be about holds. Injected on the server side, since the
250# hook takes no such request.
251git -C "$origin" update-ref refs/the-valley/integration-requests/main/zz-blob \
252 "$(echo blob | git -C "$origin" hash-object -w --stdin)"
253plan
254action "$a" hold
255says "$a" 'cannot be determined'
256
257# The human summary reads the same plan.
258valley-restacker once --report-only --repo "$origin" --state "$w/state" --principal restacker \
259 --instance "$smokePolicy/instance" > "$w/out" 2> "$w/err" || fail 'the summary failed'
260grep -qE '^[k-z]+: hold$' "$w/out" || fail 'the summary holds no family'
261# And without --report-only, nothing runs.
262if valley-restacker once --repo "$origin" --state "$w/state" --principal restacker \
263 --instance "$smokePolicy/instance" > "$w/out" 2> "$w/err"; then
264 fail 'once ran without --report-only'
265fi
266
267# ----------------------------------------------------------------------
268# A cap larger than any int. The schema admits it, so it composes, and the
269# planner counts it as the largest int: no practical cap. k, held above by
270# the cap of 2, is not held by this one. The request whose head is no
271# commit would hold k too, so it is removed first, on the server side
272# where it was injected.
273git -C "$origin" update-ref -d refs/the-valley/integration-requests/main/zz-blob
274git checkout --quiet main
275printf 'package verification\n\nproject: restack: maxAutomaticVersions: 9223372036854775808\n' \
276 > policy/project/policy.cue
277git commit --quiet -am 'a cap larger than any int'
278env -u VALLEY_PRINCIPAL git push --quiet origin main
279plan
280grep -q '"maxAutomaticVersions": 9223372036854775807,' "$w/plan.json" \
281 || fail "the plan does not count the cap as the largest int: $(cat "$w/plan.json")"
282action "$k" restack
283
284
285# ======================================================================
286# The fixtures the publishing slice's tests stand on, each proved here.
287
288# One verifier file, which the rendered hook checks pushed evidence
289# against, and the integrator and the restacker read too.
290signers="$keys/known_signers"
291grep -qF -- "--known-signers $signers" "$hook" || fail 'the rendered hook does not read the shared verifier keys'
292# ssh-keygen signs only with a key nobody else can read.
293mkdir -p "$w/keys"
294for who in contributor integrator; do install -m 600 "$keys/$who" "$w/keys/$who"; done
295contributor=contributor.valley.invalid/attestations
296integrator_name=integrator.valley.invalid/attestations
297
298# The transport (restack/e2e/transport): git reaches origin through it as
299# ssh, as the principal the URL names, and the real receive-pack runs the
300# rendered hook. A barrier is armed by writing it to $VALLEY_BARRIER/hold.
301export GIT_SSH_COMMAND=valley-restack-transport GIT_SSH_VARIANT=simple
302export VALLEY_BARRIER="$w/barrier"
303mkdir -p "$VALLEY_BARRIER"
304url() { printf 'ssh://%s@valley%s' "$1" "$2"; }
305disarm() { rm -f "${VALLEY_BARRIER:?}"/*; }
306arm() {
307 disarm
308 echo "$*" > "$VALLEY_BARRIER/hold"
309}
310arrived() {
311 local i=0
312 until [ -e "$VALLEY_BARRIER/arrived" ]; do
313 i=$((i + 1))
314 [ "$i" -lt 1200 ] || fail 'nothing reached the barrier'
315 sleep 0.05
316 done
317}
318release() { touch "$VALLEY_BARRIER/release"; }
319at() { git -C "$1" rev-parse --verify --quiet "$2" || true; }
320
321# ----------------------------------------------------------------------
322# The restacker principal holds restack and not request, so it cannot file
323# a request, which requester can.
324cd "$repo"
325git checkout --quiet -B fixture main
326if git push --quiet "$(url restacker "$origin")" fixture:refs/the-valley/integration-requests/main/zz-by-restacker \
327 2> "$w/err"; then
328 fail 'the restacker principal filed a request'
329fi
330git push --quiet "$(url requester "$origin")" fixture:refs/the-valley/integration-requests/main/zz-by-requester \
331 2> "$w/err" || fail 'requester could not file a request through the transport'
332git -C "$origin" update-ref -d refs/the-valley/integration-requests/main/zz-by-requester
333
334# A barrier holds a push before origin sees it, and releases it.
335echo held > held
336git add held
337git commit --quiet -m held
338arm receive connect
339git push --quiet "$(url alice "$origin")" fixture:refs/heads/held 2> "$w/err" &
340pid=$!
341arrived
342[ -z "$(at "$origin" refs/heads/held)" ] || fail 'a push the barrier held reached origin'
343kill -0 "$pid" 2> /dev/null || fail 'a push the barrier held ended'
344release
345wait "$pid" || fail 'a released push failed'
346[ "$(at "$origin" refs/heads/held)" = "$(git rev-parse fixture)" ] || fail 'a released push did not reach origin'
347
348# A push held there loses its lease to one made while it waits.
349was="$(git rev-parse fixture)"
350git commit --quiet --allow-empty -m mine
351arm receive connect
352git push --quiet --force-with-lease="refs/heads/held:$was" "$(url restacker "$origin")" fixture:refs/heads/held \
353 2> "$w/err" &
354pid=$!
355arrived
356git checkout --quiet -B author "$was"
357git commit --quiet --allow-empty -m "the author's"
358as alice git push --quiet origin author:held
359release
360if wait "$pid"; then fail 'a push held across another kept its lease'; fi
361grep -q 'stale info' "$w/err" || fail "the held push was not refused for its lease: $(cat "$w/err")"
362[ "$(at "$origin" refs/heads/held)" = "$(git rev-parse author)" ] || fail "the author's push did not stand"
363
364# A barrier holds a push that origin has taken, before its client hears.
365git checkout --quiet fixture
366arm receive taken refs/heads/taken
367git push --quiet "$(url alice "$origin")" fixture:refs/heads/taken 2> "$w/err" &
368pid=$!
369arrived
370[ "$(at "$origin" refs/heads/taken)" = "$(git rev-parse fixture)" ] || fail 'origin had not taken the held push'
371kill -0 "$pid" 2> /dev/null || fail 'the client heard before the release'
372release
373wait "$pid" || fail 'a push held after origin took it failed'
374
375# A dropped answer: origin takes the push, and its client reports that
376# origin never said so.
377arm receive drop refs/heads/dropped
378if git push --porcelain "$(url alice "$origin")" fixture:refs/heads/dropped > "$w/out" 2> "$w/err"; then
379 fail 'a push whose answer was lost succeeded'
380fi
381cat "$w/out" "$w/err" | grep -q 'remote failed to report status' || fail 'the client did not lose the answer'
382[ "$(at "$origin" refs/heads/dropped)" = "$(git rev-parse fixture)" ] || fail 'origin did not take the push whose answer was lost'
383disarm
384
385# ----------------------------------------------------------------------
386# A repository served with the integrator's evidence fixtures: the nix
387# stand-in (integrator/e2e), and a policy whose checks are pure, under a
388# floor that requires nothing.
389cp -r "$integratorE2e" "$w/stand-ins"
390chmod -R +w "$w/stand-ins"
391patchShebangs "$w/stand-ins" > /dev/null
392export PATH="$w/stand-ins:$PATH" VALLEY_FAKE_STORE="$w/store"
393mkdir -p "$w/floor"
394printf 'package verification\n\nfloor: {\n\tchecks: {}\n\tclasses: {}\n\tunclassified: {}\n}\n' > "$w/floor/floor.cue"
395
396served="$w/served.git"
397git init --quiet --bare "$served"
398cp "$hook" "$served/hooks/pre-receive"
399chmod +x "$served/hooks/pre-receive"
400git init --quiet "$w/fixture"
401cd "$w/fixture"
402git remote add origin "$served"
403mkdir -p docs src checks policy/project
404echo "the readme" > docs/readme.md
405echo "the source" > src/main.txt
406echo docs > checks/prose-format.inputs
407echo src > checks/code-build.inputs
408cat > policy/project/policy.cue << 'CUE'
409package verification
410
411project: {
412 checks: {
413 "prose-format": {runner: "nix", attribute: "prose-format"}
414 "code-build": {runner: "nix", attribute: "code-build"}
415 }
416 classes: {
417 prose: {paths: "docs/**": true, requires: "prose-format": true}
418 code: {paths: "src/**": true, requires: "code-build": true}
419 }
420 unclassified: {}
421}
422CUE
423git add -A
424git commit --quiet -m 'seed the project'
425env -u VALLEY_PRINCIPAL git push --quiet origin main
426
427# attested <branch> <attest run flags…>: alice's change, its evidence signed
428# by the contributor's key and pushed with it through the hook, readied;
429# prints the change ID.
430attested() {
431 local branch="$1"
432 shift
433 as alice attest run --repo . --key "$w/keys/contributor" --name "$contributor" \
434 --push origin --branch "$branch" "$@" > "$w/out" 2> "$w/err" || fail "attest run on $branch failed"
435 ok as alice valley ready
436 sed -n 's/^The change ID \([k-z]*\) is new\..*/\1/p' "$w/out"
437}
438git checkout --quiet -b lands main
439echo "a second source line" >> src/main.txt
440git commit --quiet -am 'a change the integrator lands'
441lands="$(attested lands --check code-build)"
442# Its evidence claims an effectful check where the policy runs a pure one.
443git checkout --quiet -b lies main
444echo "a readme whose evidence lies" > docs/readme.md
445git commit --quiet -am 'a change whose evidence lies about its kind'
446lies="$(attested lies --command prose-format=true)"
447git checkout --quiet main
448echo moved > moved.txt
449git add moved.txt
450git commit --quiet -m 'main moves on'
451env -u VALLEY_PRINCIPAL git push --quiet origin main
452
453integrate() {
454 integrator reconcile --repo "$served" --key "$w/keys/integrator" --name "$integrator_name" \
455 --known-signers "$signers" --instance "$w/floor" --schema "$SCHEMA_VERIFICATION" \
456 --attest-schema "$SCHEMA_ATTESTATION" --event-schema "$SCHEMA_EVENTS" > "$w/integrator.out" 2>&1 \
457 || fail "the integrator failed: $(cat "$w/integrator.out")"
458}
459judged() {
460 grep -q "^c-$1 -> refs/heads/main .*: $2\$" "$w/integrator.out" \
461 || fail "the integrator did not $2 c-$1: $(cat "$w/integrator.out")"
462}
463# requester files each request through the transport, one pass each, so
464# the reject is judged on the tip the landing left.
465git push --quiet "$(url requester "$served")" "lands:refs/the-valley/integration-requests/main/c-$lands"
466integrate
467judged "$lands" land
468git push --quiet "$(url requester "$served")" "lies:refs/the-valley/integration-requests/main/c-$lies"
469integrate
470judged "$lies" reject
471grep -q 'requires a pure check and the attestation claims an effectful check' "$w/integrator.out" \
472 || fail "the reject is not for the evidence's kind: $(cat "$w/integrator.out")"
473
474# The planner, reading the shared verifier keys, sees the landed change
475# submitted: it is no layer. Without the keys, the same landing is only
476# uncertain. The rejected change's family is released by the real
477# outcome, current at its head, tip and evidence, and the reject is noted.
478served_plan() {
479 valley-restacker once --report-only --json --repo "$(url restacker "$served")" --state "$w/served-state" \
480 --principal restacker --instance "$w/floor" "$@" > "$w/plan.json" 2> "$w/err" || fail 'the planner failed'
481}
482served_plan --known-signers "$signers" --integrator-name "$integrator_name"
483[ -z "$(family "$lands")" ] || fail "the change the integrator landed was planned: $(family "$lands")"
484action "$lies" restack
485says "$lies" 'was rejected'
486family "$lies" | jq -e --arg n "c-$lies" '.requests[] | select(.name == $n) | .decision == "reject" and .current' \
487 > /dev/null || fail "the reject was not read as current: $(family "$lies")"
488served_plan
489action "$lands" leave
490family "$lands" | jq -e '.layers[0].state == "uncertain"' > /dev/null \
491 || fail "without the keys, the landing is not uncertain: $(family "$lands")"
492
493# ----------------------------------------------------------------------
494# A pass locks its state directory: a second pass fails while a barrier
495# holds the first one's read of origin, and the first goes on once
496# released. The directory belongs to the restacker principal, so a pass
497# for another is refused it.
498pass() {
499 valley-restacker once --report-only --repo "$(url restacker "$served")" --state "$w/served-state" \
500 --principal restacker --instance "$w/floor" "$@"
501}
502arm upload connect
503pass > "$w/first.out" 2> "$w/first.err" &
504pid=$!
505arrived
506if pass > "$w/out" 2> "$w/err"; then fail 'a second pass ran while the first held the state'; fi
507grep -q 'another pass is using the state directory' "$w/err" || fail "the second pass did not say why: $(cat "$w/err")"
508release
509wait "$pid" || fail "the first pass failed once released: $(cat "$w/first.err")"
510if valley-restacker once --report-only --repo "$(url restacker "$served")" --state "$w/served-state" \
511 --principal requester --instance "$w/floor" > "$w/out" 2> "$w/err"; then
512 fail 'a pass for another principal used the state directory'
513fi
514grep -q 'give each its own --state' "$w/err" || fail "the refusal does not say why: $(cat "$w/err")"
515
516# A pass whose read of origin never returns ends at its --timeout.
517arm upload connect
518if pass --timeout 2s > "$w/out" 2> "$w/err"; then fail 'a pass held at the barrier finished'; fi
519grep -q 'ran past its --timeout of 2s' "$w/err" || fail "the pass did not end at its timeout: $(cat "$w/err")"
520disarm
521
522# A pass whose output nobody reads ends at its --timeout too, and lets go
523# of the lock on its state, so the next pass takes it. Its stdout is a
524# fifo that is held open, filled, and never read, so the pass's first
525# write to it blocks. The outer timeout only bounds this check: it kills
526# a pass that outlives the stop it sends.
527mkfifo "$w/unread"
528exec 7<> "$w/unread"
529dd if=/dev/zero of="$w/unread" bs=4096 count=1024 oflag=nonblock 2> /dev/null || true
530dd if=/dev/zero of="$w/unread" bs=1 count=4096 oflag=nonblock 2> /dev/null || true
531status=0
532start=$SECONDS
533timeout -k 5 60 valley-restacker once --report-only --repo "$(url restacker "$served")" --state "$w/served-state" \
534 --principal restacker --instance "$w/floor" --timeout 15s > "$w/unread" 2> "$w/err" || status=$?
535took=$((SECONDS - start))
536exec 7<&-
537case "$status" in
538 0) fail 'a pass whose output nobody read finished' ;;
539 124 | 137) fail 'a pass whose output nobody read did not end at its timeout' ;;
540esac
541[ "$took" -lt 45 ] || fail "a pass with a timeout of 15s took ${took}s"
542grep -q 'ran past its --timeout of 15s: the plan was not written' "$w/err" \
543 || fail "the pass did not end at its timeout while writing: $(cat "$w/err")"
544pass > "$w/out" 2> "$w/err" || fail "the next pass did not take the lock: $(cat "$w/err")"
545
546touch "$out"