8000 Investigate and fix packages/base tests that fail on some hosts (xxd and locale dependencies) (#57) by simon-inkie · Pull Request #62 · simon-inkie/inkie-deck · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions .specs/57-host-independent-base-tests/SPEC.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# #57: packages/base tests that fail on some hosts

- Issue: #57
- Branch: 57-host-independent-base-tests
- Started: 2026-10-11

## TL;DR

Under `env -i HOME=$HOME PATH=$PATH LC_ALL=C` with no `xxd`, 4 of 46 vitest
cases failed. Four host dependencies caused them: `xxd` in the inbox suite,
`$'\uXXXX'` fixtures in the inbox-push suite (bash emits `?` outside a UTF-8
locale), a multibyte bracket class in `bin/pane-idle`, and a create-agent test
that put node's install directory on PATH (which can hold a global `claude`).
All four are removed; the same command now passes 46 of 46.

## Scope

- `packages/base/test/inbox.test.sh`: `xxd -p` becomes `od -An -v -tx1`.
- `packages/base/test/inbox-push.test.sh`: `\uXXXX` escapes become UTF-8 byte
escapes.
- `packages/base/bin/pane-idle`: spinner glyph class becomes an alternation, so
it matches under any locale. This is a runtime fix, not only a test fix.
- `packages/base/test/create-agent.test.ts`: PATH exposes node via a
node-only symlink directory.
- `packages/base/README.md`: drop the `xxd` requirement.

Out of scope: `rig/` still installs and checks `xxd`; harmless, see Follow-ups.

## Acceptance

- `cd packages/base && env -i HOME=$HOME PATH=$PATH LC_ALL=C npx vitest run`
passes (PATH keeps pnpm/node; the stripped part is locale and tools), with no
`xxd` and a `claude` beside node.

## Test plan

Before and after counts under the stripped environment, recorded in the PR.

## Decisions log

- 2026-10-11: `od` over `xxd`, since POSIX guarantees it. No skip needed.
- 2026-10-11: Byte escapes in fixtures rather than pinning a locale, so the
suites need no UTF-8 locale installed.
- 2026-10-11: Fixed `pane-idle` in the script, because a cron or supervisor run
under `LC_ALL=C` would have missed the spinner and typed into a busy pane.

## Follow-ups

- `rig/` stages list `xxd` as a required tool; can be dropped.
- The create-agent no-runtime case assumes no system-wide `claude` in
/usr/bin or /bin.

## Review feedback

Opus review, round 1 (approve with minor changes):
- Should-fix: `pane-idle` ctx bar regex used `[^│]`, a multibyte negated class
that is byte-wise under C. Fixed with `grep -P` and a `(?!│).` lookahead.
- Should-fix: README overclaimed, and `BEFORE_BYTES`/`AFTER_BYTES` were never
compared. Case 11 now asserts the after-bytes equal the before-bytes with only
sent->read flipped; README reworded.
- Nits: PATH comment in create-agent test, `grep -P` (superseded by round 2) and system-claude
assumptions logged under Follow-ups, Acceptance command corrected.

Human review, round 2 (maintainer, merge after fixes):
- Major: `grep -P` in `pane_ctx_pct` breaks on BSD/macOS grep. Fixed: the
context percentage is now extracted with awk (split on the rule glyph), and the
spinner match in `check_idle` moved from `grep -qP` to `grep -qE`.
`pane-idle.test.sh` gains a static guard that fails if a PCRE grep is
reintroduced in `bin/`, plus two `pane_ctx_pct` cases (bar then percent; a
rule between glyph and percent is not a match). Checked the guard fails when
the flag is put back.
5 changes: 3 additions & 2 deletions packages/base/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -332,8 +332,9 @@ bash packages/base/test/stuck-pane-sweep.test.sh
```

The `inbox` suite needs PyYAML for its card cases, for the same reason
`inbox reply` does, plus `xxd` for the cases that compare a thread file's bytes
before and after an in-place status patch. Both are installed explicitly in CI
`inbox reply` does. Byte comparisons use `od`, which POSIX guarantees, and the
suites carry no locale dependency (fixtures use byte escapes, and the pane
glyph matches in `bin/pane-idle` are written to work under `LC_ALL=C`). PyYAML is installed explicitly in CI
rather than assumed, because a suite that is green because of what an image
happened to carry is measuring the image.

Expand Down
15 changes: 12 additions & 3 deletions packages/base/bin/pane-idle
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,15 @@
# --------------------------------------------------------------------------
check_idle() {
local pane="$1"
local spinner_re='^[·✻✶✢\*][[:space:]]*[A-Za-z]+\.\.\.'
# Alternation, not a [...] class: in a non-UTF-8 locale (LC_ALL=C, cron, a
# minimal WSL) a class of multibyte glyphs matches single bytes and the
# spinner is silently missed. Literal alternatives match byte-wise anywhere.
local spinner_re='^(·|✻|✶|✢|\*)[[:space:]]*[A-Za-z]+\.\.\.'
# Claude-family busy markers
if echo "$pane" | grep -qF 'esc to interrupt' 2>/dev/null; then return 0; fi
if echo "$pane" | grep -qF 'Cerebrating' 2>/dev/null; then return 0; fi
if echo "$pane" | grep -qF 'Compacting conversation' 2>/dev/null; then return 0; fi
if echo "$pane" | grep -qP "$spinner_re" 2>/dev/null; then return 0; fi
if echo "$pane" | grep -qE "$spinner_re" 2>/dev/null; then return 0; fi
# LIVE ELAPSED COUNTER -- the general busy signal.
#
# Every marker above is an enumerated LITERAL, and the UI moved out from
Expand Down Expand Up @@ -337,7 +340,13 @@ pane_has_codex_approval_dialog() {
# scrollback.
pane_ctx_pct() {
local pane="$1" line
line=$(printf '%s\n' "$pane" | grep -E 'ctx:[0-9]+%|(█|░)[^│]*[0-9]+%' | tail -1)
# awk, not `grep -E '(█|░)[^│]*[0-9]+%'`: a negated class of a multibyte glyph
# is byte-wise under LC_ALL=C, and grep's PCRE flag is absent from BSD/macOS.
# Splitting on │ makes each piece │-free, where `[^│]*` is just `.*`.
line=$(printf '%s\n' "$pane" | awk '
/ctx:[0-9]+%/ { print; next }
{ n = split($0, piece, "│")
for (i = 1; i <= n; i++) if (piece[i] ~ /(█|░).*[0-9]+%/) { print; break } }' | tail -1)
[ -z "$line" ] && return 1
printf '%s\n' "$line" | grep -oE '[0-9]+%' | tail -1 | tr -d '%'
}
Expand Down
12 changes: 10 additions & 2 deletions packages/base/test/create-agent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,18 @@ function stubRuntime(box: Sandbox, body: string): void {
* PATH is built explicitly, never inherited. An inherited PATH would let a real
* `claude` on the developer's machine answer the probe, which would make the
* "no runtime available" case pass for the wrong reason on their box and fail
* in CI. The node directory is included because the script shells out to node.
* in CI. Node is exposed through a directory holding only a node symlink, never
* its install directory, because that directory can also hold a global `claude`
* (npm -g puts runtimes beside node).
*/
function testPath(box: Sandbox, withStub: boolean): string {
const entries = [path.dirname(process.execPath), "/usr/bin", "/bin"];
const nodeBin = path.join(path.dirname(box.stubBin), "node-only");
fs.mkdirSync(nodeBin, { recursive: true });
const link = path.join(nodeBin, "node");
if (!fs.existsSync(link)) fs.symlinkSync(process.execPath, link);
// /usr/bin and /bin stay: the script needs coreutils. A system-wide `claude`
// there would still answer the probe, so this case assumes none is installed.
const entries = [nodeBin, "/usr/bin", "/bin"];
return (withStub ? [box.stubBin, ...entries] : entries).join(path.delimiter);
}

Expand Down
20 changes: 10 additions & 10 deletions packages/base/test/inbox-push.test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ IDLE_CLEAN=$'some transcript output\n\n> '
# Context-gate fixtures. Real statusline shapes, both live formats. The ctx bar is
# the anchor, NOT the model name: an "Opus"-anchored parser went blind to every
# Sonnet/Haiku agent when the model mix changed.
IDLE_CTX_92=$'some transcript output\n\n> \n alice \u2502 Opus 5 \u2502 ~/agents/alice \u2502 \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2591 92%'
IDLE_CTX_46=$'some transcript output\n\n> \n alice \u2502 Opus 5 \u2502 ~/agents/alice \u2502 \u2588\u2588\u2588\u2588\u2591\u2591\u2591\u2591\u2591\u2591 46%'
IDLE_CTX_80=$'some transcript output\n\n> \n alice \u2502 Opus 5 \u2502 ~/agents/alice \u2502 \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2591\u2591 80%'
IDLE_CTX_92=$'some transcript output\n\n> \n alice \xe2\x94\x82 Opus 5 \xe2\x94\x82 ~/agents/alice \xe2\x94\x82 \xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x91 92%'
IDLE_CTX_46=$'some transcript output\n\n> \n alice \xe2\x94\x82 Opus 5 \xe2\x94\x82 ~/agents/alice \xe2\x94\x82 \xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x91\xe2\x96\x91\xe2\x96\x91\xe2\x96\x91\xe2\x96\x91\xe2\x96\x91 46%'
IDLE_CTX_80=$'some transcript output\n\n> \n alice \xe2\x94\x82 Opus 5 \xe2\x94\x82 ~/agents/alice \xe2\x94\x82 \xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x91\xe2\x96\x91 80%'
IDLE_CTX_ALT=$'some transcript output\n\n> \n ~/agents/alice Opus 5 ctx:91%'
BUSY=$'· Thinking... (esc to interrupt)\n> '
BUSY_STAGED=$'· Thinking... (esc to interrupt)\n> half-typed while busy'
Expand All @@ -63,28 +63,28 @@ STAGED_OURS=$'output\n> [inbox from courier] hel'
# read as idle. Multi-word status, a hyphen inside the first token, and a
# U+2026 terminator rather than three ASCII dots. The only thing that survives
# is the parenthesised elapsed counter.
BUSY_MODERN=$'\u00b7 BUG-609 (High): "info not saving" churn bug - audit\u2026 (59s \u00b7 thought for 2s)\n\u276f '
BUSY_MODERN=$'\xc2\xb7 BUG-609 (High): "info not saving" churn bug - audit\xe2\x80\xa6 (59s \xc2\xb7 thought for 2s)\n\xe2\x9d\xaf '
# 2026-07-27: the counter does NOT always carry a middot. BUSY_MODERN and
# COMPACTING both do, so they were the only counter fixtures and the suite pinned
# the SHAPE the 26 July incident produced rather than the CATEGORY it belonged to.
# These two are the forms that read as IDLE while genuinely busy. Found live on
# alice mid-compact showing "(1m 26s)".
BUSY_BARE_SECONDS=$'\u00b7 Thinking\u2026 (12s)\n\u276f '
BUSY_BARE_SECONDS=$'\xc2\xb7 Thinking\xe2\x80\xa6 (12s)\n\xe2\x9d\xaf '
# alice, 2026-07-27: the spinner glyph is NOT a closed set. Measured ✽ (U+273D) live on
# another agent's pane, outside the class the first anchored fix enumerated. This fixture pins
# a glyph nobody has enumerated AND a status word nobody has enumerated, so it can
# only pass via the structural end-of-line counter rule.
BUSY_UNKNOWN_GLYPH=$'\u273d Dilly-dallying\u2026 (16s)\n\u276f '
BUSY_BARE_MINUTES=$'\u00b7 Auditing the sentinel ledger\u2026 (1m 26s)\n\u276f '
BUSY_UNKNOWN_GLYPH=$'\xe2\x9c\xbd Dilly-dallying\xe2\x80\xa6 (16s)\n\xe2\x9d\xaf '
BUSY_BARE_MINUTES=$'\xc2\xb7 Auditing the sentinel ledger\xe2\x80\xa6 (1m 26s)\n\xe2\x9d\xaf '
# NEGATIVE CONTROLS. A completed-turn summary carries a spinner glyph and a
# duration but the turn is OVER: these must read IDLE or every finished agent
# looks permanently busy and delivery wedges.
DONE_BREWED=$'\u273b Brewed for 39s\n\u276f \u00a0'
DONE_WORKED=$'\u273b Worked for 2m 24s\n\u276f \u00a0'
DONE_BREWED=$'\xe2\x9c\xbb Brewed for 39s\n\xe2\x9d\xaf \xc2\xa0'
DONE_WORKED=$'\xe2\x9c\xbb Worked for 2m 24s\n\xe2\x9d\xaf \xc2\xa0'
# And prose: panes are full of message text, so a parenthesised duration in a
# sentence must NOT read as busy. This is the false-positive an unanchored
# widening would introduce.
PROSE_WITH_DURATION=$' I hit it live: my pane showed (1m 26s) mid-compact\n\u276f \u00a0'
PROSE_WITH_DURATION=$' I hit it live: my pane showed (1m 26s) mid-compact\n\xe2\x9d\xaf \xc2\xa0'
NO_COMPOSER=$'output with no prompt glyph at all'
# The REAL idle Claude composer: prompt glyph (U+276F) + a NO-BREAK SPACE
# (U+00A0, bytes C2 A0), NOT a regular space. [[:space:]] does not reliably
Expand Down
12 changes: 9 additions & 3 deletions packages/base/test/inbox.test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -419,12 +419,12 @@ One from iota." > /dev/null
Body for inplace test.")

BEFORE=$(cat "$TPATH" | wc -c)
BEFORE_BYTES=$(cat "$TPATH" | xxd -p | tr -d '\n')
BEFORE_BYTES=$(cat "$TPATH" | od -An -v -tx1 | tr -d ' \n')

run_inbox "$T" "alpha" read omega > /dev/null 2>&1

AFTER=$(cat "$TPATH" | wc -c)
AFTER_BYTES=$(cat "$TPATH" | xxd -p | tr -d '\n')
AFTER_BYTES=$(cat "$TPATH" | od -An -v -tx1 | tr -d ' \n')

# Verify length unchanged
if [ "$BEFORE" -ne "$AFTER" ]; then
Expand All @@ -434,7 +434,13 @@ Body for inplace test.")
# Both are 4 bytes so length stays equal; just check "read" now present and "sent" gone
AFTER_CONTENT=$(cat "$TPATH")
if echo "$AFTER_CONTENT" | grep -q "status: read"; then
if ! echo "$AFTER_CONTENT" | grep -q "status: sent"; then
# Byte-exact: flipping the first "sent" to "read" in
# the before-bytes must reproduce the after-bytes, so nothing else moved.
EXPECTED_BYTES="${BEFORE_BYTES/73656e74/72656164}"
if [ "$EXPECTED_BYTES" != "$AFTER_BYTES" ]; then
fail "Case 11: bytes other than sent->read changed" "expected: $EXPECTED_BYTES
actual: $AFTER_BYTES"
elif ! echo "$AFTER_CONTENT" | grep -q "status: sent"; then
ok "Case 11: in-place patch -- file length unchanged, sent->read flipped, nothing else moved"
else
fail "Case 11: status: sent still present after flip" "content: $AFTER_CONTENT"
Expand Down
23 changes: 23 additions & 0 deletions packages/base/test/pane-idle.test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,29 @@ else
"the numeric validation itself errored past the integer range, and both fallbacks were silenced"
fi

# Portability guard: BSD/macOS grep has no -P, so a grep -P in bin/ makes the
# call error and the check behind it silently stop working. Linux-only runs
# cannot see that, so assert it statically.
PCRE_HITS=$(grep -rnE 'grep +(-[A-Za-z]*P|[^|]* -[A-Za-z]*P)' "$BIN" | grep -vE '^[^:]+:[0-9]+:[[:space:]]*#' || true)
if [ -n "$PCRE_HITS" ]; then
fail "portability: no grep -P in bin/" "$PCRE_HITS"
else
pass "portability: no grep -P in bin/"
fi

# pane_ctx_pct: the bar percentage, and a pipe-delimited segment must not leak
# a percentage into a bar glyph that sits behind a vertical rule.
if [ "$(pane_ctx_pct $'x \xe2\x96\x88\xe2\x96\x91 46%')" = "46" ]; then
pass "ctx pct: bar glyph then percent"
else
fail "ctx pct: bar glyph then percent"
fi
if pane_ctx_pct $'\xe2\x96\x88 bar \xe2\x94\x82 46%' >/dev/null; then
fail "ctx pct: a vertical rule between glyph and percent is not a match"
else
pass "ctx pct: a vertical rule between glyph and percent is not a match"
fi

echo
echo "pane-idle: $PASS passed, $FAILS failed"
exit "$FAILS"
Loading
0