dotfiles/claude/tests/run.sh

28 lines
920 B
Shell
Raw Permalink 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.thinking_test.sh \
statusline.isaacaudet.width_test.sh \
Pace the per-model weekly limit over the days you actually work The weekly limit resets every 7 days, but a 5-day week means the sustainable burn is 20% a day, not the 100/7 the calendar implies. Nothing on the line said that, so staying inside the limit meant doing the division by hand. Adds pace and trend to the per-model bar: "Fable 6% 19%/d ✓". pace is what is left divided by the working days still in the window, so it is the envelope for today. trend compares usage against today's band - during working day n of m, anywhere between (n-1)/m and n/m of the budget is on track - and reports the distance outside it. A band rather than a point because a point built from completed days expects 0% on the first working day of the window, so any usage at all reads as overspending: 6% on a Monday morning showed a red arrow. The band is also all whole-day granularity supports, and the sleep-aware glide in statusline.burnrate.sh is what it would take to say more. Working days come from SL_WORK_DAYS (ISO weekdays, default Mon-Fri) and are counted inside the reset window rather than assumed, so a window that starts mid-week still divides correctly. The colour thresholds derive from 100/total_workdays instead of the hardcoded 14.3-a-day ones in burnrate.sh, which would call 13%/d healthy against a 20-a-day budget. SL_NOW is a test seam for the clock. The cache-age checks deliberately stay on the real clock: a pinned SL_NOW could otherwise age a fresh fixture past USAGE_CACHE_SECS and send a test to the network with real credentials. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-02 21:02:47 +01:00
statusline.isaacaudet.pace_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"