Skip to content

Commit f7997dc

Browse files
sgwannabeclaude
andcommitted
test(advocates): apply PR #87 review feedback (gemini)
- Fix broken `diff` hint at line 109 (was syntactically invalid: a single process substitution given to `diff`, which requires two operands and would fail with `diff: missing operand`). - Add `--normalize FILE` debug subcommand that emits the canonicalized stream for one advocate file to stdout. Two invocations can be paired through `diff` to pinpoint the exact line(s) that drift, which is the actually-useful diagnostic the previous hint failed to provide. - Reword the failure-path hint to point users at the new `--normalize` flag with a copy-pasteable two-operand `diff <(...) <(...)` template. - Update header `Usage:` block + exit-code table to document the new subcommand. Verified: bash tests/test-advocate-boilerplate.sh PASSes (26→1 hash); bash scripts/verify-plugin.sh reports 57/0; `--normalize` against any two advocate files produces an empty `diff` (exit 0) on a clean tree. Refs PR #87 review comments Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent a15cd6b commit f7997dc

1 file changed

Lines changed: 43 additions & 13 deletions

File tree

tests/test-advocate-boilerplate.sh

Lines changed: 43 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,20 @@
2020
# together with the template change (intentional friction — that PR is
2121
# also the PR that should re-sync the boilerplate).
2222
#
23-
# Usage: bash tests/test-advocate-boilerplate.sh
23+
# Usage:
24+
# bash tests/test-advocate-boilerplate.sh # full lint
25+
# bash tests/test-advocate-boilerplate.sh --normalize FILE
26+
# # emit the
27+
# normalized stream for one advocate file to stdout (debug helper —
28+
# pair two invocations through `diff` to locate the drifting line).
29+
#
2430
# CI hook: invoked from .github/workflows/ci.yml under agent-counts job.
2531
#
2632
# Exit codes:
2733
# 0 PASS — all 26 files normalize to a single hash
2834
# 1 FAIL — drift detected (per-file hashes printed for diagnosis)
2935
# 2 FAIL — wrong number of advocate files (expected 26)
36+
# (also returned for --normalize argument errors)
3037

3138
set -euo pipefail
3239

@@ -38,17 +45,6 @@ if [[ ! -d "$ADVOCATES_DIR" ]]; then
3845
exit 2
3946
fi
4047

41-
# Collect advocate files (P01..P26).
42-
# Avoid `mapfile` for bash 3.2 compatibility (macOS system bash).
43-
FILES=()
44-
while IFS= read -r line; do
45-
FILES+=("$line")
46-
done < <(find "$ADVOCATES_DIR" -maxdepth 1 -name 'P*.md' -type f | sort)
47-
if [[ "${#FILES[@]}" -ne 26 ]]; then
48-
echo "FAIL: expected 26 advocate files, found ${#FILES[@]}" >&2
49-
exit 2
50-
fi
51-
5248
# normalize <file>: emit a stripped/canonicalized stream to stdout
5349
# Stripped/replaced (these are the personalized regions per advocate):
5450
# - frontmatter `name:` line (per-persona slug)
@@ -93,6 +89,32 @@ normalize() {
9389
' "$1"
9490
}
9591

92+
# Debug mode: `--normalize FILE` prints the normalized stream for a single
93+
# advocate file. Pair two invocations through `diff` to pinpoint the
94+
# specific line(s) that diverge:
95+
#
96+
# diff <(bash tests/test-advocate-boilerplate.sh --normalize FILE_A) \
97+
# <(bash tests/test-advocate-boilerplate.sh --normalize FILE_B)
98+
if [[ "${1:-}" == "--normalize" ]]; then
99+
if [[ -z "${2:-}" || ! -f "$2" ]]; then
100+
echo "FAIL: --normalize requires a path to an existing advocate file" >&2
101+
exit 2
102+
fi
103+
normalize "$2"
104+
exit 0
105+
fi
106+
107+
# Collect advocate files (P01..P26).
108+
# Avoid `mapfile` for bash 3.2 compatibility (macOS system bash).
109+
FILES=()
110+
while IFS= read -r line; do
111+
FILES+=("$line")
112+
done < <(find "$ADVOCATES_DIR" -maxdepth 1 -name 'P*.md' -type f | sort)
113+
if [[ "${#FILES[@]}" -ne 26 ]]; then
114+
echo "FAIL: expected 26 advocate files, found ${#FILES[@]}" >&2
115+
exit 2
116+
fi
117+
96118
declare -a HASHES=()
97119
for f in "${FILES[@]}"; do
98120
h=$(normalize "$f" | shasum -a 256 | awk '{print $1}')
@@ -106,7 +128,15 @@ if [[ "$distinct" -ne 1 ]]; then
106128
echo "per-file normalized hashes:" >&2
107129
printf ' %s\n' "${HASHES[@]}" | sort >&2
108130
echo "" >&2
109-
echo "Hint: run \`diff <(bash tests/test-advocate-boilerplate.sh; cd $ADVOCATES_DIR && for f in P*.md; do echo === \$f ===; done)\` and inspect divergent files." >&2
131+
echo "Hint: identify two files with different hashes above, then diff" >&2
132+
echo " their normalized streams to see the exact drifting line(s):" >&2
133+
echo "" >&2
134+
echo " diff \\" >&2
135+
echo " <(bash tests/test-advocate-boilerplate.sh --normalize <FILE_A>) \\" >&2
136+
echo " <(bash tests/test-advocate-boilerplate.sh --normalize <FILE_B>)" >&2
137+
echo "" >&2
138+
echo " (replace <FILE_A> / <FILE_B> with two paths from $ADVOCATES_DIR" >&2
139+
echo " whose hashes diverge in the table above.)" >&2
110140
exit 1
111141
fi
112142

0 commit comments

Comments
 (0)