gunk-dev/the-valley

review-notes.sh

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