Skip to content

fix: eliminate real-time waits that cause test suite hangs#823

Merged
pfleidi merged 4 commits intomainfrom
fix/tests-hang
Apr 1, 2026
Merged

fix: eliminate real-time waits that cause test suite hangs#823
pfleidi merged 4 commits intomainfrom
fix/tests-hang

Conversation

@pfleidi
Copy link
Copy Markdown
Contributor

@pfleidi pfleidi commented Apr 1, 2026

Summary

  • waitForApproval poll tests: Changed interval parameter from int (seconds) to time.Duration and added slowDownBackoff as an explicit parameter (was a mutable package-level var). Tests pass time.Millisecond for both, eliminating ~23s of real-time sleeps and a potential data race under -race.
  • attach tests: Changed force parameter from false to true to skip the interactive huh confirmation prompt that blocks indefinitely in TTY environments (e.g. mise run test from zsh).
  • waitForTranscriptFlush timeouts: Backdated transcript file mtimes in test helpers so waitForTranscriptFlush hits the stale fast-path instead of polling for 3s. Also moved PrepareTranscript inside the file-exists check in resolveAndValidateTranscript to avoid Cursor's 3s poll on non-existent files during agent auto-detection.

Net result: cli package 34s → 8s, strategy package 20s → 16s.

Test plan

  • go build ./... and go vet ./... pass
  • mise run lint — zero issues
  • go test -race -run TestWaitForApproval ./cmd/entire/cli/ — no data races
  • All TestWaitForApproval_* tests pass in ~0.01s (down from ~23s)
  • All TestAttach_* tests pass in ~0.05s each (down from ~3s), no TTY hang
  • TestSessionHasNewContentFromLiveTranscript_* tests pass in ~0.03s (down from ~3s)
  • Full go test ./... passes

🤖 Generated with Claude Code


Note

Low Risk
Low risk: primarily refactors polling/wait behavior to avoid unnecessary sleeps and test hangs, with minimal user-facing behavior change (only when/if PrepareTranscript runs).

Overview
Eliminates several sources of real-time waiting and test suite hangs in the CLI.

attach now only calls agent PrepareTranscript after confirming the transcript file exists, avoiding 3s polling during agent auto-detection; its tests run with force=true and backdate transcript mtimes so the flush-wait fast path is taken.

login refactors waitForApproval to take time.Duration values (and an explicit slowDownBackoff) and updates tests to use millisecond intervals, removing long sleeps and avoiding reliance on mutable package-level timing state.

Written by Cursor Bugbot for commit 281fb45. Configure here.

pfleidi added 2 commits March 31, 2026 17:23
waitForApproval accepted poll interval as int seconds, clamping to a
1s minimum. Tests could not go below 1s, adding ~23s of real-time
sleeps to the cli package test run. Change interval to time.Duration
so tests can pass time.Millisecond, and make slowDownBackoff a var
so the SlowDown test avoids a 5s real wait.

Entire-Checkpoint: 9492acb5b894
The attach tests called runAttach with force=false, which triggers an
interactive huh confirmation form. This blocks indefinitely in TTY
environments (e.g. running mise run test from zsh). None of the tests
assert on the amend prompt behavior, so force=true is correct here.

Entire-Checkpoint: 21ab878a620a
@pfleidi pfleidi requested a review from a team as a code owner April 1, 2026 01:06
Copilot AI review requested due to automatic review settings April 1, 2026 01:06
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR removes real-time waits in the CLI unit tests that were causing long runtimes and occasional hangs, primarily by allowing sub-second polling intervals in login device-authorization tests and bypassing interactive confirmation in attach tests.

Changes:

  • Updated waitForApproval to accept a time.Duration polling interval (instead of whole seconds), enabling millisecond polling in tests.
  • Made the login “slow_down” backoff configurable for tests to avoid multi-second sleeps.
  • Updated attach tests to run with force=true so they don’t block on interactive huh prompts in TTY environments.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
cmd/entire/cli/login.go Changes polling interval handling to time.Duration and makes slow-down backoff overrideable for tests.
cmd/entire/cli/login_test.go Uses millisecond intervals and overrides slow-down backoff to eliminate real sleeps.
cmd/entire/cli/attach_test.go Forces non-interactive attach behavior to prevent TTY hangs.

@pfleidi pfleidi enabled auto-merge April 1, 2026 01:11
@pfleidi pfleidi disabled auto-merge April 1, 2026 01:12
pfleidi added 2 commits March 31, 2026 18:15
Tests created fresh transcript files that appeared "live" to
waitForTranscriptFlush, causing it to poll for 3s per test waiting
for a sentinel that never appears. Three fixes:

- Backdate transcript file mtime in setupClaudeTranscript and
  strategy mid_turn_commit tests so the stale check fast-paths
- Move PrepareTranscript call inside the file-exists check in
  resolveAndValidateTranscript — don't poll on non-existent files
  during agent auto-detection (fixes Cursor's 3s poll on miss)

Entire-Checkpoint: c0dbb5d73ef9
… state

Replace the package-level var with a const (defaultSlowDownBackoff)
and pass the backoff duration as a parameter to waitForApproval.
Tests pass time.Millisecond, avoiding real-time waits without
mutating shared state. Fixes data race flagged by Copilot and Cursor.

Entire-Checkpoint: 1696f1f9188b
@pfleidi
Copy link
Copy Markdown
Contributor Author

pfleidi commented Apr 1, 2026

Bugbot run

@pfleidi pfleidi enabled auto-merge April 1, 2026 01:27
Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

@pfleidi pfleidi merged commit 5573952 into main Apr 1, 2026
4 checks passed
@pfleidi pfleidi deleted the fix/tests-hang branch April 1, 2026 03:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants