Skip to content

Implement counting#417

Merged
kibertoad merged 1 commit intomainfrom
feat/spy-counts
Mar 17, 2026
Merged

Implement counting#417
kibertoad merged 1 commit intomainfrom
feat/spy-counts

Conversation

@kibertoad
Copy link
Owner

@kibertoad kibertoad commented Mar 17, 2026

Summary by CodeRabbit

  • New Features

    • Added per-status message counters to Handler Spies, accessible via handlerSpy.counts. Tracks consumed, published, retryLater, and error counts. Counters increment automatically for each processed message and reset when clearing the buffer.
  • Tests

    • Added comprehensive test coverage for the new counter functionality.

@kibertoad kibertoad requested a review from CarlosGamero March 17, 2026 14:07
@coderabbitai
Copy link

coderabbitai bot commented Mar 17, 2026

Caution

Review failed

Pull request was closed or merged during review

📝 Walkthrough

Walkthrough

This PR introduces per-status message counters to the HandlerSpy class. A new SpyResultCounts type tracks consumed, published, retryLater, and error counts. HandlerSpy now maintains internal counts, exposes a getter, and increments counters during message processing. The clear() method resets counters to zero. Documentation and comprehensive tests are included.

Changes

Cohort / File(s) Summary
Documentation
README.md
Added "Counters" subsection documenting the handlerSpy.counts API, explaining counter fields, increment behavior independent of bufferSize, and reset behavior via clear().
Public API
packages/core/lib/index.ts
Exported new SpyResultCounts type from HandlerSpy module.
Core Implementation
packages/core/lib/queues/HandlerSpy.ts
Introduced SpyResultCounts type, added _counts field to track consumed/published/retryLater/error counts, exposed public counts getter returning shallow copy, and incremented appropriate counter in addProcessedMessage based on processingResult status.
Test Coverage
packages/core/test/queues/HandlerSpy.spec.ts
Added comprehensive tests covering initial counter state, per-status counter increments, aggregate counting, clear() reset behavior, and shallow copy verification.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

  • feat: test pubsub publisher #365: Modifies HandlerSpy in packages/core/lib/queues/HandlerSpy.ts by adding getAllReceivedMessages functionality alongside this counts feature.
  • Add flexible type resolution #373: Changes addProcessedMessage signature and message-type handling in HandlerSpy, directly affecting the counter increment logic introduced here.

Suggested reviewers

  • CarlosGamero

Poem

🐰 Hop along with counts so neat,
Four fields tracking messages sweet,
Consumed and published, errors too,
HandlerSpy now sees them through!
Clear it all with one quick call,

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Title check ❓ Inconclusive The title 'Implement counting' is vague and generic, failing to describe what is actually being counted or the specific feature being implemented. Use a more descriptive title such as 'Add message counter to HandlerSpy' or 'Implement per-status message counters' to clearly convey the feature being added.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/spy-counts
📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@kibertoad kibertoad merged commit 7eb1043 into main Mar 17, 2026
6 of 8 checks passed
@kibertoad kibertoad deleted the feat/spy-counts branch March 17, 2026 14:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants