test: add unit tests for HasRetry and HasStreamParsing traits #43

Merged
Snider merged 1 commit from test/service-trait-concerns into main 2026-02-23 06:08:26 +00:00
Member

Summary

Closes #12

Adds isolated unit tests for the two service concern traits that previously had no coverage:

  • tests/Unit/Concerns/HasRetryTest.php — 25 tests for HasRetry:

    • Success paths (first attempt, after 429, after 500, after ConnectionException, after RequestException)
    • Max retry limits (exhausting retries on 429/500/ConnectionException, custom maxRetries)
    • Non-retryable client errors (401, 400, 404 throw immediately without retrying)
    • Exponential backoff (sleep call count, no sleep on success, correct delay values)
    • calculateDelay formula (attempt 1/2/3 values, maxDelayMs cap, Retry-After header)
  • tests/Unit/Concerns/HasStreamParsingTest.php — 25 tests for HasStreamParsing:

    • parseSSEStream: basic extraction, [DONE] termination, blank/event/comment line skipping, invalid JSON skipping, null/empty extractor results, endings, chunked reads, remaining buffer after EOF
    • parseJSONStream: single/multiple objects, whitespace-separated, nested objects, escaped quotes, extractor filtering, chunked reads

Test plan

  • CI passes all existing tests
  • New HasRetryTest tests pass (no real HTTP calls or sleeps — both are stubbed)
  • New HasStreamParsingTest tests pass (in-memory PSR-7 stream mock — no I/O)

🤖 Generated with Claude Code

## Summary Closes #12 Adds isolated unit tests for the two service concern traits that previously had no coverage: - `tests/Unit/Concerns/HasRetryTest.php` — 25 tests for `HasRetry`: - Success paths (first attempt, after 429, after 500, after ConnectionException, after RequestException) - Max retry limits (exhausting retries on 429/500/ConnectionException, custom maxRetries) - Non-retryable client errors (401, 400, 404 throw immediately without retrying) - Exponential backoff (sleep call count, no sleep on success, correct delay values) - `calculateDelay` formula (attempt 1/2/3 values, maxDelayMs cap, Retry-After header) - `tests/Unit/Concerns/HasStreamParsingTest.php` — 25 tests for `HasStreamParsing`: - `parseSSEStream`: basic extraction, `[DONE]` termination, blank/event/comment line skipping, invalid JSON skipping, null/empty extractor results, ` ` endings, chunked reads, remaining buffer after EOF - `parseJSONStream`: single/multiple objects, whitespace-separated, nested objects, escaped quotes, extractor filtering, chunked reads ## Test plan - [ ] CI passes all existing tests - [ ] New `HasRetryTest` tests pass (no real HTTP calls or sleeps — both are stubbed) - [ ] New `HasStreamParsingTest` tests pass (in-memory PSR-7 stream mock — no I/O) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Clotho added 1 commit 2026-02-23 01:30:48 +00:00
test: add unit tests for HasRetry and HasStreamParsing traits (#12)
Some checks failed
CI / tests (pull_request) Failing after 1m8s
9c50d29c19
- tests/Unit/Concerns/HasRetryTest.php: covers withRetry success paths,
  max retry limits, non-retryable 4xx errors, exponential backoff with
  sleep verification, Retry-After header, and calculateDelay formula
- tests/Unit/Concerns/HasStreamParsingTest.php: covers parseSSEStream
  (basic extraction, [DONE] termination, line-type skipping, invalid
  JSON, chunked reads) and parseJSONStream (single/multiple objects,
  nesting, escaped strings, extractor filtering, chunked reads)

Closes #12

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Snider merged commit 143aee7d42 into main 2026-02-23 06:08:26 +00:00
Snider deleted branch test/service-trait-concerns 2026-02-23 06:08:26 +00:00
Sign in to join this conversation.
No description provided.