-
Notifications
You must be signed in to change notification settings - Fork 1
Add JetStream STREAM.INFO API implementation and reorganize tests #25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
- Implement getStreamInfo method in jetstream.zig for $JS.API.STREAM.INFO endpoint - Add comprehensive test for STREAM.INFO functionality - Reorganize JetStream tests by moving stream management tests to dedicated jetstream_stream_test.zig file - Update test runner to include new test file - All tests passing (27/27) This addresses the missing STREAM.INFO endpoint identified in the JetStream API implementation.
WalkthroughIntroduces JetStream.getStreamInfo to request and parse stream info via STREAM.INFO.{name}. Adds a new test suite for stream lifecycle and info retrieval, updates the central test aggregator to include it, and removes overlapping stream tests from the existing JetStream test file. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
actor Dev as Caller
participant JS as JetStream
participant NC as NATS Conn
participant SV as NATS Server
Dev->>JS: getStreamInfo(stream_name)
JS->>JS: Build subject "STREAM.INFO.{name}"
JS->>NC: Request(subject, payload="")
NC->>SV: PUB/INBOX (request)
SV-->>NC: MSG (stream info JSON)
NC-->>JS: Response bytes
JS->>JS: parseResponse -> StreamInfo
JS-->>Dev: Result(StreamInfo)
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
✨ Finishing Touches🧪 Generate unit tests
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (6)
src/jetstream.zig (1)
366-376: STREAM.INFO implementation looks solid and consistent with existing JetStream methods
- Correct subject construction, allocation, and cleanup.
- Uses the same parseResponse/Result pattern as add/update/delete stream.
Optional: de-duplicate stream-subject building across methods
You build "STREAM.{ACTION}.{name}" in several places (CREATE/UPDATE/DELETE/INFO). Consider a small helper to reduce repetition and centralize the format.
Apply this diff within the changed block:
- // Build the subject for the API call - const subject = try std.fmt.allocPrint(self.allocator, "STREAM.INFO.{s}", .{stream_name}); - defer self.allocator.free(subject); - - const msg = try self.sendRequest(subject, ""); + const msg = try self.sendStreamRequest("INFO", stream_name, ""); defer msg.deinit();Add this helper elsewhere in the file (outside the selected range):
fn sendStreamRequest(self: *JetStream, action: []const u8, stream_name: []const u8, payload: []const u8) !*Message { const subject = try std.fmt.allocPrint(self.allocator, "STREAM.{s}.{s}", .{ action, stream_name }); defer self.allocator.free(subject); return try self.sendRequest(subject, payload); }tests/jetstream_stream_test.zig (5)
8-40: List stream names test is clear and correct
- Creates a stream, lists names, and asserts presence. Matches API semantics and cleans up resources.
Optional: assert uniqueness to catch cross-test leakage
Since beforeEach purges all streams, you could also assert that result.value.len == 1 here to detect unexpected leftover streams. Up to you given the global cleanup.
42-71: Add stream test verifies key config fields
- Checks name, subjects, retention, storage, and limits — good coverage for creation response shape.
Optional: add a couple more invariants
- Assert num_replicas and max_bytes to fully mirror the requested config.
72-111: List streams test validates returned configs
- Finds the created stream and inspects important fields.
Optional: verify that total equals returned count in paged response
Your library currently collapses the page to a flat slice and asserts total == len internally; adding a test assertion here would guard against regressions if pagination handling changes.
112-147: Update stream test covers the happy path well
- Create, assert initial, update, assert new value — straightforward and reliable.
Optional: assert that unrelated fields remain unchanged after update
E.g., subjects or retention, to ensure partial updates don't accidentally reset fields.
148-193: Delete stream test validates pre/post conditions via listing
- Good approach to verify deletion without relying on error types.
Optional: also assert getStreamInfo fails post-delete when typed errors become available
If/when the client exposes a more granular JetStream error set, add:
- try testing.expectError(nats.JetStreamError.StreamNotFound, js.getStreamInfo("TEST_DELETE_STREAM"));
I can help wire specific JetStream error codes through maybeParseErrorResponse so tests can assert finer-grained errors. Want a follow-up PR?
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (4)
src/jetstream.zig(1 hunks)tests/all_tests.zig(1 hunks)tests/jetstream_stream_test.zig(1 hunks)tests/jetstream_test.zig(1 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-08-23T20:26:30.660Z
Learnt from: CR
PR: lalinsky/nats.zig#0
File: CLAUDE.md:0-0
Timestamp: 2025-08-23T20:26:30.660Z
Learning: Run tests (zig build test) to confirm your changes are working
Applied to files:
tests/jetstream_stream_test.zig
🔇 Additional comments (3)
tests/all_tests.zig (1)
11-11: Good test split: importing jetstream_stream_test.zig keeps suites focusedThe new import cleanly separates stream lifecycle tests from consumer tests, improving organization without altering the harness.
tests/jetstream_test.zig (1)
238-238: No functional changeThe added blank line is fine and does not affect test behavior.
tests/jetstream_stream_test.zig (1)
194-223: Unable to locate the test file path automatically—please verify thattests/jetstream_stream_test.zigexists and is named correctly. Without access to Zig or a fully cloned tree here, I cannot confirm those optionalstatefields exist.Next steps for manual verification
- Ensure that your
getStreamInforeturn type includes
•state.messages
•state.consumer_count- If so, consider adding these zero-value assertions:
try testing.expect(retrieved_info.value.state.messages == 0); try testing.expect(retrieved_info.value.state.consumer_count == 0);- Finally, run the full test suite locally and confirm all tests pass:
zig build test --summary all
Summary
$JS.API.STREAM.INFO.{stream}endpoint in JetStream APIgetStreamInfomethod to jetstream.zig with comprehensive test coverageChanges Made
JetStream API Implementation
getStreamInfo(stream_name)method to JetStream struct insrc/jetstream.zig:367-376Result(StreamInfo)for consistency with other JetStream methodsTest Organization
tests/jetstream_stream_test.zigfor stream management testsjetstream_test.zigto new file:test "list stream names"- Tests$JS.API.STREAM.NAMEStest "add stream"- Tests$JS.API.STREAM.CREATE.{stream}test "list streams"- Tests$JS.API.STREAM.LISTtest "update stream"- Tests$JS.API.STREAM.UPDATE.{stream}test "delete stream"- Tests$JS.API.STREAM.DELETE.{stream}test "get stream info"- Tests$JS.API.STREAM.INFO.{stream}⭐ NEWtests/all_tests.zigto include new test modulejetstream_test.zigTest Results
All tests pass: 27/27 ✅
jetstream_stream_test.test.get stream inforuns successfully (10.34ms)Technical Notes
This addresses one of the missing JetStream API endpoints identified in the codebase analysis. The
STREAM.INFOendpoint is commonly used for monitoring and management operations, providing stream configuration and state information without requiring create/update operations.Summary by CodeRabbit
New Features
Tests