#!/usr/bin/env bash set -euo pipefail REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" SCRIPT="$REPO_ROOT/providers/claude-code/statusline-command.sh" PASS=0 FAIL=0 pass() { echo " PASS: $1"; PASS=$((PASS + 1)); } fail() { echo " FAIL: $1"; FAIL=$((FAIL + 1)); } # Strip ANSI escape codes so assertions work on plain text strip_ansi() { sed 's/\x1b\[[0-9;]*m//g'; } # Pipe JSON to the script and return stripped output run() { echo "$1" | bash "$SCRIPT" | strip_ansi; } # Baseline input covering all segments FULL='{"workspace":{"current_dir":"/home/user/myproject"},"model":{"display_name":"Sonnet 4.6"},"context_window":{"used_percentage":20,"total_input_tokens":15000,"total_output_tokens":5000},"cost":{"total_cost_usd":0.25}}' echo "--- assembly ---" out=$(run "$FULL") grep -q "myproject" <<< "$out" && pass "shows basename of working directory" || fail "dir missing — got: $out" grep -q " · " <<< "$out" && pass "segments joined with ' · '" || fail "separator missing — got: $out" grep -q "Sonnet 4.6" <<< "$out" && pass "shows model name" || fail "model name missing — got: $out" grep -q "context 20%" <<< "$out" && pass "shows context % with 'context' label" || fail "context label wrong — got: $out" echo "" echo "--- token formatting ---" # 15k + 5k = 20k → shown as "20k tokens" grep -q "20k tokens" <<< "$out" && pass "formats total tokens as Xk when >= 1000" || fail "Xk format wrong — got: $out" # Sub-1000 total: 500 + 300 = 800 → shown as "800 tokens" LOW='{"workspace":{"current_dir":"/x"},"context_window":{"total_input_tokens":500,"total_output_tokens":300}}' out_low=$(run "$LOW") grep -q "800 tokens" <<< "$out_low" && pass "shows raw count when total tokens < 1000" || fail "sub-1000 format wrong — got: $out_low" echo "" echo "--- cost formatting ---" # 0.25 → 25¢ grep -q "25¢" <<< "$out" && pass "formats sub-dollar cost as cents (¢)" || fail "cents format wrong — got: $out" # 1.71 → $1.71 DOLLAR='{"workspace":{"current_dir":"/x"},"cost":{"total_cost_usd":1.71},"context_window":{"total_input_tokens":0,"total_output_tokens":0}}' out_dollar=$(run "$DOLLAR") grep -qF '$1.71' <<< "$out_dollar" && pass "formats dollar-plus cost as \$X.XX" || fail "dollar format wrong — got: $out_dollar" echo "" echo "--- missing fields omitted ---" # No cost field → no ¢ or $ in output NO_COST='{"workspace":{"current_dir":"/x"},"context_window":{"total_input_tokens":0,"total_output_tokens":0}}' out_nocost=$(run "$NO_COST") ! grep -qE '[¢$]' <<< "$out_nocost" && pass "omits cost segment when cost absent" || fail "cost shown unexpectedly — got: $out_nocost" # Zero tokens → no token segment ZERO_TOK='{"workspace":{"current_dir":"/x"},"context_window":{"total_input_tokens":0,"total_output_tokens":0}}' out_zerotok=$(run "$ZERO_TOK") ! grep -q "tokens" <<< "$out_zerotok" && pass "omits token segment when total is zero" || fail "token segment shown unexpectedly — got: $out_zerotok" echo "" echo "--- executable bit ---" [[ -x "$SCRIPT" ]] && pass "statusline-command.sh is executable" || fail "statusline-command.sh is not executable" echo "" echo "Results: $PASS passed, $FAIL failed" [[ $FAIL -eq 0 ]]