| 1 | # shellcheck shell=bash |
| 2 | # valley review with no change, end to end and unmocked, over the |
| 3 | # projects one test host serves: the walk through what needs the operator, |
| 4 | # across projects, in landing order, through the packaged CLI. The host is |
| 5 | # made by the integrator host's rendered valley-init, as valley-changes |
| 6 | # makes it, so discovery reads the project list a host publishes and every |
| 7 | # record and request is pushed through the hook that host installs. |
| 8 | # Paths and fixtures come from the derivation environment. |
| 9 | # shellcheck disable=SC2154 |
| 10 | set -euo pipefail |
| 11 | |
| 12 | w="$TMPDIR/valley-walk" |
| 13 | mkdir -p "$w" |
| 14 | export HOME="$w" XDG_CACHE_HOME="$w/cache" XDG_STATE_HOME="$w/state" TERM=xterm |
| 15 | export GIT_CONFIG_NOSYSTEM=1 |
| 16 | # Nobody is anybody by default: a commit made where no identity is set |
| 17 | # fails, so a review in a cache clone commits only with the identity the |
| 18 | # walk lends it from the checkout. |
| 19 | git config --global user.useConfigOnly true |
| 20 | git config --global init.defaultBranch main |
| 21 | git config --global advice.detachedHead false |
| 22 | unset VALLEY_KNOWN_SIGNERS VALLEY_INTEGRATOR_SIGNER VISUAL || true |
| 23 | |
| 24 | fail() { |
| 25 | printf 'valley-walk: %s\n' "$*" >&2 |
| 26 | for f in "$w"/out "$w"/err; do |
| 27 | if [ -s "$f" ]; then cat "$f" >&2; fi |
| 28 | done |
| 29 | exit 1 |
| 30 | } |
| 31 | |
| 32 | ok() { |
| 33 | "$@" > "$w/out" 2> "$w/err" || fail "$* failed" |
| 34 | } |
| 35 | |
| 36 | line() { |
| 37 | grep -qE -- "$1" "$w/out" || fail "no line matches $1" |
| 38 | } |
| 39 | |
| 40 | no_line() { |
| 41 | if grep -qE -- "$1" "$w/out"; then fail "a line matches $1"; fi |
| 42 | } |
| 43 | |
| 44 | # before <ERE> <ERE>: the first line matching the first comes before the |
| 45 | # first line matching the second. |
| 46 | before() { |
| 47 | local a b |
| 48 | a="$(grep -nE -m 1 -- "$1" "$w/out" | cut -d: -f1 || true)" |
| 49 | b="$(grep -nE -m 1 -- "$2" "$w/out" | cut -d: -f1 || true)" |
| 50 | [ -n "$a" ] && [ -n "$b" ] && [ "$a" -lt "$b" ] || fail "$1 does not come before $2" |
| 51 | } |
| 52 | |
| 53 | # walk <status> <answers> [<flag>...]: valley review with no change, from |
| 54 | # the open checkout, answering from a pipe; it exits with <status>. |
| 55 | walk() { |
| 56 | local want="$1" answers="$2" status=0 |
| 57 | shift 2 |
| 58 | printf '%b' "$answers" | valley review "$@" > "$w/out" 2> "$w/err" || status=$? |
| 59 | [ "$status" = "$want" ] || fail "the walk exited $status, not $want" |
| 60 | } |
| 61 | |
| 62 | # wait_for <file> <ERE>: wait until the file shows a line matching it. The |
| 63 | # walk's output is a file a child writes, which a shell has no event for, |
| 64 | # so it is read again every tenth of a second, for a minute at most. |
| 65 | wait_for() { |
| 66 | local i |
| 67 | for i in $(seq 600); do |
| 68 | if grep -qE -- "$2" "$1" 2> /dev/null; then return 0; fi |
| 69 | sleep 0.1 |
| 70 | done |
| 71 | fail "$1 never showed $2" |
| 72 | } |
| 73 | |
| 74 | # The host: guarded, open, released and sealed, with sealed the instance |
| 75 | # repository, as valley-changes makes it. sealed's main carries the floor |
| 76 | # approving derives the policy from. |
| 77 | data="$w/srv/git" |
| 78 | mkdir -p "$data" |
| 79 | sed "s|/srv/git|$data|g" "$initScriptPath" > "$w/init.sh" |
| 80 | bash "$w/init.sh" 2> "$w/init.err" || fail "valley-init failed: $(cat "$w/init.err")" |
| 81 | instance="$data/sealed.git" |
| 82 | for name in guarded open released sealed; do |
| 83 | git -C "$data/$name.git" config --unset core.sharedRepository || true |
| 84 | done |
| 85 | git init --quiet "$w/floor" |
| 86 | mkdir -p "$w/floor/policy/instance" |
| 87 | cp "$floor"/*.cue "$w/floor/policy/instance/" |
| 88 | git -C "$w/floor" add policy |
| 89 | git -C "$w/floor" -c user.name=integrator -c user.email=integrator@localhost commit --quiet -m floor |
| 90 | git -C "$w/floor" push --quiet "$instance" HEAD:refs/heads/floor |
| 91 | git -C "$instance" update-ref refs/heads/main "$(git -C "$w/floor" rev-parse HEAD)" |
| 92 | |
| 93 | id() { printf '%s%s' "$1" "$(printf 'k%.0s' $(seq $((32 - ${#1}))))"; } |
| 94 | G1="$(id kmkm)" G2="$(id knkn)" O1="$(id popo)" S1="$(id sqsq)" S2="$(id srsr)" |
| 95 | M1="$(id mlml)" M2="$(id mnmn)" M3="$(id mpmp)" |
| 96 | |
| 97 | # A checkout of a project whose main names sealed as its owning valley, |
| 98 | # with alice's identity in its own configuration alone. |
| 99 | export VALLEY_PRINCIPAL=alice |
| 100 | checkout() { |
| 101 | local dir="$w/$1" |
| 102 | git clone --quiet "$data/$1.git" "$dir" 2> /dev/null |
| 103 | git -C "$dir" config valley.principal alice |
| 104 | git -C "$dir" config user.name alice |
| 105 | git -C "$dir" config user.email alice@example.org |
| 106 | mkdir -p "$dir/policy" |
| 107 | printf '%s\n' "$instance" > "$dir/policy/valley" |
| 108 | git -C "$dir" add policy/valley |
| 109 | git -C "$dir" commit --quiet -m base |
| 110 | VALLEY_PRINCIPAL=integrator git -C "$dir" push --quiet origin main |
| 111 | } |
| 112 | |
| 113 | # branch <name> <from> <subject…>: a branch with a commit per subject, |
| 114 | # pushed to origin. |
| 115 | branch() { |
| 116 | local name="$1" from="$2" s |
| 117 | shift 2 |
| 118 | git checkout --quiet -b "$name" "$from" |
| 119 | for s in "$@"; do |
| 120 | echo "$s" > "$s.txt" |
| 121 | git add "$s.txt" |
| 122 | git commit --quiet -m "$s" |
| 123 | done |
| 124 | git push --quiet origin "$name" |
| 125 | } |
| 126 | |
| 127 | # ready <id> <branch>: the branch readied as the change, each a second |
| 128 | # after the last, so the landing order is the order they are readied in. |
| 129 | at=1700000000 |
| 130 | ready() { |
| 131 | at=$((at + 1)) |
| 132 | GIT_COMMITTER_DATE="@$at +0000" ok valley ready --change "$1" "$2" |
| 133 | } |
| 134 | |
| 135 | checkout open |
| 136 | checkout guarded |
| 137 | cd "$w/guarded" |
| 138 | branch g-one main g-one |
| 139 | ready "$G1" g-one |
| 140 | branch g-two main g-two |
| 141 | ready "$G2" g-two |
| 142 | cd "$w/open" |
| 143 | branch o-one main o-one |
| 144 | ready "$O1" o-one |
| 145 | |
| 146 | # ---------------------------------------------------------------------- |
| 147 | # Three ready changes in two projects, guarded's read through the walk's |
| 148 | # cache clone: the first approved and the second rejected there, the |
| 149 | # third skipped. Each step is headed by its place, project, change and |
| 150 | # checks, and the summary names every outcome, then what still needs the |
| 151 | # operator: the rejected change is withdrawn, and pending lists it no more. |
| 152 | walk 0 'a\nr\nyes\ns\n' |
| 153 | line '^needs you \(3, in landing order\)$' |
| 154 | before '^\[1/3\] guarded · kmkm v1 · 1 check pending$' '^\[2/3\] guarded · knkn v1 · 1 check pending$' |
| 155 | before '^\[2/3\] guarded · knkn v1' '^\[3/3\] open · popo v1 · 1 check pending$' |
| 156 | line 'rejected g-two: deleted from origin · knkn withdrawn$' |
| 157 | line '^ ✓ guarded kmkm v1 approved$' |
| 158 | line '^ ✓ guarded knkn v1 rejected · branch deleted$' |
| 159 | line '^ ◇ open popo v1 skipped$' |
| 160 | line '^still needs you \(1\): open popo$' |
| 161 | no_line 'nothing needs you' |
| 162 | [ "$(git -C "$data/guarded.git" rev-parse "refs/the-valley/integration-requests/main/c-$G1")" = \ |
| 163 | "$(git -C "$w/guarded" rev-parse g-one)" ] || fail "the approval filed no request at kmkm's head" |
| 164 | if git -C "$data/guarded.git" rev-parse --verify --quiet refs/heads/g-two > /dev/null; then |
| 165 | fail "the rejection left g-two on origin" |
| 166 | fi |
| 167 | ok valley pending --all |
| 168 | no_line knkn |
| 169 | clone="$(echo "$XDG_CACHE_HOME"/valley/repos/*-guarded)" |
| 170 | [ -d "$clone" ] || fail "guarded was read through no cache clone" |
| 171 | for key in valley.principal user.name user.email; do |
| 172 | if git -C "$clone" config --local --get "$key" > /dev/null; then fail "the walk wrote $key into the cache clone"; fi |
| 173 | done |
| 174 | |
| 175 | # ---------------------------------------------------------------------- |
| 176 | # A stale stack in guarded, based from the walk with [b]ase onto main: the |
| 177 | # rebase commits and writes records in the cache clone, as alice, with the |
| 178 | # identity the walk lent it. |
| 179 | cd "$w/guarded" |
| 180 | git checkout --quiet main |
| 181 | branch s-one main s-one |
| 182 | ready "$S1" s-one |
| 183 | branch s-two s-one s-two |
| 184 | ready "$S2" s-two |
| 185 | git checkout --quiet main |
| 186 | echo moved > moved.txt |
| 187 | git add moved.txt |
| 188 | git commit --quiet -m "main moves" |
| 189 | VALLEY_PRINCIPAL=integrator git push --quiet origin main |
| 190 | cd "$w/open" |
| 191 | walk 0 'b\nn\ns\n' --repo guarded |
| 192 | line '^needs you \(1, in landing order\)$' |
| 193 | line '^\[1/1\] guarded · srsr v1 · stack of 2 · 1 check pending$' |
| 194 | line '^ ◇ guarded srsr v1 skipped$' |
| 195 | tip="$(git -C "$data/guarded.git" rev-parse main)" |
| 196 | for b in s-one s-two; do |
| 197 | git -C "$data/guarded.git" merge-base --is-ancestor "$tip" "$b" || fail "the base left $b off main" |
| 198 | done |
| 199 | cd "$w/guarded" |
| 200 | ok valley resolve "$S2" |
| 201 | [ "$(cut -f4 "$w/out")" = 2 ] || fail "the base wrote no second version of srsr: $(cat "$w/out")" |
| 202 | |
| 203 | # ---------------------------------------------------------------------- |
| 204 | # Changes that move after the walk read its queue: while popo's prompt |
| 205 | # waits, mlml is unreadied, mnmn readied at a second version, and mpmp's |
| 206 | # branch deleted. mlml and mpmp are not reviewed, and mnmn is said to have |
| 207 | # moved, then reviewed and approved at its new version. |
| 208 | cd "$w/open" |
| 209 | branch m-one main m-one |
| 210 | ready "$M1" m-one |
| 211 | branch m-two main m-two |
| 212 | ready "$M2" m-two |
| 213 | branch m-three main m-three |
| 214 | ready "$M3" m-three |
| 215 | rm -f "$w/fifo" |
| 216 | mkfifo "$w/fifo" |
| 217 | valley review --repo open < "$w/fifo" > "$w/walk.out" 2> "$w/walk.err" & |
| 218 | walker=$! |
| 219 | exec 3> "$w/fifo" |
| 220 | wait_for "$w/walk.out" '\[s\]kip' |
| 221 | ok valley unready "$M1" |
| 222 | git checkout --quiet m-two |
| 223 | echo again > m-two.txt |
| 224 | git commit --quiet -am "m-two again" |
| 225 | git push --quiet origin m-two |
| 226 | ready "$M2" m-two |
| 227 | git push --quiet origin --delete m-three |
| 228 | printf 's\n' >&3 |
| 229 | wait_for "$w/walk.out" 'moved to v2' |
| 230 | printf 'a\n' >&3 |
| 231 | exec 3>&- |
| 232 | status=0 |
| 233 | wait "$walker" || status=$? |
| 234 | mv "$w/walk.out" "$w/out" |
| 235 | mv "$w/walk.err" "$w/err" |
| 236 | [ "$status" = 0 ] || fail "the walk with moving changes exited $status" |
| 237 | line '^\[2/4\] open · mlml v1' |
| 238 | line '^mlml is not reviewed: it is a draft$' |
| 239 | line '^mnmn moved to v2 since the queue was read$' |
| 240 | line '^ ⊘ open mlml v1 not reviewed · it is a draft$' |
| 241 | line '^ ✓ open mnmn v1 approved v2$' |
| 242 | line '^mpmp is not reviewed: its branch is gone from origin$' |
| 243 | line '^ ⊘ open mpmp v1 not reviewed · its branch is gone from origin$' |
| 244 | [ "$(git -C "$data/open.git" rev-parse "refs/the-valley/integration-requests/main/c-$M2")" = "$(git rev-parse m-two)" ] || |
| 245 | fail "mnmn was not approved at its second version" |
| 246 | |
| 247 | # ---------------------------------------------------------------------- |
| 248 | # Ctrl-C at a step's prompt, on a terminal: the step is interrupted, the |
| 249 | # summary so far is printed, and the walk exits 130. The diff is paged |
| 250 | # first, by a less that quits since it fits on one screen. |
| 251 | git config pager.diff 'less -FX' |
| 252 | status=0 |
| 253 | # On a terminal the prompt's keys are styled, so its plain tail is waited |
| 254 | # on. A walk that never gets there is ended rather than left waiting. |
| 255 | { |
| 256 | wait_for "$w/session.log" '\]kip: ' |
| 257 | printf '\003' |
| 258 | wait_for "$w/session.log" 'walked' |
| 259 | } | timeout 300 script -qec "valley review --repo open" /dev/null > "$w/session.log" 2>&1 || status=$? |
| 260 | sed -e 's/\x1b\[[0-9;?]*[a-zA-Z]//g' -e 's/\r//g' "$w/session.log" > "$w/out" |
| 261 | [ "$status" = 130 ] || fail "the interrupted walk exited $status, not 130: $(cat "$w/out")" |
| 262 | line '^walked \(1 of 2\)$' |
| 263 | line '^ ◇ open popo v1 interrupted$' |
| 264 | no_line 'still needs you|nothing needs you' |
| 265 | git config --unset pager.diff |
| 266 | |
| 267 | # ---------------------------------------------------------------------- |
| 268 | # A project that does not read is said, and nothing says that nothing |
| 269 | # needs the operator. An empty queue says that nothing does, with the |
| 270 | # counts pending gives, and exits 0. |
| 271 | mv "$data/released.git" "$data/released.moved" |
| 272 | walk 1 '' --repo released |
| 273 | line '^✗ released did not read: ' |
| 274 | no_line 'nothing needs you' |
| 275 | mv "$data/released.moved" "$data/released.git" |
| 276 | ok valley withdraw "$O1" |
| 277 | ok valley withdraw "$M3" |
| 278 | walk 0 '' --repo open |
| 279 | line '^nothing needs you · 1 moving · 1 draft' |
| 280 | |
| 281 | # ---------------------------------------------------------------------- |
| 282 | # Two steps in different repositories, on a terminal, their answers read |
| 283 | # from one file: an approval in guarded's cache clone, then a rejection |
| 284 | # confirmed in the open checkout. Each step's pager runs in the step's |
| 285 | # repository root and environment: the clone's is lent the checkout's |
| 286 | # principal through GIT_CONFIG_COUNT, and the checkout's step carries |
| 287 | # nothing of the clone's. A review that read ahead of its answer would |
| 288 | # take the next step's. |
| 289 | G3="$(id kvkv)" O2="$(id pqpq)" O3="$(id pxpx)" G4="$(id kxkx)" O4="$(id pzpz)" O5="$(id pwpw)" |
| 290 | cd "$w/guarded" |
| 291 | ok valley withdraw "$S2" |
| 292 | ok valley withdraw "$S1" |
| 293 | git checkout --quiet main |
| 294 | branch v-one main v-one |
| 295 | ready "$G3" v-one |
| 296 | cd "$w/open" |
| 297 | git checkout --quiet main |
| 298 | branch q-one main q-one |
| 299 | ready "$O2" q-one |
| 300 | git checkout --quiet main |
| 301 | printf '%s\n' '#!/bin/sh' \ |
| 302 | 'printf "%s %s %s\n" "$(pwd -P)" "$(git config --show-origin --get valley.principal | cut -f1)" "${GIT_CONFIG_COUNT:-none}" >> "$PAGER_LOG"' \ |
| 303 | 'exec cat' > "$w/pager.sh" |
| 304 | chmod +x "$w/pager.sh" |
| 305 | git config --global pager.diff "$w/pager.sh" |
| 306 | printf 'a\nr\nyes\n' > "$w/answers" |
| 307 | status=0 |
| 308 | { |
| 309 | wait_for "$w/session.log" 'nothing needs you|still needs you' |
| 310 | } | PAGER_LOG="$w/pager.log" LESS=-FX timeout 300 \ |
| 311 | script -qec "stty rows 200 cols 200; valley review < $w/answers" /dev/null > "$w/session.log" 2>&1 || status=$? |
| 312 | sed -e 's/\x1b\[[0-9;?]*[a-zA-Z]//g' -e 's/\r//g' "$w/session.log" > "$w/out" |
| 313 | git config --global --unset pager.diff |
| 314 | [ "$status" = 0 ] || fail "the walk from one answers file exited $status" |
| 315 | line '^ ✓ guarded kvkv v1 approved$' |
| 316 | line '^ ✓ open pqpq v1 rejected · branch deleted$' |
| 317 | [ "$(git -C "$data/guarded.git" rev-parse "refs/the-valley/integration-requests/main/c-$G3")" = \ |
| 318 | "$(git -C "$w/guarded" rev-parse v-one)" ] || fail "the approval in the clone filed no request at kvkv's head" |
| 319 | if git -C "$data/open.git" rev-parse --verify --quiet refs/heads/q-one > /dev/null; then |
| 320 | fail "the rejection left q-one on origin" |
| 321 | fi |
| 322 | printf '%s command line: 3\n%s file:.git/config none\n' "$(cd "$clone" && pwd -P)" "$(pwd -P)" > "$w/pager.want" |
| 323 | cmp -s "$w/pager.log" "$w/pager.want" || fail "the steps' pagers ran as $(cat "$w/pager.log")" |
| 324 | |
| 325 | # ---------------------------------------------------------------------- |
| 326 | # A step that fails does not end the walk. While the first step's prompt |
| 327 | # waits, the second step's branch is moved on guarded's origin and a stale |
| 328 | # lock is left on the cache clone's remote-tracking ref for it. The step |
| 329 | # passes the walk's valley check, and its review's fetch, the first thing |
| 330 | # the review does, cannot update the ref and fails. The step ends in error |
| 331 | # with git's message, and the third is reviewed. |
| 332 | branch x-one main x-one |
| 333 | ready "$O3" x-one |
| 334 | cd "$w/guarded" |
| 335 | git checkout --quiet main |
| 336 | branch x-two main x-two |
| 337 | ready "$G4" x-two |
| 338 | cd "$w/open" |
| 339 | branch z-one main z-one |
| 340 | ready "$O4" z-one |
| 341 | git checkout --quiet main |
| 342 | rm -f "$w/fifo" |
| 343 | mkfifo "$w/fifo" |
| 344 | valley review < "$w/fifo" > "$w/walk.out" 2> "$w/walk.err" & |
| 345 | walker=$! |
| 346 | exec 3> "$w/fifo" |
| 347 | wait_for "$w/walk.out" '\[s\]kip' |
| 348 | git -C "$data/guarded.git" update-ref refs/heads/x-two refs/heads/main |
| 349 | mkdir -p "$clone/.git/refs/remotes/origin" |
| 350 | touch "$clone/.git/refs/remotes/origin/x-two.lock" |
| 351 | printf 's\ns\n' >&3 |
| 352 | exec 3>&- |
| 353 | status=0 |
| 354 | wait "$walker" || status=$? |
| 355 | rm -f "$clone/.git/refs/remotes/origin/x-two.lock" |
| 356 | mv "$w/walk.out" "$w/out" |
| 357 | mv "$w/walk.err" "$w/err" |
| 358 | [ "$status" = 1 ] || fail "the walk with a failing step exited $status, not 1" |
| 359 | before '^\[2/3\] guarded · kxkx v1' '^\[3/3\] open · pzpz v1' |
| 360 | line '^ ◇ open pxpx v1 skipped$' |
| 361 | line '^ ✗ guarded kxkx v1 error' |
| 362 | no_line 'could not read which valley' |
| 363 | grep -q 'fetching ref refs/remotes/origin/x-two failed' "$w/err" || fail "the walk's stderr does not carry the review's fetch failure: $(cat "$w/err")" |
| 364 | line '^ ◇ open pzpz v1 skipped$' |
| 365 | |
| 366 | # ---------------------------------------------------------------------- |
| 367 | # SIGTERM sent to the walk alone while a step's prompt waits ends the step |
| 368 | # interrupted, and the walk as Ctrl-C does: the summary so far, exit 130, |
| 369 | # and nothing of its own left in its TMPDIR. |
| 370 | mkdir "$w/term-tmp" |
| 371 | rm -f "$w/fifo" |
| 372 | mkfifo "$w/fifo" |
| 373 | TMPDIR="$w/term-tmp" valley review --repo open < "$w/fifo" > "$w/walk.out" 2> "$w/walk.err" & |
| 374 | walker=$! |
| 375 | exec 3> "$w/fifo" |
| 376 | wait_for "$w/walk.out" '\[s\]kip' |
| 377 | kill -TERM "$walker" |
| 378 | status=0 |
| 379 | wait "$walker" || status=$? |
| 380 | exec 3>&- |
| 381 | mv "$w/walk.out" "$w/out" |
| 382 | mv "$w/walk.err" "$w/err" |
| 383 | [ "$status" = 130 ] || fail "the walk sent SIGTERM exited $status, not 130" |
| 384 | line '^walked \(1 of 2\)$' |
| 385 | line '^ ◇ open pxpx v1 interrupted$' |
| 386 | no_line 'still needs you|nothing needs you' |
| 387 | [ -z "$(ls -A "$w/term-tmp")" ] || fail "the walk left $(ls -A "$w/term-tmp") in its TMPDIR" |
| 388 | |
| 389 | # ---------------------------------------------------------------------- |
| 390 | # Ctrl-C while less pages a step's diff, on a terminal: less takes it and |
| 391 | # quits (-K), and once it has, the step ends interrupted, the summary so |
| 392 | # far is printed, the walk exits 130, and nothing of its own is left in |
| 393 | # its TMPDIR. |
| 394 | mkdir "$w/pager-tmp" |
| 395 | status=0 |
| 396 | { |
| 397 | wait_for "$w/session.log" '\(END\)' |
| 398 | printf '\003' |
| 399 | wait_for "$w/session.log" 'walked' |
| 400 | } | TMPDIR="$w/pager-tmp" LESS=-K timeout 300 script -qec "valley review --repo open" /dev/null > "$w/session.log" 2>&1 || status=$? |
| 401 | sed -e 's/\x1b\[[0-9;?]*[a-zA-Z]//g' -e 's/\r//g' "$w/session.log" > "$w/out" |
| 402 | [ "$status" = 130 ] || fail "the walk interrupted in its pager exited $status, not 130" |
| 403 | line '^walked \(1 of 2\)$' |
| 404 | line '^ ◇ open pxpx v1 interrupted$' |
| 405 | no_line '\]kip: ' |
| 406 | [ -z "$(ls -A "$w/pager-tmp")" ] || fail "the walk left $(ls -A "$w/pager-tmp") in its TMPDIR" |
| 407 | |
| 408 | # ---------------------------------------------------------------------- |
| 409 | # Ctrl-C during a step's approval checks, sent to the walk's process group |
| 410 | # as a terminal sends it: the checks stop, the step ends interrupted, the |
| 411 | # walk exits 130, and nothing is left behind: no worktree, nothing in its |
| 412 | # TMPDIR, no request. open's policy gates held/ on a check that holds until |
| 413 | # it is stopped. |
| 414 | ssh-keygen -q -t ed25519 -N "" -C valley-walk -f "$w/attest-key" |
| 415 | mkdir -p policy/project |
| 416 | printf '%s\n' 'package verification' '' 'project: {' ' checks: hold: {' ' runner: "command"' \ |
| 417 | " command: \"echo started > $w/held && sleep 600\"" ' }' ' classes: held: {' \ |
| 418 | ' paths: "held/**": true' ' requires: hold: true' ' }' '}' > policy/project/policy.cue |
| 419 | git add policy/project/policy.cue |
| 420 | git commit --quiet -m "a check that holds until it is stopped" |
| 421 | VALLEY_PRINCIPAL=integrator git push --quiet origin main |
| 422 | git checkout --quiet -b w-held main |
| 423 | mkdir held |
| 424 | echo held > held/readme.md |
| 425 | git add held |
| 426 | git commit --quiet -m "a change the held check gates" |
| 427 | git push --quiet origin w-held |
| 428 | ready "$O5" w-held |
| 429 | git checkout --quiet main |
| 430 | printf 's\ns\na\n' > "$w/answers" |
| 431 | mkdir "$w/held-tmp" |
| 432 | TMPDIR="$w/held-tmp" VALLEY_ATTEST_KEY="$w/attest-key" setsid valley review --repo open < "$w/answers" > "$w/out" 2> "$w/err" & |
| 433 | walker=$! |
| 434 | wait_for "$w/held" started |
| 435 | kill -INT -- "-$walker" |
| 436 | status=0 |
| 437 | wait "$walker" || status=$? |
| 438 | [ "$status" = 130 ] || fail "the walk interrupted in its checks exited $status, not 130" |
| 439 | line '^walked \(3 of 3\)$' |
| 440 | line '^ ◇ open pwpw v1 interrupted$' |
| 441 | [ -z "$(ls -A "$w/held-tmp")" ] || fail "the walk left $(ls -A "$w/held-tmp") in its TMPDIR" |
| 442 | [ "$(git worktree list --porcelain | grep -c '^worktree ')" = 1 ] || fail "the checks' worktree outlived the walk" |
| 443 | if git -C "$data/open.git" rev-parse --verify --quiet "refs/the-valley/integration-requests/main/c-$O5" > /dev/null; then |
| 444 | fail "an approval interrupted during its checks filed a request" |
| 445 | fi |
| 446 | |
| 447 | touch "$out" |