Skip to content

Commit 4380bd1

Browse files
Stop the matrix depending on tools BusyBox does not ship
Two of my own assertions failed on Alpine for reasons that had nothing to do with the product. The no-jq case read the installed hook command with python3, which a slim image does not have, so a real assertion about install.sh reported as an environment failure. And the idempotency case fingerprinted the tree with shasum, which is macOS's spelling; BusyBox ships sha256sum and no shasum. The harness may use jq freely — the jq-less constraint is on install.sh's PATH, not on the test — so the hook command is read with jq now. The fingerprint takes whichever checksum tool exists and falls back to size and path, which is enough to catch a second run rewriting the tree. Verified by re-running with python3 and shasum removed from PATH.
1 parent 508d9b9 commit 4380bd1

1 file changed

Lines changed: 15 additions & 4 deletions

File tree

tests/install-matrix.sh

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,10 @@ if want no-jq; then
161161
# there is no project dir, so a verbatim copy produced an install that reported success and
162162
# exited 127 on every hook. This case checked that the files arrived and called it a pass,
163163
# which is exactly the shape of a test that measures the wrong half of the claim.
164-
cmd=$(python3 -c 'import json,sys;print(json.load(open(sys.argv[1]))["hooks"]["SessionStart"][0]["hooks"][0]["command"])' \
165-
"$H/.claude/settings.json" 2>/dev/null)
164+
# jq, not python3: Alpine's slim image has no python3, and the jq-less constraint applies to
165+
# install.sh's PATH, not to this harness. Reading it with a tool the container lacks turned a
166+
# product assertion into an environment failure.
167+
cmd=$(jq -r '.hooks.SessionStart[0].hooks[0].command' "$H/.claude/settings.json" 2>/dev/null)
166168
case "$cmd" in
167169
*CLAUDE_PROJECT_DIR*) e="$e; hook command still points at \$CLAUDE_PROJECT_DIR" ;;
168170
"") e="$e; could not read the configured hook command" ;;
@@ -194,9 +196,18 @@ fi
194196
if want idempotent; then
195197
H="$ROOT/idem"; mkdir -p "$H"
196198
HOME="$H" "$SRC/install.sh" >/dev/null 2>&1
197-
a=$(cd "$H/.claude" && find . -type f | sort | xargs shasum 2>/dev/null | shasum)
199+
# BusyBox ships sha256sum and no shasum; macOS ships shasum. Pick whichever is present, or
200+
# fall back to size+path, which is enough to catch a second run rewriting the tree.
201+
if command -v shasum >/dev/null 2>&1; then SUM=shasum
202+
elif command -v sha256sum >/dev/null 2>&1; then SUM=sha256sum
203+
else SUM=""; fi
204+
tree_fingerprint(){ # <dir>
205+
if [ -n "$SUM" ]; then (cd "$1" && find . -type f | sort | xargs $SUM 2>/dev/null | $SUM)
206+
else (cd "$1" && find . -type f -exec ls -l {} + 2>/dev/null | awk '{print $5, $NF}' | sort); fi
207+
}
208+
a=$(tree_fingerprint "$H/.claude")
198209
HOME="$H" "$SRC/install.sh" >/dev/null 2>&1; rc=$?
199-
b=$(cd "$H/.claude" && find . -type f | sort | xargs shasum 2>/dev/null | shasum)
210+
b=$(tree_fingerprint "$H/.claude")
200211
e=""
201212
[ "$a" = "$b" ] || e="$e; second run changed the tree"
202213
[ "$(grep -c '>>> claude-parity >>>' "$H/.zshrc" 2>/dev/null)" = 1 ] || e="$e; .zshrc block duplicated"

0 commit comments

Comments
 (0)