From 97a5222ab4b2327ecaa78fc6a91295f58d642141 Mon Sep 17 00:00:00 2001 From: david catalan Date: Thu, 26 Nov 2026 16:13:02 +0100 Subject: [PATCH 01/33] Pick how to show what changed since the last round --- lib/delta.sh | 139 ++++++++++++++++++++++++++++++ tests/delta.sh | 223 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 362 insertions(+) create mode 100644 lib/delta.sh create mode 100644 tests/delta.sh diff --git a/lib/delta.sh b/lib/delta.sh new file mode 100644 index 0000000..7fd4a48 --- /dev/null +++ b/lib/delta.sh @@ -0,0 +1,139 @@ +#!/usr/bin/env bash +# What changed since the last round: how to show it (pick_delta) and which files it touched (changed_files). +# Functions only. Git runs quietly in the review checkout: stdout carries the JSON or the paths, nothing else. + +# Prints `{mode, reason, commands, prev_head, prev_base, head, base}` as one compact JSON line. Modes: +# incremental the previous head is an ancestor of the head: `git diff --stat` and `git diff` from it. +# rebased the previous head is not an ancestor (rebase or force-push): a `git range-diff` of the two ranges. +# full anything else, with a short human reason. The round then reviews the whole PR. +# The four SHA fields are full SHAs when the checkout has the commit, else as given ("" when unknown); changed_files +# reads them. Never fails: every git error ends in `full`. +pick_delta() { # + local repo=$1 prev_head=$2 prev_base=$3 head=$4 base=$5 sha old new reason + if [[ -z "$prev_head" ]]; then + delta_json full "no previous round" "$prev_head" "$prev_base" "$head" "$base" + return 0 + fi + if sha=$(delta_resolve "$repo" "$head"); then head=$sha; else + delta_json full "head ${head:0:12} not in the checkout" "$prev_head" "$prev_base" "$head" "$base" + return 0 + fi + if sha=$(delta_find "$repo" "$prev_head"); then prev_head=$sha; else + delta_json full "previous head ${prev_head:0:12} not found after fetch" "$prev_head" "$prev_base" "$head" "$base" + return 0 + fi + delta_connect "$repo" "$prev_head" "$head" + + if git -C "$repo" merge-base --is-ancestor "$prev_head" "$head" >/dev/null 2>&1; then + reason="previous head is an ancestor of the head" + [[ "$prev_head" != "$head" ]] || reason="no new commits since the previous round" + delta_json incremental "$reason" "$prev_head" "$prev_base" "$head" "$base" \ + "git diff --stat ${prev_head}..${head}" "git diff ${prev_head}..${head}" + return 0 + fi + + # Rebase or force-push: a plain diff would mix in what the base branch did, so compare the two ranges instead. + if [[ -z "$prev_base" ]]; then + delta_json full "previous base unknown" "$prev_head" "$prev_base" "$head" "$base" + return 0 + fi + if sha=$(delta_find "$repo" "$prev_base"); then prev_base=$sha; else + delta_json full "previous base ${prev_base:0:12} not found after fetch" "$prev_head" "$prev_base" "$head" "$base" + return 0 + fi + if sha=$(delta_resolve "$repo" "$base"); then base=$sha; else + delta_json full "base ${base:0:12} not in the checkout" "$prev_head" "$prev_base" "$head" "$base" + return 0 + fi + old="${prev_base}..${prev_head}" + new="${base}..${head}" + # Try it before handing it to the reviewer: a range it cannot walk (shallow history, odd ranges) fails here. + if git -C "$repo" range-diff --no-color "$old" "$new" >/dev/null 2>&1; then + delta_json rebased "previous head is not an ancestor of the head (rebase or force-push)" \ + "$prev_head" "$prev_base" "$head" "$base" "git range-diff $old $new" + else + reason="range-diff failed on ${prev_base:0:12}..${prev_head:0:12} ${base:0:12}..${head:0:12}" + delta_json full "$reason" "$prev_head" "$prev_base" "$head" "$base" + fi + return 0 +} + +# Prints the paths the delta touched, one per line, sorted and unique: the code that counts as "touched". +# incremental the files changed between the previous head and the head. +# rebased the files whose change in the PR differs between the old and the new version (index lines and +# hunk line numbers ignored, so the base moving under an unchanged patch does not count), plus the +# files the PR newly touches or no longer touches. +# full nothing. +changed_files() { # + local repo=$1 mode prev_head prev_base head base path old new + { + IFS= read -r mode + IFS= read -r prev_head + IFS= read -r prev_base + IFS= read -r head + IFS= read -r base + } < <(jq -r '.mode, .prev_head // "", .prev_base // "", .head // "", .base // ""' <<<"$2") + case "$mode" in + incremental) + git -C "$repo" diff --name-only --no-renames -z "$prev_head" "$head" | tr '\0' '\n' | LC_ALL=C sort -u + ;; + rebased) + { + git -C "$repo" diff --name-only --no-renames -z "$base" "$head" + git -C "$repo" diff --name-only --no-renames -z "$prev_base" "$prev_head" + } | tr '\0' '\n' | LC_ALL=C sort -u | while IFS= read -r path; do + old=$(delta_file_patch "$repo" "$prev_base" "$prev_head" "$path") + new=$(delta_file_patch "$repo" "$base" "$head" "$path") + [[ "$old" == "$new" ]] || printf '%s\n' "$path" + done + ;; + esac +} + +# ── helpers ────────────────────────────────────────────────────────────────── + +delta_json() { # [command...] + jq -cn --arg mode "$1" --arg reason "$2" --arg prev_head "$3" --arg prev_base "$4" --arg head "$5" \ + --arg base "$6" '{mode: $mode, reason: $reason, commands: $ARGS.positional, + prev_head: $prev_head, prev_base: $prev_base, head: $head, base: $base}' --args "${@:7}" +} + +# Prints the full SHA of a commit the checkout has. Fails when it is missing (or the SHA is empty). +delta_resolve() { # + [[ -n "$2" ]] || return 1 + git -C "$1" rev-parse --verify --quiet "${2}^{commit}" 2>/dev/null +} + +# Like delta_resolve, but a missing commit gets one fetch by SHA first. GitHub serves commits that are still in the +# repository (refs/pull/* keeps many alive), so a commit older than the clone's depth usually comes back. +delta_find() { # + delta_resolve "$1" "$2" && return 0 + local depth=() + # --depth only in a shallow clone: in a full one it would cut the history short. + if delta_shallow "$1"; then depth=(--depth 50); fi + # Same credentials as the clone (GIT_AUTH, when the script set it), no hooks, quiet; errors only mean "missing". + git -C "$1" ${GIT_AUTH[@]+"${GIT_AUTH[@]}"} -c core.hooksPath=/dev/null \ + fetch --quiet --no-tags ${depth[@]+"${depth[@]}"} origin "$2" >/dev/null 2>&1 || true + delta_resolve "$1" "$2" +} + +# In a shallow clone the previous head can be an ancestor of the head yet sit below the head's shallow boundary: +# the histories then share no commit and --is-ancestor says no. Deepen the head's history once, so the check can +# see the link. Connected histories, or a full clone, need nothing. +delta_connect() { # + delta_shallow "$1" || return 0 + git -C "$1" merge-base "$2" "$3" >/dev/null 2>&1 && return 0 + git -C "$1" ${GIT_AUTH[@]+"${GIT_AUTH[@]}"} -c core.hooksPath=/dev/null \ + fetch --quiet --no-tags --deepen 50 origin "$3" >/dev/null 2>&1 || true +} + +delta_shallow() { # + [[ "$(git -C "$1" rev-parse --is-shallow-repository 2>/dev/null)" == true ]] +} + +# One file's patch between two commits, without what moves when the base moves: the `index` line (blob SHAs) and +# the line numbers of the `@@` hunk headers. Literal pathspec: a path is a name, never a glob. +delta_file_patch() { # + git --literal-pathspecs -C "$1" diff --no-color --no-ext-diff --no-textconv --no-renames "$2" "$3" -- "$4" | + sed -e '/^index /d' -e 's/^@@ -[0-9,]* +[0-9,]* @@/@@ @@/' +} diff --git a/tests/delta.sh b/tests/delta.sh new file mode 100644 index 0000000..67038c2 --- /dev/null +++ b/tests/delta.sh @@ -0,0 +1,223 @@ +#!/usr/bin/env bash +# Picks how to show what changed since the last round (pick_delta, changed_files), with real git on local repos. +# A bare repo plays GitHub: `https://h/o/r.git` points at it through GIT_CONFIG_COUNT, so nothing uses the network. +# HOME, XDG_CONFIG_HOME, the global and the system git config are isolated from the user's. +# Conditions are single-quoted on purpose: expect() evals them after each case sets out (and files). +# SC2034: GIT_AUTH is read by the sourced pick_delta. SC2329: has runs inside expect's eval. +# SC2030/SC2031: the cases that break the remote URL do it in a subshell on purpose. +# shellcheck disable=SC2016,SC2030,SC2031,SC2034,SC2329 +set -euo pipefail +root=$(cd "$(dirname "$0")/.." && pwd) +tmp=$(mktemp -d) +trap 'rm -rf "$tmp"' EXIT +fail=0 + +unset GIT_DIR GIT_WORK_TREE GIT_INDEX_FILE GIT_OBJECT_DIRECTORY GIT_ALTERNATE_OBJECT_DIRECTORIES GIT_CONFIG \ + GIT_CONFIG_PARAMETERS GIT_CEILING_DIRECTORIES GIT_AUTH +mkdir -p "$tmp/home" +export HOME="$tmp/home" XDG_CONFIG_HOME="$tmp/home/.config" GIT_CONFIG_NOSYSTEM=1 GIT_CONFIG_GLOBAL="$tmp/home/.gitconfig" +export GIT_AUTHOR_NAME=Test GIT_AUTHOR_EMAIL=test@example.com GIT_COMMITTER_NAME=Test GIT_COMMITTER_EMAIL=test@example.com +export GIT_TERMINAL_PROMPT=0 +remote="$tmp/remote.git" +export GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0="url.file://$remote.insteadOf" GIT_CONFIG_VALUE_0="https://h/o/r.git" +# Points every https://h/ URL at a folder that does not exist: a fetch through it fails, locally. +broken_key="url.file://$tmp/nowhere/.insteadOf" broken_value="https://h/" + +# shellcheck source=lib/delta.sh +source "$root/lib/delta.sh" + +expect() { # name condition + if eval "$2"; then echo "ok $1"; else + echo "FAIL $1 ($2)" + printf '%s\n' "$out" | sed 's/^/ | /' + fail=1 + fi +} + +world() { # a fresh "GitHub" remote and the author's repo, on main + rm -rf "$remote" "$tmp/src" + git init --quiet --bare -b main "$remote" + # GitHub serves a commit by SHA as long as it still has the object, even after a force-push. + git -C "$remote" config uploadpack.allowAnySHA1InWant true + git init --quiet -b main "$tmp/src" + git -C "$tmp/src" remote add origin "$remote" +} + +src() { git -C "$tmp/src" "$@"; } + +commit() { # ...: writes the files and commits them + local message=$1 pair + shift + for pair in "$@"; do printf '%s\n' "${pair#*=}" >"$tmp/src/${pair%%=*}"; done + src add -A + src commit --quiet -m "$message" +} + +publish() { # pushes main and the PR branch, as GitHub keeps refs/pull/1/head + src push --quiet --force origin main feature feature:refs/pull/1/head +} + +checkout() { # : the review checkout, as gh-pr-review clones it. Prints its path. + local dir + dir=$(mktemp -d "$tmp/checkout-XXXXX")/repo + git clone --depth "$1" --quiet https://h/o/r.git "$dir" + git -C "$dir" fetch origin pull/1/head:pr-branch --depth "$1" --quiet + git -C "$dir" fetch origin main:refs/remotes/origin/main --depth "$1" --quiet + printf '%s\n' "$dir" +} + +has() { git -C "$1" cat-file -e "${2}^{commit}" 2>/dev/null; } # + +ten=$(printf 'line %s\n' 1 2 3 4 5 6 7 8 9 10) +ten_changed=${ten/line 8/LINE 8} + +# ── sourcing ───────────────────────────────────────────────────────────────── +out=$(bash -c 'before=$(set -o; shopt); source "$1"; [[ $(set -o; shopt) == "$before" ]] && echo same' _ \ + "$root/lib/delta.sh") +expect "source: defines functions only (no output, no options)" '[[ $out == same ]]' + +# ── incremental: a plain new commit ────────────────────────────────────────── +world +commit m1 "a.txt=$ten" +src checkout --quiet -b feature +commit f1 b.txt=one +publish +prev_head=$(src rev-parse HEAD) prev_base=$(src rev-parse main) +commit f2 b.txt=two e.txt=new +publish +repo=$(checkout 50) +head=$(git -C "$repo" rev-parse pr-branch) +base=$(git -C "$repo" merge-base pr-branch origin/main) +out=$(pick_delta "$repo" "$prev_head" "$prev_base" "$head" "$base") +expect "incremental: stdout is one JSON line" '[[ $(wc -l <<<"$out") -eq 1 ]] && jq -e . <<<"$out" >/dev/null' +expect "incremental: mode" '[[ $(jq -r .mode <<<"$out") == incremental ]]' +expect "incremental: reason" '[[ $(jq -r .reason <<<"$out") == "previous head is an ancestor of the head" ]]' +expect "incremental: diff --stat and diff, full SHAs" \ + '[[ $(jq -c .commands <<<"$out") == "[\"git diff --stat $prev_head..$head\",\"git diff $prev_head..$head\"]" ]]' +expect "incremental: SHA fields" \ + '[[ $(jq -r "[.prev_head, .prev_base, .head, .base] | join(\" \")" <<<"$out") == "$prev_head $prev_base $head $base" ]]' +files=$(changed_files "$repo" "$out") +expect "incremental: changed_files" '[[ $files == "b.txt"$'"'\n'"'"e.txt" ]]' +out=$(pick_delta "$repo" "$head" "$base" "$head" "$base") +expect "incremental: same head says so" \ + '[[ $(jq -r .mode,.reason <<<"$out" | paste -sd, -) == "incremental,no new commits since the previous round" ]]' + +# ── rebased: onto a moved base, with a changed patch ───────────────────────── +world +commit m1 "a.txt=$ten" c.txt=c1 +src checkout --quiet -b feature +commit f1 "a.txt=$ten_changed" +commit f2 b.txt=old g.txt=dropped-later +publish +prev_head=$(src rev-parse HEAD) prev_base=$(src rev-parse main) +# The base moves: lines above the PR's change in a.txt (new hunk line numbers, same patch), and c.txt. +src checkout --quiet main +commit m2 "a.txt=top"$'\n'"$ten" c.txt=c2 +# The author redoes the PR on the new base: same a.txt change, b.txt changed, d.txt new, g.txt gone. +src checkout --quiet -B feature main +commit f1 "a.txt=top"$'\n'"$ten_changed" +commit f2 b.txt=new d.txt=added +publish +repo=$(checkout 50) +head=$(git -C "$repo" rev-parse pr-branch) +base=$(git -C "$repo" merge-base pr-branch origin/main) +expect "rebased: setup, the old head is not in the checkout" '! has "$repo" "$prev_head"' +out=$(pick_delta "$repo" "$prev_head" "$prev_base" "$head" "$base") +expect "rebased: stdout is one JSON line" '[[ $(wc -l <<<"$out") -eq 1 ]] && jq -e . <<<"$out" >/dev/null' +expect "rebased: mode" '[[ $(jq -r .mode <<<"$out") == rebased ]]' +expect "rebased: range-diff of the two ranges" \ + '[[ $(jq -c .commands <<<"$out") == "[\"git range-diff $prev_base..$prev_head $base..$head\"]" ]]' +expect "rebased: the old head was fetched" 'has "$repo" "$prev_head"' +files=$(changed_files "$repo" "$out") +expect "rebased: changed_files, the changed, new and dropped files only" \ + '[[ $files == "b.txt"$'"'\n'"'"d.txt"$'"'\n'"'"g.txt" ]]' +out=$(pick_delta "$repo" "$prev_head" "" "$head" "$base") +expect "rebased: no previous base is full" \ + '[[ $(jq -r .mode,.reason <<<"$out" | paste -sd, -) == "full,previous base unknown" ]]' +# A git that fails on range-diff only: the round falls back to full and says why. +real_git=$(command -v git) +mkdir -p "$tmp/bin" +cat >"$tmp/bin/git" < Date: Thu, 26 Nov 2026 16:13:02 +0100 Subject: [PATCH 02/33] Track each finding's status across rounds, and write the progress line --- lib/records.jq | 130 ++++++++++++++++++++++++++++++++++------ lib/records.sh | 10 +++- tests/records.sh | 150 +++++++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 267 insertions(+), 23 deletions(-) diff --git a/lib/records.jq b/lib/records.jq index 7354cd5..8d42836 100644 --- a/lib/records.jq +++ b/lib/records.jq @@ -65,24 +65,93 @@ def normalize_findings: | select(.severity == "critical" or .severity == "important" or .severity == "minor")) else [] end; -# The highest "F" in a record, or 0. -def _last_finding_number: [(.findings // [])[]? | .id | strings | capture("^F(?\\d+)$").n | tonumber] | max // 0; +# The highest "" ID in a record's findings, its later list and its last_ids, or 0. The last_ids field +# keeps the numbers of findings that were not carried (fixed, declined, Later), so an ID is never given twice. +def _last_number($prefix): + [((.findings // [])[]?, (.later // [])[]?) | objects | .id | strings + | capture("^" + $prefix + "(?\\d+)$").n | tonumber] + + [(.last_ids // {})[$prefix]? | numbers] + | max // 0; + +def _severity_ok: . == "critical" or . == "important" or . == "minor"; + +# One entry of the model's array, typed: id and status as given (strings or null), the rest as normalize_findings. +def _entry: + {id: (.id | _str | if . then _trim else null end), status: (.status | if type == "string" then ascii_downcase | _trim + else null end), severity: (.severity | if type == "string" then ascii_downcase | _trim else null end), + file: (.file | _str), line: (.line | _num), title: (.title | _str | _title100), in_delta: (.in_delta == true), + later: (.later == true)}; + +# The findings of a code-review round, from the model's array and the previous record's findings. +# Out: {findings, later, last_ids}. Known IDs keep their ID and first round, with the model's status (open on an +# ID last marked fixed is regressed; a status outside fixed, open, declined is open and unverified). Entries +# without an ID, or with an ID the previous record doesn't have, are new: F, or L with later true. The first +# entry for an ID wins. Previous open, new or regressed findings the reply leaves out are carried, unverified. +def _track($findings; $prev; $round): + (($prev // {}).findings // [] | map(objects | select(.id | type == "string"))) as $old + | (reduce $old[] as $f ({}; if has($f.id) then . else .[$f.id] = $f end)) as $known + | reduce ((if ($findings | type) == "array" then $findings else [] end)[] | objects | _entry) as $e ( + {seen: {}, findings: [], later: [], f: (($prev // {}) | _last_number("F")), l: (($prev // {}) | _last_number("L"))}; + if $e.id != null and .seen[$e.id] then . + else (if $e.id != null then .seen[$e.id] = true else . end) + | if $e.id != null and $known[$e.id] != null then + $known[$e.id] as $p + | (if $e.status == "fixed" or $e.status == "declined" then {status: $e.status} + elif $e.status == "open" or $e.status == "regressed" then + {status: (if $p.status == "fixed" or $p.status == "regressed" and $e.status == "regressed" + then "regressed" else "open" end)} + else {status: "open", unverified: true} end) as $s + | .findings += [{id: $e.id, + severity: (if ($e.severity | _severity_ok) then $e.severity else $p.severity end), + status: $s.status, first_round: ($p.first_round // $round), in_delta: $e.in_delta, + file: ($e.file // $p.file), line: ($e.line // $p.line), title: ($e.title // $p.title)} + + (if $s.unverified then {unverified: true} else {} end)] + elif ($e.severity | _severity_ok) | not then . + elif $e.later then + .l += 1 + | .later += [{id: "L\(.l)", severity: $e.severity, file: $e.file, line: $e.line, title: $e.title}] + else + .f += 1 + | .findings += [{id: "F\(.f)", severity: $e.severity, status: "new", first_round: $round, + in_delta: $e.in_delta, file: $e.file, line: $e.line, title: $e.title}] + end + end) + | .seen as $seen + | {findings: (.findings + [$old[] | select(.status == "open" or .status == "new" or .status == "regressed") + | select($seen[.id] | not) + | {id, severity, status: "open", first_round, in_delta: false, file, line, title, unverified: true}] + | reduce .[] as $f ({ids: {}, out: []}; if .ids[$f.id] then . else .ids[$f.id] = true | .out += [$f] end) + | .out), + later: .later, last_ids: {F: .f, L: .l}}; # round.json from the run's facts, the findings (block or parser) and the previous record (or null). +# Round 1 findings carry no id or status: all are new. From round 2, see _track. def build_record($meta; $findings; $prev): ($meta.code_review != false) as $code_review - | (($prev // {}) | _last_finding_number) as $last | ($meta.round | _num) as $round - | (if $code_review then $findings | normalize_findings else [] end) as $found - | ($found | to_entries | map({id: "F\(.key + $last + 1)", severity: .value.severity, status: "new", - first_round: $round, in_delta: false, file: .value.file, line: .value.line, title: .value.title})) as $items - | def count($s): $items | map(select(.severity == $s)) | length; - { + | (if $code_review then _track($findings; $prev; $round) + else {findings: [], later: [], last_ids: {F: (($prev // {}) | _last_number("F")), + L: (($prev // {}) | _last_number("L"))}} end) as $t + | $t.findings as $items + | def open: select(.status == "open" or .status == "new" or .status == "regressed"); + def count($s): [$items[] | open | select(.severity == $s)] | length; + def status($s): [$items[] | select(.status == $s)] | length; + (if $code_review then + {open_blocking: (count("critical") + count("important")), critical: count("critical"), + important: count("important"), minor: count("minor"), new: status("new"), fixed: status("fixed"), + declined: status("declined"), regressed: status("regressed"), later: ($t.later | length), + unverified: ([$items[] | select(.unverified == true)] | length)} + else + {open_blocking: null, critical: null, important: null, minor: null, new: null, + fixed: null, declined: null, regressed: null, later: null, unverified: null} + end) as $counts + | { schema: 1, source: $meta.source, pr: ($meta.pr | if type == "object" then {host, owner, repo, number: (.number | _num)} else null end), round: $round, mode: $meta.mode, + mode_reason: ($meta.mode_reason | _str), reviewer: $meta.reviewer, model: $meta.model, posted_at: $meta.posted_at, @@ -91,21 +160,48 @@ def build_record($meta; $findings; $prev): previous_head_sha: ($meta.previous_head_sha // ($prev // {}).head_sha), approach: $meta.approach, ready: $meta.ready, + ready_overridden: ($code_review and ($meta.ready == "yes" or $meta.ready == "yes-with-fixes") + and $counts.open_blocking > 0), decision: $meta.decision, preview: ($meta.preview == true), code_review: $code_review, findings: $items, - later: [], - counts: (if $code_review then - {open_blocking: (count("critical") + count("important")), critical: count("critical"), - important: count("important"), minor: count("minor"), new: ($items | length), - fixed: 0, declined: 0, regressed: 0} - else - {open_blocking: null, critical: null, important: null, minor: null, new: null, - fixed: null, declined: null, regressed: null} - end) + later: $t.later, + last_ids: $t.last_ids, + counts: $counts }; +# The progress line that opens a round 2 or later body, for a person. $prev: the previous code-review record, or +# null (no line). $decision: loop_decide over the history with this record, so its label is this round's. +# ### Round 3 · since round 2 +# 4 fixed · 2 still open · 3 new (1 in the new commits) · open blocking: 5 (was 6) · loop: converging +def progress_line($prev; $decision): + . as $r + | if $prev == null then empty + else "### Round \($r.round) · since round \($prev.round)", + if $r.code_review == false then "code review skipped: the approach needs a rethink" + else ($r.findings // []) as $f + | def n($s): [$f[] | select(.status == $s and (.unverified != true))] | length; + def part($n; $text): if $n > 0 then ["\($n) \($text)"] else [] end; + ([$f[] | select(.status == "new" and .in_delta == true)] | length) as $delta + | ([$f[] | select(.unverified == true)] | length) as $unverified + | (part(n("fixed"); "fixed") + part(n("open"); "still open") + part(n("regressed"); "regressed") + + (if n("new") > 0 then ["\(n("new")) new" + (if $delta > 0 then " (\($delta) in the new commits)" + else "" end)] else [] end) + + part(n("declined"); "declined") + part(($r.later // []) | length; "for later") + + part($unverified; "not re-checked") + + ["open blocking: \($r.counts.open_blocking // 0)" + + (if ($prev.counts.open_blocking? | type) == "number" then " (was \($prev.counts.open_blocking))" + else "" end)] + + (if ($decision.label? | type) == "string" + then ["loop: " + (if $decision.label == "nit-loop" then "nit loop" else $decision.label end)] + else [] end) + + (if $r.mode == "full" then ["full review" + (if ($r.mode_reason | type) == "string" + then " (\($r.mode_reason))" else "" end)] else [] end)) + | join(" · ") + end + end; + # A record rebuilt from an old review (GitHub REST review object). The caller reads the verdict lines. def backfill_record($review; $prev; $round; $pr; $approach; $ready; $code_review): ($review.body // "") as $body diff --git a/lib/records.sh b/lib/records.sh index befa994..634c154 100644 --- a/lib/records.sh +++ b/lib/records.sh @@ -50,12 +50,20 @@ normalize_ready() { # esac } -# round.json from the run's facts (meta JSON), the findings JSON and the previous record JSON (or null). +# round.json from the run's facts (meta JSON), the findings JSON and the previous record JSON (or null). The +# previous record is the last one with a code review. From round 2 the findings carry IDs and statuses. build_record() { # jq -L "${LIB_DIR:?}" -n --argjson meta "$1" --argjson findings "${2:-[]}" --argjson prev "${3:-null}" \ 'include "records"; build_record($meta; $findings; $prev)' } +# The two-line progress line that opens a round 2 or later body. Nothing without a previous record. The decision +# is loop_decide_json over the history including this record. +progress_line() { # + jq -r -L "${LIB_DIR:?}" -n --argjson record "$1" --argjson prev "${2:-null}" --argjson decision "${3:-null}" \ + 'include "records"; $record | progress_line($prev; $decision)' +} + # The hidden marker line for a record file, sized for a body of characters. marker_line() { # jq -r -L "${LIB_DIR:?}" --argjson len "$2" 'include "records"; marker_line($len)' "$1" diff --git a/tests/records.sh b/tests/records.sh index f305c2f..353729a 100644 --- a/tests/records.sh +++ b/tests/records.sh @@ -98,7 +98,11 @@ rec=$(build_record "$meta" "$(parse_findings "$fixtures/bullets.md")" "$prev") check "ids continue after F7" "$(jq -r '[.findings[].id] | join(" ")' <<<"$rec")" "F8 F9 F10 F11 F12 F13" check "open_blocking" "$(jq '.counts.open_blocking' <<<"$rec")" 4 check "counts" "$(jq -c '.counts' <<<"$rec")" \ - '{"open_blocking":4,"critical":1,"important":3,"minor":2,"new":6,"fixed":0,"declined":0,"regressed":0}' + '{"open_blocking":4,"critical":1,"important":3,"minor":2,"new":6,"fixed":0,"declined":0,"regressed":0,"later":0,"unverified":0}' +check "round 1: no unverified key" "$(jq '[.findings[] | has("unverified")] | any' <<<"$rec")" false +check "round 1: last ids" "$(jq -c '.last_ids' <<<"$rec")" '{"F":13,"L":0}' +check "round 1: ready kept, not overridden" "$(jq -c '[.ready, .ready_overridden]' <<<"$rec")" '["yes-with-fixes",true]' +check "mode kept, no reason" "$(jq -c '[.mode, .mode_reason]' <<<"$rec")" '["full",null]' check "finding fields" "$(jq -c '.findings[0] | [.status, .first_round, .in_delta]' <<<"$rec")" '["new",2,false]' check "schema, later, preview" "$(jq -c '[.schema, .later, .preview]' <<<"$rec")" '[1,[],false]' check "missing meta keys are null" "$(jq -c '[.base_sha, .posted_at, .decision]' <<<"$rec")" '[null,null,null]' @@ -112,6 +116,100 @@ rethink=$(build_record "$(jq -c '.code_review = false | .approach = "rethink"' < '[{"severity":"critical","title":"t"}]' null) check "rethink: no findings" "$(jq -c '.findings' <<<"$rethink")" "[]" check "rethink: null counts" "$(jq -c '[.counts[]] | unique' <<<"$rethink")" "[null]" +check "rethink: count keys" "$(jq -c '.counts | keys' <<<"$rethink")" \ + '["critical","declined","fixed","important","later","minor","new","open_blocking","regressed","unverified"]' +check "rethink: not overridden, no later" "$(jq -c '[.ready_overridden, .later]' <<<"$rethink")" '[false,[]]' + +# ── build_record with statuses (round 2 and later) ────────────────────────── +# Round 2: F1 open, F2 fixed, F3 declined, F4 new, F5 regressed, L6 later. F and L number apart, each from its +# highest. +meta2=$(jq -c '.round = 3 | .mode = "incremental" | .mode_reason = null | .ready = "no"' <<<"$meta") +prev2=$(jq -nc '{round: 2, head_sha: "aaa", counts: {open_blocking: 3}, findings: [ + {id: "F1", severity: "critical", status: "open", first_round: 1, in_delta: false, file: "a.ts", line: 1, title: "one"}, + {id: "F2", severity: "important", status: "fixed", first_round: 1, in_delta: false, file: "b.ts", line: 2, title: "two"}, + {id: "F3", severity: "important", status: "declined", first_round: 1, in_delta: false, file: "c.ts", line: 3, title: "three"}, + {id: "F4", severity: "minor", status: "new", first_round: 2, in_delta: true, file: "d.ts", line: 4, title: "four"}, + {id: "F5", severity: "important", status: "regressed", first_round: 1, in_delta: false, file: "e.ts", line: 5, + title: "five"}], + later: [{id: "L6", severity: "minor", file: "f.ts", line: 6, title: "six"}]}') +r3() { build_record "$meta2" "$1" "$prev2"; } +one() { jq -c --arg id "$2" '(.findings + .later)[] | select(.id == $id) + | [.status, .first_round, .severity, .file, .line, .title, (.unverified // false)]' <<<"$1"; } + +rec=$(r3 '[{"id":"F1","status":"fixed"}]') +check "known id keeps its status" "$(one "$rec" F1)" '["fixed",1,"critical","a.ts",1,"one",false]' +rec=$(r3 '[{"id":"F1","status":"open","severity":"minor","file":"z.ts","line":9,"title":"new title"}]') +check "known id: model fields win" "$(one "$rec" F1)" '["open",1,"minor","z.ts",9,"new title",false]' +rec=$(r3 '[{"id":"F2","status":"open"}]') +check "fixed then open: regressed" "$(one "$rec" F2)" '["regressed",1,"important","b.ts",2,"two",false]' +check "regressed counts as blocking" "$(jq -c '.counts | [.regressed, .open_blocking]' <<<"$rec")" '[1,3]' +rec=$(r3 '[{"id":"F5","status":"open"}]') +check "regressed then open: open" "$(one "$rec" F5)" '["open",1,"important","e.ts",5,"five",false]' +rec=$(r3 '[{"severity":"minor","title":"n1"},{"severity":"important","title":"l1","later":true}, + {"severity":"critical","title":"n2","in_delta":true}]') +check "new ids continue after F5 and L6" "$(jq -c '[.findings[] | select(.status == "new") | .id], [.later[].id]' \ + <<<"$rec" | tr -d '\n')" '["F6","F7"]["L7"]' +check "new finding fields" "$(jq -c '.findings[] | select(.id == "F7") | [.status, .first_round, .in_delta]' \ + <<<"$rec")" '["new",3,true]' +check "later item fields" "$(jq -c '.later[0]' <<<"$rec")" \ + '{"id":"L7","severity":"important","file":null,"line":null,"title":"l1"}' +check "last ids" "$(jq -c '.last_ids' <<<"$rec")" '{"F":7,"L":7}' +check "later items not blocking" "$(jq -c '.counts | [.later, .important]' <<<"$rec")" '[1,1]' +check "previous later not carried" "$(jq -c '[.later[].id] | index("L6")' <<<"$rec")" null +rec=$(r3 '[]') +check "missing ids carried as unverified open" \ + "$(jq -c '[.findings[] | [.id, .status, .unverified]]' <<<"$rec")" \ + '[["F1","open",true],["F4","open",true],["F5","open",true]]' +check "carried keep first round" "$(one "$rec" F4)" '["open",2,"minor","d.ts",4,"four",true]' +check "fixed and declined not carried" "$(jq -c '[.findings[].id | select(. == "F2" or . == "F3")]' <<<"$rec")" "[]" +check "carried: counts" "$(jq -c '.counts' <<<"$rec")" \ + '{"open_blocking":2,"critical":1,"important":1,"minor":1,"new":0,"fixed":0,"declined":0,"regressed":0,"later":0,"unverified":3}' +check "numbering survives an empty round" "$(build_record "$meta2" '[{"severity":"minor","title":"x"}]' "$rec" | + jq -r '.findings[] | select(.status == "new") | .id')" F6 +rec=$(r3 '[{"id":"F1","status":"fixed"},{"id":"F1","status":"open"}]') +check "duplicate keeps the first" "$(jq -c '[.findings[] | select(.id == "F1") | .status]' <<<"$rec")" '["fixed"]' +rec=$(r3 '[{"id":"F99","status":"open","severity":"important","title":"ghost"}]') +check "unknown id becomes new" "$(jq -c '.findings[0] | [.id, .status, .first_round, .title]' <<<"$rec")" \ + '["F6","new",3,"ghost"]' +rec=$(r3 '[{"id":"F1","status":"maybe"}]') +check "bad status: open, unverified" "$(one "$rec" F1)" '["open",1,"critical","a.ts",1,"one",true]' +check "bad status: not carried twice" "$(jq '[.findings[] | select(.id == "F1")] | length' <<<"$rec")" 1 +check "in_delta kept as a boolean" "$(r3 '[{"severity":"minor","title":"t","in_delta":"yes"}]' | + jq -c '.findings[0].in_delta')" false + +rec=$(build_record "$(jq -c '.ready = "yes"' <<<"$meta2")" '[{"id":"F1","status":"open"}]' "$prev2") +check "ready yes with open blocking: overridden" "$(jq -c '[.ready, .ready_overridden]' <<<"$rec")" '["yes",true]' +rec=$(build_record "$(jq -c '.ready = "yes"' <<<"$meta2")" \ + '[{"id":"F1","status":"fixed"},{"id":"F4","status":"open"},{"id":"F5","status":"declined"}]' "$prev2") +check "ready yes, nothing blocking: not overridden" "$(jq -c '[.ready_overridden, .counts.open_blocking]' \ + <<<"$rec")" '[false,0]' +check "ready no: not overridden" "$(r3 '[]' | jq .ready_overridden)" false +rec=$(build_record "$(jq -c '.mode = "full" | .mode_reason = "the previous head is gone"' <<<"$meta2")" '[]' "$prev2") +check "mode and mode_reason kept" "$(jq -c '[.mode, .mode_reason]' <<<"$rec")" '["full","the previous head is gone"]' +rec=$(build_record "$(jq -c '.code_review = false | .approach = "rethink"' <<<"$meta2")" \ + '[{"id":"F1","status":"fixed"}]' "$prev2") +check "rethink after round 2: no findings, null counts" "$(jq -c '[.findings, .later, ([.counts[]] | unique)]' \ + <<<"$rec")" '[[],[],[null]]' + +# A full round 3 on the round 2 record: every status moves. +reply='[ + {"id":"F2","status":"open","in_delta":true}, + {"id":"F5","status":"fixed"}, + {"id":"F4","status":"declined","title":"four, declined"}, + {"id":"F2","status":"fixed"}, + {"id":"F3","status":"open"}, + {"id":"F77","status":"fixed","severity":"minor","file":"g.ts","line":7,"title":"unknown"}, + {"severity":"critical","file":"h.ts","line":8,"title":"in delta","in_delta":true}, + {"severity":"important","file":"i.ts","line":9,"title":"later one","later":true}, + {"severity":"nit","title":"dropped"} +]' +rec=$(r3 "$reply") +check "round 3: findings" "$(jq -c '[.findings[] | [.id, .status, .first_round, (.unverified // false)]]' <<<"$rec")" \ + '[["F2","regressed",1,false],["F5","fixed",1,false],["F4","declined",2,false],["F3","open",1,false],["F6","new",3,false],["F7","new",3,false],["F1","open",1,true]]' +check "round 3: later" "$(jq -c '[.later[] | [.id, .title]]' <<<"$rec")" '[["L7","later one"]]' +check "round 3: counts" "$(jq -c '.counts' <<<"$rec")" \ + '{"open_blocking":4,"critical":2,"important":2,"minor":1,"new":2,"fixed":1,"declined":1,"regressed":1,"later":1,"unverified":1}' +check "round 3: kept the round 2 head" "$(jq -r .previous_head_sha <<<"$rec")" aaa # ── normalize_ready ───────────────────────────────────────────────────────── for pair in "Yes=yes" "yes.=yes" "Yes with fixes=yes-with-fixes" "Yes, with fixes=yes-with-fixes" \ @@ -137,16 +235,58 @@ check "marker_record: the last marker wins" \ check "marker_record: no marker, nothing" "$(marker_record $'text\n')" "" check "marker_record: broken JSON, nothing" "$(marker_record '')" "" -line=$(marker_line "$tmp/round.json" 59000) -check "marker: 59,000-character body drops titles" "$(grep -c '"title"' <<<"$line" || true)" 0 -check "marker: 59,000-character body keeps findings" \ +line=$(marker_line "$tmp/round.json" 58900) +check "marker: 58,900-character body drops titles" "$(grep -c '"title"' <<<"$line" || true)" 0 +check "marker: 58,900-character body keeps findings" \ "$(marker_record "$line" | jq '.findings | length')" 4 -check "marker: fits under 60,000" "$((59000 + 1 + ${#line} <= 60000))" 1 +check "marker: fits under 60,000" "$((58900 + 1 + ${#line} <= 60000))" 1 line=$(marker_line "$tmp/round.json" 59800) check "marker: no room drops later and findings" "$(marker_record "$line" | jq -c '[has("later"), has("findings")]')" \ '[false,false]' check "marker: counts stay" "$(marker_record "$line" | jq .counts.open_blocking)" 3 +build_record "$meta2" "$reply" "$prev2" >"$tmp/round3.json" +line=$(marker_line "$tmp/round3.json" 1000) +check "marker: statuses and later round trip" "$(marker_record "$line" | jq -S .)" "$(jq -S . "$tmp/round3.json")" +check "marker: no -- with statuses" "$(grep -c -- '--' <<<"${line:4:${#line}-8}" || true)" 0 +cap=$((60000 - 1 - ${#line} + 40)) +line=$(marker_line "$tmp/round3.json" "$cap") +check "marker: over the cap drops titles first" "$(marker_record "$line" | + jq -c '[has("later"), (.findings | length), ([.findings[], .later[] | has("title")] | any)]')" '[true,7,false]' +jq 'del(.findings[].title, .later)' "$tmp/round3.json" >"$tmp/short.json" +short=$(marker_line "$tmp/short.json" 0) +line=$(marker_line "$tmp/round3.json" "$((60000 - 1 - ${#short} - 5))") +check "marker: then later before findings" "$(marker_record "$line" | jq -c '[has("later"), (.findings | length)]')" \ + '[false,7]' +check "marker: last ids and counts stay" "$(marker_record "$line" | jq -c '[.last_ids, .counts.unverified]')" \ + '[{"F":7,"L":7},1]' + +# ── progress_line ─────────────────────────────────────────────────────────── +dec='{"label":"converging"}' +check "progress: all counts" "$(progress_line "$(cat "$tmp/round3.json")" "$prev2" "$dec")" \ + "### Round 3 · since round 2 +1 fixed · 1 still open · 1 regressed · 2 new (1 in the new commits) · 1 declined · 1 for later · 1 not re-checked \ +· open blocking: 4 (was 3) · loop: converging" +rec=$(r3 '[{"id":"F1","status":"fixed"},{"id":"F4","status":"open"},{"id":"F5","status":"open"}, + {"severity":"minor","title":"n"}]') +check "progress: zero counts dropped" "$(progress_line "$rec" "$(jq -c 'del(.counts)' <<<"$prev2")" \ + '{"label":"nit-loop"}' | tail -n 1)" "1 fixed · 2 still open · 1 new · open blocking: 1 · loop: nit loop" +check "progress: unverified, no label" "$(progress_line "$(r3 '[]')" "$prev2" '{"label":null}' | tail -n 1)" \ + "3 not re-checked · open blocking: 2 (was 3)" +check "progress: still open excludes unverified" "$(progress_line "$(r3 '[{"id":"F1","status":"open"}]')" "$prev2" \ + "$dec" | tail -n 1)" "1 still open · 2 not re-checked · open blocking: 2 (was 3) · loop: converging" +rec=$(build_record "$(jq -c '.mode = "full" | .mode_reason = "the previous head is gone"' <<<"$meta2")" \ + '[{"id":"F1","status":"fixed"},{"id":"F4","status":"fixed"},{"id":"F5","status":"fixed"}]' "$prev2") +check "progress: full with a reason" "$(progress_line "$rec" "$prev2" '{"label":"ready"}' | tail -n 1)" \ + "3 fixed · open blocking: 0 (was 3) · loop: ready · full review (the previous head is gone)" +check "progress: full without a reason" "$(progress_line "$(jq -c '.mode_reason = null' <<<"$rec")" "$prev2" \ + '{"label":"ready"}' | tail -n 1)" "3 fixed · open blocking: 0 (was 3) · loop: ready · full review" +check "progress: no previous record, nothing" "$(progress_line "$rec" null "$dec")" "" +rec=$(build_record "$(jq -c '.code_review = false | .approach = "rethink"' <<<"$meta2")" '[]' "$prev2") +check "progress: rethink" "$(progress_line "$rec" "$prev2" "$dec")" \ + "### Round 3 · since round 2 +code review skipped: the approach needs a rethink" + # ── backfill_record ───────────────────────────────────────────────────────── pr='{"host":"github.com","owner":"o","repo":"r","number":7}' review() { # fixture [state] -> GitHub REST review JSON From a428099cf5cd24b842bd885d71d3519199b440bd Mon Sep 17 00:00:00 2001 From: david catalan Date: Thu, 26 Nov 2026 16:13:02 +0100 Subject: [PATCH 03/33] Build round 2 and later on the last code review: earlier findings, what changed, a progress line and --full --- README.md | 38 +++++++ gh-pr-review | 281 ++++++++++++++++++++++++++++++++++++++++++++++++-- tests/flow.sh | 118 ++++++++++++++++++++- 3 files changed, 423 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index f3f78d5..f873f0c 100644 --- a/README.md +++ b/README.md @@ -63,6 +63,7 @@ Inside a repo clone, a bare number works: `gh pr-review 42`. | `--check` | off | Run only the loop check (see below) and exit 0, 3 or 5. No clone, no model call | | `--json` | off | With `--check`: print the decision as JSON on stdout | | `--force-round` | off | Run a round even when the loop check stops it or nothing changed | +| `--full` | off | Review the whole PR again, as in round 1. Earlier findings are still re-checked by ID | | `--doctor` | — | Check prerequisites and exit | Environment variables: `GH_PR_REVIEW_MODEL` (default model), @@ -147,6 +148,43 @@ The label says whether the loop converges: `early` (fewer than 3 rounds), back) or `churning`. `--json` prints the records and the decision; `-u ` picks the gh account, as for a review. +## Round 2 and later + +From the second round, the reviewer builds on the last code review instead of +starting over: + +1. **Earlier findings are re-checked by ID.** Each one comes back `fixed`, + `open` (a fix attempt that did not work stays open) or `declined` (only with + a reason from the PR discussion, quoted). A finding fixed earlier that comes + back is `regressed`. One the reviewer forgets is kept `open` and marked as + not re-checked: nothing disappears silently. +2. **What changed since that round is reviewed in full**, at every severity: + `git diff ..`, or `git range-diff` when the author + rebased. +3. **Outside what changed, only Critical findings are raised.** Important and + Minor issues there go to a folded **Later** list. Later items don't block + the PR, and can become follow-up issues. + +The owner pass starts from its previous verdict, and keeps it in one line +unless the changes or the discussion change it. After a Rethink it judges +afresh. + +The posted review opens with a progress line counted from the round record, +not from the model's text: + +``` +### Round 3 · since round 2 +4 fixed · 2 still open · 3 new (1 in the new commits) · open blocking: 5 (was 6) · loop: converging +``` + +Fixed findings and the Later list follow the open ones, folded. "Ready to +merge? Yes" with blocking findings still open posts as a comment: the record +wins. + +When the previous head is gone (a force-push) or the comparison fails, the +round is a full review, and it says why. `--full` asks for one, for example +after a rewrite. + ## Loop check Before a round, the tool reads the PR's earlier rounds and decides whether diff --git a/gh-pr-review b/gh-pr-review index b25b06f..abccfbf 100755 --- a/gh-pr-review +++ b/gh-pr-review @@ -17,6 +17,7 @@ # --check Run only the loop check: print it and exit 0 (run), 3 (stop) or 5 (no new commits) # --json With --check, print the decision as JSON # --force-round Run a round even when the loop check stops it or nothing changed +# --full Review the whole PR again (round 2 and later still re-check the earlier findings) # --doctor Check all prerequisites and exit # -h, --help Show this help # @@ -76,6 +77,7 @@ GH_USER="${GH_PR_REVIEW_USER:-}" CHECK_ONLY=false CHECK_JSON=false FORCE_ROUND=false +FULL_ROUND=false # ── arg parsing ────────────────────────────────────────────────────────────── while [[ $# -gt 0 ]]; do @@ -120,6 +122,10 @@ while [[ $# -gt 0 ]]; do FORCE_ROUND=true shift ;; + --full) + FULL_ROUND=true + shift + ;; --no-post) POST_TO_PR=false shift @@ -160,7 +166,7 @@ while [[ $# -gt 0 ]]; do done if [[ "$DOCTOR" == "false" && -z "$TARGET" ]]; then - echo "Usage: gh pr-review [--model ] [--no-post] [--skip-approach] [-y] [--check [--json]] [--force-round] [--doctor]" >&2 + echo "Usage: gh pr-review [--model ] [--no-post] [--skip-approach] [-y] [--check [--json]] [--force-round] [--full] [--doctor]" >&2 exit 1 fi if [[ "$CHECK_JSON" == "true" && "$CHECK_ONLY" == "false" ]]; then @@ -460,7 +466,98 @@ echo "" CONTEXT_DIR="${SESSION_DIR}/context" write_pr_context "$CONTEXT_DIR" +# ── previous round ───────────────────────────────────────────────────────────────── +# Round 2 and later build on the last round with a code review (a Rethink round has none): its open findings are +# re-checked by ID, and what changed since its head is reviewed in full. Anything unusable makes a full round. +FINDINGS_BASE=$(jq -c '[.[] | select(.code_review != false)] | last // null' <<<"$RECORDS") +BASE_ROUND=$(jq -r '.round // empty' <<<"$FINDINGS_BASE") +PREVIOUS_OPEN=$(jq '[.findings[]? | select(.status == "open" or .status == "new" or .status == "regressed")] | length' \ + <<<"$FINDINGS_BASE") +if [[ "$FINDINGS_BASE" == null ]]; then + if [[ "$PREVIOUS_RECORD" == null ]]; then DELTA_REASON="no previous round"; else DELTA_REASON="no earlier code review"; fi + DELTA=$(jq -cn --arg reason "$DELTA_REASON" '{mode: "full", reason: $reason, commands: []}') +elif [[ "$FULL_ROUND" == "true" ]]; then + DELTA='{"mode":"full","reason":"--full","commands":[]}' +else + DELTA=$(pick_delta "$REVIEW_DIR" "$(jq -r '.head_sha // ""' <<<"$FINDINGS_BASE")" \ + "$(jq -r '.base_sha // ""' <<<"$FINDINGS_BASE")" "$HEAD_SHA" "$BASE_SHA") || + DELTA='{"mode":"full","reason":"could not compare with the last round","commands":[]}' +fi +ROUND_MODE=$(jq -r '.mode' <<<"$DELTA") +changed_files "$REVIEW_DIR" "$DELTA" >"$CONTEXT_DIR/delta-files.txt" 2>/dev/null || : >"$CONTEXT_DIR/delta-files.txt" +if [[ "$ROUND" -gt 1 ]]; then + if [[ "$ROUND_MODE" == full ]]; then + echo " mode: full ($(jq -r '.reason' <<<"$DELTA"))" + else + echo " mode: ${ROUND_MODE} since round ${BASE_ROUND} · ${PREVIOUS_OPEN} earlier findings to re-check" + fi + echo "" +fi + +# The n-th gh-pr-review review on the PR, without its marker lines. +round_body() { # + jq -r --argjson n "$1" '[.reviews[] | select((.body // "") | contains(""))] + | sort_by(.submittedAt) | .[$n - 1].body // ""' "$CONTEXT_DIR/discussion.json" | grep -v '^\n\n" + $md)}]' \ + "$stub/rest-reviews.json" >"$stub/r.tmp" && mv "$stub/r.tmp" "$stub/rest-reviews.json" + jq -c --arg rec "$1" --arg md "$2" --argjson n "$n" '.reviews += [{author: {login: "me"}, state: "COMMENTED", + submittedAt: "2026-01-0\($n)T00:00:00Z", + body: ("\n\n" + $md)}]' \ + "$stub/discussion.json" >"$stub/d.tmp" && mv "$stub/d.tmp" "$stub/discussion.json" +} +session_file() { cat "$stub"/work/pr-review-sessions/pr-review-*/context/"$1" 2>/dev/null; } +two_rounds() { # round 1 (F1, F2) and round 2 (F1 open, F2 fixed, F3 new), both Sound + add_round '{"schema":1,"source":"model","round":1,"head_sha":"h1","base_sha":"b1","approach":"sound","ready":"no","code_review":true,"findings":[{"id":"F1","severity":"important","status":"new","first_round":1,"file":"a.js","line":3,"title":"thing breaks"},{"id":"F2","severity":"minor","status":"new","first_round":1,"file":"b.js","line":1,"title":"nit"}],"counts":{"open_blocking":1,"critical":0,"important":1,"minor":1}}' \ + $'### Approach\n\n**Approach:** Sound\n\n### Issues\n- round one' + add_round '{"schema":1,"source":"model","round":2,"head_sha":"h2","base_sha":"b1","approach":"sound","ready":"no","code_review":true,"findings":[{"id":"F1","severity":"important","status":"open","first_round":1,"file":"a.js","line":3,"title":"thing breaks"},{"id":"F2","severity":"minor","status":"fixed","first_round":1,"file":"b.js","line":1,"title":"nit"},{"id":"F3","severity":"critical","status":"new","first_round":2,"file":"c.js","line":9,"title":"data loss"}],"counts":{"open_blocking":2,"critical":1,"important":1,"minor":0}}' \ + $'### Approach\n\n**What it does:** x\n\n**Approach:** Sound\n\n### Issues\n- **F3 · `c.js:9`** — data loss' +} +round3=$'### Issues\n#### 🚨 Critical (Must Fix Before Merge)\n- **F3 · `c.js:9`** — still loses data.\n' +round3+=$'#### ⚠️ Important (Should Fix)\n- **`d.js:2`** — retry loop has no bound.\n\n**Ready to merge?** No\n\n' +round3+=$'```json findings\n[{"id":"F1","status":"fixed","severity":"important","file":"a.js","line":3,"title":"thing breaks","in_delta":false,"later":false},\n' +round3+=$' {"id":"F3","status":"open","severity":"critical","file":"c.js","line":9,"title":"data loss","in_delta":false,"later":false},\n' +round3+=$' {"id":null,"status":"new","severity":"important","file":"d.js","line":2,"title":"retry loop has no bound","in_delta":true,"later":false},\n' +round3+=$' {"id":null,"status":"new","severity":"minor","file":"e.js","line":5,"title":"old helper is slow","in_delta":false,"later":true}]\n```' + +setup $'**Approach:** Sound' $'**Ready to merge?** Yes' +run +expect "round 1: no Previous round section" '[[ $rc == 0 ]] && ! grep -q "## Previous round" "$stub/code-prompt.txt"' +expect "round 1: no previous verdict for the owner" '! grep -q "Your previous verdict" "$stub/owner-prompt.txt"' +expect "round 1: a full round, no progress line" '[[ $(jq -r ".mode, .mode_reason" <<<"$record" | paste -sd, -) == "full,no previous round" && $body != *"### Round "* ]]' + +setup $'### Approach\n\n**Approach:** Sound' "$round3" +two_rounds +run +expect "round 3: incremental since round 2" '[[ $rc == 0 && $(jq -r ".round, .mode, .previous_head_sha" <<<"$record" | paste -sd, -) == "3,incremental,h2" ]] && grep -q "mode: incremental since round 2" "$stub/out.log"' +expect "round 3: the code prompt has the three rules" 'grep -q "## Previous round" "$stub/code-prompt.txt" && grep -q "Check every earlier finding" "$stub/code-prompt.txt" && grep -q "Review what changed since round 2 in full" "$stub/code-prompt.txt" && grep -q "Outside what changed, raise only Critical" "$stub/code-prompt.txt"' +expect "round 3: the diff since the previous head" 'grep -qF "git diff --stat h2..aaaa" "$stub/code-prompt.txt" && grep -qF "git diff h2..aaaa" "$stub/code-prompt.txt"' +expect "round 3: the later-round output format" 'grep -q "Fixed since the last round" "$stub/code-prompt.txt" && grep -q "\"id\": \"F3\" or null" "$stub/code-prompt.txt"' +expect "round 3: previous-findings.md lists the open findings first" '[[ $(session_file previous-findings.md | sed -n 1,2p) == "F1 · important · a.js:3 · thing breaks"$'"'"'\n'"'"'"F3 · critical · c.js:9 · data loss" ]]' +expect "round 3: then the fixed ones, to catch a regression" '[[ $(session_file previous-findings.md | sed -n 4,5p) == "Fixed in round 2 (report one only if the problem is back, as open):"$'"'"'\n'"'"'"F2 · minor · b.js:1 · nit" ]]' +expect "round 3: previous-review.md is round 2 without markers" '[[ $(session_file previous-review.md) == *"F3 · \`c.js:9\`"* && $(session_file previous-review.md) != *""; diff --git a/tests/flow.sh b/tests/flow.sh index abb010b..e5b5096 100644 --- a/tests/flow.sh +++ b/tests/flow.sh @@ -609,6 +609,18 @@ for capped in '"findings_dropped":true' '"findings_dropped":false'; do expect "capped marker ($capped): an empty reply does not claim progress over the lost findings" '[[ $(sed -n 4p <<<"$body") == "open blocking: 0 · "* && $body != *"(was 3)"* && $(sed -n 4p <<<"$body") == *"full review (the last record lost its findings to the size cap)" ]]' done +# A later round posted without its marker (no room for it): its Markdown shows only what it re-checked, so reading +# it back gives no findings list, and the next round is full. +setup $'**Approach:** Sound' $'**Ready to merge?** Yes\n\n```json findings\n[]\n```' +add_round '{"schema":1,"source":"model","round":1,"head_sha":"'"$H1"'","base_sha":"'"$B1"'","approach":"sound","ready":"no","code_review":true,"findings":[{"id":"F1","severity":"important","status":"new","first_round":1,"file":"a.js","line":3,"title":"thing breaks"}],"counts":{"open_blocking":1,"critical":0,"important":1,"minor":0}}' $'### Issues\n- round one' +jq -c --arg h "$H2" '. + [{user: {login: "me", type: "User"}, state: "APPROVED", commit_id: $h, + submitted_at: "2026-01-02T00:00:00Z", body: "\n### Round 2 · since round 1\n1 not re-checked · open blocking: 1 (was 1)\n\n### Issues\n\n*(none found)*\n\n**Ready to merge?** Yes"}]' \ + "$stub/rest-reviews.json" >"$stub/r.tmp" && mv "$stub/r.tmp" "$stub/rest-reviews.json" +run +expect "markerless later round: the next round is full and says why" \ + '[[ $rc == 0 && $(jq -r ".round, .mode, .mode_reason" <<<"$record" | paste -sd, -) == "3,full,the last round has no record of its findings" ]] && grep -q "mode: full (the last round has no record of its findings)" "$stub/out.log"' +expect "markerless later round: no claim of progress over it" '[[ $(sed -n 4p <<<"$body") == "open blocking: 0 · "* && $body != *"(was "* ]]' + setup $'### Approach\n\n**Approach:** Sound' "$round3" add_round '{"schema":1,"source":"model","round":1,"head_sha":"'"$H1"'","base_sha":"'"$B1"'","approach":"rethink","ready":"unknown","code_review":false,"findings":[],"counts":{"open_blocking":null}}' $'### Approach\n\n**Approach:** Rethink' run diff --git a/tests/records.sh b/tests/records.sh index 0248f85..62baedf 100644 --- a/tests/records.sh +++ b/tests/records.sh @@ -543,6 +543,43 @@ check "backfill after backfill: IDs continue, previous head kept" \ "$(jq -r '[.findings[0].id == "F\($n + 1)", .previous_head_sha == $h] | all' --argjson n "$(jq '[.findings[].id[1:] | tonumber] | max' <<<"$rec")" \ --arg h "$(jq -r .head_sha <<<"$rec")" <<<"$rec2")" true check "backfill bullets: ready" "$(jq -r .ready <<<"$rec")" yes-with-fixes +has_list() { jq -L "$LIB_DIR" 'include "records"; has_findings_list' <<<"$1"; } +check "backfill: a standalone review keeps its findings list" "$(has_list "$rec")" true + +# A later round posted without its marker: its record carried an Important finding the body does not show (omitted +# by the model, so not re-checked). Read back from the Markdown alone, it must not look like a verified empty list. +prev1=$(jq -nc '{round: 1, head_sha: "aaa", counts: {open_blocking: 1}, findings: [{id: "F1", severity: "important", + status: "new", first_round: 1, file: "a.ts", line: 1, title: "one"}]}') +r2=$(build_record "$(jq -c '.round = 2 | .mode = "incremental" | .ready = "yes"' <<<"$meta")" \ + '[{"severity":"minor","file":"m.ts","line":2,"title":"Tiny nit"}]' "$prev1") +check "later round without marker: setup, the record carries F1" \ + "$(jq -c '[.counts.open_blocking, .counts.unverified, .last_ids.F]' <<<"$r2")" '[1,1,2]' +later_body() { # : the round 2 body as posted, with a filler paragraph before the Assessment + echo '' + progress_line "$r2" "$prev1" '{"label":"early"}' + printf '\n### Issues\n\n#### 🚨 Critical (Must Fix Before Merge)\n\n*(none found)*\n\n' + printf '#### ⚠️ Important (Should Fix)\n\n*(none found)*\n\n#### 💡 Minor (Nice to Have)\n\n' + printf -- '- **F2 · `m.ts:2`** — Tiny nit.\n\n' + head -c "$1" /dev/zero | tr '\0' x + printf '\n\n### Assessment\n\n**Ready to merge?** Yes\n' +} +filler=$((59776 - $(later_body 1 | jq -Rs length) + 1)) +later_body "$filler" >"$tmp/later-padded.md" +check "later round without marker: setup, a 59,776-character body" "$(jq -Rs length "$tmp/later-padded.md")" 59776 +check "later round without marker: setup, no room for the marker" \ + "$(marker_line <(jq -c . <<<"$r2") "$(tail -n +2 "$tmp/later-padded.md")")" "" +rec=$(backfill_record "$(jq -n --rawfile body "$tmp/later-padded.md" '{body: $body, commit_id: "bbb", + submitted_at: "2026-01-03T00:00:00Z", user: {login: "rev"}, state: "APPROVED"}')" "$prev1" 2 "$pr") +check "later round without marker: no findings list" "$(has_list "$rec")" false +check "later round without marker: the blocking count of the progress line, IDs covered" \ + "$(jq -c '[.findings_dropped, .counts.open_blocking, .ready_overridden, .last_ids.F, has("findings")]' <<<"$rec")" \ + '[true,1,true,2,false]' +check "later round without marker: the next round carries nothing it cannot know" \ + "$(build_record "$meta2" '[]' "$rec" | jq -c '[.findings, .counts.open_blocking]')" '[[],0]' +printf '### Issues\n\n- **`a.ts:1`** — x\n\n
Later (1)\n\n- **[e.ts:5]** — slow.\n\n
\n' \ + >"$tmp/folded.md" +rec=$(backfill_record "$(jq -n --rawfile body "$tmp/folded.md" '{body: $body}')" null 2 "$pr") +check "later round without marker: a folded Later section is enough" "$(has_list "$rec")" false finished=true exit "$fail" From 825768018cab11ab1db7b95a4d50ecf8c53afa3a Mon Sep 17 00:00:00 2001 From: david catalan Date: Thu, 26 Nov 2026 21:01:54 +0100 Subject: [PATCH 22/33] Review the whole PR when its base is not a descendant of the previous base --- lib/delta.sh | 30 ++++++++++++++++++++---------- tests/delta.sh | 26 ++++++++++++++++++++++++++ tests/flow.sh | 15 ++++++++++++--- 3 files changed, 58 insertions(+), 13 deletions(-) diff --git a/lib/delta.sh b/lib/delta.sh index 11bc3d7..f719580 100644 --- a/lib/delta.sh +++ b/lib/delta.sh @@ -7,8 +7,8 @@ # author merged the base branch in since, the diff starts from the previous head merged onto the new # base (a tree, in the extra field `from`), so what the base brought is left out. # rebased the previous head is not an ancestor (rebase or force-push): a `git range-diff` of the two ranges. -# full anything else, with a short human reason, a base merge with conflicts included. The round then -# reviews the whole PR. +# full anything else, with a short human reason: a base merge with conflicts, or a base that is not a +# descendant of the previous base (the PR was retargeted). The round then reviews the whole PR. # The previous head and base come from a marker on the PR, which anyone can edit: they count only as full object IDs # (40 or 64 hex digits), checked before git sees them. A name (HEAD, main), a short SHA or an option is `full`. # The four SHA fields are full SHAs when the checkout has the commit, else as given ("" when unknown); changed_files @@ -37,6 +37,24 @@ pick_delta() { # fi delta_connect "$repo" "$prev_head" "$head" + # The PR's base moved backward or sideways (it was retargeted, say from a parent branch to main): commits that were + # base last round are in the PR now, and no diff of the PR's own commits shows them. Only the whole PR does. + if [[ -n "$prev_base" ]]; then + if sha=$(delta_find "$repo" "$prev_base"); then prev_base=$sha; else + delta_json full "previous base ${prev_base:0:12} not found after fetch" "$prev_head" "$prev_base" "$head" "$base" + return 0 + fi + if sha=$(delta_resolve "$repo" "$base"); then base=$sha; else + delta_json full "base ${base:0:12} not in the checkout" "$prev_head" "$prev_base" "$head" "$base" + return 0 + fi + delta_connect "$repo" "$prev_base" "$base" + if ! git -C "$repo" merge-base --is-ancestor "$prev_base" "$base" >/dev/null 2>&1; then + delta_json full "the PR's base changed" "$prev_head" "$prev_base" "$head" "$base" + return 0 + fi + fi + if git -C "$repo" merge-base --is-ancestor "$prev_head" "$head" >/dev/null 2>&1; then # The author merged the base branch in since: a plain diff would show everything the base brought. Compare with # the previous head merged onto the new base instead, which leaves the author's own changes. @@ -67,14 +85,6 @@ pick_delta() { # delta_json full "previous base unknown" "$prev_head" "$prev_base" "$head" "$base" return 0 fi - if sha=$(delta_find "$repo" "$prev_base"); then prev_base=$sha; else - delta_json full "previous base ${prev_base:0:12} not found after fetch" "$prev_head" "$prev_base" "$head" "$base" - return 0 - fi - if sha=$(delta_resolve "$repo" "$base"); then base=$sha; else - delta_json full "base ${base:0:12} not in the checkout" "$prev_head" "$prev_base" "$head" "$base" - return 0 - fi old="${prev_base}..${prev_head}" new="${base}..${head}" # Try it before handing it to the reviewer: a range it cannot walk (shallow history, odd ranges) fails here. diff --git a/tests/delta.sh b/tests/delta.sh index ddea321..e64a17b 100644 --- a/tests/delta.sh +++ b/tests/delta.sh @@ -158,6 +158,32 @@ expect "base merged in with conflicts: a range-diff would not" \ files=$(changed_files "$repo" "$out") expect "base merged in with conflicts: no delta files" '[[ -z $files ]]' +# ── full: a stacked PR retargeted from its parent branch to main ───────────── +# Last round the PR targeted parent: its base was parent's tip. Retargeted to main, parent's commit is in the PR now, +# though the previous head is still an ancestor of the head: an incremental diff would show child.txt only. +world +commit m1 "a.txt=$ten" +src checkout --quiet -b parent +commit p1 parent.txt=from-parent +src checkout --quiet -b feature +commit c1 child.txt=one +src push --quiet origin parent +publish +prev_head=$(src rev-parse HEAD) prev_base=$(src rev-parse parent) +commit c2 child.txt=two +publish +repo=$(checkout 50) +head=$(git -C "$repo" rev-parse pr-branch) +base=$(git -C "$repo" merge-base pr-branch origin/main) +expect "retargeted: setup, the PR now holds parent.txt too" \ + '[[ $(git -C "$repo" diff --name-only "$base" "$head" | paste -sd, -) == "child.txt,parent.txt" ]]' +out=$(pick_delta "$repo" "$prev_head" "$prev_base" "$head" "$base") +expect "retargeted: full, and it says why" \ + '[[ $(jq -r .mode,.reason <<<"$out" | paste -sd, -) == "full,the PR'"'"'s base changed" && $(jq -c .commands <<<"$out") == "[]" ]]' +# Retargeted back to parent: the base moved forward from main's m1 to parent's p1, which is fine. +out=$(pick_delta "$repo" "$prev_head" "$base" "$head" "$prev_base") +expect "retargeted: a base that moved forward stays incremental" '[[ $(jq -r .mode <<<"$out") == incremental ]]' + # ── rebased: onto a moved base, with a changed patch ───────────────────────── world commit m1 "a.txt=$ten" c.txt=c1 diff --git a/tests/flow.sh b/tests/flow.sh index e5b5096..c26c1f1 100644 --- a/tests/flow.sh +++ b/tests/flow.sh @@ -20,7 +20,7 @@ setup() { # approach-output code-review-output [discussion-exit-code] [failing-p echo '{"comments":[],"reviews":[]}' >"$stub/discussion.json" echo '[]' >"$stub/rest-reviews.json" echo '[]' >"$stub/rest-comments.json" - rm -f "$stub/git.missing" "$stub/git.rebased" "$stub/git.diff-fails" "$stub/git.far-base" "$stub/git.deepened" + rm -f "$stub/git.missing" "$stub/git.rebased" "$stub/git.retargeted" "$stub/git.diff-fails" "$stub/git.far-base" "$stub/git.deepened" cat >"$stub/bin/gh" <"$stub/bin/git" <<'S' #!/usr/bin/env bash @@ -53,7 +54,9 @@ case "$*" in ;; *rev-parse*) echo aaaa ;; *"fetch "*--deepen*) printf '%s\n' "$*" >>"$s/git.deepened" ;; -*"merge-base --is-ancestor"*) [[ ! -f "$s/git.rebased" ]] ;; +*"merge-base --is-ancestor"*aaaa) [[ ! -f "$s/git.rebased" ]] ;; +*"merge-base --is-ancestor"*bbbb) [[ ! -f "$s/git.retargeted" ]] ;; +*"merge-base --is-ancestor"*) true ;; *merge-base*) if [[ -f "$s/git.far-base" ]] && { [[ ! -f "$s/git.deepened" ]] || grep -qx never "$s/git.far-base"; }; then exit 1; fi echo bbbb @@ -548,6 +551,12 @@ touch "$stub/git.rebased" run expect "rebased: a range-diff of the two versions" '[[ $(jq -r ".mode" <<<"$record") == rebased ]] && grep -qF "git range-diff $B1..$H2 bbbb..aaaa" "$stub/code-prompt.txt" && grep -q "The author rebased" "$stub/code-prompt.txt"' +setup $'**Approach:** Sound' "$round3" +two_rounds +touch "$stub/git.retargeted" +run +expect "retargeted: a full round that says why" '[[ $(jq -r ".mode, .mode_reason" <<<"$record" | paste -sd, -) == "full,the PR'"'"'s base changed" ]] && ! grep -q "Outside what changed" "$stub/code-prompt.txt"' + setup $'**Approach:** Sound' "$round3" two_rounds echo "$H2" >"$stub/git.missing" From 68b1497655839de61563bdf87ba912b07df191b6 Mon Sep 17 00:00:00 2001 From: david catalan Date: Thu, 26 Nov 2026 21:03:03 +0100 Subject: [PATCH 23/33] Compare a rebased file's two versions directly when the base left it alone --- lib/delta.sh | 27 ++++++++++++++++++++++----- tests/delta.sh | 30 ++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 5 deletions(-) diff --git a/lib/delta.sh b/lib/delta.sh index f719580..275d96e 100644 --- a/lib/delta.sh +++ b/lib/delta.sh @@ -100,9 +100,10 @@ pick_delta() { # # Prints the paths the delta touched, one per line, sorted and unique: the code that counts as "touched". # incremental the files changed between the previous head (or `from`) and the head. -# rebased the files whose change in the PR differs between the old and the new version (index lines and -# hunk line numbers ignored, so the base moving under an unchanged patch does not count; a binary -# file compares its blob IDs), plus the files the PR newly touches or no longer touches. +# rebased the files whose change in the PR differs between the old and the new version, plus the files the +# PR newly touches or no longer touches. A file the base did not change compares its old and new +# content. One the base changed compares the two patches, index lines and hunk line numbers ignored, +# so the base moving under an unchanged patch does not count (a binary file compares its blob IDs). # full nothing. # Fails when git cannot list or compare the files: an unknown scope is not an empty one. changed_files() { # @@ -127,8 +128,16 @@ changed_files() { # names=$(printf '%s\n%s\n' "$names" "$old" | LC_ALL=C sort -u) while IFS= read -r path; do [[ -n "$path" ]] || continue - old=$(delta_file_patch "$repo" "$prev_base" "$prev_head" "$path") || return 1 - new=$(delta_file_patch "$repo" "$base" "$head" "$path") || return 1 + old=$(delta_blob "$repo" "$prev_base" "$path") || return 1 + new=$(delta_blob "$repo" "$base" "$path") || return 1 + if [[ "$old" == "$new" ]]; then + # The base did not touch the file: the two versions of the PR's file say it all, where a moved hunk counts. + old=$(delta_blob "$repo" "$prev_head" "$path") || return 1 + new=$(delta_blob "$repo" "$head" "$path") || return 1 + else + old=$(delta_file_patch "$repo" "$prev_base" "$prev_head" "$path") || return 1 + new=$(delta_file_patch "$repo" "$base" "$head" "$path") || return 1 + fi [[ "$old" == "$new" ]] || printf '%s\n' "$path" done <<<"$names" ;; @@ -191,6 +200,14 @@ delta_shallow() { # [[ "$(git -C "$1" rev-parse --is-shallow-repository 2>/dev/null)" == true ]] } +# A file's mode, type and blob ID in a commit, or nothing when the commit does not have it. Fails when git does. +delta_blob() { # + ( + set -o pipefail + git --literal-pathspecs -C "$1" ls-tree -z --full-tree "$2" -- "$3" | tr '\0' '\n' | awk -F '\t' 'NR == 1 { print $1 }' + ) +} + # One file's patch between two commits, without what moves when the base moves: the `index` line (blob SHAs) and # the line numbers of the `@@` hunk headers. A binary file's patch is one "Binary files … differ" line whatever the # content, so it gets its `git diff --raw` line instead (modes and full blob IDs). Literal pathspec: a path is a diff --git a/tests/delta.sh b/tests/delta.sh index e64a17b..f91ba83 100644 --- a/tests/delta.sh +++ b/tests/delta.sh @@ -261,6 +261,36 @@ expect "binary: setup, rebased and git sees binary files" \ files=$(changed_files "$repo" "$out") expect "binary: changed_files lists the changed binary, not the same one" '[[ $files == logo.gif ]]' +# ── rebased: an edit moved between two identical blocks ────────────────────── +# Without line numbers the two patches are the same text, though the change moved. The base never touched the file, +# so the old and new versions of the file decide. +block=$(printf ' x = 1\n y = 2\n z = 3\n w = 4\n v = 5') +blocks() { # : four copies of the block, z = 3 changed in one of them + local i + for i in 1 2 3 4; do + if [[ $i == "$1" ]]; then printf '%s\n' "${block/z = 3/z = 4}"; else printf '%s\n' "$block"; fi + done +} +world +commit m1 "x.txt=$(blocks 0)" +src checkout --quiet -b feature +commit f1 "x.txt=$(blocks 2)" +publish +prev_head=$(src rev-parse HEAD) prev_base=$(src rev-parse main) +src checkout --quiet main +commit m2 c.txt=from-main +src checkout --quiet -B feature main +commit f1 "x.txt=$(blocks 3)" +publish +repo=$(checkout 50) +head=$(git -C "$repo" rev-parse pr-branch) +base=$(git -C "$repo" merge-base pr-branch origin/main) +out=$(pick_delta "$repo" "$prev_head" "$prev_base" "$head" "$base") +expect "moved edit: setup, rebased, and the patches differ only in their line numbers" \ + '[[ $(jq -r .mode <<<"$out") == rebased && "$(delta_file_patch "$repo" "$prev_base" "$prev_head" x.txt)" == "$(delta_file_patch "$repo" "$base" "$head" x.txt)" ]]' +files=$(changed_files "$repo" "$out") +expect "moved edit: changed_files lists the file" '[[ $files == x.txt ]]' + # ── changed_files: git failing is an error, not an empty list ──────────────── cat >"$tmp/bin/git" < Date: Thu, 26 Nov 2026 21:08:40 +0100 Subject: [PATCH 24/33] Recover a carried finding's file and title from earlier rounds, and test three rounds read back from GitHub --- gh-pr-review | 6 +++-- lib/records.jq | 15 ++++++++++++ tests/flow.sh | 62 ++++++++++++++++++++++++++++++++++++++++++------ tests/records.sh | 13 ++++++++++ 4 files changed, 87 insertions(+), 9 deletions(-) diff --git a/gh-pr-review b/gh-pr-review index c4fde62..264d451 100755 --- a/gh-pr-review +++ b/gh-pr-review @@ -547,10 +547,12 @@ round_body() { # # counts as regressed instead of looking new. if [[ "$PREVIOUS_OPEN" -gt 0 || "$PREVIOUS_FIXED" -gt 0 ]]; then round_body "$BASE_ROUND" >"$CONTEXT_DIR/previous-review.md" + # A detail the last marker left out (its review did not show it) comes back from an earlier round, by ID. finding_lines() { # - jq -r ".findings[] | objects | select($1) + jq -r -L "$LIB_DIR" --argjson base "$FINDINGS_BASE" "include \"records\"; . as \$history | \$base + | recover_details(\$history) | .findings[] | objects | select($1) | [.id, .severity, ((.file // \"(no file)\") + (if .line then \":\\(.line)\" else \"\" end)), (.title // \"\")] - | join(\" · \")" <<<"$FINDINGS_BASE" + | join(\" · \")" <<<"$RECORDS" } { if [[ "$PREVIOUS_OPEN" -gt 0 ]]; then diff --git a/lib/records.jq b/lib/records.jq index 25ce10f..229fed0 100644 --- a/lib/records.jq +++ b/lib/records.jq @@ -196,6 +196,21 @@ def _track($findings; $prev; $round; $mode; $floor; $delta_files): | .out), later: .later, last_ids: {F: .f, L: .l}}; +# A record whose findings miss a file, line or title (a marker leaves out what its review does not show, such as a +# finding the model left out and the round carried) gets them back from the newest record in $history (an array of +# records, oldest first) that has the same ID with that detail. +def recover_details($history): + ([($history // [])[] | objects | (.findings // [])[]? | objects | select(.id | type == "string")] | reverse) + as $earlier + | if (.findings | type) == "array" then + .findings |= map(if type == "object" and (.id | type == "string") then + .id as $id | [$earlier[] | select(.id == $id)] as $same + | .file = (.file // first($same[] | .file | strings) // null) + | .line = (.line // first($same[] | .line | numbers) // null) + | .title = (.title // first($same[] | .title | strings) // null) + else . end) + else . end; + # The ID floor of a history (an array of records): the highest F and L numbers any round used. Older markers have # no last_ids: their findings and later IDs seed it. def id_floor: map(objects) | {F: (map(_last_number("F")) | max // 0), L: (map(_last_number("L")) | max // 0)}; diff --git a/tests/flow.sh b/tests/flow.sh index c26c1f1..079e0b7 100644 --- a/tests/flow.sh +++ b/tests/flow.sh @@ -20,7 +20,7 @@ setup() { # approach-output code-review-output [discussion-exit-code] [failing-p echo '{"comments":[],"reviews":[]}' >"$stub/discussion.json" echo '[]' >"$stub/rest-reviews.json" echo '[]' >"$stub/rest-comments.json" - rm -f "$stub/git.missing" "$stub/git.rebased" "$stub/git.retargeted" "$stub/git.diff-fails" "$stub/git.far-base" "$stub/git.deepened" + rm -f "$stub/git.head" "$stub/git.base" "$stub/git.missing" "$stub/git.rebased" "$stub/git.retargeted" "$stub/git.diff-fails" "$stub/git.far-base" "$stub/git.deepened" cat >"$stub/bin/gh" <"$stub/posted.args" ;; esac S - # git: HEAD is aaaa and the merge-base bbbb. Any other SHA resolves to itself, unless listed in git.missing. The + # git: HEAD is aaaa and the merge-base bbbb (or the SHAs in git.head and git.base). Any other SHA resolves to + # itself, unless listed in git.missing. The # previous head is an ancestor of the head unless git.rebased exists, and the previous base one of the base unless # git.retargeted exists. git.diff-fails makes `git diff` fail. # git.far-base: no merge-base until a `fetch --deepen` (logged in git.deepened); "never": not even then. cat >"$stub/bin/git" <<'S' #!/usr/bin/env bash s=$(cd "$(dirname "$0")/.." && pwd) +H=$(cat "$s/git.head" 2>/dev/null || echo aaaa) B=$(cat "$s/git.base" 2>/dev/null || echo bbbb) for a in "$@"; do [[ "$a" == clone ]] && mkdir -p "${@: -1}"; done case "$*" in *"rev-parse --is-shallow-repository"*) echo false ;; @@ -49,17 +51,17 @@ case "$*" in sha=${*: -1} sha=${sha%^\{commit\}} if grep -qx -- "$sha" "$s/git.missing" 2>/dev/null; then exit 1; fi - [[ $sha == HEAD ]] && sha=aaaa + [[ $sha == HEAD ]] && sha=$H echo "$sha" ;; -*rev-parse*) echo aaaa ;; +*rev-parse*) echo "$H" ;; *"fetch "*--deepen*) printf '%s\n' "$*" >>"$s/git.deepened" ;; -*"merge-base --is-ancestor"*aaaa) [[ ! -f "$s/git.rebased" ]] ;; -*"merge-base --is-ancestor"*bbbb) [[ ! -f "$s/git.retargeted" ]] ;; +*"merge-base --is-ancestor"*" $H") [[ ! -f "$s/git.rebased" ]] ;; +*"merge-base --is-ancestor"*" $B") [[ ! -f "$s/git.retargeted" ]] ;; *"merge-base --is-ancestor"*) true ;; *merge-base*) if [[ -f "$s/git.far-base" ]] && { [[ ! -f "$s/git.deepened" ]] || grep -qx never "$s/git.far-base"; }; then exit 1; fi - echo bbbb + echo "$B" ;; *"diff --name-only"*) [[ ! -f "$s/git.diff-fails" ]] || exit 1 @@ -654,5 +656,51 @@ expect "round trip: the decision sees round 1 on this head" \ bash "$root/gh-pr-review" https://github.com/o/r/pull/1 --check --json >"$stub/check.json" 2>"$stub/out.log") && rc=0 || rc=$? expect "round trip: --check exits 5 on the same head" \ '[[ $rc == 5 && $(jq -r ".decision, .next_round, .series[0]" "$stub/check.json" | paste -sd, -) == "nothing-new,2,1" ]]' + +# ── producer to consumer, three code-review rounds: each round reads the last one back as GitHub returns it +H3=$(printf 'c3%.0s' {1..20}) +post_back() { # : the body just posted, as a submitted review in the REST reviews and the discussion + jq -c --arg body "$body" --arg c "$1" --arg d "$2" '. + [{id: (length + 1), user: {login: "me", type: "User"}, + state: "COMMENTED", commit_id: $c, submitted_at: $d, body: $body}]' "$stub/rest-reviews.json" >"$stub/r.tmp" && + mv "$stub/r.tmp" "$stub/rest-reviews.json" + jq -c --arg body "$body" --arg d "$2" '.reviews += [{author: {login: "me"}, state: "COMMENTED", submittedAt: $d, + body: $body}]' "$stub/discussion.json" >"$stub/d.tmp" && mv "$stub/d.tmp" "$stub/discussion.json" +} +r1=$'### Issues\n#### 🚨 Critical (Must Fix Before Merge)\n- **`c.js:9` — data loss.**\n' +r1+=$'#### ⚠️ Important (Should Fix)\n- **`a.js:3` — thing breaks.**\n\n**Ready to merge?** No\n\n' +r1+=$'```json findings\n[{"severity":"important","file":"a.js","line":3,"title":"thing breaks"},' +r1+=$'{"severity":"critical","file":"c.js","line":9,"title":"data loss"}]\n```' +setup $'**Approach:** Sound' "$r1" +echo "$H1" >"$stub/git.head" +echo "$B1" >"$stub/git.base" +run +expect "three rounds: round 1 posted" '[[ $rc == 0 && $(jq -r "[.findings[] | .id + \":\" + .file] | join(\" \")" <<<"$record") == "F1:a.js F2:c.js" ]]' +post_back "$H1" 2026-06-01T10:00:00Z +# Round 2 leaves F1 out of both the block and the Markdown: carried, not re-checked, and its file and title appear +# nowhere in the body, so the marker drops them. F2's title is not shown word for word either. +r2=$'### Issues\n#### 🚨 Critical (Must Fix Before Merge)\n- **F2 · `c.js:9`** — still loses data.\n' +r2+=$'#### ⚠️ Important (Should Fix)\n*(none found)*\n#### 💡 Minor (Nice to Have)\n- **`d.js:4`** — typo in a comment.\n\n' +r2+=$'**Ready to merge?** No\n\n```json findings\n[{"id":"F2","status":"open","severity":"critical","file":"c.js","line":9,' +r2+=$'"title":"data loss","in_delta":false,"later":false},{"id":null,"status":"new","severity":"minor","file":"d.js",' +r2+=$'"line":4,"title":"typo in a comment","in_delta":true,"later":false}]\n```' +printf '%s' "$r2" >"$stub/review.out" +echo "$H2" >"$stub/git.head" +run +expect "three rounds: round 2 incremental from round 1's head" \ + '[[ $rc == 0 && $(jq -r ".round, .mode, .previous_head_sha" <<<"$record" | paste -sd, -) == "2,incremental,$H1" ]] && grep -qF "git diff --stat $H1..$H2" "$stub/code-prompt.txt"' +expect "three rounds: round 2 carries F1, and its marker drops what the body does not show" \ + '[[ $(jq -r "[.findings[] | .id + \":\" + .status + (if .unverified then \"?\" else \"\" end)] | join(\" \")" <<<"$record") == "F2:open F3:new F1:open?" ]] && + [[ $(sed -n 2p <<<"$body" | sed "s/^$//" | jq -c "[.findings[] | select(.id != \"F3\") | [.id, .file, .title]]") == "[[\"F2\",\"c.js\",null],[\"F1\",null,null]]" ]]' +post_back "$H2" 2026-06-02T10:00:00Z +printf '%s' $'**Ready to merge?** No\n\n```json findings\n[]\n```' >"$stub/review.out" +echo "$H3" >"$stub/git.head" +run +expect "three rounds: round 3 compares with round 2's head" \ + '[[ $rc == 0 && $(jq -r ".round, .mode, .previous_head_sha" <<<"$record" | paste -sd, -) == "3,incremental,$H2" ]] && + grep -qF "git diff --stat $H2..$H3" "$stub/code-prompt.txt" && grep -qF "git diff $H2..$H3" "$stub/code-prompt.txt"' +expect "three rounds: every carried finding is identifiable, details recovered from round 1" \ + '[[ $(session_file previous-findings.md) == "F2 · critical · c.js:9 · data loss"$'"'"'\n'"'"'"F3 · minor · d.js:4 · typo in a comment"$'"'"'\n'"'"'"F1 · important · a.js:3 · thing breaks" ]]' +expect "three rounds: both blockers still count" '[[ $(jq -r ".counts.open_blocking, .counts.unverified" <<<"$record" | paste -sd, -) == "2,3" ]]' + finished=true exit "$fail" diff --git a/tests/records.sh b/tests/records.sh index 62baedf..50e0a19 100644 --- a/tests/records.sh +++ b/tests/records.sh @@ -329,6 +329,19 @@ check "id_floor: the next ID comes after the floor, not the previous record" \ "$(build_record "$(jq -c '.id_floor = {F: 9, L: 4}' <<<"$meta")" "$one" "$r1" | jq -c '[.findings[0].id, .last_ids]')" '["F10",{"F":10,"L":4}]' +# ── recover_details ───────────────────────────────────────────────────────── +# Round 3's marker left out F1's file and title and F2's title; earlier rounds had them. The newest one wins. +history=$(jq -nc '[{findings: [{id: "F1", file: "old.ts", line: 1, title: "first title"}, {id: "F2", title: "two"}]}, + {findings: [{id: "F1", file: "a.ts", line: 3, title: "thing breaks"}]}, + {findings_dropped: true}, + {findings: [{id: "F1", severity: "important", line: 7}, {id: "F2", file: "c.ts", line: 9}, {id: "F9"}]}]') +check "recover_details: missing details from the newest earlier round with the ID" \ + "$(jq -c -L "$LIB_DIR" 'include "records"; .[-1] | recover_details($h) | [.findings[] | [.id, .file, .line, .title]]' \ + --argjson h "$history" <<<"$history")" \ + '[["F1","a.ts",7,"thing breaks"],["F2","c.ts",9,"two"],["F9",null,null,null]]' +check "recover_details: no history, no change" \ + "$(jq -c -L "$LIB_DIR" 'include "records"; recover_details(null) | .findings' <<<'{"findings":[{"id":"F1"}]}')" '[{"id":"F1","file":null,"line":null,"title":null}]' + ok_block() { # [known ids] jq -c -L "$LIB_DIR" --argjson ids "${2:-[]}" 'include "records"; map(findings_block_ok($ids))' <<<"$1" } From 38079a28baba961b0f2d1c295f9e94b01c761ab2 Mon Sep 17 00:00:00 2001 From: david catalan Date: Thu, 26 Nov 2026 21:09:14 +0100 Subject: [PATCH 25/33] Wrap the long lines of records.jq --- lib/records.jq | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/lib/records.jq b/lib/records.jq index 229fed0..2e4214e 100644 --- a/lib/records.jq +++ b/lib/records.jq @@ -145,14 +145,14 @@ def known_ids: if has_findings_list then [.findings[] | objects | .id | strings] # The findings of a code-review round, from the model's array and the previous record's findings. # Out: {findings, later, last_ids}. Known IDs keep their ID and first round, with the model's status (open on an # ID last marked fixed is regressed; declined without a reason, or a status outside fixed, open, declined, is open -# and unverified, with the previous severity). Entries without an ID, or with an ID the previous record doesn't have, are new: F, or L -# when Later applies: later true on an Important or Minor finding outside the delta, in an incremental or rebased -# round ($mode), with a file that is not in $delta_files (the files the delta touched). A Critical one, one marked in -# the delta, one in a touched file, one without a file, any when the file list is unknown (not an array) and any in -# a full round stay findings. The first entry for an -# ID wins. Previous open, new or regressed findings the reply leaves out are carried, unverified. A -# previous record without its findings list (has_findings_list) knows no ID and carries nothing. New IDs start after -# $floor ({F, L}: the highest numbers in the whole history) and the previous record's. +# and unverified, with the previous severity). Entries without an ID, or with an ID the previous record doesn't +# have, are new: F, or L when Later applies: later true on an Important or Minor finding outside the delta, in +# an incremental or rebased round ($mode), with a file that is not in $delta_files (the files the delta touched). A +# Critical one, one marked in the delta, one in a touched file, one without a file, any when the file list is unknown +# (not an array) and any in a full round stay findings. The first entry for an ID wins. Previous open, new or +# regressed findings the reply leaves out are carried, unverified. A previous record without its findings list +# (has_findings_list) knows no ID and carries nothing. New IDs start after $floor ({F, L}: the highest numbers in the +# whole history) and the previous record's. def _track($findings; $prev; $round; $mode; $floor; $delta_files): (if $prev | has_findings_list then $prev.findings | map(objects | select(.id | type == "string")) else [] end) as $old @@ -172,7 +172,8 @@ def _track($findings; $prev; $round; $mode; $floor; $delta_files): else {status: "open", unverified: true} end) as $s | .findings += [{id: $e.id, # A rejected status update (unverified) keeps the previous severity: it cannot downgrade a blocker. - severity: (if ($e.severity | _severity_ok) and ($s.unverified | not) then $e.severity else $p.severity end), + severity: (if ($e.severity | _severity_ok) and ($s.unverified | not) then $e.severity + else $p.severity end), status: $s.status, first_round: ($p.first_round // $round), in_delta: $e.in_delta, file: ($e.file // $p.file), line: ($e.line // $p.line), title: ($e.title // $p.title)} + (if $s.unverified then {unverified: true} else {} end)] @@ -332,7 +333,8 @@ def backfill_record($review; $prev; $round; $pr; $approach; $ready; $code_review last_ids: {F: ($prev | _last_number("F")), L: ($prev | _last_number("L"))}} end)) | if $later_round | not then . else ([$body | parse_findings[] | .id | strings | capture("^F(?\\d+)$").n | tonumber] | max // 0) as $shown - | ([$body | split("\n")[0:8][] | capture("open blocking: (?\\d+)").n | tonumber] | first // null) as $blocking + | ([$body | split("\n")[0:8][] | capture("open blocking: (?\\d+)").n | tonumber] | first // null) + as $blocking | del(.findings, .later) | .findings_dropped = true | .last_ids.F = ([.last_ids.F, $shown] | max) | if $blocking == null then . From 0b415ba96a1a0ecebc661cfa2e6001aac2f7b148 Mon Sep 17 00:00:00 2001 From: david catalan Date: Thu, 26 Nov 2026 21:11:17 +0100 Subject: [PATCH 26/33] Give marker_line a record file in the markerless-round test, as Bash 3.2 closes a process substitution --- tests/records.sh | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tests/records.sh b/tests/records.sh index 50e0a19..f399d45 100644 --- a/tests/records.sh +++ b/tests/records.sh @@ -579,8 +579,11 @@ later_body() { # : the round 2 body as posted, with a filler para filler=$((59776 - $(later_body 1 | jq -Rs length) + 1)) later_body "$filler" >"$tmp/later-padded.md" check "later round without marker: setup, a 59,776-character body" "$(jq -Rs length "$tmp/later-padded.md")" 59776 -check "later round without marker: setup, no room for the marker" \ - "$(marker_line <(jq -c . <<<"$r2") "$(tail -n +2 "$tmp/later-padded.md")")" "" +printf '%s\n' "$r2" >"$tmp/r2.json" +tail -n +2 "$tmp/later-padded.md" >"$tmp/r2-review.md" +check "later round without marker: setup, the marker fits a short review" \ + "$(marker_line "$tmp/r2.json" "$(head -c 300 "$tmp/r2-review.md")" | cut -c 1-24)" "$//" | jq -c "[.findings[] | select(.id != \"F3\") | [.id, .file, .title]]") == "[[\"F2\",\"c.js\",null],[\"F1\",null,null]]" ]]' post_back "$H2" 2026-06-02T10:00:00Z +# An outsider's generated review between rounds 1 and 2: no round, so it must not shift round 2 out of place as the +# previous review. +outsider=$'\n### Issues\n- outsider text' +jq -c --arg body "$outsider" '. + [{id: (length + 1), user: {login: "eve", type: "User"}, author_association: "NONE", + state: "COMMENTED", commit_id: "'"$H1"'", submitted_at: "2026-06-01T12:00:00Z", body: $body}]' \ + "$stub/rest-reviews.json" >"$stub/r.tmp" && mv "$stub/r.tmp" "$stub/rest-reviews.json" +jq -c --arg body "$outsider" '.reviews += [{author: {login: "eve"}, authorAssociation: "NONE", state: "COMMENTED", + submittedAt: "2026-06-01T12:00:00Z", body: $body}]' "$stub/discussion.json" >"$stub/d.tmp" && + mv "$stub/d.tmp" "$stub/discussion.json" printf '%s' $'**Ready to merge?** No\n\n```json findings\n[]\n```' >"$stub/review.out" echo "$H3" >"$stub/heads" run +expect "three rounds: an outsider's generated review is not the previous review" \ + '[[ $(session_file previous-review.md) == *"still loses data"* && $(session_file previous-review.md) != *"outsider text"* ]]' expect "three rounds: round 3 compares with round 2's head" \ '[[ $rc == 0 && $(jq -r ".round, .mode, .previous_head_sha" <<<"$record" | paste -sd, -) == "3,incremental,$H2" ]] && grep -qF "git diff --stat $H2..$H3" "$stub/code-prompt.txt" && grep -qF "git diff $H2..$H3" "$stub/code-prompt.txt"' From c701fa77351a63aad073ce4fd0db328704b3b94c Mon Sep 17 00:00:00 2001 From: david catalan Date: Sat, 28 Nov 2026 08:43:58 +0100 Subject: [PATCH 29/33] Approve automatically only on a record that shows zero open blockers --- README.md | 2 +- gh-pr-review | 33 ++++++++++++++++++++++----------- tests/flow.sh | 31 +++++++++++++++++++++++++++++++ 3 files changed, 54 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 6702cea..4fa5aea 100644 --- a/README.md +++ b/README.md @@ -58,7 +58,7 @@ Inside a repo clone, a bare number works: `gh pr-review 42`. | `--no-post` | posting on (with confirm) | Print the review only | | `--instructions ` | none | Extra guidance for both passes, for example `"Focus on db/; skip style nits"`. For a file: `--instructions "$(cat notes.md)"`. The tool does not post them, and the reviewer is told not to quote them, but the review can still reflect them: use `--no-post` to preview a review shaped by sensitive notes | | `--skip-approach` | off | Skip the maintainer's approach pass and run the code review only, for example when the approach is already agreed | -| `--decision ` | from verdict | `comment`, `approve`, `request-changes`. Unset: an approach verdict of Rethink → request-changes. Otherwise the last "Ready to merge?" line decides: No → request-changes, a bare Yes → approve (comment when the round's blocker count is unknown, as for a code review read from its Markdown with no severity section; a valid empty findings block is a known zero, and approves), anything else (Yes with fixes, Yes, with fixes, …) → comment. On your own PR it is always comment. `-y` submits the decision without asking | +| `--decision ` | from verdict | `comment`, `approve`, `request-changes`. Unset: an approach verdict of Rethink → request-changes. Otherwise the last "Ready to merge?" line decides: No → request-changes, a bare Yes → approve only when the round's record shows 0 open blockers (comment when blockers are open, or when the count is unknown, as for a code review read from its Markdown with no severity section; a valid empty findings block is a known zero, and approves), anything else (Yes with fixes, Yes, with fixes, …) → comment. On your own PR it is always comment. `-y` submits the decision without asking | | `-y`, `--yes` | off | Skip the confirmations. A loop-check stop then exits with code 3, and no new commits with code 5, instead of asking | | `--check` | off | Run only the loop check (see below) and exit 0, 3 or 5. No clone, no model call | | `--json` | off | With `--check`: print the decision as JSON on stdout | diff --git a/gh-pr-review b/gh-pr-review index 736799d..9240674 100755 --- a/gh-pr-review +++ b/gh-pr-review @@ -1326,11 +1326,22 @@ review_landed() { | length == 1' <<<"$json" >/dev/null 2>&1 } -# True only when the record file shows how many blockers its round has: a numeric counts.open_blocking. An unknown -# count (a code review read from its Markdown without a severity section), a missing file or a failed read is false: -# an automatic approve needs this to succeed. -known_blockers() { # - jq -e '(.counts.open_blocking | type) == "number"' "$1" >/dev/null 2>&1 +# True only when a successful read of the record file shows that its round has no open blocker: counts.open_blocking +# is the number 0. A nonzero count, an unknown one (a code review read from its Markdown without a severity section), +# a missing file or a failed read is false: an automatic approve needs this to succeed. +no_blockers() { # + jq -e '(.counts.open_blocking | type) == "number" and .counts.open_blocking == 0' "$1" >/dev/null 2>&1 +} + +# Why an automatic approve became a comment, after no_blockers failed on the record file: its open blockers when it +# shows a number other than 0, else an unknown count (as when the check itself failed). +blockers_note() { # + local n + if n=$(jq -er '.counts.open_blocking | numbers | select(. != 0)' "$1" 2>/dev/null); then + echo "But ${n} blocking findings are still open: posting as comment, not approve." + else + echo "The review's blockers are unknown: posting as comment, not approve." + fi } # The final record: round.json as posted, with DECISION, built and checked here. Only a record that passes is @@ -1372,13 +1383,13 @@ if [[ "$POST_TO_PR" == "true" ]] && [[ -n "$REVIEW" ]]; then DECISION=comment echo " but $(jq -r '.counts.open_blocking' "$RECORD_FILE") blocking findings are still open → ${DECISION}" # An approval says the findings were checked; without a record nothing can show that, so only comment. Nor - # can a record whose blocker count is unknown (known_blockers): that round is not ready. + # can a record that does not show a blocker count of 0 (no_blockers), whatever the lookup above said. elif [[ "$DECISION" == approve && -z "${RECORD_FILE:-}" ]]; then DECISION=comment echo "No round record for this review: posting as comment, not approve." - elif [[ "$DECISION" == approve ]] && ! known_blockers "$RECORD_FILE"; then + elif [[ "$DECISION" == approve ]] && ! no_blockers "$RECORD_FILE"; then DECISION=comment - echo "The review's blockers are unknown: posting as comment, not approve." + blockers_note "$RECORD_FILE" fi fi @@ -1448,16 +1459,16 @@ if [[ "$POST_TO_PR" == "true" ]] && [[ -n "$REVIEW" ]]; then posted_record # Right before posting: an automatic approve (the verdict's, or its default taken at the prompt) needs a posted - # record that shows its blocker count (known_blockers); otherwise it posts as comment, and the record is built + # record that shows a blocker count of 0 (no_blockers); otherwise it posts as comment, and the record is built # again with that decision, so the event, the marker and round.json all say comment. An approve someone chose # stays. if [[ "$DECISION" == approve && "$AUTO_DECISION" == true ]]; then if [[ -z "$POSTED_RECORD" ]]; then DECISION=comment echo "No round record for this review: posting as comment, not approve." - elif ! known_blockers "$POSTED_RECORD"; then + elif ! no_blockers "$POSTED_RECORD"; then DECISION=comment - echo "The review's blockers are unknown: posting as comment, not approve." + blockers_note "$POSTED_RECORD" posted_record fi fi diff --git a/tests/flow.sh b/tests/flow.sh index 9253575..9adeb4f 100644 --- a/tests/flow.sh +++ b/tests/flow.sh @@ -1115,6 +1115,37 @@ expect "only the pre-post blocker-count check fails: event, marker and round.jso $(jq -c "[.decision, .preview]" <<<"$record") == "[\"comment\",false]" ]] && grep -q "blockers are unknown: posting as comment" "$stub/out.log"' rm "$stub/bin/jq" +# An automatic approve needs a successful check that the count is 0, not only a number. Round 3 says Yes with F3, a +# Critical, still open (1 blocker, ready_overridden). The lookup of ready_overridden fails: the count check still +# comments. When the first count check wrongly passes too, the final one, on the posted record, does. An approve +# chosen stays. +yes_open=$'**Ready to merge?** Yes\n\n```json findings\n[{"id":"F3","status":"open","severity":"critical","file":"c.js","line":9,"title":"data loss","in_delta":false,"later":false},{"id":"F1","status":"fixed","in_delta":false,"later":false}]\n```' +setup $'**Approach:** Sound' "$yes_open" +two_rounds +cat >"$stub/bin/jq" <"$stub/bin/jq" <$//" | jq -c "[.decision, .counts.open_blocking]") == "[\"comment\",1]" && + $(jq -c "[.decision, .preview]" <<<"$record") == "[\"comment\",false]" ]]' +rm "$stub/bin/jq" +run --decision approve +expect "1 open blocker, approve chosen: stays an approval" '[[ $rc == 0 && $flag == --approve ]]' # ── the review is bound to the commit it read setup $'**Approach:** Sound' "$clean" From 78a526946f4c2ece59aa3f3c48466238e7ce5a1e Mon Sep 17 00:00:00 2001 From: david catalan Date: Sat, 28 Nov 2026 08:45:08 +0100 Subject: [PATCH 30/33] Review the whole PR when the previous round's base is unknown --- README.md | 5 +++-- lib/delta.sh | 42 +++++++++++++++++++++--------------------- tests/delta.sh | 9 ++++++++- 3 files changed, 32 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index 4fa5aea..b3dd640 100644 --- a/README.md +++ b/README.md @@ -237,8 +237,9 @@ its number reserved. When the comparison is not safe, the round is a full review, and it says why: the previous head is gone (a force-push), the base branch was merged in with -conflicts, git cannot list the changed files, or the last round's record lost -its findings to GitHub's size cap. `--full` asks for one, for example after a +conflicts, the PR's base changed (a retarget), the last round's base is unknown +(a review read back from its Markdown), git cannot list the changed files, or +the last round's record lost its findings to GitHub's size cap. `--full` asks for one, for example after a rewrite. ## Loop check diff --git a/lib/delta.sh b/lib/delta.sh index 275d96e..5c0a984 100644 --- a/lib/delta.sh +++ b/lib/delta.sh @@ -7,8 +7,10 @@ # author merged the base branch in since, the diff starts from the previous head merged onto the new # base (a tree, in the extra field `from`), so what the base brought is left out. # rebased the previous head is not an ancestor (rebase or force-push): a `git range-diff` of the two ranges. -# full anything else, with a short human reason: a base merge with conflicts, or a base that is not a -# descendant of the previous base (the PR was retargeted). The round then reviews the whole PR. +# full anything else, with a short human reason: a base merge with conflicts, a base that is not a +# descendant of the previous base (the PR was retargeted), or a previous base that is unknown (a round +# read back from its Markdown has none): what the last round reviewed can't be established, so a +# retarget can't be ruled out. The round then reviews the whole PR. # The previous head and base come from a marker on the PR, which anyone can edit: they count only as full object IDs # (40 or 64 hex digits), checked before git sees them. A name (HEAD, main), a short SHA or an option is `full`. # The four SHA fields are full SHAs when the checkout has the commit, else as given ("" when unknown); changed_files @@ -23,7 +25,11 @@ pick_delta() { # delta_json full "previous head is not a full commit ID" "$prev_head" "$prev_base" "$head" "$base" return 0 fi - if [[ -n "$prev_base" ]] && ! delta_object_id "$prev_base"; then + if [[ -z "$prev_base" ]]; then + delta_json full "the previous round's base is unknown" "$prev_head" "$prev_base" "$head" "$base" + return 0 + fi + if ! delta_object_id "$prev_base"; then delta_json full "previous base is not a full commit ID" "$prev_head" "$prev_base" "$head" "$base" return 0 fi @@ -39,20 +45,18 @@ pick_delta() { # # The PR's base moved backward or sideways (it was retargeted, say from a parent branch to main): commits that were # base last round are in the PR now, and no diff of the PR's own commits shows them. Only the whole PR does. - if [[ -n "$prev_base" ]]; then - if sha=$(delta_find "$repo" "$prev_base"); then prev_base=$sha; else - delta_json full "previous base ${prev_base:0:12} not found after fetch" "$prev_head" "$prev_base" "$head" "$base" - return 0 - fi - if sha=$(delta_resolve "$repo" "$base"); then base=$sha; else - delta_json full "base ${base:0:12} not in the checkout" "$prev_head" "$prev_base" "$head" "$base" - return 0 - fi - delta_connect "$repo" "$prev_base" "$base" - if ! git -C "$repo" merge-base --is-ancestor "$prev_base" "$base" >/dev/null 2>&1; then - delta_json full "the PR's base changed" "$prev_head" "$prev_base" "$head" "$base" - return 0 - fi + if sha=$(delta_find "$repo" "$prev_base"); then prev_base=$sha; else + delta_json full "previous base ${prev_base:0:12} not found after fetch" "$prev_head" "$prev_base" "$head" "$base" + return 0 + fi + if sha=$(delta_resolve "$repo" "$base"); then base=$sha; else + delta_json full "base ${base:0:12} not in the checkout" "$prev_head" "$prev_base" "$head" "$base" + return 0 + fi + delta_connect "$repo" "$prev_base" "$base" + if ! git -C "$repo" merge-base --is-ancestor "$prev_base" "$base" >/dev/null 2>&1; then + delta_json full "the PR's base changed" "$prev_head" "$prev_base" "$head" "$base" + return 0 fi if git -C "$repo" merge-base --is-ancestor "$prev_head" "$head" >/dev/null 2>&1; then @@ -81,10 +85,6 @@ pick_delta() { # fi # Rebase or force-push: a plain diff would mix in what the base branch did, so compare the two ranges instead. - if [[ -z "$prev_base" ]]; then - delta_json full "previous base unknown" "$prev_head" "$prev_base" "$head" "$base" - return 0 - fi old="${prev_base}..${prev_head}" new="${base}..${head}" # Try it before handing it to the reviewer: a range it cannot walk (shallow history, odd ranges) fails here. diff --git a/tests/delta.sh b/tests/delta.sh index f91ba83..e5cf691 100644 --- a/tests/delta.sh +++ b/tests/delta.sh @@ -183,6 +183,13 @@ expect "retargeted: full, and it says why" \ # Retargeted back to parent: the base moved forward from main's m1 to parent's p1, which is fine. out=$(pick_delta "$repo" "$prev_head" "$base" "$head" "$prev_base") expect "retargeted: a base that moved forward stays incremental" '[[ $(jq -r .mode <<<"$out") == incremental ]]' +# The same retarget after a round with no known base (a review read back from its Markdown): nothing shows what +# that round reviewed, so the whole PR is in scope, parent.txt included, not an incremental diff of child.txt. +out=$(pick_delta "$repo" "$prev_head" "" "$head" "$base") +expect "previous base unknown: full, and it says why" \ + '[[ $(jq -r .mode,.reason <<<"$out" | paste -sd, -) == "full,the previous round'"'"'s base is unknown" && $(jq -c .commands <<<"$out") == "[]" ]]' +files=$(changed_files "$repo" "$out") +expect "previous base unknown: no delta files, the whole PR is reviewed" '[[ -z $files ]]' # ── rebased: onto a moved base, with a changed patch ───────────────────────── world @@ -215,7 +222,7 @@ expect "rebased: changed_files, the changed, new and dropped files only" \ '[[ $files == "b.txt"$'"'\n'"'"d.txt"$'"'\n'"'"g.txt" ]]' out=$(pick_delta "$repo" "$prev_head" "" "$head" "$base") expect "rebased: no previous base is full" \ - '[[ $(jq -r .mode,.reason <<<"$out" | paste -sd, -) == "full,previous base unknown" ]]' + '[[ $(jq -r .mode,.reason <<<"$out" | paste -sd, -) == "full,the previous round'"'"'s base is unknown" ]]' # A git that fails on range-diff only: the round falls back to full and says why. real_git=$(command -v git) mkdir -p "$tmp/bin" From d16d8c9a3ce6a052171a436ea509341334d76ad4 Mon Sep 17 00:00:00 2001 From: david catalan Date: Sat, 28 Nov 2026 08:46:27 +0100 Subject: [PATCH 31/33] List every PR file the base changed in a rebased round --- lib/delta.sh | 23 +++-------------------- tests/delta.sh | 35 ++++++++++++++++++++++++++++++----- 2 files changed, 33 insertions(+), 25 deletions(-) diff --git a/lib/delta.sh b/lib/delta.sh index 5c0a984..9dff6a4 100644 --- a/lib/delta.sh +++ b/lib/delta.sh @@ -102,8 +102,9 @@ pick_delta() { # # incremental the files changed between the previous head (or `from`) and the head. # rebased the files whose change in the PR differs between the old and the new version, plus the files the # PR newly touches or no longer touches. A file the base did not change compares its old and new -# content. One the base changed compares the two patches, index lines and hunk line numbers ignored, -# so the base moving under an unchanged patch does not count (a binary file compares its blob IDs). +# content. A file the base changed between the previous base and the new one is always listed: the +# PR's edit can move inside it in ways no comparison of the two patches can tell from the base's own +# changes, so it counts as touched. # full nothing. # Fails when git cannot list or compare the files: an unknown scope is not an empty one. changed_files() { # @@ -134,9 +135,6 @@ changed_files() { # # The base did not touch the file: the two versions of the PR's file say it all, where a moved hunk counts. old=$(delta_blob "$repo" "$prev_head" "$path") || return 1 new=$(delta_blob "$repo" "$head" "$path") || return 1 - else - old=$(delta_file_patch "$repo" "$prev_base" "$prev_head" "$path") || return 1 - new=$(delta_file_patch "$repo" "$base" "$head" "$path") || return 1 fi [[ "$old" == "$new" ]] || printf '%s\n' "$path" done <<<"$names" @@ -207,18 +205,3 @@ delta_blob() { # git --literal-pathspecs -C "$1" ls-tree -z --full-tree "$2" -- "$3" | tr '\0' '\n' | awk -F '\t' 'NR == 1 { print $1 }' ) } - -# One file's patch between two commits, without what moves when the base moves: the `index` line (blob SHAs) and -# the line numbers of the `@@` hunk headers. A binary file's patch is one "Binary files … differ" line whatever the -# content, so it gets its `git diff --raw` line instead (modes and full blob IDs). Literal pathspec: a path is a -# name, never a glob. Fails when git does. -delta_file_patch() { # - local patch - patch=$(git --literal-pathspecs -C "$1" diff --no-color --no-ext-diff --no-textconv --no-renames "$2" "$3" -- "$4") || - return 1 - if grep -q '^Binary files ' <<<"$patch"; then - git --literal-pathspecs -C "$1" diff --raw --no-abbrev --no-renames "$2" "$3" -- "$4" - else - sed -e '/^index /d' -e 's/^@@ -[0-9,]* +[0-9,]* @@/@@ @@/' <<<"$patch" - fi -} diff --git a/tests/delta.sh b/tests/delta.sh index e5cf691..5df888e 100644 --- a/tests/delta.sh +++ b/tests/delta.sh @@ -3,7 +3,7 @@ # A bare repo plays GitHub: `https://h/o/r.git` points at it through GIT_CONFIG_COUNT, so nothing uses the network. # HOME, XDG_CONFIG_HOME, the global and the system git config are isolated from the user's. # Conditions are single-quoted on purpose: expect() evals them after each case sets out (and files). -# SC2034: GIT_AUTH is read by the sourced pick_delta. SC2329: has runs inside expect's eval. +# SC2034: GIT_AUTH is read by the sourced pick_delta. SC2329: has and patch_text run inside expect's eval. # SC2030/SC2031: the cases that break the remote URL do it in a subshell on purpose. # shellcheck disable=SC2016,SC2030,SC2031,SC2034,SC2329 set -euo pipefail @@ -69,6 +69,8 @@ checkout() { # : the review checkout, as gh-pr-review clones it. Prints i } has() { git -C "$1" cat-file -e "${2}^{commit}" 2>/dev/null; } # +# One file's patch between two commits, without its index line and its hunk line numbers. +patch_text() { git -C "$1" diff --no-color "$2" "$3" -- "$4" | sed -e '/^index /d' -e 's/^@@ -[0-9,]* +[0-9,]* @@/@@ @@/'; } # ten=$(printf 'line %s\n' 1 2 3 4 5 6 7 8 9 10) ten_changed=${ten/line 8/LINE 8} @@ -199,7 +201,8 @@ commit f1 "a.txt=$ten_changed" commit f2 b.txt=old g.txt=dropped-later publish prev_head=$(src rev-parse HEAD) prev_base=$(src rev-parse main) -# The base moves: lines above the PR's change in a.txt (new hunk line numbers, same patch), and c.txt. +# The base moves: lines above the PR's change in a.txt (new hunk line numbers, same patch), and c.txt. c.txt is not +# the PR's; a.txt is listed all the same: a file the base changed too counts as touched. src checkout --quiet main commit m2 "a.txt=top"$'\n'"$ten" c.txt=c2 # The author redoes the PR on the new base: same a.txt change, b.txt changed, d.txt new, g.txt gone. @@ -218,8 +221,8 @@ expect "rebased: range-diff of the two ranges" \ '[[ $(jq -c .commands <<<"$out") == "[\"git range-diff $prev_base..$prev_head $base..$head\"]" ]]' expect "rebased: the old head was fetched" 'has "$repo" "$prev_head"' files=$(changed_files "$repo" "$out") -expect "rebased: changed_files, the changed, new and dropped files only" \ - '[[ $files == "b.txt"$'"'\n'"'"d.txt"$'"'\n'"'"g.txt" ]]' +expect "rebased: changed_files, the changed, new and dropped files, and a.txt, which the base changed too" \ + '[[ $files == "a.txt"$'"'\n'"'"b.txt"$'"'\n'"'"d.txt"$'"'\n'"'"g.txt" ]]' out=$(pick_delta "$repo" "$prev_head" "" "$head" "$base") expect "rebased: no previous base is full" \ '[[ $(jq -r .mode,.reason <<<"$out" | paste -sd, -) == "full,the previous round'"'"'s base is unknown" ]]' @@ -294,10 +297,32 @@ head=$(git -C "$repo" rev-parse pr-branch) base=$(git -C "$repo" merge-base pr-branch origin/main) out=$(pick_delta "$repo" "$prev_head" "$prev_base" "$head" "$base") expect "moved edit: setup, rebased, and the patches differ only in their line numbers" \ - '[[ $(jq -r .mode <<<"$out") == rebased && "$(delta_file_patch "$repo" "$prev_base" "$prev_head" x.txt)" == "$(delta_file_patch "$repo" "$base" "$head" x.txt)" ]]' + '[[ $(jq -r .mode <<<"$out") == rebased && "$(patch_text "$repo" "$prev_base" "$prev_head" x.txt)" == "$(patch_text "$repo" "$base" "$head" x.txt)" ]]' files=$(changed_files "$repo" "$out") expect "moved edit: changed_files lists the file" '[[ $files == x.txt ]]' +# The same moved edit, with an unrelated line the base added at the end of x.txt: the base changed the file, so it is +# listed whatever its two patches look like. +world +commit m1 "x.txt=$(blocks 0)" +src checkout --quiet -b feature +commit f1 "x.txt=$(blocks 2)" +publish +prev_head=$(src rev-parse HEAD) prev_base=$(src rev-parse main) +src checkout --quiet main +commit m2 "x.txt=$(blocks 0)"$'\n'"upstream line" +src checkout --quiet -B feature main +commit f1 "x.txt=$(blocks 3)"$'\n'"upstream line" +publish +repo=$(checkout 50) +head=$(git -C "$repo" rev-parse pr-branch) +base=$(git -C "$repo" merge-base pr-branch origin/main) +out=$(pick_delta "$repo" "$prev_head" "$prev_base" "$head" "$base") +expect "moved edit, the base changed the file: setup, rebased, the patches differ only in their line numbers" \ + '[[ $(jq -r .mode <<<"$out") == rebased && "$(patch_text "$repo" "$prev_base" "$prev_head" x.txt)" == "$(patch_text "$repo" "$base" "$head" x.txt)" ]]' +files=$(changed_files "$repo" "$out") +expect "moved edit, the base changed the file: changed_files lists the file" '[[ $files == x.txt ]]' + # ── changed_files: git failing is an error, not an empty list ──────────────── cat >"$tmp/bin/git" < Date: Sat, 28 Nov 2026 08:50:05 +0100 Subject: [PATCH 32/33] Keep a promoted Later finding that the Markdown shows in its Later list --- README.md | 8 ++++++-- gh-pr-review | 26 ++++++++++++++++++-------- lib/records.jq | 46 ++++++++++++++++++++++++++++++++++++---------- tests/flow.sh | 24 ++++++++++++++++++++++++ tests/records.sh | 30 ++++++++++++++++++++++++++---- 5 files changed, 110 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index b3dd640..759ab3e 100644 --- a/README.md +++ b/README.md @@ -170,8 +170,12 @@ next round: stop · churning · approach-stuck too-big · Settle the approach be The Markdown is the cross-check for the model's findings block: it is parsed before the block is accepted, and a block that leaves out a blocker the Markdown -shows, or has one where it says none, is rejected. It is also the source when -the block is rejected, and for a review without a usable marker. The reader +shows, or has one where it says none, is rejected. A Later item that can't be +Later (it is in what changed) is kept as a finding: the Markdown showing it in +its Later list instead of its severity section is no contradiction. The +Markdown is also the source when the block is rejected, and for a review +without a usable marker; when the rejected block had such an item, the +Markdown can't count it, so the round's blocker count is unknown. The reader follows the format the tool asks the model for (the `### Issues` section with severity headings, findings as list items, the folded Fixed and Later lists, each `
` tag on its own line), and is best effort for other Markdown: diff --git a/gh-pr-review b/gh-pr-review index 9240674..2da1e05 100755 --- a/gh-pr-review +++ b/gh-pr-review @@ -1172,7 +1172,7 @@ fi # It runs under `if !`, where errexit is off: every step checks its own status, and the record is checked before use. THIS_LOOP="" write_round_record() { - local findings parsed source=model code_review=true no_sections=false approach ready meta history delta_files + local findings parsed source=model code_review=true unknown_counts=false approach ready meta history delta_files local tmp="${RECORD_FILE}.tmp" # The files the delta touched (null in a full round): the record builder and the block checks decide Later with them. delta_files=$(jq -cn --argjson delta "$DELTA" --arg files "$DELTA_FILES" \ @@ -1192,12 +1192,14 @@ write_round_record() { # value, an array: anything else ("[] [ … ]") is read from the Markdown. So is a block with an open finding of a # severity the Markdown says it has none of ("*(none found)*"). Its entries are checked as the record will store # them (stored_findings, the builder's own decision): a declined one without a reason, or a Later one that is not - # honoured, is open; one stored as fixed, declined or Later is not. + # honoured, is open; one stored as fixed, declined or Later is not. A Later one that is not honoured (promoted) + # and that the Markdown shows in its Later list is no contradiction: the block keeps it as a finding. if jq -se -L "$LIB_DIR" --slurpfile parsed "$parsed" --rawfile md "$REVIEW_BODY_FILE" \ --argjson base "$FINDINGS_BASE" --argjson delta "$DELTA" --argjson files "$delta_files" \ 'include "records"; length == 1 and (.[0] | findings_block_ok($base | known_ids) and (later_files($delta.mode; $files) as $later | block_covers_markdown($parsed[0]; $base; $later) - and block_respects_empty($md | empty_severities; $base; $later)))' "$FINDINGS_FILE" >/dev/null 2>&1; then + and block_respects_empty($md | empty_severities; $md | later_items; $base; $later)))' \ + "$FINDINGS_FILE" >/dev/null 2>&1; then findings=$(jq -cs '.[0]' "$FINDINGS_FILE") || return 1 else if [[ -s "$FINDINGS_FILE" ]]; then @@ -1205,9 +1207,17 @@ write_round_record() { fi source=parsed findings=$(jq -c . "$parsed") || findings='[]' - # No severity section in the Markdown: the blockers are unknown (null counts), as when read back. - no_sections=$(jq -Rs -L "$LIB_DIR" 'include "records"; _sections | length == 0' "$REVIEW_BODY_FILE") || - no_sections=true + # No severity section in the Markdown: the blockers are unknown (null counts), as when read back. So are they + # when the rejected block promoted a Later entry to a finding: the parser leaves the Later list out, so the + # Markdown's count would miss it. + unknown_counts=$(jq -Rs -L "$LIB_DIR" 'include "records"; _sections | length == 0' "$REVIEW_BODY_FILE") || + unknown_counts=true + if [[ "$unknown_counts" != true ]] && jq -se -L "$LIB_DIR" --argjson base "$FINDINGS_BASE" \ + --argjson delta "$DELTA" --argjson files "$delta_files" \ + 'include "records"; length == 1 and (.[0] | block_promotes($base; later_files($delta.mode; $files)))' \ + "$FINDINGS_FILE" >/dev/null 2>&1; then + unknown_counts=true + fi fi rm -f "$parsed" fi @@ -1221,14 +1231,14 @@ write_round_record() { --arg base "$BASE_SHA" --arg head "$HEAD_SHA" --argjson previous "$PREVIOUS_RECORD" \ --argjson findings_base "$FINDINGS_BASE" --argjson delta "$DELTA" \ --arg approach "$approach" --arg ready "$ready" --argjson code_review "$code_review" \ - --argjson id_floor "$ID_FLOOR" --argjson delta_files "$delta_files" --argjson no_sections "$no_sections" \ + --argjson id_floor "$ID_FLOOR" --argjson delta_files "$delta_files" --argjson unknown_counts "$unknown_counts" \ '{source: $source, pr: {host: $host, owner: $owner, repo: $repo, number: $number}, round: $round, mode: $delta.mode, mode_reason: ($delta.reason // null), delta_files: $delta_files, reviewer: (if $reviewer == "" then null else $reviewer end), model: $model, base_sha: $base, head_sha: $head, previous_head_sha: ($findings_base.head_sha? // $previous.head_sha? // null), approach: $approach, ready: $ready, decision: null, posted_at: null, - code_review: $code_review, preview: true, id_floor: $id_floor, no_sections: $no_sections}') || return 1 + code_review: $code_review, preview: true, id_floor: $id_floor, unknown_counts: $unknown_counts}') || return 1 if ! build_record "$meta" "$findings" "$FINDINGS_BASE" >"$tmp" || ! jq -e 'type == "object" and (.round | type == "number") and (.counts | type == "object")' \ "$tmp" >/dev/null 2>&1; then diff --git a/lib/records.jq b/lib/records.jq index 6bcdfa3..1f6a70f 100644 --- a/lib/records.jq +++ b/lib/records.jq @@ -314,17 +314,44 @@ def entry_outcome($known; $later_files): {status: "later", severity, file, line, title} else {status: "new", severity, file, line, title} end; +# stored_findings, each entry the model marked Later but entry_outcome stores as a finding (a Later that does not +# apply: a file the delta touched, a Critical, no file, a full round) with promoted: true. +def _stored($base; $later_files): + _known_findings($base) as $known + | [_block_entries[] | .later as $later | entry_outcome($known; $later_files) + | select(. != null and .status != "later") + | if $later and .status == "new" then . + {promoted: true} else . end]; + # A model's findings block as the record stores it (entry_outcome), for the block checks (block_covers_markdown, # block_respects_empty), so they never disagree with the record about which entries are open: its findings, without # the Later ones (the record keeps those apart). $base: the last code review (null in round 1: every entry is new). # The findings a round carries (left out of the block, unverified) are not part of it. -def stored_findings($base; $later_files): - _known_findings($base) as $known - | [_block_entries[] | entry_outcome($known; $later_files) | select(. != null and .status != "later")]; +def stored_findings($base; $later_files): _stored($base; $later_files) | map(del(.promoted)); + +# True when the model's block ($base, $later_files: as for stored_findings) has an entry it marked Later that the +# record stores as a finding (promoted, _stored). When such a block is rejected, the Markdown, which shows that +# finding in its Later list, gives no blocker count: the round's count is unknown. +def block_promotes($base; $later_files): any(_stored($base; $later_files)[]; .promoted == true); + +# The items of a review's folded Later list (_lines), as the reader sees them: {file, line, line_end}. +def later_items: + [_lines[] | select(.f == "later") | .l | select(test("^([-*+]|\\d+\\.)\\s+\\S") and (_none_line | not)) + | _finding(null) | {file, line, line_end}]; + +# True for a promoted entry the Markdown shows in its Later list ($items: later_items): an item in the same file, at +# the same line (or a range holding it) when both have one. +def _shown_later($items): + .file as $f | .line as $l + | ($f | type) == "string" + and any($items[]; .file == $f and (.line == null or $l == null or .line == $l + or (.line_end != null and $l >= .line and $l <= .line_end))); # False when the model's block ($base, $later_files: as for stored_findings) has an open entry, as stored, of a -# severity the Markdown says it has none of ($empty: empty_severities): the round is parsed instead. -def block_respects_empty($empty; $base; $later_files): stored_findings($base; $later_files) | _respects_empty($empty); +# severity the Markdown says it has none of ($empty: empty_severities): the round is parsed instead. A promoted entry +# the Markdown shows in its Later list ($later: later_items) is no contradiction: the record keeps it as a finding. +def block_respects_empty($empty; $later; $base; $later_files): + _stored($base; $later_files) | map(select((.promoted == true and _shown_later($later)) | not)) + | _respects_empty($empty); # True when the model's block ($base, $later_files: as for stored_findings), as stored, shows every blocker the # review's Markdown does ($parsed: parse_findings of the posted body; _covers_markdown). Otherwise the round is parsed @@ -431,9 +458,8 @@ def reconcile_record($earlier; $position): # round.json from the run's facts, the findings (block or parser) and the previous record (or null). Round 1 # findings carry no id or status: all are new. From round 2, see _track. New findings are numbered after # $meta.id_floor ({F, L}, from id_floor over the whole history) and the previous record. $meta.delta_files: the paths -# the delta touched (changed_files), for Later. A code review read from a Markdown with no severity section -# ($meta.no_sections: true) does not say how many blockers it has: its counts are null, so its blocking is unknown, -# never 0. +# the delta touched (changed_files), for Later. A code review whose blocker count is unknown ($meta.unknown_counts: +# true; one read from a Markdown with no severity section, say) gets null counts, so its blocking is unknown, never 0. def build_record($meta; $findings; $prev): ($meta.code_review != false) as $code_review | ([($meta.id_floor // {}).F | numbers] + [($prev // {}) | _last_number("F")] | max) as $last @@ -445,7 +471,7 @@ def build_record($meta; $findings; $prev): | def open: select(.status == "open" or .status == "new" or .status == "regressed"); def count($s): [$items[] | open | select(.severity == $s)] | length; def status($s): [$items[] | select(.status == $s)] | length; - (if $code_review and $meta.no_sections != true then + (if $code_review and $meta.unknown_counts != true then {open_blocking: (count("critical") + count("important")), critical: count("critical"), important: count("important"), minor: count("minor"), new: status("new"), fixed: status("fixed"), declined: status("declined"), regressed: status("regressed"), later: ($t.later | length), @@ -549,7 +575,7 @@ def backfill_record($review; $prev; $round; $pr; $approach; $ready; $code_review | .[$review.state | strings] // null), posted_at: $review.submitted_at, code_review: $code_review, - no_sections: ($body | code_review_part | _sections | length == 0) + unknown_counts: ($body | code_review_part | _sections | length == 0) }; (if $code_review then $body | code_review_part | parse_findings else [] end); # An old review says nothing about which earlier findings were fixed: the previous record only numbers the IDs, # so a backfilled round counts what it found, never carries the round before. diff --git a/tests/flow.sh b/tests/flow.sh index 9adeb4f..4db826a 100644 --- a/tests/flow.sh +++ b/tests/flow.sh @@ -818,6 +818,30 @@ expect "only fixed before: the comeback keeps its ID, regressed and blocking" '[ run --full expect "only fixed before, --full: still watches them" '[[ $(jq -r .mode <<<"$record") == full ]] && grep -q "Check whether an earlier finding came back" "$stub/code-prompt.txt"' +# Round 3 shows an Important for d.js in its Later list only, and its block marks it Later; d.js is in the delta, so +# the record keeps it as a finding. The empty Important section does not reject the block: the Later list shows it. +# The record has 1 blocker, and the Yes posts as comment. A Later item that does not show the entry (another file or +# line) rejects the block: the Markdown leaves the Later list out of its count, so the count is unknown: comment too. +later_promoted() { # + local md=$'### Issues\n#### 🚨 Critical (Must Fix Before Merge)\n*(none found)*\n#### ⚠️ Important (Should Fix)\n*(none found)*\n' + md+=$'#### 💡 Minor (Nice to Have)\n*(none found)*\n\n
Later (1)\n\n' + md+="- **\`$1\`** — retry loop has no bound."$'\n\n
\n\n**Ready to merge?** Yes\n\n```json findings\n' + md+=$'[{"id":null,"status":"new","severity":"important","file":"d.js","line":2,"title":"retry loop has no bound","in_delta":false,"later":true}]\n```' + setup $'**Approach:** Sound' "$md" + fixed_only + run +} +later_promoted d.js:2 +expect "a Later entry in a touched file, shown in the Later list only: the block is used, 1 blocker, comment" \ + '[[ $rc == 0 && $flag == --comment && $(session_file delta-files.txt) == d.js && + $(jq -c "[.source, .counts.open_blocking, .counts.important, (.later | length), (.findings[] | select(.file == \"d.js\") | .status)]" <<<"$record") == "[\"model\",1,1,0,\"new\"]" ]]' +for elsewhere in e.js:2 d.js:40; do + later_promoted "$elsewhere" + expect "a Later entry in a touched file, the Later list shows $elsewhere: parsed, unknown count, comment" \ + '[[ $rc == 0 && $flag == --comment && $(jq -c "[.source, .counts.open_blocking]" <<<"$record") == "[\"parsed\",null]" ]] && + grep -q "blockers are unknown: posting as comment" "$stub/out.log"' +done + # A marker cut to fit the size cap: the counts survive, the findings do not. Nothing can be re-checked by ID, so the # round reviews the whole PR, as a first code review. for capped in '"findings_dropped":true' '"findings_dropped":false'; do diff --git a/tests/records.sh b/tests/records.sh index d61276f..ae44b66 100644 --- a/tests/records.sh +++ b/tests/records.sh @@ -489,7 +489,7 @@ check "parse_findings: an indented Issues heading and an indented closing headin check "parse_findings: 4 spaces are no heading" \ "$(printf '### Issues\n#### Minor\n- a\n ### Notes\n- b\n' | jq -c -Rs -L "$LIB_DIR" 'include "records"; parse_findings | map(.title)')" '["a","b"]' respects() { # round 1 block -> block_respects_empty, judged as stored - jq -c -n -L "$LIB_DIR" --argjson b "$1" 'include "records"; $b | block_respects_empty(["critical"]; null; null)' + jq -c -n -L "$LIB_DIR" --argjson b "$1" 'include "records"; $b | block_respects_empty(["critical"]; []; null; null)' } check "block_respects_empty: an open Critical where the Markdown has none" "$(respects '[{"severity":"Critical","title":"x"}]')" false check "block_respects_empty: round 1 fixed, declined and later Criticals are stored as new: open" \ @@ -500,7 +500,7 @@ check "block_respects_empty: other severities are fine" "$(respects '[{"severity # entries are judged open. fixed_crit='[{"severity":"critical","status":"fixed","file":"a.go","line":10},{"severity":"critical","status":"declined"}]' check "block_*: fixed and declined entries from the model's block are judged open" \ - "$(jq -c -n -L "$LIB_DIR" --argjson b "$fixed_crit" 'include "records"; $b | [block_respects_empty(["critical"]; null; null), block_covers_markdown([{severity: "critical", file: "a.go", line: 10}]; null; null)]')" \ + "$(jq -c -n -L "$LIB_DIR" --argjson b "$fixed_crit" 'include "records"; $b | [block_respects_empty(["critical"]; []; null; null), block_covers_markdown([{severity: "critical", file: "a.go", line: 10}]; null; null)]')" \ '[false,true]' stored=$(build_record '{"round":1,"code_review":true}' '[{"severity":"critical","status":"fixed","later":true,"title":"x"}]' null) check "build_record: stores a fixed, later entry as the checks judge it: new and open" \ @@ -510,10 +510,32 @@ check "build_record: stores a fixed, later entry as the checks judge it: new and for st in '"status":"fixed"' '"status":"declined","reason":"by design"'; do check "block checks: round 3, F1 {$st} is not open" \ "$(jq -c -n -L "$LIB_DIR" --argjson base "$prev2" --argjson b "[{\"id\":\"F1\",$st}]" 'include "records"; - $b | [block_covers_markdown([{severity: "critical"}]; $base; null), block_respects_empty(["critical"]; $base; null)]')" \ + $b | [block_covers_markdown([{severity: "critical"}]; $base; null), block_respects_empty(["critical"]; []; $base; null)]')" \ '[false,true]' done +# Round 3 on prev2, delta t.ts: an Important marked Later in t.ts is promoted to a finding. Under an empty Important +# section, the Later list showing it (same file, the same line or a range holding it, or no line on either side) is +# no contradiction; one that shows another file or line is. +promoted='[{"severity":"important","title":"x","file":"t.ts","line":7,"later":true}]' +later_md() { printf '### Issues\n#### Important\n*(none found)*\n\n
Later (1)\n\n- **`%s`** — x.\n\n
\n' "$1"; } +respects_later() { # -> block_respects_empty for the promoted entry + later_md "$1" | jq -c -Rs -L "$LIB_DIR" --argjson b "$promoted" --argjson base "$prev2" --argjson meta "$meta2" 'include "records"; + . as $md | $b | block_respects_empty($md | empty_severities; $md | later_items; $base; later_files($meta.mode; $meta.delta_files))' +} +check "later_items: the Later list's items, with a range's end" \ + "$(later_md 't.ts:5–9' | jq -c -Rs -L "$LIB_DIR" 'include "records"; later_items')" '[{"file":"t.ts","line":5,"line_end":9}]' +check "block_respects_empty: a promoted entry the Later list shows (t.ts:7, t.ts:5–9, t.ts) is no contradiction" \ + "$(respects_later t.ts:7),$(respects_later 't.ts:5–9'),$(respects_later t.ts)" true,true,true +check "block_respects_empty: a promoted entry the Later list does not show (t.ts:8, u.ts:7) is one" \ + "$(respects_later t.ts:8),$(respects_later u.ts:7)" false,false +check "block_promotes: a Later entry in a touched file, not one outside it, nor a status-only earlier ID" \ + "$(jq -c -n -L "$LIB_DIR" --argjson base "$prev2" --argjson meta "$meta2" 'include "records"; + later_files($meta.mode; $meta.delta_files) as $l + | [([{severity: "important", title: "x", file: "t.ts", later: true}] | block_promotes($base; $l)), + ([{severity: "important", title: "x", file: "z.ts", later: true}] | block_promotes($base; $l)), + ([{id: "F1", status: "open", later: true}] | block_promotes($base; $l))]')" '[true,false,false]' + # ── entry_outcome: one decision for the record builder and the block checks ──────────────────────────────── # Round 3 on prev2 (F1 Critical open, a.ts:1), incremental, delta t.ts: stored_findings says what build_record stores. judged() { # -> [status, severity] per stored entry, then the record's [status, severity] per block entry @@ -734,7 +756,7 @@ check "progress: full without a reason" "$(progress_line "$(jq -c '.mode_reason check "progress: no previous record, nothing" "$(progress_line "$rec" null "$dec")" "" # A later round parsed from a Markdown with no severity section: its counts are null, so the line says unknown, and # the reader takes no blocker count from it. -rec=$(build_record "$(jq -c '.no_sections = true' <<<"$meta2")" '[]' "$prev2") +rec=$(build_record "$(jq -c '.unknown_counts = true' <<<"$meta2")" '[]' "$prev2") unknown_line=$(progress_line "$rec" "$prev2" '{"label":"unknown"}') check "progress: no severity section, open blocking unknown, never 0" \ "$(tail -n 1 <<<"$unknown_line")" "3 not re-checked · open blocking: unknown (was 3) · loop: unknown" From 86210e48c0f5bd215a9681370636d389f503b16a Mon Sep 17 00:00:00 2001 From: david catalan Date: Sat, 28 Nov 2026 08:59:44 +0100 Subject: [PATCH 33/33] Mark a later round whose record failed, and read its count back as unknown --- README.md | 4 +++- gh-pr-review | 16 ++++++++++++++++ lib/records.jq | 11 +++++++++-- lib/rounds.sh | 6 +++++- tests/flow.sh | 32 ++++++++++++++++++++++++++++++++ tests/records.sh | 11 +++++++++++ 6 files changed, 76 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 759ab3e..936e6a5 100644 --- a/README.md +++ b/README.md @@ -243,7 +243,9 @@ When the comparison is not safe, the round is a full review, and it says why: the previous head is gone (a force-push), the base branch was merged in with conflicts, the PR's base changed (a retarget), the last round's base is unknown (a review read back from its Markdown), git cannot list the changed files, or -the last round's record lost its findings to GitHub's size cap. `--full` asks for one, for example after a +the last round's record lost its findings to GitHub's size cap or could not be +built. A later round whose record could not be built still posts a minimal +marker that says so: read back, its blocker count is unknown, never 0. `--full` asks for one, for example after a rewrite. ## Loop check diff --git a/gh-pr-review b/gh-pr-review index 2da1e05..5d0366c 100755 --- a/gh-pr-review +++ b/gh-pr-review @@ -1257,9 +1257,22 @@ write_round_record() { fi rm -f "$tmp" } +# Without a record, round 2 and later still post a minimal marker (FALLBACK_RECORD): this is a later round, its +# findings list is missing and its blocker count unknown (null), with the history's last IDs. Its Markdown may leave +# out the blockers it carried, and a reader would otherwise take it for a first review: the next round then builds on +# an empty baseline. Read back, the round has null counts and no findings list (marker_counts_unknown), so the next +# round is full. +FALLBACK_RECORD="" if ! write_round_record; then echo "Warning: could not write the round record; the review is posted without it." >&2 RECORD_FILE="" + if [[ "$ROUND" -gt 1 ]]; then + FALLBACK_RECORD="${SESSION_DIR}/round-fallback.json" + jq -n --argjson round "$ROUND" --arg ids "$ID_FLOOR" '{schema: 1, round: $round, findings_dropped: true} + + ($ids | fromjson? // null | if type == "object" then {last_ids: .} else {} end) + + {counts: {open_blocking: null, critical: null, important: null, minor: null}}' \ + >"$FALLBACK_RECORD" 2>/dev/null || FALLBACK_RECORD="" + fi fi # Round 2 and later open with a progress line, counted from the record. It replaces the loop line, and carries the @@ -1494,6 +1507,9 @@ if [[ "$POST_TO_PR" == "true" ]] && [[ -n "$REVIEW" ]]; then echo " round.json keeps the full record: ${RECORD_FILE}" >&2 fi [[ -z "$MARKER" ]] || MARKER+=$'\n' + elif [[ -n "${FALLBACK_RECORD:-}" ]]; then + MARKER=$(marker_line "$FALLBACK_RECORD" "$REVIEW" 2>/dev/null) || MARKER="" + [[ -z "$MARKER" ]] || MARKER+=$'\n' fi COMMENT=$(printf '\n%s%s' "$MARKER" "$REVIEW") diff --git a/lib/records.jq b/lib/records.jq index 1f6a70f..a7c594b 100644 --- a/lib/records.jq +++ b/lib/records.jq @@ -607,6 +607,11 @@ def _visible: gsub("[*`]"; "") | gsub("\\s+"; " ") | _trim; # A string as a regex that matches it literally. def _re_literal: gsub("(?[\\\\^$.|?*+()\\[\\]{}/-])"; "\\\(.c)"); +# True for a marker that says its round's blocker count is unknown: counts holds open_blocking, and it is null. The +# reader honours it: the round read back has null counts, whatever its Markdown shows (fetch_round_records). A round +# whose record could not be built posts such a marker (minimal: no findings list either). +def marker_counts_unknown: (.counts | type) == "object" and (.counts | has("open_blocking")) and .counts.open_blocking == null; + # The marker line for a record, posted right below the generated header and above $body, the exact review text. # One HTML comment: every "--" in the JSON is written "-\u002d". The marker never publishes text the review does not # show. A file stays only when $body shows that exact path, as a whole path: the whole content of a code span, less @@ -617,7 +622,8 @@ def _re_literal: gsub("(?[\\\\^$.|?*+()\\[\\]{}/-])"; "\\\(.c)"); # The whole body (header, newline, marker, newline, review) must fit in 60,000 characters, under GitHub's 65,536: it # drops titles, then file, line, first_round and in_delta, then later, then findings (findings_dropped: true; counts # and last_ids stay). When even that does not fit: a minimal marker, {schema, round, findings_dropped: true} and -# last_ids if it fits, so a later round knows the baseline is missing. Nothing when even that does not fit. +# last_ids if it fits, so a later round knows the baseline is missing, with {counts: {open_blocking: null}} for a code +# review whose blocker count is unknown (marker_counts_unknown). Nothing when even that does not fit. def marker_line($body): ($body | _visible) as $seen | ($body | [scan("`([^`\n]+)`") | .[0] | sub(":\\d+.*$"; "") | _trim]) as $spans @@ -642,7 +648,8 @@ def marker_line($body): .later[]?.file, .later[]?.line, .later[]?.first_round, .later[]?.in_delta) end | if fits then . else del(.later) end | if fits then . else del(.findings) | .findings_dropped = true end - | if fits then . else {schema: 1, round, findings_dropped: true} + (if .last_ids then {last_ids} else {} end) end + | if fits then . else {schema: 1, round, findings_dropped: true} + (if .last_ids then {last_ids} else {} end) + + (if marker_counts_unknown and .code_review != false then {counts: {open_blocking: null}} else {} end) end | if fits then . else del(.last_ids) end | if fits then line else empty end; diff --git a/lib/rounds.sh b/lib/rounds.sh index e16abb5..561510f 100644 --- a/lib/rounds.sh +++ b/lib/rounds.sh @@ -56,6 +56,8 @@ fetch_round_records() { # [] [] # counts.new is the marker's. Otherwise every finding the Markdown shows takes a new ID # (backfill_record), and reconcile_record numbers a round two runs claimed after the floor. The L floor # is the marker's and the backfill's, which reserves an L ID per item of a later round's Later list. + # A marker that says its blocker count is unknown (marker_counts_unknown) gets null counts: its + # Markdown may show fewer blockers than the round had. record=$(printf '%s\n%s\n%s\n' "$records" "$record" "$marker" | jq -cs -L "${LIB_DIR:?}" --argjson round "$round" 'include "records"; .[0] as $earlier | .[2] as $m @@ -64,7 +66,9 @@ fetch_round_records() { # [] [] | {F: ($from | map(_last_number("F")) | max), L: (.[1:] | map(_last_number("L")) | max)} as $ids | .[1] + ($m | del(.source, .findings, .later, .counts)) + {findings_dropped: true, last_ids: $ids} | del(.findings) - | if $own then .counts.new = (($m.counts.new? | numbers) // null) else . end') || return 1 + | if $own then .counts.new = (($m.counts.new? | numbers) // null) else . end + | if $m | marker_counts_unknown then .counts |= map_values(null) | .ready_overridden = false + else . end') || return 1 fi fi facts=$(jq -c '({posted_at: .submitted_at, head_sha: .commit_id, reviewer: .user.login} diff --git a/tests/flow.sh b/tests/flow.sh index 4db826a..440c450 100644 --- a/tests/flow.sh +++ b/tests/flow.sh @@ -1371,5 +1371,37 @@ for m in '{"schema":1,"round":2,"findings_dropped":true,"last_ids":{"F":5,"L":1} '[[ $rc == 0 && $(grep "^2 " "$stub/rounds.out" | sed "s/ */ /g") == "$(sed "s/ */ /g; s/ 2 1 early model/ 1 1 early backfill/" <<<"$full_table")" ]]' done +# Rounds 1–2 leave two blockers open (F1, F3). Round 3's record can't be built: it posts as comment, its Markdown +# shows neither blocker, and its minimal marker says it is a later round with an unknown count and no findings list. +# Read back that way, round 4 does not build on it as an empty baseline: it is a full review of the whole PR, as a +# first code review (no previous-round rules, no previous-findings.md), and round 3 counts as unknown, not as 0 +# blockers. A full review re-reads the whole PR, so its clean verdict stands: it approves. +setup $'**Approach:** Sound' "$clean" +two_rounds +echo "$H3" >"$stub/heads" +echo "$B1" >"$stub/git.base" +break_record fail +run +expect "record fails in round 3: posted as comment, with a minimal marker of unknown count" \ + '[[ $rc == 0 && $flag == --comment && -z $record && + $(sed -n 2p <<<"$body" | sed "s/^$//" | jq -c .) == "{\"schema\":1,\"round\":3,\"findings_dropped\":true,\"last_ids\":{\"F\":3,\"L\":0},\"counts\":{\"open_blocking\":null,\"critical\":null,\"important\":null,\"minor\":null}}" ]]' +rm "$stub/bin/jq" +post_back "$H3" 2026-01-03T00:00:00Z +read_rounds --json +expect "record fails in round 3: read back with unknown counts and no findings list" \ + '[[ $rc == 0 && $(jq -c ".records[2] | [.round, .counts.open_blocking, .counts.critical, .findings_dropped, has(\"findings\"), .last_ids.F]" "$stub/rounds.out") == "[3,null,null,true,false,3]" && + $(jq -c ".decision.series" "$stub/rounds.out") == "[1,2,null]" ]]' +H4=$(printf 'c4%.0s' {1..20}) +echo "$H4" >"$stub/heads" +run +expect "record failed in round 3: round 4 is a full review, not an increment on an empty baseline" \ + '[[ $rc == 0 && $(jq -r ".round, .mode, .mode_reason" <<<"$record" | paste -sd, -) == "4,full,the last round has no record of its findings" ]] && + grep -q "mode: full (the last round has no record of its findings)" "$stub/out.log"' +expect "record failed in round 3: round 4 has no previous-round rules and no previous-findings.md" \ + '! grep -q -e "## Previous round" -e "Check every earlier finding" -e "Outside what changed" "$stub/code-prompt.txt" && + [[ -z $(session_file previous-findings.md) ]]' +expect "record failed in round 3: round 4, a clean full review, approves" \ + '[[ $flag == --approve && $(jq -c "[.counts.open_blocking, .decision]" <<<"$record") == "[0,\"approve\"]" ]]' + finished=true exit "$fail" diff --git a/tests/records.sh b/tests/records.sh index ae44b66..ba68b00 100644 --- a/tests/records.sh +++ b/tests/records.sh @@ -714,6 +714,17 @@ check "marker cap: no room even for the minimal marker, no marker" "$(marker_lin check "marker cap: round.json keeps everything" "$(jq -c '[(.findings | length), (.later | length)]' "$tmp/big.json")" \ "[4,1]" +# A record with an unknown blocker count (null counts, as a round whose record could not be built posts) keeps that +# signal in its minimal marker; one with a known count, or a Rethink, does not. +jq -c '.counts.open_blocking = null' "$tmp/big.json" >"$tmp/unknown.json" +pad_to 59780 +check "marker cap: an unknown count stays in the minimal marker" \ + "$(marker_record "$(generated "$(marker_line "$tmp/unknown.json" "$tmp/body.md")")")" \ + '{"schema":1,"round":2,"findings_dropped":true,"last_ids":{"F":4,"L":0},"counts":{"open_blocking":null}}' +check "marker_counts_unknown: an explicit null count only" \ + "$(jq -c -L "$LIB_DIR" 'include "records"; map(marker_counts_unknown)' <<<'[{"counts": {"open_blocking": null}}, + {"counts": {"open_blocking": 0}}, {"counts": {}}, {}, {"counts": null}]')" '[true,false,false,false,false]' + # A marker is read as it is only with the full counts every marker_line step but the minimal one writes. check "complete_marker: a Rethink and full counts; not partial, inconsistent or minimal ones" \ "$(jq -c -L "$LIB_DIR" 'include "records"; map(complete_marker)' <<<'[{"code_review": false},