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 <[email protected]>
110 lines
5.9 KiB
Shell
Executable file
110 lines
5.9 KiB
Shell
Executable file
#!/usr/bin/env bash
|
|
#
|
|
# test-public-text-checks.sh
|
|
#
|
|
# Self-test of scripts/check-public-names.sh and scripts/check-comparative-prose.sh.
|
|
# Each case feeds a check a fixture file (or a pattern list) and states the exit
|
|
# status it must give:
|
|
# - a hit exits 1, a clean file exits 0;
|
|
# - an opt-out with a reason is honoured, and one with an empty reason (the
|
|
# comment form `<!-- allow-name: -->`, whose `-->` must not count as the
|
|
# reason) is not;
|
|
# - a pattern grep cannot compile exits 2, never "clean".
|
|
# The fixture names a made-up company, never a real one.
|
|
#
|
|
# Exit status: 0 when every case gives its stated status, 1 otherwise.
|
|
|
|
set -uo pipefail
|
|
|
|
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
|
names="$REPO_ROOT/scripts/check-public-names.sh"
|
|
prose="$REPO_ROOT/scripts/check-comparative-prose.sh"
|
|
tmp="$(mktemp -d)"
|
|
trap 'rm -rf "$tmp"' EXIT
|
|
|
|
failures=0
|
|
in_dir() { # in_dir <dir> <command...>: run a command from another directory
|
|
local d="$1"
|
|
shift
|
|
(cd "$d" && "$@")
|
|
}
|
|
names_file() { # names_file <file> <command...>: the command exits 2 and its output names <file>
|
|
local f="$1"
|
|
shift
|
|
"$@" >"$tmp/named" 2>&1
|
|
local got=$?
|
|
[ "$got" -eq 2 ] && grep -qF "$f" "$tmp/named"
|
|
}
|
|
expect() { # expect <status> <label> <command...>
|
|
local want="$1" label="$2"
|
|
shift 2
|
|
"$@" >"$tmp/out" 2>&1
|
|
local got=$?
|
|
if [ "$got" -eq "$want" ]; then
|
|
echo "ok $label (exit $got)"
|
|
else
|
|
echo "FAIL $label: exit $got, expected $want"
|
|
sed 's/^/ /' "$tmp/out"
|
|
failures=$((failures + 1))
|
|
fi
|
|
}
|
|
|
|
printf 'This line names Zyxwvut Holdings.\n' > "$tmp/bare.md"
|
|
printf 'Zyxwvut Holdings <!-- allow-name: a model-hub id the tool defaults to -->\n' > "$tmp/reasoned.md"
|
|
printf 'Zyxwvut Holdings <!-- allow-name: -->\n' > "$tmp/empty-comment.md"
|
|
printf 'Zyxwvut Holdings // allow-name:\n' > "$tmp/empty-line.rs"
|
|
printf 'This line names nothing.\n' > "$tmp/clean.md"
|
|
|
|
list='Zyxwvut'
|
|
expect 1 "names: a bare name is a hit" env WAI_NAME_DENYLIST="$list" bash "$names" "$tmp/bare.md"
|
|
expect 0 "names: an opt-out with a reason is honoured" env WAI_NAME_DENYLIST="$list" bash "$names" "$tmp/reasoned.md"
|
|
expect 1 "names: an opt-out with an empty reason in a comment is not" env WAI_NAME_DENYLIST="$list" bash "$names" "$tmp/empty-comment.md"
|
|
expect 1 "names: an opt-out with an empty reason at end of line is not" env WAI_NAME_DENYLIST="$list" bash "$names" "$tmp/empty-line.rs"
|
|
expect 0 "names: a clean file is clean" env WAI_NAME_DENYLIST="$list" bash "$names" "$tmp/clean.md"
|
|
expect 2 "names: a malformed pattern fails closed" env WAI_NAME_DENYLIST="$(printf 'Zyxwvut\n([unclosed')" bash "$names" "$tmp/clean.md"
|
|
expect 2 "names: an unset list fails closed" env -u WAI_NAME_DENYLIST bash "$names" "$tmp/clean.md"
|
|
expect 2 "names: a missing file fails closed" env WAI_NAME_DENYLIST="$list" bash "$names" "$tmp/no-such-file.md"
|
|
mkdir -p "$tmp/sub"
|
|
for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30; do
|
|
printf 'Clean line %s.\n' "$i" > "$tmp/sub/clean-$i.md"
|
|
done
|
|
many=()
|
|
for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30; do many+=("sub/clean-$i.md"); done
|
|
expect 1 "names: a path relative to the caller's directory is read from there" in_dir "$tmp" env WAI_NAME_DENYLIST="$list" bash "$names" bare.md
|
|
expect 0 "names: many clean files given relative to the caller's directory are clean" in_dir "$tmp" env WAI_NAME_DENYLIST="$list" bash "$names" "${many[@]}"
|
|
expect 1 "names: a hit among many relative paths is a hit" in_dir "$tmp" env WAI_NAME_DENYLIST="$list" bash "$names" "${many[@]}" bare.md
|
|
expect 0 "names: a missing file among many fails closed and is named" names_file "gone.md" in_dir "$tmp" env WAI_NAME_DENYLIST="$list" bash "$names" "${many[@]}" sub/gone.md
|
|
expect 0 "names: a directory given as a file fails closed and is named" names_file "/sub" in_dir "$tmp" env WAI_NAME_DENYLIST="$list" bash "$names" "${many[@]}" sub
|
|
|
|
printf 'Its reproducibility is the superiority claim.\n' > "$tmp/superiority.md"
|
|
printf 'About 8 kbps, well below Xcodec at the same quality.\n' > "$tmp/well-below.md"
|
|
printf 'Its token rate is among the lowest of any codec.\n' > "$tmp/among.md"
|
|
printf 'One property nothing else in the field offers.\n' > "$tmp/nothing-else.md"
|
|
printf 'State-feeds are the biggest commercial wedge.\n' > "$tmp/wedge.md"
|
|
printf 'Joules-per-decode, the unclaimed metric.\n' > "$tmp/unclaimed.md"
|
|
printf 'Haptics is a fast win.\n' > "$tmp/fast-win.md"
|
|
printf 'Carriage is not a differentiator any more.\n' > "$tmp/differentiator.md"
|
|
printf 'It is not a rate-competitive codec.\n' > "$tmp/rate-competitive.md"
|
|
printf 'This is the moat <!-- allow-phrase: -->\n' > "$tmp/prose-empty.md"
|
|
printf 'WAI_MOAT_DIR <!-- allow-phrase: an environment variable name, not prose -->\n' > "$tmp/prose-reasoned.md"
|
|
printf 'The decoder is integer all the way down.\n' > "$tmp/prose-clean.md"
|
|
|
|
expect 1 "prose: superiority" bash "$prose" "$tmp/superiority.md"
|
|
expect 1 "prose: well below <Name>" bash "$prose" "$tmp/well-below.md"
|
|
expect 1 "prose: among the lowest" bash "$prose" "$tmp/among.md"
|
|
expect 1 "prose: nothing else ... offers" bash "$prose" "$tmp/nothing-else.md"
|
|
expect 1 "prose: commercial wedge" bash "$prose" "$tmp/wedge.md"
|
|
expect 1 "prose: unclaimed" bash "$prose" "$tmp/unclaimed.md"
|
|
expect 1 "prose: fast win" bash "$prose" "$tmp/fast-win.md"
|
|
expect 1 "prose: differentiator" bash "$prose" "$tmp/differentiator.md"
|
|
expect 1 "prose: rate-competitive" bash "$prose" "$tmp/rate-competitive.md"
|
|
expect 1 "prose: an opt-out with an empty reason is not honoured" bash "$prose" "$tmp/prose-empty.md"
|
|
expect 0 "prose: an opt-out with a reason is honoured" bash "$prose" "$tmp/prose-reasoned.md"
|
|
expect 0 "prose: a clean file is clean" bash "$prose" "$tmp/prose-clean.md"
|
|
expect 2 "prose: a missing file fails closed" bash "$prose" "$tmp/no-such-file.md"
|
|
|
|
if [ $failures -gt 0 ]; then
|
|
echo "$failures case(s) gave the wrong status"
|
|
exit 1
|
|
fi
|
|
echo "public-text check self-test: every case gave its stated status"
|