Commit graph dotfiles/claude/tests/statusline.isaacaudet.cache_test.sh
Author SHA1 Message Date
Jonny Barnes
ab96dfc52a
Give the usage bars a line of their own, always
Squeezing the 5h/7d group onto line one was what cost the reset times and
the pace figure at laptop width, and it made the layout jump between one
and two lines as the branch name or the cost changed width. Line two is
now the group's own at every terminal size, so both timestamps and the
burn rate fit; the ladder only starts giving things up below ~80 columns.

The bars also survive down to 35 columns now rather than being dropped
below 68, since a line of their own is all they need. Every rung of the
ladder is fit-checked, the last one included: with the floor that low, a
percentage the API reports in more digits than anyone expects would
otherwise have overflowed the line rather than dropped the group.

The two timestamps still cost ~10 subprocesses to format on a line that
redraws per keystroke, so that is skipped when line two provably cannot
show them -- an under-estimate, so the fit check stays the decider.

With nothing left to squeeze, WRAP_NARROW, the wrap band and the split
tier go: line one is the full tier down to 150, wide to 68, then narrow.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-03 19:18:32 +01:00
Jonny Barnes
35e170b40c
Back off after a failed usage fetch instead of retrying every redraw
A failed fetch left the cache mtime untouched, so with no network every
redraw — and a redraw happens on every keystroke — tried curl again and
could wait --max-time 10 for it. Cutting the TTL from an hour to five
minutes made that start 55 minutes sooner, so it is worth fixing now.

The marker is a separate file rather than a touch of the cached
response: a cold /tmp has no response to touch, and that is exactly the
case with no stale data to fall back on, where the timeout is paid in
full with nothing to show for it.

It goes down before the request and is cleared when that lands, not
written afterwards. A fetch is in flight for as long as curl takes to
give up, and this cache dir is shared by every session, so redraws
starting inside that window are real rather than hypothetical: they now
serve stale data instead of each launching their own doomed request.
Every attempt writes it, so a repeated failure restarts the backoff, and
only an attempt does, so the redraws it suppresses cannot keep
re-stamping it and it always lapses.

Missing credentials stays outside the backoff — it costs no timeout, and
the redraw after a login should show the bars rather than wait out a
retry window it had no part in earning.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-02 13:22:52 +01:00
Jonny Barnes
f2dbe61276
Refresh the usage bars every 5 minutes, not every hour
The 5h/7d bars were served from a cache with a one-hour TTL, so a bar
could sit unchanged for most of a 5-hour window. The TTL is now a named
config setting next to GIT_CACHE_SECS at 300s: worst case 12 requests an
hour, shared across every session through /tmp/claude.

The section header claimed "cached 60s" — inherited from upstream and
never true here — which is what set the expectation the code did not
meet. It now names the setting instead of a number that can drift.

The refresh is gated on the same width-tier check as the bars, so a
render that shows them is a render that refreshes them: the new tests
pin that from full width down to WRAP_FLOOR, and pin that one column
below it, where the bars are dropped, no request is paid for either.
Those widths are given in usable columns, as in the sibling width test,
so the suite does not depend on the padding in the live settings.json.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-02 13:07:19 +01:00