Skip to content

test(resumable-streams): add unit tests for core factory functions and chat session#1332

Open
nuthalapativarun wants to merge 2 commits into
VoltAgent:mainfrom
nuthalapativarun:test/1329-resumable-streams-unit-tests
Open

test(resumable-streams): add unit tests for core factory functions and chat session#1332
nuthalapativarun wants to merge 2 commits into
VoltAgent:mainfrom
nuthalapativarun:test/1329-resumable-streams-unit-tests

Conversation

@nuthalapativarun
Copy link
Copy Markdown

@nuthalapativarun nuthalapativarun commented May 29, 2026

PR Checklist

  • Commit message follows conventional commits: <type>(<scope>): <description>
  • Related issue(s) linked
  • Tests added/updated
  • Docs added/updated if needed
  • Changeset created via pnpm changeset

What is the current behavior?

The @voltagent/resumable-streams package 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-streams covering factory functions, store type detection, and chat session resume/finish flows. Addresses Linear #1329 and stabilizes tests with ESM-safe config and env guards.

  • Dependencies
    • Add vitest and @vitest/coverage-v8; include vitest.config.ts with coverage, path aliases, and ESM-safe __dirname. Tests use safeStringify and stubbed env vars for reliability.

Written for commit 5646fd7. Summary will update on new commits.

Review in cubic

Summary by CodeRabbit

  • Tests
    • Added comprehensive unit tests covering resumable stream behavior, stores, adapters, and error/edge cases to improve reliability and correctness.
  • Chores
    • Added a test runner configuration and test-related dev dependencies.
    • Added a changeset entry to trigger a patch release for the resumable-streams package.

Review Change Stack

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 29, 2026

🦋 Changeset detected

Latest commit: 5646fd7

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@voltagent/resumable-streams Patch

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

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 29, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: a66fdeb2-3db3-4864-8cfa-bd7f7398aa95

📥 Commits

Reviewing files that changed from the base of the PR and between d9ca890 and 5646fd7.

📒 Files selected for processing (2)
  • packages/resumable-streams/src/resumable-streams.spec.ts
  • packages/resumable-streams/vitest.config.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/resumable-streams/vitest.config.ts
  • packages/resumable-streams/src/resumable-streams.spec.ts

📝 Walkthrough

Walkthrough

This 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.

Changes

Resumable Streams Unit Tests

Layer / File(s) Summary
Test configuration and changeset
packages/resumable-streams/vitest.config.ts, packages/resumable-streams/package.json, .changeset/resumable-streams-unit-tests.md
Adds Vitest config with aliases, coverage (v8) and timeouts; adds vitest and @vitest/coverage-v8 to devDependencies; adds a changeset file noting tests and a patch bump.
Chat Session API Tests
packages/resumable-streams/src/chat-session.spec.ts
Adds helper builders and comprehensive tests for createResumableChatSession: input validation, delegation to adapter.createStream, resumeStream/null handling, getActiveStreamId, clearActiveStream semantics, consumeSseStream/onFinish error resilience, and resumeResponse HTTP behavior (204/200 cases).
Store and Adapter Factory Tests
packages/resumable-streams/src/resumable-streams.spec.ts
Adds tests (with mocks) for memory/generic/VoltOps stores and adapter creation/resolution: disabled-state detection, store-type markers, keyPrefix behavior, publisher/subscriber validation, adapter capability enforcement, and resolver logging on disabled/invalid adapters.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Suggested reviewers

  • omeraplak

Poem

🐰 With whiskers twitching, tests hop in place,
Streams resume with steady grace,
Mocks and configs dance in tune,
Coverage rising like the moon,
A tiny patch — a testing embrace.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: adding unit tests for core factory functions and chat session in the resumable-streams package.
Description check ✅ Passed The description adequately covers current behavior, new behavior, the linked issue, testing approach, and relevant implementation notes. All key aspects are addressed.
Linked Issues check ✅ Passed The PR fully implements the requirements from issue #1329: comprehensive unit tests for resumable-streams.ts factory functions and chat-session.ts flows using mocked dependencies.
Out of Scope Changes check ✅ Passed All changes are directly related to the linked issue objectives: test files, test configuration, vitest dependencies, and changesets. No extraneous modifications detected.
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 unit tests (beta)
  • Create PR with unit tests

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

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint skipped: no ESLint configuration detected in root package.json. To enable, add eslint to devDependencies.


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.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
packages/resumable-streams/src/resumable-streams.spec.ts (1)

60-67: ⚡ Quick win

Avoid JSON.stringify in the mock body.

Use safeStringify from @voltagent/internal to build the mocked Response body.

♻️ 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 safeStringify function 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

📥 Commits

Reviewing files that changed from the base of the PR and between 41cad53 and d9ca890.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (5)
  • .changeset/resumable-streams-unit-tests.md
  • packages/resumable-streams/package.json
  • packages/resumable-streams/src/chat-session.spec.ts
  • packages/resumable-streams/src/resumable-streams.spec.ts
  • packages/resumable-streams/vitest.config.ts

Comment thread packages/resumable-streams/src/resumable-streams.spec.ts
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 6 files

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread packages/resumable-streams/vitest.config.ts
…fy, guard env vars in tests

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@nuthalapativarun
Copy link
Copy Markdown
Author

Done — replaced JSON.stringify with safeStringify from @voltagent/internal in the mock response body. Thanks @coderabbitai!

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 31, 2026

Tip

For best results, initiate chat on the files or code changes.

@nuthalapativarun: Great work — using safeStringify is the right call for safely handling circular references or non-serializable values in the mock response body. Thanks for the update!

(´。• ᵕ •。`) ♡


If you found this review helpful, would you consider giving us a shout-out on X?

Thank you for using CodeRabbit!

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.

test: add unit tests for @voltagent/resumable-streams

1 participant