From abc2932dd0ffd703836058f3fc298023cca07a43 Mon Sep 17 00:00:00 2001 From: Brennan Benson <79079362+brennanb2025@users.noreply.github.com> Date: Tue, 21 Jul 2026 20:42:26 -0700 Subject: [PATCH] test(rate-limits): exercise overlapping statusline ticks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The stamp check/write is deliberately lock-free (a lock could wedge the feed closed; fail-open is the contract), so a truly concurrent burst may post more than once, bounded by overlap width — an exact at-most-one assertion would be flaky by design. Assert the invariants that do hold: every overlapping run exits 0, the raced stamp lands valid, and it throttles the following ticks. --- src/main/claude/statusline-script.test.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/main/claude/statusline-script.test.ts b/src/main/claude/statusline-script.test.ts index db64f733ae7..1f5f3f6d51b 100644 --- a/src/main/claude/statusline-script.test.ts +++ b/src/main/claude/statusline-script.test.ts @@ -275,6 +275,24 @@ describe.skipIf(process.platform === 'win32')('statusline curl throttle (posix b expect(lineCount(curlLog)).toBe(2) }) + it('stays bounded and keeps a valid stamp under overlapping same-pane ticks', async () => { + const { scriptPath, dir, curlLog } = makeHarness() + // Why: the stamp check/write is deliberately lock-free — a lock could wedge the feed closed, + // and fail-open is the contract — so a truly concurrent burst may post more than once, + // bounded by the overlap width. The deterministic invariants are: every overlapping run + // exits 0, the raced stamp still lands valid, and it throttles the very next ticks. + await Promise.all( + Array.from({ length: 10 }, () => runScript(scriptPath, dir, rateLimitPayload(1_000))) + ) + const burstPosts = lineCount(curlLog) + expect(burstPosts).toBeGreaterThanOrEqual(1) + expect(readFileSync(stampPathFor(dir), 'utf8')).toBe('1') + for (let index = 0; index < 5; index += 1) { + await runScript(scriptPath, dir, rateLimitPayload(2_000 + index * 100)) + } + expect(lineCount(curlLog)).toBe(burstPosts) + }) + it('preserves multiline payloads while capturing stdin with shell builtins', async () => { const { scriptPath, dir, payloadLog } = makeHarness() const payload = JSON.stringify(JSON.parse(rateLimitPayload(1_000)), null, 2)