From e63b39cb2abe6cb5bac83838f551f8ae91928637 Mon Sep 17 00:00:00 2001 From: jparker2006 <85816763+jparker2006@users.noreply.github.com> Date: Sun, 22 Nov 2026 23:13:14 +0000 Subject: [PATCH 1/2] #2503: red: the workflow proof must catch a step that skips its fetch or tolerates its failure --- ci/test-comment-check.sh | 48 ++++++++++++++++++++++++++-------------- 1 file changed, 31 insertions(+), 17 deletions(-) diff --git a/ci/test-comment-check.sh b/ci/test-comment-check.sh index a258812..adfcb00 100644 --- a/ci/test-comment-check.sh +++ b/ci/test-comment-check.sh @@ -28,28 +28,38 @@ pull_request_ci() { } workflow=$root/.github/workflows/checks.yml -step_if=$(awk ' - /^ *- name: comment-check *$/ { s = 1; ind = index($0, "-"); next } - s && /^ *- / && index($0, "-") <= ind { exit } - s && /^ *if: / { sub(/^ *if: */, ""); print; exit } -' "$workflow") -step_run=$(awk ' - /^ *- name: comment-check *$/ { s = 1; ind = index($0, "-"); next } - s && /^ *- / && index($0, "-") <= ind { exit } - r { match($0, /^ */); if ($0 !~ /^ *$/ && RLENGTH < k) exit; print; next } - s && /^ *run: *\| *$/ { r = 1; k = index($0, "r"); next } -' "$workflow") +no_fetch=$tmp/no-fetch.yml +sed '/git fetch/d' "$workflow" > "$no_fetch" +tolerant=$tmp/tolerant.yml +awk '{ print } /^ *- name: comment-check *$/ { match($0, /^ */); print substr($0, 1, RLENGTH) " continue-on-error: true" }' "$workflow" > "$tolerant" +for copy in "$no_fetch" "$tolerant"; do + if cmp -s "$workflow" "$copy"; then + echo "test-comment-check: could not make $(basename "$copy") from $workflow" >&2 + exit 1 + fi +done workflow_step() { - repo="$tmp/$1" + repo="$tmp/$1" wf=$2 + step_if=$(awk ' + /^ *- name: comment-check *$/ { s = 1; ind = index($0, "-"); next } + s && /^ *- / && index($0, "-") <= ind { exit } + s && /^ *if: / { sub(/^ *if: */, ""); print; exit } + ' "$wf") + step_run=$(awk ' + /^ *- name: comment-check *$/ { s = 1; ind = index($0, "-"); next } + s && /^ *- / && index($0, "-") <= ind { exit } + r { match($0, /^ */); if ($0 !~ /^ *$/ && RLENGTH < k) exit; print; next } + s && /^ *run: *\| *$/ { r = 1; k = index($0, "r"); next } + ' "$wf") cd "$repo" mkdir -p ci tools/comment-check cp "$root/ci/comment-check.sh" ci/ cp "$root/tools/comment-check/check.py" tools/comment-check/ - git remote add origin "file://$repo" + git remote get-url origin > /dev/null 2>&1 || git remote add origin "file://$repo" set +e if [ "$step_if" != "github.event_name == 'pull_request'" ] || [ -z "$step_run" ]; then - out="no comment-check step that runs on pull requests in $workflow (if: '$step_if')" + out="no comment-check step that runs on pull requests in $wf (if: '$step_if')" code=missing else out=$(GITHUB_SHA=$(git rev-parse HEAD) bash -e -c "$step_run" 2>&1) @@ -72,17 +82,21 @@ expect() { pull_request_ci disallowed catalog/x/check.sh '# a plain comment' expect 'catches: a pull request adding a disallowed comment passes CI' 1 'catalog/x/check.sh:2: comment:' -workflow_step disallowed +workflow_step disallowed "$workflow" expect 'catches: the pull request workflow passes a disallowed comment' 1 'catalog/x/check.sh:2: comment:' +workflow_step disallowed "$no_fetch" +expect 'catches: the workflow proof passes a comment-check step that never fetches the merge parents' 2 'HEAD^1' +workflow_step disallowed "$tolerant" +expect 'catches: the workflow proof passes a comment-check step that tolerates its own failure' tolerated 'continue-on-error: true' pull_request_ci escaped catalog/x/check.sh '# comment-ok: the runner reads this line' expect 'catches: a reasoned escape tag still fails CI' 0 '' -workflow_step escaped +workflow_step escaped "$workflow" expect 'catches: the pull request workflow fails a reasoned escape tag' 0 '' pull_request_ci fixture format/fixtures/valid/x/check.sh '# Prints nothing: nothing is due.' expect 'catches: a format fixture planting a comment the validator reads fails CI' 0 '' -workflow_step fixture +workflow_step fixture "$workflow" expect 'catches: the pull request workflow fails a format fixture comment' 0 '' [ "$failures" -eq 0 ] || exit 1 From 9063d145187fdba7c5ebd77f5c30fd11a0efdcc2 Mon Sep 17 00:00:00 2001 From: jparker2006 <85816763+jparker2006@users.noreply.github.com> Date: Sun, 22 Nov 2026 23:14:04 +0000 Subject: [PATCH 2/2] #2503: green: the workflow proof runs from a depth-1 clone and refuses failure-tolerating settings --- ci/test-comment-check.sh | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/ci/test-comment-check.sh b/ci/test-comment-check.sh index adfcb00..e94f8fb 100644 --- a/ci/test-comment-check.sh +++ b/ci/test-comment-check.sh @@ -30,17 +30,19 @@ pull_request_ci() { workflow=$root/.github/workflows/checks.yml no_fetch=$tmp/no-fetch.yml sed '/git fetch/d' "$workflow" > "$no_fetch" +with_step_setting() { + awk -v setting="$1" '{ print } /^ *- name: comment-check *$/ { match($0, /^ */); print substr($0, 1, RLENGTH) " " setting }' "$workflow" > "$2" +} tolerant=$tmp/tolerant.yml -awk '{ print } /^ *- name: comment-check *$/ { match($0, /^ */); print substr($0, 1, RLENGTH) " continue-on-error: true" }' "$workflow" > "$tolerant" -for copy in "$no_fetch" "$tolerant"; do - if cmp -s "$workflow" "$copy"; then - echo "test-comment-check: could not make $(basename "$copy") from $workflow" >&2 - exit 1 - fi -done +with_step_setting 'continue-on-error: true' "$tolerant" +other_shell=$tmp/other-shell.yml +with_step_setting 'shell: bash {0}' "$other_shell" workflow_step() { - repo="$tmp/$1" wf=$2 + origin="$tmp/$1" wf=$2 + repo="$tmp/$1-$(basename "$wf" .yml)-checkout" + git clone -q --depth 1 --no-tags "file://$origin" "$repo" + tolerates=$(grep -n -E "^ *[\"']?(continue-on-error|shell)[\"']? *:" "$wf" | grep -v -E 'continue-on-error: *false *$' || true) step_if=$(awk ' /^ *- name: comment-check *$/ { s = 1; ind = index($0, "-"); next } s && /^ *- / && index($0, "-") <= ind { exit } @@ -56,9 +58,11 @@ workflow_step() { mkdir -p ci tools/comment-check cp "$root/ci/comment-check.sh" ci/ cp "$root/tools/comment-check/check.py" tools/comment-check/ - git remote get-url origin > /dev/null 2>&1 || git remote add origin "file://$repo" set +e - if [ "$step_if" != "github.event_name == 'pull_request'" ] || [ -z "$step_run" ]; then + if [ -n "$tolerates" ]; then + out="$wf sets what tolerates a failing comment-check, or runs it in another shell than the bash -e this proof models: $tolerates" + code=tolerated + elif [ "$step_if" != "github.event_name == 'pull_request'" ] || [ -z "$step_run" ]; then out="no comment-check step that runs on pull requests in $wf (if: '$step_if')" code=missing else @@ -88,6 +92,8 @@ workflow_step disallowed "$no_fetch" expect 'catches: the workflow proof passes a comment-check step that never fetches the merge parents' 2 'HEAD^1' workflow_step disallowed "$tolerant" expect 'catches: the workflow proof passes a comment-check step that tolerates its own failure' tolerated 'continue-on-error: true' +workflow_step disallowed "$other_shell" +expect 'catches: the workflow proof passes a comment-check step run in a shell that ignores a failing command' tolerated 'shell: bash {0}' pull_request_ci escaped catalog/x/check.sh '# comment-ok: the runner reads this line' expect 'catches: a reasoned escape tag still fails CI' 0 ''