| 1 | # shellcheck shell=bash |
| 2 | # Paths and fixtures come from the derivation environment. |
| 3 | # shellcheck disable=SC2154 |
| 4 | export HOME="$TMPDIR" XDG_STATE_HOME="$TMPDIR/state" TERM=xterm |
| 5 | export GIT_CONFIG_NOSYSTEM=1 |
| 6 | unset VISUAL || true |
| 7 | git config --global user.name valley-check |
| 8 | git config --global user.email valley-check@localhost |
| 9 | git config --global init.defaultBranch main |
| 10 | |
| 11 | # A project with an origin and one branch to review: two |
| 12 | # files, changed twice and once, far enough apart that the |
| 13 | # diff has two hunks in the first file and one in the second. |
| 14 | git init --quiet --bare "$TMPDIR/origin.git" |
| 15 | git init --quiet "$TMPDIR/work" |
| 16 | cd "$TMPDIR/work" || exit 1 |
| 17 | git remote add origin "$TMPDIR/origin.git" |
| 18 | seq 1 20 | sed 's/^/alpha /' > alpha.md |
| 19 | seq 1 10 | sed 's/^/beta /' > beta.md |
| 20 | git add -A |
| 21 | git commit --quiet -m seed |
| 22 | git push --quiet -u origin main |
| 23 | git checkout --quiet -b scratch |
| 24 | sed -i -e '3s/.*/alpha 3 changed/' -e '15s/.*/alpha 15 changed/' alpha.md |
| 25 | sed -i -e '5s/.*/beta 5 changed/' beta.md |
| 26 | git commit --quiet -am "touch both files" |
| 27 | git push --quiet origin scratch |
| 28 | git checkout --quiet main |
| 29 | git fetch --quiet origin |
| 30 | |
| 31 | # A pager filter that restructures the diff, as delta's |
| 32 | # rendering does: if v were handed what less displays, every |
| 33 | # anchor below would be wrong. |
| 34 | git config --global pager.diff "sed -e 's/^/| /'" |
| 35 | export EDITOR="$reviewer" |
| 36 | mkdir -p "$XDG_STATE_HOME" |
| 37 | |
| 38 | # wait_for <log> <pattern>: wait until <log> shows <pattern>, and fail |
| 39 | # after a minute. A review reads every key from the one terminal, so a |
| 40 | # verdict typed before the prompt that takes it would go to whatever held |
| 41 | # the terminal then, such as less. Each log waited on here is written by |
| 42 | # one review only, so no earlier review's output can match. |
| 43 | wait_for() { |
| 44 | local i=0 |
| 45 | until grep -q -- "$2" "$1" 2> /dev/null; do |
| 46 | if [ "$i" -ge 600 ]; then |
| 47 | printf 'review-notes: %s never showed %s\n' "$1" "$2" >&2 |
| 48 | return 1 |
| 49 | fi |
| 50 | sleep 0.1 |
| 51 | i=$((i + 1)) |
| 52 | done |
| 53 | } |
| 54 | |
| 55 | # answer_after <log> <prompt> <command> <answers>: wait until the review |
| 56 | # writing to <log> has asked <prompt>, run <command>, then answer. A page |
| 57 | # is shown before its prompt, so the command runs after the page is shown |
| 58 | # and before the answer. |
| 59 | answer_after() { |
| 60 | wait_for "$1" "$2" |
| 61 | eval "$3" |
| 62 | printf '%b' "$4" |
| 63 | } |
| 64 | |
| 65 | # v alone opens the editor, and the pager shows the notes, |
| 66 | # rendered, once it returns; q then leaves the pager, and s is |
| 67 | # the verdict. The verdict waits for its prompt, and the keys |
| 68 | # stay open until the notes are printed. A wait that fails |
| 69 | # still sends q, so the check fails rather than hang in less. |
| 70 | # shellcheck disable=SC2094 # the answers wait on the review's own output |
| 71 | { |
| 72 | printf v |
| 73 | if ! wait_for "$XDG_STATE_HOME/editor.log" 'editor got: ' \ |
| 74 | || ! wait_for session.log '| a note above every file'; then |
| 75 | printf q |
| 76 | exit 1 |
| 77 | fi |
| 78 | printf q |
| 79 | answer_after session.log '\]kip: ' : 's\n' |
| 80 | wait_for session.log '5 note(s) on scratch' |
| 81 | } | script -qec "valley review scratch" /dev/null > session.log 2>&1 |
| 82 | sed -e 's/\x1b\[[0-9;?]*[a-zA-Z]//g' -e 's/\r//g' session.log > plain.log |
| 83 | |
| 84 | # The anchors, exactly: above every file, on a file header |
| 85 | # above the first hunk, mid-hunk, in a second hunk whose |
| 86 | # numbering starts elsewhere, and in a second file. |
| 87 | diff -u - "$XDG_STATE_HOME/valley/notes/scratch.md" <<EOF |
| 88 | ## scratch at $(git rev-parse --short origin/scratch) |
| 89 | |
| 90 | (unanchored): a note above every file |
| 91 | alpha.md: alpha reads like two files |
| 92 | alpha.md:3: why is 3 changed at all? |
| 93 | alpha.md:13: and this hunk is fine |
| 94 | beta.md:5: beta wants the same treatment |
| 95 | |
| 96 | EOF |
| 97 | |
| 98 | # The editor was given the buffer valley wrote, not the |
| 99 | # rendering less displayed, and given a line to open at. |
| 100 | grep -qE 'editor got: \+[0-9]+ .*/review\.diff$' \ |
| 101 | "$XDG_STATE_HOME/editor.log" |
| 102 | # The filter did run: what the pager showed was its output. |
| 103 | # less showed no warning before editing the file it paged. |
| 104 | grep -q '^| @@ ' plain.log |
| 105 | if grep -q 'WARNING' plain.log; then exit 1; fi |
| 106 | |
| 107 | # q alone leaves the pager, and the editor never runs. |
| 108 | rm "$XDG_STATE_HOME/editor.log" |
| 109 | # shellcheck disable=SC2094 # the answers wait on the review's own output |
| 110 | { |
| 111 | printf q |
| 112 | answer_after quit.log '\]kip: ' : 's\n' |
| 113 | wait_for quit.log 'skipped scratch; nothing done' |
| 114 | } | script -qec "valley review scratch" /dev/null > quit.log 2>&1 |
| 115 | [ ! -e "$XDG_STATE_HOME/editor.log" ] |
| 116 | if grep -q 'note(s) on scratch' quit.log; then exit 1; fi |
| 117 | # The line the reviewer edited instead of inserting is gone, |
| 118 | # and said so. |
| 119 | grep -q 'changed or deleted diff line(s) ignored' plain.log |
| 120 | if grep -q 'alpha SEVENTEEN' "$XDG_STATE_HOME/valley/notes/scratch.md"; then exit 1; fi |
| 121 | |
| 122 | # The verdict is unchanged, and the notes come after it. |
| 123 | grep -q 'skipped scratch; nothing done' plain.log |
| 124 | verdict="$(grep -n 'skipped scratch' plain.log | cut -d: -f1)" |
| 125 | notes="$(grep -n '5 note(s) on scratch' plain.log | cut -d: -f1)" |
| 126 | [ "$verdict" -lt "$notes" ] |
| 127 | |
| 128 | # Piped, review is what it always was: the diff on stdout, |
| 129 | # the verdict from stdin, and no notes to take. |
| 130 | printf 's\n' | valley review scratch > piped.log |
| 131 | grep -q '^diff --git a/alpha.md b/alpha.md$' piped.log |
| 132 | grep -q 'skipped scratch; nothing done' piped.log |
| 133 | if grep -q 'note(s) on scratch' piped.log; then exit 1; fi |
| 134 | |
| 135 | # The pending list of branches titles each by the subject of its first |
| 136 | # own commit, on the line under its name, and cuts a long one short with … |
| 137 | # to fit 80 columns when stdout is no terminal. Nothing it prints there is |
| 138 | # an escape code. |
| 139 | valley pending --branches > pending.log |
| 140 | grep -A1 '^scratch ' pending.log | grep -q '^ touch both files$' |
| 141 | git checkout --quiet -b longsubject origin/main |
| 142 | git commit --quiet --allow-empty -m "$(printf 'x%.0s' $(seq 1 80))" |
| 143 | git push --quiet origin longsubject |
| 144 | git checkout --quiet main |
| 145 | valley pending --branches > pending.log |
| 146 | grep -A1 '^longsubject ' pending.log | grep -qE '^ x{77}…$' |
| 147 | if grep -q $'\x1b' pending.log; then exit 1; fi |
| 148 | |
| 149 | # On a terminal, pending fits the terminal's width and sets each name in |
| 150 | # bold. With NO_COLOR set, it prints no escape code. |
| 151 | script -qec "stty cols 100; valley pending --branches" /dev/null < /dev/null > tty.log 2>&1 |
| 152 | grep -q $'^\x1b\\[1mlongsubject\x1b\\[0m ' tty.log |
| 153 | grep -qE $'^ x{80}\r?$' tty.log |
| 154 | NO_COLOR=1 script -qec "stty cols 100; valley pending --branches" /dev/null < /dev/null > tty.log 2>&1 |
| 155 | grep -q '^longsubject ' tty.log |
| 156 | if grep -q $'\x1b' tty.log; then exit 1; fi |
| 157 | |
| 158 | # ---------------------------------------------------------------------- |
| 159 | # A stack: a branch, then two changes with records, each on the one |
| 160 | # below, in a project whose floor requires nothing, so approving files a |
| 161 | # request with no evidence. Its origin logs every push it receives, which |
| 162 | # is how "publishes nothing" is read. |
| 163 | stack="$TMPDIR/stack.git" |
| 164 | pushlog="$TMPDIR/pushlog" |
| 165 | git init --quiet --bare "$stack" |
| 166 | cat > "$stack/hooks/pre-receive" << EOF |
| 167 | #!/bin/sh |
| 168 | echo '--- push' >> $pushlog |
| 169 | cat >> $pushlog |
| 170 | EOF |
| 171 | chmod +x "$stack/hooks/pre-receive" |
| 172 | git init --quiet "$TMPDIR/stackwork" |
| 173 | cd "$TMPDIR/stackwork" || exit 1 |
| 174 | git remote add origin "$stack" |
| 175 | git config valley.principal operator |
| 176 | mkdir -p policy/instance |
| 177 | cat > policy/instance/floor.cue << 'EOF' |
| 178 | package verification |
| 179 | |
| 180 | floor: { |
| 181 | classes: everything: { |
| 182 | paths: "**": true |
| 183 | requires: {} |
| 184 | } |
| 185 | unclassified: {} |
| 186 | } |
| 187 | EOF |
| 188 | git add -A |
| 189 | git commit --quiet -m seed |
| 190 | git push --quiet -u origin main |
| 191 | from=main |
| 192 | for layer in one two three; do |
| 193 | git checkout --quiet -b "$layer" "$from" |
| 194 | echo "layer $layer" > "$layer.md" |
| 195 | git add -A |
| 196 | git commit --quiet -m "layer $layer" |
| 197 | git push --quiet origin "$layer" |
| 198 | from="$layer" |
| 199 | done |
| 200 | two="$(git rev-parse two)" three="$(git rev-parse three)" |
| 201 | q=qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq p=pppppppppppppppppppppppppppppppp |
| 202 | valley ready --change "$q" two > /dev/null |
| 203 | valley ready --change "$p" three > /dev/null |
| 204 | git checkout --quiet main |
| 205 | requests="refs/the-valley/integration-requests/main" |
| 206 | |
| 207 | # s at the first layer, on a terminal, with a note written in its diff: |
| 208 | # the note is kept under the first layer's branch and printed at the end, |
| 209 | # and nothing is published. |
| 210 | cat > "$TMPDIR/stack-editor" << 'EOF' |
| 211 | #!/bin/sh |
| 212 | f="$1" |
| 213 | case "$1" in +*) f="$2" ;; esac |
| 214 | sed -i '/^+layer one$/a one wants a second line' "$f" |
| 215 | EOF |
| 216 | chmod +x "$TMPDIR/stack-editor" |
| 217 | : > "$pushlog" |
| 218 | # shellcheck disable=SC2094 # the answers wait on the review's own output |
| 219 | { |
| 220 | printf vq |
| 221 | answer_after stack-tty.log 'one, 1 of 3: \[n\]ext layer, .*\[s\]top? ' : 's\n' |
| 222 | wait_for stack-tty.log '1 note(s) on one' |
| 223 | } | EDITOR="$TMPDIR/stack-editor" script -qec "valley review pppp" /dev/null > stack-tty.log 2>&1 |
| 224 | sed -e 's/\x1b\[[0-9;?]*[a-zA-Z]//g' -e 's/\r//g' stack-tty.log > stack-plain.log |
| 225 | grep -q 'pppp is a stack of 3 changes; reviewing from the bottom, each against the one below it:$' stack-plain.log |
| 226 | grep -qxF 'read each layer and go on with [n]; approving pppp at the top lands all 3. [a] on a lower layer lands it and the layers under it, and ends the review.' stack-plain.log |
| 227 | grep -q '| change 1 of 3: one on main$' stack-plain.log |
| 228 | grep -qF 'one, 1 of 3: [n]ext layer, [a]pprove one alone, [v]iew full diff, [s]top? ' stack-plain.log |
| 229 | grep -q 'stopped reviewing pppp at change 1 of 3, one; nothing done' stack-plain.log |
| 230 | if grep -q 'change 2 of 3' stack-plain.log; then exit 1; fi |
| 231 | grep -qx 'one.md:1: one wants a second line' "$XDG_STATE_HOME/valley/notes/one.md" |
| 232 | grep -q '1 note(s) on one, appended to .*/valley/notes/one.md:' stack-plain.log |
| 233 | grep -q '^ one.md:1: one wants a second line$' stack-plain.log |
| 234 | [ ! -e "$XDG_STATE_HOME/valley/notes/two.md" ] |
| 235 | [ ! -s "$pushlog" ] |
| 236 | |
| 237 | # n, n, a: the layers are paged bottom up, each diff holds only its own |
| 238 | # layer's file, and the top's request is filed at the top's head. Each |
| 239 | # prompt names its layer and place, and what approving there lands. |
| 240 | : > "$pushlog" |
| 241 | printf 'n\nn\na\n' | valley review pppp > stack.out 2> stack.err |
| 242 | grep -q '^ 1\. one (branch): layer one$' stack.out |
| 243 | grep -q '^ 2\. qqqq (ready): layer two$' stack.out |
| 244 | grep -q '^ 3\. pppp (ready): layer three$' stack.out |
| 245 | grep -qxF 'read each layer and go on with [n]; approving pppp at the top lands all 3. [a] on a lower layer lands it and the layers under it, and ends the review.' stack.out |
| 246 | grep -qF 'one, 1 of 3: [n]ext layer, [a]pprove one alone, [v]iew full diff, [s]top? ' stack.out |
| 247 | grep -qF 'qqqq, 2 of 3: [n]ext layer, [a]pprove one and qqqq, [v]iew full diff, [s]top? ' stack.out |
| 248 | grep -qF '[a]pprove all 3 [v]iew diff [r]eject pppp [s]top: ' stack.out |
| 249 | # Piped, each page's first line follows the prompt before it. |
| 250 | [ "$(grep -o 'change [0-9] of 3: [a-z]* on [a-z]*$' stack.out)" = "$(printf '%s\n' \ |
| 251 | 'change 1 of 3: one on main' 'change 2 of 3: qqqq on one' 'change 3 of 3: pppp on qqqq')" ] |
| 252 | for n in 1 2 3; do |
| 253 | awk -v n="$n" '/change [0-9] of 3: /{ on = index($0, "change " n " of 3: ") > 0 } on' stack.out > "page$n" |
| 254 | done |
| 255 | [ "$(grep '^diff --git' page1)" = 'diff --git a/one.md b/one.md' ] |
| 256 | [ "$(grep '^diff --git' page2)" = 'diff --git a/two.md b/two.md' ] |
| 257 | [ "$(grep '^diff --git' page3)" = 'diff --git a/three.md b/three.md' ] |
| 258 | [ "$(git -C "$stack" rev-parse "$requests/c-$p")" = "$three" ] |
| 259 | if git -C "$stack" rev-parse --verify --quiet "$requests/c-$q" > /dev/null; then exit 1; fi |
| 260 | git -C "$stack" update-ref -d "$requests/c-$p" |
| 261 | |
| 262 | # a at the second layer files the second layer's request at its head, and |
| 263 | # nothing for the top, whose review never starts: neither its page nor its |
| 264 | # prompt is shown. |
| 265 | : > "$pushlog" |
| 266 | printf 'n\na\n' | valley review pppp > stack-two.out 2> stack-two.err |
| 267 | grep -qF 'qqqq, 2 of 3: [n]ext layer, [a]pprove one and qqqq, [v]iew full diff, [s]top? ' stack-two.out |
| 268 | [ "$(git -C "$stack" rev-parse "$requests/c-$q")" = "$two" ] |
| 269 | if git -C "$stack" rev-parse --verify --quiet "$requests/c-$p" > /dev/null; then exit 1; fi |
| 270 | grep -q "c-$q" "$pushlog" |
| 271 | if grep -q "c-$p" "$pushlog"; then exit 1; fi |
| 272 | if grep -q 'change 3 of 3' stack-two.out; then exit 1; fi |
| 273 | if grep -q '3 of 3: ' stack-two.out; then exit 1; fi |
| 274 | |
| 275 | # A draft in the middle is named in the warning before anything is paged. |
| 276 | # It is readied again after, since review offers no [a]pprove at or above |
| 277 | # a draft, and the stacks below approve above it. |
| 278 | valley unready qqqq > /dev/null 2>&1 |
| 279 | printf 's\n' | valley review pppp > stack-draft.out 2>&1 |
| 280 | grep -q '^warning: qqqq, change 2 of 3, is a draft\. The integrator refuses to land it or anything above it (refused-not-ready)\.$' stack-draft.out |
| 281 | valley ready --change "$q" two > /dev/null |
| 282 | |
| 283 | # A change with no stack under it pages and prompts as it always has. |
| 284 | printf 's\n' | valley review one > stack-one.out 2>&1 |
| 285 | grep -q '^branch one, log against origin/main:$' stack-one.out |
| 286 | grep -q '^\[a\]pprove \[v\]iew diff \[r\]eject \[s\]kip: skipped one; nothing done$' stack-one.out |
| 287 | if grep -q 'stack of\|change 1 of' stack-one.out; then exit 1; fi |
| 288 | |
| 289 | seed="$(git rev-parse main)" onehead="$(git rev-parse one)" |
| 290 | |
| 291 | # [a]pprove at the bottom, on a plain branch under the top, files that |
| 292 | # branch's head under its own request name, and nothing for the top. |
| 293 | : > "$pushlog" |
| 294 | printf 'a\n' | valley review pppp > stack-a-one.out 2>&1 |
| 295 | [ "$(git -C "$stack" rev-parse "$requests/one")" = "$onehead" ] |
| 296 | grep -q "$requests/one" "$pushlog" |
| 297 | if grep -q "c-$p" "$pushlog"; then exit 1; fi |
| 298 | |
| 299 | # Once a page is shown, the head approved is the head shown. When the |
| 300 | # branch moves on origin, and is fetched, after the page is shown and |
| 301 | # before the answer, approving refuses, names both heads, and publishes |
| 302 | # nothing: for a plain branch under the top, for a plain branch at the top |
| 303 | # of a stack, and for a plain branch alone. The request each would file is |
| 304 | # absent first, so a filing would push. |
| 305 | git -C "$stack" update-ref -d "$requests/one" |
| 306 | : > "$pushlog" |
| 307 | # shellcheck disable=SC2094 # the answers wait on the review's own output |
| 308 | answer_after moved-one.out 'one, 1 of 3: \[n\]ext' "git -C '$stack' update-ref refs/heads/one $seed; git fetch -q origin" 'a\ns\n' \ |
| 309 | | valley review pppp > moved-one.out 2>&1 |
| 310 | grep -q "not approved · origin/one moved from ${onehead:0:7}[0-9a-f]*, the head shown, to ${seed:0:7}" moved-one.out |
| 311 | [ ! -s "$pushlog" ] |
| 312 | if git -C "$stack" rev-parse --verify --quiet "$requests/one" > /dev/null; then exit 1; fi |
| 313 | git -C "$stack" update-ref refs/heads/one "$onehead" |
| 314 | git fetch -q origin |
| 315 | |
| 316 | git checkout --quiet -b four three |
| 317 | echo "layer four" > four.md |
| 318 | git add four.md |
| 319 | git commit --quiet -m "layer four" |
| 320 | git push --quiet origin four |
| 321 | fourhead="$(git rev-parse four)" |
| 322 | git checkout --quiet -b solo main |
| 323 | echo "solo" > solo.md |
| 324 | git add solo.md |
| 325 | git commit --quiet -m "solo" |
| 326 | git push --quiet origin solo |
| 327 | solohead="$(git rev-parse solo)" |
| 328 | git checkout --quiet main |
| 329 | |
| 330 | : > "$pushlog" |
| 331 | # shellcheck disable=SC2094 # the answers wait on the review's own output |
| 332 | { |
| 333 | printf 'n\nn\nn\n' |
| 334 | answer_after moved-four.out '\[a\]pprove all 4 \[v\]iew diff \[r\]eject four \[s\]top:' "git -C '$stack' update-ref refs/heads/four $seed; git fetch -q origin" 'a\ns\n' |
| 335 | } | valley review four > moved-four.out 2>&1 |
| 336 | grep -q '^four is a stack of 4 changes' moved-four.out |
| 337 | # From the third layer up, a lower layer's prompt counts what approving |
| 338 | # there lands. The top's prompt names the top, and says approving it |
| 339 | # lands all 4. |
| 340 | grep -qF 'pppp, 3 of 4: [n]ext layer, [a]pprove the 3 up to pppp, [v]iew full diff, [s]top? ' moved-four.out |
| 341 | grep -qF '[a]pprove all 4 [v]iew diff [r]eject four [s]top: ' moved-four.out |
| 342 | grep -q "not approved · origin/four moved from ${fourhead:0:7}[0-9a-f]*, the head shown, to ${seed:0:7}" moved-four.out |
| 343 | grep -q 'stopped reviewing four at change 4 of 4; nothing done' moved-four.out |
| 344 | [ ! -s "$pushlog" ] |
| 345 | if git -C "$stack" rev-parse --verify --quiet "$requests/four" > /dev/null; then exit 1; fi |
| 346 | |
| 347 | : > "$pushlog" |
| 348 | # shellcheck disable=SC2094 # the answers wait on the review's own output |
| 349 | answer_after moved-solo.out '^\[a\]pprove \[v\]iew diff' "git -C '$stack' update-ref refs/heads/solo $seed; git fetch -q origin" 'a\ns\n' \ |
| 350 | | valley review solo > moved-solo.out 2>&1 |
| 351 | grep -q '^branch solo, log against origin/main:$' moved-solo.out |
| 352 | grep -q "not approved · origin/solo moved from ${solohead:0:7}[0-9a-f]*, the head shown, to ${seed:0:7}" moved-solo.out |
| 353 | [ ! -s "$pushlog" ] |
| 354 | if git -C "$stack" rev-parse --verify --quiet "$requests/solo" > /dev/null; then exit 1; fi |
| 355 | |
| 356 | # ---------------------------------------------------------------------- |
| 357 | # A stack whose bottom does not fast-forward from main. The top gains a |
| 358 | # second version, and main moves on under the stack. |
| 359 | git checkout --quiet three |
| 360 | echo "layer three, again" >> three.md |
| 361 | git commit --quiet -am "layer three again" |
| 362 | git push --quiet origin three |
| 363 | threeagain="$(git rev-parse three)" |
| 364 | valley ready --change "$p" three > /dev/null |
| 365 | git checkout --quiet main |
| 366 | echo "main moves on" > moved.md |
| 367 | git add moved.md |
| 368 | git commit --quiet -m "main moves on" |
| 369 | git push --quiet origin main |
| 370 | |
| 371 | # Approving the top is refused before any check runs, at its active head |
| 372 | # and at an earlier version's head, and the refusal names the rebase that |
| 373 | # fixes it. Nothing is published. |
| 374 | : > "$pushlog" |
| 375 | for head in "$threeagain" "$three"; do |
| 376 | if valley approve --head "$head" pppp > stale-approve.out 2>&1; then exit 1; fi |
| 377 | grep -qF 'not approved · stack is behind main (includes qqqq)' stale-approve.out |
| 378 | grep -qx ' run: valley rebase pppp' stale-approve.out |
| 379 | if grep -q 'requires no check' stale-approve.out; then exit 1; fi |
| 380 | done |
| 381 | [ ! -s "$pushlog" ] |
| 382 | # The bottom layer has no change under it, so it is approved as it is. |
| 383 | valley approve one > stale-bottom.out 2>&1 |
| 384 | grep -qx '✓ one approved · no checks required · landing on main' stale-bottom.out |
| 385 | [ "$(git -C "$stack" rev-parse "$requests/one")" = "$onehead" ] |
| 386 | git -C "$stack" update-ref -d "$requests/one" |
| 387 | |
| 388 | # review asks, before any layer is paged, whether to rebase the stack. |
| 389 | # [s]top ends it there, and nothing is done. |
| 390 | : > "$pushlog" |
| 391 | printf 's\n' | valley review pppp > stale-stop.out 2>&1 |
| 392 | grep -qxF 'pppp · stack of 3 · behind main' stale-stop.out |
| 393 | grep -qF '[b]ase onto main [v]iew diff [s]kip: stopped reviewing pppp before its first layer; nothing done' stale-stop.out |
| 394 | if grep -q 'change 1 of 3' stale-stop.out; then exit 1; fi |
| 395 | [ ! -s "$pushlog" ] |
| 396 | |
| 397 | # [b]ase rebases the whole stack. The review then lists the stack again |
| 398 | # and pages the rebased layers, and [a]pprove at the top files the |
| 399 | # request at the top's rebased head. |
| 400 | printf 'b\nn\nn\na\n' | valley review pppp > stale-review.out 2>&1 |
| 401 | grep -qF '[b]ase onto main [v]iew diff [s]kip: ' stale-review.out |
| 402 | grep -qF 'the stack under pppp, bottom first:' stale-review.out |
| 403 | git fetch --quiet origin |
| 404 | newone="$(git rev-parse origin/one)" newthree="$(git rev-parse origin/three)" |
| 405 | [ "$newone" != "$onehead" ] |
| 406 | git merge-base --is-ancestor origin/main "$newone" |
| 407 | awk '/change 1 of 3: /{ on = 1 } /change 2 of 3: /{ on = 0 } on' stale-review.out > stale-page1 |
| 408 | grep -q "^$(git rev-parse --short "$newone") layer one$" stale-page1 |
| 409 | if grep -q "$(git rev-parse --short "$onehead")" stale-page1; then exit 1; fi |
| 410 | grep -qF '[a]pprove all 3 [v]iew diff [r]eject pppp [s]top: ' stale-review.out |
| 411 | [ "$(git -C "$stack" rev-parse "$requests/c-$p")" = "$newthree" ] |
| 412 | # qqqq's v1 was approved earlier, and the rebase gave it v2 with the same |
| 413 | # file delta, so its layer is printed as a clean restack of v1, and not |
| 414 | # paged. pppp has no approved version, so its layer is paged in full. |
| 415 | grep -qx "qqqq v2 at [0-9a-f]*: clean restack of approved v1 at $(git rev-parse --short "$two")\." stale-review.out |
| 416 | awk '/change 2 of 3: /{ on = 1 } /change 3 of 3: /{ on = 0 } on' stale-review.out > stale-page2 |
| 417 | if grep -q '^diff --git' stale-page2; then exit 1; fi |
| 418 | awk '/change 3 of 3: /{ on = 1 } on' stale-review.out > stale-page3 |
| 419 | [ "$(grep '^diff --git' stale-page3)" = 'diff --git a/three.md b/three.md' ] |
| 420 | |
| 421 | # ---------------------------------------------------------------------- |
| 422 | # A note taken on a changed comparison. v1 of a change is approved, and |
| 423 | # v2 edits line 9 of its file, so review pages v2 as changed since v1. |
| 424 | # range-diff's hunks carry no line numbers, so the page ends with v2's |
| 425 | # own diff of the file, and the note written beside the edited line there |
| 426 | # keeps its file and line. |
| 427 | git checkout --quiet -b edited main |
| 428 | seq 1 12 | sed 's/^/line /' > lines.md |
| 429 | git add lines.md |
| 430 | git commit --quiet -m "add the lines" |
| 431 | git push --quiet origin edited |
| 432 | m=mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm |
| 433 | valley ready --change "$m" edited > /dev/null |
| 434 | git -C "$stack" update-ref "$requests/c-$m" "$(git rev-parse edited)" |
| 435 | sed -i 's/^line 9$/line 9 edited/' lines.md |
| 436 | git commit --quiet -am "edit line 9" |
| 437 | git push --quiet origin edited |
| 438 | valley ready --change "$m" edited > /dev/null |
| 439 | git checkout --quiet main |
| 440 | cat > "$TMPDIR/changed-editor" << 'EOF' |
| 441 | #!/bin/sh |
| 442 | f="$1" |
| 443 | case "$1" in +*) f="$2" ;; esac |
| 444 | sed -i '/^+line 9 edited$/a why edit line 9?' "$f" |
| 445 | EOF |
| 446 | chmod +x "$TMPDIR/changed-editor" |
| 447 | # shellcheck disable=SC2094 # the answers wait on the review's own output |
| 448 | { |
| 449 | printf vq |
| 450 | answer_after changed-tty.log '\]kip: ' : 's\n' |
| 451 | wait_for changed-tty.log '1 note(s) on edited' |
| 452 | } | EDITOR="$TMPDIR/changed-editor" script -qec "valley review mmmm" /dev/null > changed-tty.log 2>&1 |
| 453 | sed -e 's/\x1b\[[0-9;?]*[a-zA-Z]//g' -e 's/\r//g' changed-tty.log > changed-plain.log |
| 454 | grep -q "| mmmm v2 at [0-9a-f]*: changed since approved v1 at " changed-plain.log |
| 455 | grep -qx 'lines.md:9: why edit line 9?' "$XDG_STATE_HOME/valley/notes/edited.md" |
| 456 | grep -q '^ lines.md:9: why edit line 9?$' changed-plain.log |
| 457 | |
| 458 | touch "$out" |