From 32a35e99043ff14498977203c9ab626df8180c60 Mon Sep 17 00:00:00 2001 From: Transaction Science Date: Wed, 21 Oct 2026 15:19:18 -0400 Subject: [PATCH 01/60] check-public-names: read file arguments from the caller's directory; name a file it cannot read The script moved to the repository's root before reading its arguments, so paths given from a subdirectory (a builder in wai/ or wai/wai-rs) did not exist and grep exited 2 for the whole list; a list built from git diff after main moved, naming a file absent from the work tree, failed the same way with nothing to say which. Each relative argument is now resolved against the caller's directory, and every argument that is not a readable regular file is named before the scan (still exit 2, fail closed). The self-test gains cases for relative paths, many files, a missing file and a directory among many. Co-Authored-By: Claude Opus 5.5 --- scripts/check-public-names.sh | 30 +++++++++++++++++++++++++++--- scripts/test-public-text-checks.sh | 23 +++++++++++++++++++++++ 2 files changed, 50 insertions(+), 3 deletions(-) diff --git a/scripts/check-public-names.sh b/scripts/check-public-names.sh index 34b2e7d8b..2ae91631f 100755 --- a/scripts/check-public-names.sh +++ b/scripts/check-public-names.sh @@ -19,7 +19,8 @@ # Scope: the tracked files under wai/ with the extensions .md .rs .toml .py # .sh .mjs .js .json .html .css .ttl .h .c .txt, and wai/'s .gitignore files; # or, when files are given as arguments, those files (the self-test, -# scripts/test-public-text-checks.sh, uses this). Excluded: +# scripts/test-public-text-checks.sh, uses this), each a path relative to the +# directory the script is run from, or absolute. Excluded: # - the settled OER/2 documents and corpus (wai/extensions/oer-receipts.md, # wai/wai-rs/src/oer.rs, wai/oer-conformance/), which no change may edit. # @@ -32,12 +33,16 @@ # function, not the owner. # # Exit status: 0 clean; 1 a hit; 2 WAI_NAME_DENYLIST unset or empty, a pattern -# grep cannot compile, or any other grep error. The check never reads an error +# grep cannot compile, a file given that is not a readable regular file (each +# such file is named), or any other grep error. The check never reads an error # as "clean". set -euo pipefail REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" +# The files given as arguments are paths from the caller's directory: remember it +# before moving to the repository's root, where the default scope is listed. +CALLER_DIR="$(pwd)" cd "$REPO_ROOT" if [ -z "${WAI_NAME_DENYLIST:-}" ]; then @@ -67,7 +72,12 @@ fi files=() if [ $# -gt 0 ]; then - files=("$@") + for f in "$@"; do + case "$f" in + /*) files+=("$f") ;; + *) files+=("$CALLER_DIR/$f") ;; + esac + done else while IFS= read -r f; do case "$f" in @@ -83,6 +93,20 @@ if [ ${#files[@]} -eq 0 ]; then exit 2 fi +# A file grep cannot read makes it exit 2 with the whole list unchecked; name each +# such file instead of reporting a bare grep failure. File names are not private. +unreadable=0 +for f in "${files[@]}"; do + if [ ! -f "$f" ] || [ ! -r "$f" ]; then + echo "::error::not a readable file: $f" >&2 + unreadable=$((unreadable + 1)) + fi +done +if [ $unreadable -gt 0 ]; then + echo "::error::$unreadable of ${#files[@]} files given cannot be read; nothing was checked" >&2 + exit 2 +fi + set +e grep -HnE -f "$patterns" -- "${files[@]}" > "$out" 2>/dev/null rc=$? diff --git a/scripts/test-public-text-checks.sh b/scripts/test-public-text-checks.sh index 85aa775c8..a2c8b0bea 100755 --- a/scripts/test-public-text-checks.sh +++ b/scripts/test-public-text-checks.sh @@ -23,6 +23,18 @@ tmp="$(mktemp -d)" trap 'rm -rf "$tmp"' EXIT failures=0 +in_dir() { # in_dir : run a command from another directory + local d="$1" + shift + (cd "$d" && "$@") +} +names_file() { # names_file : the command exits 2 and its output names + local f="$1" + shift + "$@" >"$tmp/named" 2>&1 + local got=$? + [ "$got" -eq 2 ] && grep -qF "$f" "$tmp/named" +} expect() { # expect