Skip to content

feat(e2e-cli): add flush-retry loop with drop detection#1175

Open
abueide wants to merge 11 commits intomasterfrom
tapi/cli-flush-retry-loop
Open

feat(e2e-cli): add flush-retry loop with drop detection#1175
abueide wants to merge 11 commits intomasterfrom
tapi/cli-flush-retry-loop

Conversation

@abueide
Copy link
Contributor

@abueide abueide commented Mar 19, 2026

Summary

  • Refactor e2e CLI (cli.ts) with extracted helpers (buildConfig, dispatchEvent, waitForQueueDrain) for clarity and robustness
  • Expose droppedEvents() on SegmentClient to surface permanently dropped event counts from SegmentDestination
  • Wire flush-retry loop that uses real flush policies, reports success/failure based on pending + dropped events

Test plan

  • Run e2e CLI against a live or mock Segment endpoint and verify events are flushed
  • Verify droppedEvents() returns correct count when events are permanently rejected
  • Confirm CLI exits with success: false when events remain pending or are dropped

🤖 Generated with Claude Code

abueide and others added 11 commits March 19, 2026 13:29
The CLI previously called flush() once and exited, so events that
received retryable errors (5xx, 429) stayed in the queue with no
retry. This implements the retry loop that flush policies drive in a
real app: flush → check pending → wait for backoff → repeat.

- Flush-retry loop respects maxRetries from test config
- Forward-compatible with tapi RetryManager (reads backoff state when
  available, falls back to fixed delay on master)
- Tracks permanently dropped events via logger interception
- Reports success=false when events remain or are dropped
- Computes sentBatches from delivered event count
- Enables retry test suite in e2e-config.json

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Instead of manually calling flush() in a loop and reading private
RetryManager state, let the SDK's built-in flush policies drive
retries. TimerFlushPolicy fires every flushInterval (100ms default
for e2e), and the RetryManager gates actual uploads during backoff.

The CLI just triggers the initial flush, then polls pendingEvents()
until the queue drains or 30s timeout.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Pass maxRetries from test config into httpConfig overrides so the SDK
  enforces retry limits during e2e tests
- Set output.error when permanentDropCount > 0 so failure reporting tests
  get a truthy error field
- Add BROWSER_BATCHING=true to e2e-config.json to skip tests that assume
  ephemeral per-request batching (RN uses persistent queue re-chunking)
- Add jsx: react to tsconfig.json for .tsx transitive imports

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Extract buildConfig, dispatchEvent, waitForQueueDrain, and
interceptDropCount from main(). Drop redundant per-event validation
warnings and error handling. 367 -> 256 lines.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Return boolean from waitForQueueDrain to indicate drain vs timeout
- Add JSDoc for interceptDropCount noting coupling to SegmentDestination log format
- Add console.warn in dispatchEvent when events are skipped for missing fields
- Add comment on sentBatches approximation

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Replace fragile log-interception pattern in e2e-cli with a proper
counter on SegmentDestination. The CLI now calls client.droppedEvents()
instead of monkey-patching logger.error and regex-matching drop messages.

- Add droppedEventCount property to SegmentDestination
- Add droppedEvents() accessor on SegmentClient (mirrors pendingEvents)
- Remove interceptDropCount helper from e2e-cli

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The retry e2e tests require RetryManager and SegmentDestination retry
wiring from downstream branches. Re-enable once that stack lands.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant