test(resumable-streams): add unit tests for core factory functions and chat session#1332
Conversation
🦋 Changeset detectedLatest commit: 5646fd7 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughThis PR adds Vitest configuration and dev dependencies, a changeset, and two new test suites: chat-session tests exercising create/resume/clear flows and HTTP responses, and store/adapter factory tests covering memory, generic, and VoltOps stores with mocked external dependencies. ChangesResumable Streams Unit Tests
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
ESLint skipped: no ESLint configuration detected in root package.json. To enable, add 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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
packages/resumable-streams/src/resumable-streams.spec.ts (1)
60-67: ⚡ Quick winAvoid
JSON.stringifyin the mock body.Use
safeStringifyfrom@voltagent/internalto build the mockedResponsebody.♻️ Proposed change
+import { safeStringify } from "`@voltagent/internal`"; + vi.mock("`@voltagent/core`", () => ({ getGlobalVoltOpsClient: vi.fn(() => null), VoltOpsClient: vi.fn().mockImplementation(() => ({ sendRequest: vi.fn( - async () => new Response(JSON.stringify({ streamId: "test-id" }), { status: 200 }), + async () => new Response(safeStringify({ streamId: "test-id" }), { status: 200 }), ), })), }));As per coding guidelines: "Never use JSON.stringify; use the
safeStringifyfunction instead, imported from@voltagent/internal".🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/resumable-streams/src/resumable-streams.spec.ts` around lines 60 - 67, Replace the inline JSON.stringify used in the mocked Response body with the project's safe serializer: import safeStringify from "`@voltagent/internal`" at the top of the test file (if not already imported) and update the vi.mock block so the VoltOpsClient.sendRequest mock returns new Response(safeStringify({ streamId: "test-id" }), { status: 200 }) instead of JSON.stringify(...); keep the rest of the mock (getGlobalVoltOpsClient, VoltOpsClient, sendRequest) unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/resumable-streams/src/resumable-streams.spec.ts`:
- Around line 262-266: The disabled-state tests flip when
VOLTAGENT_PUBLIC_KEY/VOLTAGENT_SECRET_KEY are present because
createResumableStreamVoltOpsStore (used by createResumableStreamAdapter and
resolveResumableStreamAdapter) falls back to env vars via
resolveVoltOpsClient/getGlobalVoltOpsClient; add the same test setup/teardown
you used in the first describe block to the resolveResumableStreamAdapter
describe block: in beforeEach, save and clear process.env.VOLTAGENT_PUBLIC_KEY
and VOLTAGENT_SECRET_KEY (or stub getGlobalVoltOpsClient/resolveVoltOpsClient to
return null), and in afterEach restore the saved env values (or restore the
stub) so createResumableStreamVoltOpsStore is forced disabled during those
tests.
---
Nitpick comments:
In `@packages/resumable-streams/src/resumable-streams.spec.ts`:
- Around line 60-67: Replace the inline JSON.stringify used in the mocked
Response body with the project's safe serializer: import safeStringify from
"`@voltagent/internal`" at the top of the test file (if not already imported) and
update the vi.mock block so the VoltOpsClient.sendRequest mock returns new
Response(safeStringify({ streamId: "test-id" }), { status: 200 }) instead of
JSON.stringify(...); keep the rest of the mock (getGlobalVoltOpsClient,
VoltOpsClient, sendRequest) unchanged.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: d95b3d5c-3f23-458f-a599-50cdb1c7632a
⛔ Files ignored due to path filters (1)
pnpm-lock.yamlis excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (5)
.changeset/resumable-streams-unit-tests.mdpackages/resumable-streams/package.jsonpackages/resumable-streams/src/chat-session.spec.tspackages/resumable-streams/src/resumable-streams.spec.tspackages/resumable-streams/vitest.config.ts
There was a problem hiding this comment.
1 issue found across 6 files
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
…fy, guard env vars in tests Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
Done — replaced |
|
Tip For best results, initiate chat on the files or code changes.
(´。• ᵕ •。`) ♡ If you found this review helpful, would you consider giving us a shout-out on X? Thank you for using CodeRabbit! |
PR Checklist
<type>(<scope>): <description>pnpm changesetWhat is the current behavior?
The
@voltagent/resumable-streamspackage has zero test coverage.What is the new behavior?
Unit tests cover the core factory functions, store type detection, and chat session flows using mocked external dependencies.
fixes #1329
Notes for reviewers
Tests use vitest with vi.mock() for Redis and VoltOps deps so no external services are required.
Summary by cubic
Add unit tests for
@voltagent/resumable-streamscovering factory functions, store type detection, and chat session resume/finish flows. Addresses Linear #1329 and stabilizes tests with ESM-safe config and env guards.vitestand@vitest/coverage-v8; includevitest.config.tswith coverage, path aliases, and ESM-safe__dirname. Tests usesafeStringifyand stubbed env vars for reliability.Written for commit 5646fd7. Summary will update on new commits.
Summary by CodeRabbit