Skip to content

Conversation

@ai16z-demirix
Copy link

@ai16z-demirix ai16z-demirix commented Jul 5, 2025

Issue related: #34

  • Migrated the Twitter plugin tests from Vitest to the Bun test runner
  • Replaced Vitest-specific APIs with Bun's native testing utilities
  • Created and enhanced mocks for the @elizaos/core module to support Bun's mocking system
  • Added ChannelType enum and UUID type exports to mocks for test compatibility
  • Fixed TypeScript compatibility issues in the e2e tests with a UUID utility function
  • Implemented type assertions for IAgentRuntime compatibility in e2e tests
  • Updated all test commands and documentation in TESTING_GUIDE.md and README.md
  • Added a dedicated documentation section explaining the Bun mocking approach
  • Added documentation about TypeScript compatibility fixes for UUID template literals
  • Pushed all changes to the fix/issue-34 branch with all tests now passing under Bun

Summary by CodeRabbit

  • Chores

    • Migrated all tests from Vitest to Bun's native test runner.
    • Updated test scripts and dependencies to use Bun, removing Vitest-related packages.
    • Added Bun-specific configuration and type support.
    • Introduced a global test setup file and updated documentation to reflect the new testing approach.
  • Documentation

    • Revised the testing guide to detail Bun test runner usage, setup, and new mocking strategies.
  • Tests

    • Updated all test files to use Bun's testing and mocking APIs.
    • Enhanced type safety in tests with stricter UUID typing and helper functions.
    • Adjusted test assertions and mocks for compatibility with Bun.

@coderabbitai
Copy link

coderabbitai bot commented Jul 5, 2025

Warning

Rate limit exceeded

@ai16z-demirix has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 6 minutes and 54 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between e4001a3 and 948e73c.

📒 Files selected for processing (1)
  • src/services/__tests__/PostService.test.ts (14 hunks)

Walkthrough

The codebase was migrated from the Vitest testing framework to Bun's native test runner. This involved updating test scripts, dependencies, mocking strategies, and type declarations. A new Bun test preload configuration and setup file were introduced to provide consistent mocks and environment preparation. Test files and documentation were updated accordingly.

Changes

File(s) Change Summary
bunfig.toml, tsconfig.json Added Bun test preload configuration and included @types/bun in TypeScript compiler options.
package.json Removed Vitest and coverage-v8 dependencies; added @types/bun; replaced test scripts with Bun-based commands for unit, E2E, and coverage testing.
src/test-setup.ts New Bun test setup file; globally mocks @elizaos/core exports including UUID generator, logger, event types, and channel types.
src/__mocks__/@elizaos/core.ts Added a mock module defining UUID type, channel type enum, logger mocks, event type constants, and a UUID creation function for testing.
src/__tests__/TESTING_GUIDE.md Updated testing documentation to reflect Bun test runner usage, new commands, Bun mocking APIs, test organization, and TypeScript UUID typing.
src/__tests__/e2e/twitter-integration.test.ts Migrated from Vitest to Bun test framework; replaced imports and mocks; introduced local UUID type and helper; updated typing of IDs; removed commented rate limit test.
src/__tests__/environment.test.ts Migrated from Vitest to Bun test framework; replaced mocks and removed environment variable stubbing; preserved test logic.
src/client/__tests__/auth.test.ts Migrated from Vitest to Bun test framework; replaced Vitest mocks with Bun mocks; updated mock setup and test syntax; preserved test logic.
src/services/__tests__/MessageService.test.ts, src/services/__tests__/PostService.test.ts Migrated from Vitest to Bun test framework; updated mocks to Bun style; added stricter UUID string typing; adjusted assertions for dynamic fields; removed explicit core mocking in PostService tests relying on preload mock.

Sequence Diagram(s)

sequenceDiagram
    participant TestRunner as Bun Test Runner
    participant Preload as test-setup.ts
    participant MockedCore as @elizaos/core (Mock)
    participant Test as Test File

    TestRunner->>Preload: Load preload setup (test-setup.ts)
    Preload->>MockedCore: Mock core exports (logger, createUniqueUuid, etc.)
    TestRunner->>Test: Execute test file
    Test->>MockedCore: Import and use mocked core
    Test->>TestRunner: Run assertions and report results
Loading

Poem

In a meadow of code, the tests now run,
Bun hops in where Vitest was done.
Mocks and scripts, all fresh and new,
With UUIDs and logs, the coverage grew.
The rabbits rejoice with a twitch of the ear—
"Bun's in the burrow, the tests are clear!" 🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai auto-generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@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 (3)
src/services/__tests__/MessageService.test.ts (1)

1-18: Migration to Bun completed successfully.

The imports and mocking setup are correctly updated for Bun. However, there's some redundancy with the preload mocking - the individual mock declarations and mock.module() call might be unnecessary since @elizaos/core is already mocked globally in test-setup.ts.

Consider simplifying the mock setup since the global preload already handles @elizaos/core:

-// Mock the dependencies
-const mockCreateUniqueUuid = mock((runtime, id) => `uuid-${id}`);
-const mockLoggerError = mock();
-const mockLoggerDebug = mock();
-
-mock.module("@elizaos/core", () => ({
-  createUniqueUuid: mockCreateUniqueUuid,
-  logger: {
-    error: mockLoggerError,
-    debug: mockLoggerDebug,
-  },
-}));
+// @elizaos/core is mocked in the test-setup.ts preload file
src/__mocks__/@elizaos/core.ts (2)

17-20: Type the logger stubs

Giving the stubs a signature (e.g. (msg: string, ...meta: unknown[]) => void) avoids any leakage and catches incorrect usage inside tests.

-const mockError = mock();
-const mockDebug = mock();
-const mockInfo = mock();
-const mockWarn = mock();
+const mockError = mock<(msg: string, ...meta: unknown[]) => void>();
+const mockDebug = mock<(msg: string, ...meta: unknown[]) => void>();
+const mockInfo  = mock<(msg: string, ...meta: unknown[]) => void>();
+const mockWarn  = mock<(msg: string, ...meta: unknown[]) => void>();

31-42: Freeze the EventType object to preserve literal types

Appending as const makes every value a readonly string literal, giving you correct union types downstream while preventing accidental mutation.

-export const EventType = {
+export const EventType = {
   WORLD_JOINED: 'WORLD_JOINED',
   MESSAGE_CREATED: 'MESSAGE_CREATED',
   MESSAGE_RECEIVED: 'MESSAGE_RECEIVED',
   CHANNEL_CREATED: 'CHANNEL_CREATED',
   ENTITY_CREATED: 'ENTITY_CREATED',
   ENTITY_UPDATED: 'ENTITY_UPDATED',
   ENTITY_DELETED: 'ENTITY_DELETED',
   AGENT_CREATED: 'AGENT_CREATED',
   AGENT_UPDATED: 'AGENT_UPDATED',
   AGENT_DELETED: 'AGENT_DELETED',
-};
+} as const;
+
+export type EventTypeKey = keyof typeof EventType;
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Cache: Disabled due to data retention organization setting
Knowledge Base: Disabled due to data retention organization setting

📥 Commits

Reviewing files that changed from the base of the PR and between eab1e88 and 787ef4c.

⛔ Files ignored due to path filters (1)
  • bun.lock is excluded by !**/*.lock
📒 Files selected for processing (11)
  • bunfig.toml (1 hunks)
  • package.json (1 hunks)
  • src/__mocks__/@elizaos/core.ts (1 hunks)
  • src/__tests__/TESTING_GUIDE.md (4 hunks)
  • src/__tests__/e2e/twitter-integration.test.ts (12 hunks)
  • src/__tests__/environment.test.ts (13 hunks)
  • src/client/__tests__/auth.test.ts (10 hunks)
  • src/services/__tests__/MessageService.test.ts (13 hunks)
  • src/services/__tests__/PostService.test.ts (14 hunks)
  • src/test-setup.ts (1 hunks)
  • tsconfig.json (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
src/__tests__/environment.test.ts (1)
src/environment.ts (2)
  • shouldTargetUser (63-83)
  • validateTwitterConfig (103-220)
src/test-setup.ts (1)
src/__mocks__/@elizaos/core.ts (1)
  • UUID (5-5)
🔇 Additional comments (22)
bunfig.toml (1)

1-3: LGTM! Proper Bun test configuration.

The bunfig.toml configuration correctly sets up test preloading for the src/test-setup.ts file, which is essential for consistent mocking and environment setup across all tests in the Bun test runner.

tsconfig.json (1)

13-13: LGTM! Proper TypeScript configuration for Bun.

Adding "bun-types" to the types array correctly enables TypeScript support for Bun's APIs and testing utilities, which is essential for the migration from Vitest to Bun's test framework.

src/__tests__/environment.test.ts (3)

1-1: LGTM! Correct migration to Bun test framework.

The import changes from Vitest to Bun's test framework are properly implemented.


14-14: LGTM! Proper API migration from Vitest to Bun.

The changes correctly replace Vitest's it with Bun's test function and vi.fn() with mock(). The test logic and assertions remain intact.

Also applies to: 22-22, 27-27, 32-32, 41-41, 50-50, 61-61, 80-80, 88-88, 110-110, 131-131, 157-157, 176-176, 193-193, 208-208, 227-227, 239-239


158-160: No process.env mutations detected—removing stubEnv is safe
I searched all tests and found only reads of process.env (no writes), so commenting out vi.stubEnv won’t introduce cross-test interference. Removing the stub is safe.

package.json (2)

27-27: LGTM! Proper dependency migration to Bun.

The changes correctly remove Vitest dependencies and add bun-types for TypeScript support with Bun's test framework.

Also applies to: 30-30


36-40: LGTM! Well-structured test scripts for Bun.

The new test scripts provide good granularity:

  • test:unit for unit tests
  • test:e2e for end-to-end tests
  • test:all for comprehensive testing
  • test:coverage for coverage reports

The script patterns correctly target the appropriate test directories.

src/client/__tests__/auth.test.ts (4)

1-1: LGTM! Correct import migration to Bun.

The imports are properly changed from Vitest to Bun's test framework.


4-24: LGTM! Proper Bun module mocking setup.

The module mocking approach correctly follows Bun's pattern:

  1. Create mock instances first
  2. Set up the mock module with mock.module
  3. Import the module after mocking

This ensures the mocks are properly established before the module is imported and used.


31-38: LGTM! Correct mock reset approach for Bun.

The beforeEach correctly uses Bun's mock reset methods (mockReset() and mockClear()) instead of Vitest's approach. The comment about "not needed with Bun's mocking approach" is appropriate.


48-48: LGTM! Proper API migration from Vitest to Bun.

All test cases are correctly changed from it to test to match Bun's testing API. The test logic and assertions remain unchanged.

Also applies to: 59-59, 66-66, 79-79, 86-86, 95-95, 145-145, 166-166, 194-194, 204-204, 227-227, 231-231

src/test-setup.ts (2)

1-6: LGTM! Good approach for centralized test setup.

The preload file correctly uses Bun's mocking system and provides a centralized location for global mocks. The UUID type definition is consistent with the pattern used throughout the codebase.


8-37: Comprehensive mock implementation for @elizaos/core.

The mock module covers all the essential exports needed by the test suites. The mock implementations are appropriate:

  • createUniqueUuid returns predictable test values
  • Logger methods are properly mocked
  • EventType and ChannelType enums include all necessary constants
src/services/__tests__/PostService.test.ts (3)

1-7: Successful migration to Bun test framework.

The imports are correctly updated to use bun:test instead of Vitest, and the comment appropriately notes that @elizaos/core is now mocked in the preload file.


16-16: Consistent UUID type casting throughout tests.

The UUID type casting using template literals is applied consistently across all test cases. The change to individual field assertions instead of deep equality is a good improvement for handling dynamic fields like timestamps.

Also applies to: 54-55, 68-84


111-130: Proper spy management in logger test.

Good practice using spyOn with mockRestore() to ensure test isolation and proper cleanup of mocks.

src/services/__tests__/MessageService.test.ts (1)

28-28: Consistent UUID type casting applied.

The UUID template literal type casting is consistently applied across all test cases, maintaining type safety while adapting to the new testing framework.

Also applies to: 76-76, 91-92

src/__tests__/TESTING_GUIDE.md (2)

44-54: Comprehensive update of test commands.

All test commands have been correctly updated from npm test to bun test, including pattern matching and watch mode examples. The syntax is appropriate for Bun's CLI.

Also applies to: 62-66


202-248: Excellent documentation of the new Bun test setup.

The new section provides clear, comprehensive guidance on:

  • Bun's test runner configuration
  • Mocking strategy with mock() and mock.module()
  • TypeScript compatibility with UUID template literals
  • Test organization and patterns

The examples are consistent with the actual implementation in the codebase.

src/__tests__/e2e/twitter-integration.test.ts (3)

1-30: Well-structured migration with local type definitions.

The migration to bun:test is clean, and the local IAgentRuntime type definition is a smart approach to avoid external dependencies in E2E tests. This makes the tests more self-contained and less prone to import issues.


33-37: Good TypeScript compatibility solution.

The UuidString type and asUuid helper function provide a clean way to handle UUID template literal types while maintaining compatibility. This pattern is consistent with the approach documented in the testing guide.


61-72: Consistent UUID casting in runtime and cleanup logic.

The UUID type casting is properly applied to the agent ID and throughout the cleanup logic, ensuring type consistency across all test operations.

Also applies to: 96-96

@ai16z-demirix
Copy link
Author

@ChristopherTrimboli @wtfsayo please review when available

@wtfsayo
Copy link
Member

wtfsayo commented Jul 8, 2025

bun add -D @types/bun

@ai16z-demirix
Copy link
Author

@wtfsayo done

@ai16z-demirix
Copy link
Author

Any more changes/fixes required here? @wtfsayo

@wtfsayo
Copy link
Member

wtfsayo commented Jul 14, 2025

remove local-ai dependency + bun lock checked in

@ai16z-demirix
Copy link
Author

remove local-ai dependency + bun lock checked in

On it sir! 🫡

@ai16z-demirix
Copy link
Author

Done @wtfsayo

cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Bug: Test Fails Due to Missing Environment Variable

The test "should prioritize config over runtime over env" cannot fully verify the config > runtime > env priority chain. The vi.stubEnv call for TWITTER_API_KEY is commented out, with a note that Bun uses process.env directly, but no alternative is provided to set the environment variable for the test.

src/__tests__/environment.test.ts#L156-L161

test("should prioritize config over runtime over env", async () => {
// Bun doesn't need stubEnv - will use process.env directly
// vi.stubEnv("TWITTER_API_KEY", "env-api-key");
mockRuntime.getSetting = mock((key) => {

Fix in CursorFix in Web


Was this report helpful? Give feedback by reacting with 👍 or 👎

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.

2 participants