dotfiles/claude/tests/run.sh

26 lines
824 B
Shell
Raw Normal View History

Show the per-model usage limit, and size the status line by measurement /usage reports a weekly limit scoped to a single model (Fable) that the status line did not surface. It is absent from both the status line's stdin JSON and the legacy seven_day_opus/seven_day_sonnet fields, which are always null now; it lives in the usage API's .limits[] under kind "weekly_scoped". Render it labelled by scope.model.display_name so it follows whichever model the limit applies to, inside the 7d segment since both are weekly limits sharing one reset time. Fitting it exposed a problem with sizing by width tier. Tiers only know the terminal width, so content that varies with session state — branch name, cwd, model display name — could push a line past the edge and be clipped by the renderer. Measure the assembled line instead (vis_len) and emit the richest of four rate-limit variants that fits, on one line or two: with reset times, with extra-usage credits, bars only, or bars without the per-model segment. Every branch is fit-checked, including with wrapping disabled. Two lines render correctly in the status line. Cap the cwd basename as well: nothing else shortened line one, so a long project directory could overflow it on its own. Correct the usable width. Claude Code exports COLUMNS but applies the `padding` setting on top of it rather than deducting it first, so a line sized to COLUMNS is clipped; deduct padding on both sides plus a column of margin. Sanitise payload data before rendering. printf %b interprets backslash escapes, which is how the colour variables work, so a cwd or model name containing a literal \n — or a real newline, which jq decodes from the JSON — would split the line and break both the width measurement and the two-line guarantee. Parse the usage payload in one jq pass rather than ten. The status line runs on every redraw and per-field parsing had become the dominant cost; this brings a render back to roughly what it was before (~155ms vs ~115ms parent), the remainder being the reset times the tiered version did not show at this width. Fields are read one per line rather than via @tsv: tab is IFS whitespace, so `read` collapses runs of it and an empty field — no scoped limit, which is the common case — silently shifted every later field along by one. Tests cover the API payload shapes including malformed and hostile input, the width invariants (never exceed the usable width, never more than two lines, never wrap unnecessarily), and a sweep over widths, branch lengths, model names, cwd lengths and extra-usage. They restore the live usage cache on exit, and remove the fixture outright when there was no cache to restore — otherwise a test run would leave fabricated usage figures live for an hour. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-27 17:55:35 +01:00
#!/bin/bash
# Run every test for claude/statusline.isaacaudet.sh.
#
# Usage: claude/tests/run.sh
#
# The tests render the status line directly, so they need the same tools it
# does (bash, jq, git, python3). They point STATUSLINE_CACHE_DIR at a temporary
# directory and write their fixtures there, so the caches the live status line
# reads are never touched.
Show the per-model usage limit, and size the status line by measurement /usage reports a weekly limit scoped to a single model (Fable) that the status line did not surface. It is absent from both the status line's stdin JSON and the legacy seven_day_opus/seven_day_sonnet fields, which are always null now; it lives in the usage API's .limits[] under kind "weekly_scoped". Render it labelled by scope.model.display_name so it follows whichever model the limit applies to, inside the 7d segment since both are weekly limits sharing one reset time. Fitting it exposed a problem with sizing by width tier. Tiers only know the terminal width, so content that varies with session state — branch name, cwd, model display name — could push a line past the edge and be clipped by the renderer. Measure the assembled line instead (vis_len) and emit the richest of four rate-limit variants that fits, on one line or two: with reset times, with extra-usage credits, bars only, or bars without the per-model segment. Every branch is fit-checked, including with wrapping disabled. Two lines render correctly in the status line. Cap the cwd basename as well: nothing else shortened line one, so a long project directory could overflow it on its own. Correct the usable width. Claude Code exports COLUMNS but applies the `padding` setting on top of it rather than deducting it first, so a line sized to COLUMNS is clipped; deduct padding on both sides plus a column of margin. Sanitise payload data before rendering. printf %b interprets backslash escapes, which is how the colour variables work, so a cwd or model name containing a literal \n — or a real newline, which jq decodes from the JSON — would split the line and break both the width measurement and the two-line guarantee. Parse the usage payload in one jq pass rather than ten. The status line runs on every redraw and per-field parsing had become the dominant cost; this brings a render back to roughly what it was before (~155ms vs ~115ms parent), the remainder being the reset times the tiered version did not show at this width. Fields are read one per line rather than via @tsv: tab is IFS whitespace, so `read` collapses runs of it and an empty field — no scoped limit, which is the common case — silently shifted every later field along by one. Tests cover the API payload shapes including malformed and hostile input, the width invariants (never exceed the usable width, never more than two lines, never wrap unnecessarily), and a sweep over widths, branch lengths, model names, cwd lengths and extra-usage. They restore the live usage cache on exit, and remove the fixture outright when there was no cache to restore — otherwise a test run would leave fabricated usage figures live for an hour. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-27 17:55:35 +01:00
cd "$(dirname "${BASH_SOURCE[0]}")" || exit 1
status=0
for t in statusline.isaacaudet.payload_test.sh \
statusline.isaacaudet.width_test.sh \
statusline.isaacaudet.cache_test.sh; do
Show the per-model usage limit, and size the status line by measurement /usage reports a weekly limit scoped to a single model (Fable) that the status line did not surface. It is absent from both the status line's stdin JSON and the legacy seven_day_opus/seven_day_sonnet fields, which are always null now; it lives in the usage API's .limits[] under kind "weekly_scoped". Render it labelled by scope.model.display_name so it follows whichever model the limit applies to, inside the 7d segment since both are weekly limits sharing one reset time. Fitting it exposed a problem with sizing by width tier. Tiers only know the terminal width, so content that varies with session state — branch name, cwd, model display name — could push a line past the edge and be clipped by the renderer. Measure the assembled line instead (vis_len) and emit the richest of four rate-limit variants that fits, on one line or two: with reset times, with extra-usage credits, bars only, or bars without the per-model segment. Every branch is fit-checked, including with wrapping disabled. Two lines render correctly in the status line. Cap the cwd basename as well: nothing else shortened line one, so a long project directory could overflow it on its own. Correct the usable width. Claude Code exports COLUMNS but applies the `padding` setting on top of it rather than deducting it first, so a line sized to COLUMNS is clipped; deduct padding on both sides plus a column of margin. Sanitise payload data before rendering. printf %b interprets backslash escapes, which is how the colour variables work, so a cwd or model name containing a literal \n — or a real newline, which jq decodes from the JSON — would split the line and break both the width measurement and the two-line guarantee. Parse the usage payload in one jq pass rather than ten. The status line runs on every redraw and per-field parsing had become the dominant cost; this brings a render back to roughly what it was before (~155ms vs ~115ms parent), the remainder being the reset times the tiered version did not show at this width. Fields are read one per line rather than via @tsv: tab is IFS whitespace, so `read` collapses runs of it and an empty field — no scoped limit, which is the common case — silently shifted every later field along by one. Tests cover the API payload shapes including malformed and hostile input, the width invariants (never exceed the usable width, never more than two lines, never wrap unnecessarily), and a sweep over widths, branch lengths, model names, cwd lengths and extra-usage. They restore the live usage cache on exit, and remove the fixture outright when there was no cache to restore — otherwise a test run would leave fabricated usage figures live for an hour. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-27 17:55:35 +01:00
echo "== $t"
bash "$t" || status=1
echo
done
echo "== statusline.isaacaudet.overflow_test.py"
python3 statusline.isaacaudet.overflow_test.py || status=1
echo
[ "$status" -eq 0 ] && echo "ALL TESTS PASSED" || echo "SOME TESTS FAILED"
exit "$status"