#!/bin/bash # Tests for claude/statusline.isaacaudet.sh — the Isaac Audet-inspired Claude # Code status line (the variant symlinked from ~/.claude/statusline.sh). # # Sibling variants in claude/ (statusline.burnrate.sh, statusline.original.sh) # are NOT covered by these tests. # # Payload shapes: how the usage API's rate-limit JSON is rendered, in # particular the per-model ("weekly_scoped") limit such as Fable, and how the # renderer degrades when the group will not fit. SCRIPT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)/statusline.isaacaudet.sh" # Render into a throwaway cache directory. The live cache must not be touched: # ~/.claude/statusline.sh is a symlink to the script under test, so a fixture # written there is shown in the running TUI as real usage until it expires. export STATUSLINE_CACHE_DIR="$(mktemp -d)" CACHE="$STATUSLINE_CACHE_DIR/statusline-usage-cache.json" REPO="$(mktemp -d)" cleanup() { rm -rf "$STATUSLINE_CACHE_DIR" "$REPO"; } trap cleanup EXIT git -C "$REPO" init -q 2>/dev/null git -C "$REPO" -c user.email=t@t -c user.name=t commit -q --allow-empty -m init 2>/dev/null pass=0; fail=0 ok() { echo " PASS $1"; pass=$((pass+1)); } bad() { echo " FAIL $1"; [ -n "$2" ] && printf '%s\n' "$2" | sed 's/^/ /'; fail=$((fail+1)); } # Render, with ANSI stripped. $1 = TERM_WIDTH, $2 = cwd, $3 = model name. render() { local w="$1" cwd="${2:-$REPO}" model="${3:-Opus 5}" stdin_json "$cwd" "$model" \ | TERM_WIDTH="$w" bash "$SCRIPT" 2>&1 | sed $'s/\033\[[0-9;]*m//g' } # Build the payload in python: a backslash written into shell-constructed JSON # is a JSON escape, so "pro\nj" would reach the script as a REAL newline rather # than the literal characters the hostile-string tests mean to exercise. stdin_json() { CWD="$1" MODEL="$2" python3 -c ' import json, os print(json.dumps({"model": {"display_name": os.environ["MODEL"]}, "cwd": os.environ["CWD"], "cost": {"total_cost_usd": 0.5}, "context_window": {"context_window_size": 200000, "current_usage": {"input_tokens": 1000}}}))' } nth() { printf '%s\n' "$1" | sed -n "${2}p"; } count() { printf '%s\n' "$1" | wc -l | tr -d ' '; } vis() { printf '%s' "$1" | python3 -c " import sys,unicodedata s=sys.stdin.read(); print(sum(2 if unicodedata.east_asian_width(c) in 'WF' else 1 for c in s))"; } fixture() { cat > "$CACHE"; } BASE='"five_hour":{"utilization":5.0,"resets_at":"2026-08-27T15:40:00+00:00"}, "seven_day":{"utilization":7.0,"resets_at":"2026-08-28T02:00:00+00:00"}' # ---------------------------------------------------------------- scoped limit echo "Per-model (weekly_scoped) limit:" fixture < "$NOWRAP" fixture <&1 | sed $'s/\033\[[0-9;]*m//g') u=$(( w - 5 )); c=$(vis "$out") [ "$(count "$out")" = "1" ] && [ "$c" -le "$u" ] \ && ok "width $w: one line, $c <= usable $u" \ || bad "width $w: one line within usable $u (got $(count "$out") line/s, $c cols)" "$out" done rm -f "$NOWRAP" echo; echo "pass=$pass fail=$fail"; [ "$fail" -eq 0 ]