Skip to content

Conversation

@ymc9
Copy link
Member

@ymc9 ymc9 commented Dec 1, 2025

Summary by CodeRabbit

  • New Features

    • Bun-based end-to-end testing added (runtime, test package, generation script, and generated schema/type exports).
  • Tests

    • Test orchestration switched to Turbo; test caching disabled and TEST_DB_PROVIDER forwarded.
    • New e2e/Bun tests covering SQLite and Postgres CRUD and policy scenarios.
  • Improvements

    • Payload type signatures extended to accept client option generics for finer typing.
  • Chores

    • CI now sets up Bun; various test package dependency adjustments.

✏️ Tip: You can customize this high-level summary in your review settings.

Copilot AI review requested due to automatic review settings December 1, 2025 13:08
@coderabbitai
Copy link

coderabbitai bot commented Dec 1, 2025

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

Walkthrough

Exports PostgreSQL test config, adds Bun-based end-to-end tests and generated schema/type artifacts, updates generated payload types to accept ClientOptions, adjusts workspace catalog and test orchestration to use turbo, and adds CI step to install Bun. (50 words)

Changes

Cohort / File(s) Summary
Root build & orchestration
package.json, turbo.json
Switch test script to turbo run test; add cache: false to turbo test task and globalPassThroughEnv: ["TEST_DB_PROVIDER"].
Workspace / manifests
pnpm-workspace.yaml, tests/e2e/package.json, tests/regression/package.json
Reworked pnpm catalog entries; removed @types/uuid from tests/e2e/package.json; added @types/node to tests/regression/package.json.
Test utilities (Postgres)
packages/testtools/src/client.ts
Exported TEST_PG_CONFIG; added exported TEST_PG_URL; refactored createTestClient to use TEST_PG_URL.
Bun test package config & tooling
tests/bun/package.json, tests/bun/tsconfig.json, tests/bun/scripts/generate.ts
Added Bun test package, scripts (build/test/typecheck/generate), Bun TS config, and a generation script invoking bunx --bun zen generate.
Bun schema sources & generated artifacts
tests/bun/schemas/schema.zmodel, tests/bun/schemas/schema.ts, tests/bun/schemas/models.ts, tests/bun/schemas/input.ts
Added zmodel schema (User, Post, CommonFields, Role) and generated TypeScript schema, model types, and CRUD payload/type aliases.
Bun E2E tests
tests/bun/e2e.test.ts
New Bun-backed E2E tests exercising SQLite (BunSqliteDialect) and Postgres (PostgresDialect) CRUD and policy enforcement; includes dynamic Postgres DB setup.
Regression fixtures & types
tests/regression/test/issue-204/input.ts, tests/regression/test/issue-422/input.ts, tests/regression/tsconfig.json
Extended generated GetPayload type aliases to accept Options extends $ClientOptions<$Schema> (defaulted); added Node types to regression tsconfig.
CI workflow
.github/workflows/build-test.yml
Inserted "Use Bun" step to install Bun (oven-sh/setup-bun@v2) before subsequent steps.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~50 minutes

  • Areas needing extra attention:
    • packages/testtools/src/client.ts — public export changes and URL construction usage across tests.
    • tests/bun/schemas/schema.zmodel / generated schema.ts — access-control policy correctness and generated typing.
    • tests/bun/e2e.test.ts — DB lifecycle (create/drop), connection management, and policy assertions across dialects.
    • Updated generated GetPayload signatures — ensure call sites and tooling remain compatible.

Possibly related PRs

Poem

🐇 I hopped in with a schema bright,
Bun and Postgres set to flight,
Turbo hums and tests take wing,
Types aligned — the rabbit sings,
Small hops, big green CI light.

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'test(bun): basic e2e tests' directly corresponds to the main changes, which add comprehensive end-to-end tests for Bun runtime support including test configuration, schema definitions, and CI/CD setup.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch test/bun-e2e

📜 Recent review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f6f1c5c and 6e1589e.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (3)
  • pnpm-workspace.yaml (1 hunks)
  • tests/bun/e2e.test.ts (1 hunks)
  • tests/bun/package.json (1 hunks)
🧰 Additional context used
🧠 Learnings (8)
📓 Common learnings
Learnt from: CR
Repo: zenstackhq/zenstack-v3 PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-26T01:55:04.540Z
Learning: Applies to tests/e2e/**/*.{ts,tsx} : E2E tests should validate real-world schema compatibility with established projects
📚 Learning: 2025-11-26T01:55:04.540Z
Learnt from: CR
Repo: zenstackhq/zenstack-v3 PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-26T01:55:04.540Z
Learning: Applies to tests/e2e/**/*.{ts,tsx} : E2E tests should validate real-world schema compatibility with established projects

Applied to files:

  • tests/bun/e2e.test.ts
  • tests/bun/package.json
📚 Learning: 2025-11-26T01:55:04.540Z
Learnt from: CR
Repo: zenstackhq/zenstack-v3 PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-26T01:55:04.540Z
Learning: Applies to packages/zenstackhq/orm/**/*.test.{ts,tsx} : ORM package tests should include comprehensive client API tests and policy tests

Applied to files:

  • tests/bun/e2e.test.ts
📚 Learning: 2025-11-26T01:55:04.540Z
Learnt from: CR
Repo: zenstackhq/zenstack-v3 PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-26T01:55:04.540Z
Learning: Applies to tests/**/type*.{ts,tsx} : Ensure TypeScript inference and type coverage are validated through type coverage tests

Applied to files:

  • tests/bun/e2e.test.ts
  • tests/bun/package.json
📚 Learning: 2025-11-26T01:55:04.540Z
Learnt from: CR
Repo: zenstackhq/zenstack-v3 PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-26T01:55:04.540Z
Learning: Applies to packages/zenstackhq/cli/**/*.test.{ts,tsx} : CLI package tests should focus on action-specific tests for each command

Applied to files:

  • tests/bun/e2e.test.ts
  • tests/bun/package.json
📚 Learning: 2025-11-26T01:55:04.540Z
Learnt from: CR
Repo: zenstackhq/zenstack-v3 PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-26T01:55:04.540Z
Learning: Use `pnpm` with workspaces for package management, pinned to version `pnpm10.12.1`

Applied to files:

  • pnpm-workspace.yaml
📚 Learning: 2025-11-26T01:55:04.540Z
Learnt from: CR
Repo: zenstackhq/zenstack-v3 PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-26T01:55:04.540Z
Learning: Applies to packages/zenstackhq/orm/**/*.{ts,tsx} : Use Kysely as the query builder interface for low-level database queries, avoiding raw SQL when possible

Applied to files:

  • pnpm-workspace.yaml
📚 Learning: 2025-11-26T01:55:04.540Z
Learnt from: CR
Repo: zenstackhq/zenstack-v3 PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-26T01:55:04.540Z
Learning: Applies to packages/zenstackhq/orm/**/*.{ts,tsx} : Implement plugin hooks at ORM, Kysely, and entity mutation levels for query interception and customization

Applied to files:

  • pnpm-workspace.yaml
🧬 Code graph analysis (1)
tests/bun/e2e.test.ts (5)
packages/plugins/policy/src/plugin.ts (1)
  • PolicyPlugin (6-29)
packages/common-helpers/src/clone.ts (1)
  • clone (6-24)
tests/bun/schemas/schema.ts (1)
  • schema (176-176)
packages/testtools/src/client.ts (1)
  • TEST_PG_URL (35-35)
packages/orm/src/dialects/postgres.ts (1)
  • PostgresDialect (1-1)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: claude-review
  • GitHub Check: build-test (20.x, postgresql)
  • GitHub Check: build-test (20.x, sqlite)
🔇 Additional comments (4)
pnpm-workspace.yaml (1)

7-14: Remove the incorrect claim about better-sqlite3 being for Bun support.

The Bun e2e tests use native bun:sqlite and the kysely-bun-sqlite dialect, not better-sqlite3. The better-sqlite3: ^12.2.0 catalog entry is actually used in tests/e2e/, not in Bun tests.

The pg: ^8.13.1 version is correct—it's actively used in tests/bun/e2e.test.ts for PostgreSQL test fixtures (confirmed via Client and Pool imports from 'pg'). The caret range is appropriate and resolves to [email protected], which is compatible.

Remove the verification request about better-sqlite3 compatibility with Bun. The mixed pinning strategy in the catalog is acceptable since exact versions (e.g., next, svelte, react) are used for frontend frameworks, while ranges are used for backend/utility libraries.

Likely an incorrect or invalid review comment.

tests/bun/package.json (1)

1-27: Package configuration looks appropriate for Bun E2E tests.

The setup correctly uses Bun's test runner and includes the necessary ZenStack workspace dependencies. The script chain (buildgeneratetypecheck) is well-structured.

One minor note: the test:generate script uses tsx which isn't listed as a dependency. Verify that tsx is available from the workspace root or consider adding it to devDependencies if this package needs to run in isolation.

tests/bun/e2e.test.ts (2)

1-11: Imports are well-organized and appropriate.

Clean separation of concerns with ORM utilities, dialect implementations, test framework imports, and database drivers.


13-84: Tests provide good coverage of CRUD and policy enforcement.

The test suite effectively validates:

  • Full CRUD lifecycle (create, read, update, delete, count)
  • Policy plugin integration with authentication contexts

Based on learnings, this aligns with the goal that E2E tests should validate real-world schema compatibility.


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.

@claude
Copy link

claude bot commented Dec 1, 2025

Claude finished @ymc9's task —— View job


Code Review: Bun E2E Tests

Reviewing PR that adds Bun e2e testing infrastructure to ZenStack v3.

Review Tasks

  • Examine new Bun test directory structure and configuration
  • Review ZModel schema and generated TypeScript files
  • Analyze e2e test implementation and coverage
  • Check workspace and build system integration
  • Evaluate code quality and best practices
  • Assess security and performance considerations
  • Provide comprehensive feedback

Review Summary

This PR adds comprehensive Bun e2e testing infrastructure to ZenStack v3. Overall, the implementation is well-structured and follows good practices. Here's my detailed analysis:

✅ Positive Aspects

Test Structure & Organization

  • Well-organized directory structure: tests/bun/ with clear separation of schemas, scripts, and tests
  • Proper dual database testing: Tests run against both SQLite (in-memory) and PostgreSQL
  • Good test coverage: Tests basic CRUD operations and policy enforcement
  • Follows existing patterns: Mirrors the structure of other test directories in the project

Code Quality

  • Clean test implementation: tests/bun/e2e.test.ts:13-82 uses parameterized tests for both database providers
  • Proper schema generation: Uses automated generation via scripts/generate.ts:17 with bunx --bun zen generate
  • Type safety: Generated TypeScript types are properly imported and used
  • Good error handling: Database creation/cleanup is handled correctly

Integration

  • Proper workspace integration: Added to pnpm-workspace.yaml:4 and turbo.json:18
  • Consistent dependency management: Uses workspace references and catalog versions
  • Build system integration: Proper build, test:generate, and test:typecheck scripts

🔍 Areas for Improvement

Code Quality Issues

  1. Type Casting Safety (tests/bun/e2e.test.ts:88,93)

    (_schema as any).provider.type = 'sqlite';
    (_schema as any).provider.type = 'postgresql';

    Issue: Using any type casting bypasses type safety
    Recommendation: Create a proper type-safe method to update provider type or use structured cloning with proper typing

  2. Missing Error Handling (tests/bun/e2e.test.ts:98-100)

    await pgClient.query(`DROP DATABASE IF EXISTS "${dbName}"`);
    await pgClient.query(`CREATE DATABASE "${dbName}"`);

    Issue: No error handling for database operations that could fail
    Recommendation: Add try-catch blocks and proper error logging

  3. Hardcoded Test Data (tests/bun/e2e.test.ts:17-22)
    Issue: Test uses hardcoded IDs and email addresses
    Recommendation: Use test data generators or factories for more robust testing

Test Coverage Gaps

  1. Limited Policy Testing (tests/bun/e2e.test.ts:44-81)

    • Only tests basic read policies
    • Missing write, update, delete policy validation
    • No testing of complex policy expressions
  2. No Edge Case Testing

    • Missing validation of required fields
    • No testing of constraint violations
    • No concurrent operation testing
  3. No Performance Testing

    • No benchmarking against expected performance baselines
    • Missing stress testing with larger datasets

Configuration Issues

  1. Inconsistent Package Manager (package.json:5)

    "packageManager": "[email protected]"

    Issue: Root package.json uses [email protected] but CLAUDE.md indicates [email protected] is pinned
    Recommendation: Align package manager versions across the project

  2. Missing Test Timeout Configuration
    Issue: No explicit timeout configuration for potentially slow database operations
    Recommendation: Add appropriate timeouts for database setup/teardown

🚨 Security Considerations

  1. SQL Injection Risk (tests/bun/e2e.test.ts:98-99)
    Issue: Database names are interpolated directly into SQL queries
    Current: DROP DATABASE IF EXISTS "${dbName}"
    Recommendation: Use parameterized queries or validate/sanitize database names

  2. Test Database Isolation
    Good: Uses unique database names per test
    Good: Properly cleans up test databases

📈 Performance Considerations

  1. Database Connection Management
    Good: Uses connection pooling for PostgreSQL
    Good: Uses in-memory SQLite for fast testing

  2. Test Efficiency
    Good: Parameterized tests avoid code duplication
    Potential improvement: Consider test parallelization for faster CI runs

🔧 Recommendations

High Priority

  1. Fix type casting in createClient() function - use proper typing instead of any
  2. Add error handling for database operations
  3. Align package manager versions across the project

Medium Priority

  1. Expand policy testing to cover write operations and complex scenarios
  2. Add test data factories for more maintainable tests
  3. Add explicit timeout configuration for database operations

Low Priority

  1. Consider adding performance benchmarks
  2. Add stress testing with larger datasets
  3. Implement test parallelization for faster CI

🎯 Conclusion

This is a high-quality addition that follows ZenStack's patterns and provides valuable testing infrastructure for Bun runtime compatibility. The implementation is solid with only minor improvements needed. The PR successfully:

  • ✅ Adds comprehensive Bun e2e testing
  • ✅ Maintains compatibility with existing test infrastructure
  • ✅ Follows project conventions and patterns
  • ✅ Provides good test coverage for basic functionality

Recommendation: Approve with minor fixes - address the type casting and error handling issues before merging.


Copilot finished reviewing on behalf of ymc9 December 1, 2025 13:12
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds basic end-to-end tests for Bun runtime support, expanding the project's test coverage to ensure ZenStack works correctly with Bun. The changes include infrastructure updates to support Bun testing, new test files, schema generation scripts, and updates to generated type definitions.

Key Changes:

  • Added new Bun e2e test suite with SQLite and PostgreSQL support
  • Exported TEST_PG_URL and TEST_PG_CONFIG from testtools for better reusability
  • Updated turbo.json to disable test caching and pass through TEST_DB_PROVIDER environment variable
  • Updated catalog versions and cleaned up unused dependencies

Reviewed changes

Copilot reviewed 18 out of 19 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
tests/bun/e2e.test.ts New Bun e2e test file testing basic CRUD and policy enforcement across sqlite and postgres
tests/bun/package.json Package configuration for Bun test suite with dependencies and test scripts
tests/bun/tsconfig.json TypeScript configuration for Bun tests with bun-types
tests/bun/scripts/generate.ts Schema generation script using bunx zen generate
tests/bun/schemas/*.ts Auto-generated schema files for Bun tests
tests/bun/schemas/schema.zmodel ZModel schema definition with User/Post models and access policies
packages/testtools/src/client.ts Exported TEST_PG_CONFIG and TEST_PG_URL for reusability across test suites
turbo.json Disabled test caching and added TEST_DB_PROVIDER to global pass-through env vars
pnpm-workspace.yaml Reorganized and updated catalog (alphabetized, updated pg version)
tests/e2e/package.json Removed unused @types/uuid dependency
tests/regression/package.json Added @types/node dependency
tests/regression/tsconfig.json Added "node" to types array
tests/regression/test/issue-*/input.ts Updated generated type signatures with ClientOptions parameter
package.json Changed test script from vitest to turbo for consistent test orchestration
Files not reviewed (1)
  • pnpm-lock.yaml: Language not supported

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review for a chance to win a $100 gift card. Take the survey.

@claude
Copy link

claude bot commented Dec 1, 2025

Claude finished @ymc9's task —— View job


Code Review: Bun E2E Tests

Reviewing PR that adds Bun e2e testing infrastructure to ZenStack v3.

Review Tasks

  • Examine new Bun test directory structure and configuration
  • Review ZModel schema and generated TypeScript files
  • Analyze e2e test implementation and coverage
  • Check workspace and build system integration
  • Evaluate code quality and best practices
  • Assess security and performance considerations
  • Provide comprehensive feedback

Review Summary

This PR adds comprehensive Bun e2e testing infrastructure to ZenStack v3. Overall, the implementation is well-structured and follows good practices. Here's my detailed analysis:

✅ Positive Aspects

Test Structure & Organization

  • Well-organized directory structure: tests/bun/ with clear separation of schemas, scripts, and tests
  • Proper dual database testing: Tests run against both SQLite (in-memory) and PostgreSQL
  • Good test coverage: Tests basic CRUD operations and policy enforcement
  • Follows existing patterns: Mirrors the structure of other test directories in the project

Code Quality

  • Clean test implementation: tests/bun/e2e.test.ts:13-82 uses parameterized tests for both database providers
  • Proper schema generation: Uses automated generation via scripts/generate.ts:17 with bunx --bun zen generate
  • Type safety: Generated TypeScript types are properly imported and used
  • Good error handling: Database creation/cleanup is handled correctly

Integration

  • Proper workspace integration: Added to pnpm-workspace.yaml:4 and turbo.json:18
  • Consistent dependency management: Uses workspace references and catalog versions
  • Build system integration: Proper build, test:generate, and test:typecheck scripts

🔍 Areas for Improvement

Code Quality Issues

  1. Type Casting Safety (tests/bun/e2e.test.ts:88,93)

    (_schema as any).provider.type = 'sqlite';
    (_schema as any).provider.type = 'postgresql';

    Issue: Using any type casting bypasses type safety
    Recommendation: Create a proper type-safe method to update provider type or use structured cloning with proper typing

  2. Missing Error Handling (tests/bun/e2e.test.ts:98-100)

    await pgClient.query(`DROP DATABASE IF EXISTS "${dbName}"`);
    await pgClient.query(`CREATE DATABASE "${dbName}"`);

    Issue: No error handling for database operations that could fail
    Recommendation: Add try-catch blocks and proper error logging

  3. Hardcoded Test Data (tests/bun/e2e.test.ts:17-22)
    Issue: Test uses hardcoded IDs and email addresses
    Recommendation: Use test data generators or factories for more robust testing

Test Coverage Gaps

  1. Limited Policy Testing (tests/bun/e2e.test.ts:44-81)

    • Only tests basic read policies
    • Missing write, update, delete policy validation
    • No testing of complex policy expressions
  2. No Edge Case Testing

    • Missing validation of required fields
    • No testing of constraint violations
    • No concurrent operation testing
  3. No Performance Testing

    • No benchmarking against expected performance baselines
    • Missing stress testing with larger datasets

Configuration Issues

  1. Inconsistent Package Manager (package.json:5)

    "packageManager": "[email protected]"

    Issue: Root package.json uses [email protected] but CLAUDE.md indicates [email protected] is pinned
    Recommendation: Align package manager versions across the project

  2. Missing Test Timeout Configuration
    Issue: No explicit timeout configuration for potentially slow database operations
    Recommendation: Add appropriate timeouts for database setup/teardown

🚨 Security Considerations

  1. SQL Injection Risk (tests/bun/e2e.test.ts:98-99)
    Issue: Database names are interpolated directly into SQL queries
    Current: DROP DATABASE IF EXISTS "${dbName}"
    Recommendation: Use parameterized queries or validate/sanitize database names

  2. Test Database Isolation
    Good: Uses unique database names per test
    Good: Properly cleans up test databases

📈 Performance Considerations

  1. Database Connection Management
    Good: Uses connection pooling for PostgreSQL
    Good: Uses in-memory SQLite for fast testing

  2. Test Efficiency
    Good: Parameterized tests avoid code duplication
    Potential improvement: Consider test parallelization for faster CI runs

🔧 Recommendations

High Priority

  1. Fix type casting in createClient() function - use proper typing instead of any
  2. Add error handling for database operations
  3. Align package manager versions across the project

Medium Priority

  1. Expand policy testing to cover write operations and complex scenarios
  2. Add test data factories for more maintainable tests
  3. Add explicit timeout configuration for database operations

Low Priority

  1. Consider adding performance benchmarks
  2. Add stress testing with larger datasets
  3. Implement test parallelization for faster CI

🎯 Conclusion

This is a high-quality addition that follows ZenStack's patterns and provides valuable testing infrastructure for Bun runtime compatibility. The implementation is solid with only minor improvements needed. The PR successfully:

  • ✅ Adds comprehensive Bun e2e testing
  • ✅ Maintains compatibility with existing test infrastructure
  • ✅ Follows project conventions and patterns
  • ✅ Provides good test coverage for basic functionality

Recommendation: Approve with minor fixes - address the type casting and error handling issues before merging.


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: 0

🧹 Nitpick comments (6)
tests/bun/scripts/generate.ts (2)

16-18: Remove unnecessary async keyword.

The generate function uses synchronous execSync, making the async keyword misleading. Also consider adding error handling for generation failures.

-async function generate(schemaPath: string) {
-    execSync('bunx --bun zen generate', { cwd: path.dirname(schemaPath) });
+function generate(schemaPath: string) {
+    execSync('bunx --bun zen generate', { cwd: path.dirname(schemaPath), stdio: 'inherit' });
 }

Adding stdio: 'inherit' would surface any generation errors to the console.


8-14: Consider simplifying the main function.

Since generate doesn't need to be async, the main function can also be simplified.

-async function main() {
+function main() {
     const zmodelFiles = [...glob.sync(path.resolve(dir, '../schemas/*.zmodel'))];
     for (const file of zmodelFiles) {
         console.log(`Generating TS schema for: ${file}`);
-        await generate(file);
+        generate(file);
     }
 }
packages/testtools/src/client.ts (1)

28-36: Consider URL-encoding credentials in TEST_PG_URL.

If TEST_PG_PASSWORD contains special characters (e.g., @, :, /, #), the URL will be malformed. Consider encoding user/password components.

-export const TEST_PG_URL = `postgres://${TEST_PG_CONFIG.user}:${TEST_PG_CONFIG.password}@${TEST_PG_CONFIG.host}:${TEST_PG_CONFIG.port}`;
+export const TEST_PG_URL = `postgres://${encodeURIComponent(TEST_PG_CONFIG.user)}:${encodeURIComponent(TEST_PG_CONFIG.password)}@${TEST_PG_CONFIG.host}:${TEST_PG_CONFIG.port}`;
tests/bun/package.json (1)

22-27: Consider removing unused @zenstackhq/vitest-config dependency.

Since this package uses bun test (line 10) rather than Vitest, the @zenstackhq/vitest-config dev dependency appears unused. Consider removing it to keep dependencies minimal.

     "devDependencies": {
         "@types/pg": "^8.15.6",
         "@zenstackhq/typescript-config": "workspace:*",
-        "@zenstackhq/vitest-config": "workspace:*",
         "bun-types": "^1.3.3"
     }
tests/bun/e2e.test.ts (1)

84-111: Consider explicit Postgres DB/Pool lifecycle management to avoid flaky e2e runs

The Postgres branch dynamically drops/creates databases and instantiates a new Pool per createClient call, but the pool isn’t explicitly cleaned up or tied to a teardown, and the DB names are hard-coded. In more parallel or long-running e2e scenarios this can cause:

  • lingering connections keeping the process alive
  • transient failures if other workers reuse the same DB names

Consider:

  • tracking created Pool instances and closing them in a test teardown (e.g., a file-level cleanup hook), and/or
  • deriving unique DB names per worker/run (e.g., suffixing with a random or process-specific identifier) to avoid cross-run collisions.

This is not a blocker but would make the Bun e2e suite more robust.

tests/bun/schemas/schema.zmodel (1)

1-45: Schema and policies match the Bun e2e expectations

The User/Post models and policy rules (@@deny('all', auth() == null), author-based full access, and published-only read) line up with what the Bun e2e test asserts for anon / author / other user counts, so the model is consistent with the test behavior. Since this is the authoritative ZModel source, just ensure zenstack generate is rerun whenever this file changes so the TS artifacts under tests/bun/schemas stay in sync.

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 61719d5 and 5001f00.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (17)
  • package.json (1 hunks)
  • packages/testtools/src/client.ts (2 hunks)
  • pnpm-workspace.yaml (1 hunks)
  • tests/bun/e2e.test.ts (1 hunks)
  • tests/bun/package.json (1 hunks)
  • tests/bun/schemas/input.ts (1 hunks)
  • tests/bun/schemas/models.ts (1 hunks)
  • tests/bun/schemas/schema.ts (1 hunks)
  • tests/bun/schemas/schema.zmodel (1 hunks)
  • tests/bun/scripts/generate.ts (1 hunks)
  • tests/bun/tsconfig.json (1 hunks)
  • tests/e2e/package.json (0 hunks)
  • tests/regression/package.json (1 hunks)
  • tests/regression/test/issue-204/input.ts (2 hunks)
  • tests/regression/test/issue-422/input.ts (4 hunks)
  • tests/regression/tsconfig.json (1 hunks)
  • turbo.json (1 hunks)
💤 Files with no reviewable changes (1)
  • tests/e2e/package.json
🧰 Additional context used
📓 Path-based instructions (1)
**/*.zmodel

📄 CodeRabbit inference engine (CLAUDE.md)

**/*.zmodel: Always run zenstack generate after modifying ZModel schemas
ZModel schema files should define database structure and policies that compile to TypeScript via zenstack generate

Files:

  • tests/bun/schemas/schema.zmodel
🧠 Learnings (12)
📓 Common learnings
Learnt from: CR
Repo: zenstackhq/zenstack-v3 PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-26T01:55:04.540Z
Learning: Applies to tests/e2e/**/*.{ts,tsx} : E2E tests should validate real-world schema compatibility with established projects
📚 Learning: 2025-11-26T01:55:04.540Z
Learnt from: CR
Repo: zenstackhq/zenstack-v3 PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-26T01:55:04.540Z
Learning: Use Turbo for build orchestration and run `pnpm build`, `pnpm watch`, `pnpm lint`, and `pnpm test` for development tasks

Applied to files:

  • turbo.json
  • package.json
📚 Learning: 2025-11-26T01:55:04.540Z
Learnt from: CR
Repo: zenstackhq/zenstack-v3 PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-26T01:55:04.540Z
Learning: Applies to tests/**/type*.{ts,tsx} : Ensure TypeScript inference and type coverage are validated through type coverage tests

Applied to files:

  • tests/bun/tsconfig.json
  • tests/bun/schemas/models.ts
  • tests/bun/e2e.test.ts
  • tests/regression/tsconfig.json
  • tests/regression/package.json
📚 Learning: 2025-11-26T01:55:04.540Z
Learnt from: CR
Repo: zenstackhq/zenstack-v3 PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-26T01:55:04.540Z
Learning: Applies to tests/e2e/**/*.{ts,tsx} : E2E tests should validate real-world schema compatibility with established projects

Applied to files:

  • tests/bun/tsconfig.json
  • tests/bun/package.json
  • tests/bun/schemas/models.ts
  • tests/bun/e2e.test.ts
  • tests/bun/scripts/generate.ts
  • tests/regression/tsconfig.json
  • tests/regression/package.json
  • tests/bun/schemas/schema.ts
  • tests/bun/schemas/input.ts
📚 Learning: 2025-11-26T01:55:04.540Z
Learnt from: CR
Repo: zenstackhq/zenstack-v3 PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-26T01:55:04.540Z
Learning: Applies to **/*.zmodel : ZModel schema files should define database structure and policies that compile to TypeScript via `zenstack generate`

Applied to files:

  • tests/bun/tsconfig.json
  • tests/bun/schemas/models.ts
  • tests/bun/scripts/generate.ts
  • tests/regression/tsconfig.json
  • tests/regression/package.json
  • tests/bun/schemas/schema.zmodel
  • tests/bun/schemas/schema.ts
  • tests/bun/schemas/input.ts
📚 Learning: 2025-11-26T01:55:04.540Z
Learnt from: CR
Repo: zenstackhq/zenstack-v3 PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-26T01:55:04.540Z
Learning: Applies to packages/zenstackhq/cli/**/*.test.{ts,tsx} : CLI package tests should focus on action-specific tests for each command

Applied to files:

  • tests/bun/package.json
  • tests/regression/tsconfig.json
  • tests/regression/package.json
📚 Learning: 2025-11-26T01:55:04.540Z
Learnt from: CR
Repo: zenstackhq/zenstack-v3 PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-26T01:55:04.540Z
Learning: Use `pnpm` with workspaces for package management, pinned to version `pnpm10.12.1`

Applied to files:

  • pnpm-workspace.yaml
📚 Learning: 2025-11-26T01:55:04.540Z
Learnt from: CR
Repo: zenstackhq/zenstack-v3 PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-26T01:55:04.540Z
Learning: Applies to packages/zenstackhq/orm/**/*.{ts,tsx} : Use Kysely as the query builder interface for low-level database queries, avoiding raw SQL when possible

Applied to files:

  • pnpm-workspace.yaml
  • tests/bun/schemas/models.ts
  • tests/regression/test/issue-204/input.ts
  • tests/bun/schemas/schema.ts
  • tests/regression/test/issue-422/input.ts
  • tests/bun/schemas/input.ts
📚 Learning: 2025-11-26T01:55:04.540Z
Learnt from: CR
Repo: zenstackhq/zenstack-v3 PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-26T01:55:04.540Z
Learning: Applies to packages/zenstackhq/orm/**/*.{ts,tsx} : Implement plugin hooks at ORM, Kysely, and entity mutation levels for query interception and customization

Applied to files:

  • pnpm-workspace.yaml
  • tests/bun/schemas/models.ts
  • tests/regression/test/issue-204/input.ts
  • tests/regression/package.json
  • tests/bun/schemas/schema.ts
  • tests/regression/test/issue-422/input.ts
  • tests/bun/schemas/input.ts
📚 Learning: 2025-10-21T16:09:31.218Z
Learnt from: ymc9
Repo: zenstackhq/zenstack-v3 PR: 319
File: packages/runtime/src/client/executor/zenstack-query-executor.ts:63-72
Timestamp: 2025-10-21T16:09:31.218Z
Learning: In ZenStack, TypeDefs can be inherited by models. When a TypeDef contains fields with `map` attributes, those mapped field names need to be processed by the QueryNameMapper since they become part of the inheriting model's schema. Therefore, when checking if a schema has mapped names (e.g., in `schemaHasMappedNames`), both `schema.models` and `schema.typeDefs` must be inspected for `@map` and `map` attributes.

Applied to files:

  • tests/bun/schemas/models.ts
  • tests/bun/schemas/schema.ts
📚 Learning: 2025-11-26T01:55:04.540Z
Learnt from: CR
Repo: zenstackhq/zenstack-v3 PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-26T01:55:04.540Z
Learning: Applies to packages/zenstackhq/orm/**/*.test.{ts,tsx} : ORM package tests should include comprehensive client API tests and policy tests

Applied to files:

  • tests/regression/test/issue-204/input.ts
  • tests/bun/e2e.test.ts
  • tests/regression/package.json
  • tests/bun/schemas/schema.ts
  • tests/regression/test/issue-422/input.ts
  • tests/bun/schemas/input.ts
📚 Learning: 2025-11-26T01:55:04.540Z
Learnt from: CR
Repo: zenstackhq/zenstack-v3 PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-26T01:55:04.540Z
Learning: Applies to **/*.zmodel : Always run `zenstack generate` after modifying ZModel schemas

Applied to files:

  • tests/bun/scripts/generate.ts
🧬 Code graph analysis (5)
packages/testtools/src/client.ts (2)
packages/orm/src/client/crud/dialects/postgresql.ts (1)
  • provider (33-35)
packages/orm/src/client/crud/dialects/sqlite.ts (1)
  • provider (27-29)
tests/bun/e2e.test.ts (5)
packages/plugins/policy/src/plugin.ts (1)
  • PolicyPlugin (6-29)
packages/common-helpers/src/clone.ts (1)
  • clone (6-24)
tests/bun/schemas/schema.ts (1)
  • schema (176-176)
packages/testtools/src/client.ts (1)
  • TEST_PG_URL (35-35)
packages/orm/src/dialects/postgres.ts (1)
  • PostgresDialect (1-1)
tests/bun/schemas/schema.ts (2)
packages/schema/src/expression-utils.ts (1)
  • ExpressionUtils (19-123)
packages/schema/src/schema.ts (1)
  • SchemaDef (11-19)
tests/regression/test/issue-422/input.ts (1)
tests/bun/schemas/input.ts (1)
  • UserGetPayload (30-30)
tests/bun/schemas/input.ts (1)
tests/regression/test/issue-422/input.ts (20)
  • UserFindManyArgs (31-31)
  • UserFindUniqueArgs (32-32)
  • UserFindFirstArgs (33-33)
  • UserCreateArgs (34-34)
  • UserCreateManyArgs (35-35)
  • UserCreateManyAndReturnArgs (36-36)
  • UserUpdateArgs (37-37)
  • UserUpdateManyArgs (38-38)
  • UserUpdateManyAndReturnArgs (39-39)
  • UserUpsertArgs (40-40)
  • UserDeleteArgs (41-41)
  • UserDeleteManyArgs (42-42)
  • UserCountArgs (43-43)
  • UserAggregateArgs (44-44)
  • UserGroupByArgs (45-45)
  • UserWhereInput (46-46)
  • UserSelect (47-47)
  • UserInclude (48-48)
  • UserOmit (49-49)
  • UserGetPayload (50-50)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: Agent
  • GitHub Check: build-test (20.x, postgresql)
  • GitHub Check: build-test (20.x, sqlite)
  • GitHub Check: claude-review
🔇 Additional comments (16)
tests/bun/tsconfig.json (1)

1-8: LGTM!

The TypeScript configuration is well-suited for Bun-based tests: noEmit: true is appropriate since tests don't need to emit JS, and bun-types correctly provides Bun-specific type definitions.

tests/regression/package.json (1)

20-21: LGTM!

Adding @types/node via catalog reference correctly pairs with the tsconfig update and follows the monorepo's dependency management pattern.

tests/regression/tsconfig.json (1)

5-5: LGTM!

Adding "node" to the types array correctly enables Node.js type definitions, complementing the @types/node devDependency.

packages/testtools/src/client.ts (1)

109-109: LGTM!

Using the centralized TEST_PG_URL constant simplifies the URL construction and ensures consistency.

tests/regression/test/issue-204/input.ts (1)

9-10: Auto-generated file updated correctly.

The new ClientOptions generic parameter with a default value maintains backward compatibility while enabling client option customization in payload types.

tests/regression/test/issue-422/input.ts (2)

9-10: Auto-generated file updated consistently.

The ClientOptions import and updated payload type signatures are consistent with other generated files in the PR.


30-30: Payload type signatures follow consistent pattern.

SessionGetPayload, UserGetPayload, and ProfileGetPayload all correctly include the new Options generic parameter with appropriate defaults, matching the pattern in tests/bun/schemas/input.ts and tests/regression/test/issue-204/input.ts.

pnpm-workspace.yaml (1)

29-30: Fix Zod v4 breaking changes before deploying ^4.0.0.

Zod 4.0 has multiple breaking changes that will break the current codebase:

  1. zod/v3 import path removed (packages/orm/src/client/crud/validator/utils.ts): import { ZodIssueCode } from 'zod/v3' will fail. In Zod 4, use z.ZodIssueCode directly.

  2. .strict() and .passthrough() methods removed (packages/server/src/api/rest/index.ts lines 210, 223, 225): Replace .passthrough() with z.looseObject() and .strict() with z.strictObject() where applicable.

  3. ZodError API changes: Error handling in packages/orm/src/utils/zod-utils.ts and packages/server/src/api/utils.ts may be affected by ZodError format/flatten() removal in favor of treeifyError().

Run the automated codemod (npx zod-v3-to-v4) and update imports and schema definitions accordingly before upgrading.

⛔ Skipped due to learnings
Learnt from: CR
Repo: zenstackhq/zenstack-v3 PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-26T01:55:04.540Z
Learning: Applies to **/*.zmodel : ZModel schema files should define database structure and policies that compile to TypeScript via `zenstack generate`
Learnt from: CR
Repo: zenstackhq/zenstack-v3 PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-26T01:55:04.540Z
Learning: Applies to packages/zenstackhq/orm/**/*.test.{ts,tsx} : ORM package tests should include comprehensive client API tests and policy tests
Learnt from: CR
Repo: zenstackhq/zenstack-v3 PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-26T01:55:04.540Z
Learning: Applies to packages/zenstackhq/orm/**/*.{ts,tsx} : Implement plugin hooks at ORM, Kysely, and entity mutation levels for query interception and customization
Learnt from: CR
Repo: zenstackhq/zenstack-v3 PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-26T01:55:04.540Z
Learning: Applies to tests/e2e/**/*.{ts,tsx} : E2E tests should validate real-world schema compatibility with established projects
package.json (1)

11-11: LGTM!

The switch from vitest run to turbo run test aligns with the project's Turbo-based orchestration strategy. This enables proper dependency handling (tests depend on build) and consistent test execution across all workspaces.

turbo.json (2)

21-22: LGTM!

The globalPassThroughEnv configuration correctly allows TEST_DB_PROVIDER to be passed through to test tasks, enabling database provider selection during test execution.


17-20: The dependsOn: ["build"] configuration is correct.

Test packages depend on @zenstackhq workspace packages (@cli, @Orm, @language, @Schema, @plugin-policy, @SDK, @testtools). However, using "build" (without caret) is intentional and correct because the build task itself has dependsOn: ["^build"]. This creates the proper dependency chain: dependencies are built first (via ^build), then the current package is built (via build), then tests run. Adding "^build" directly to the test task would be redundant since the required builds are already ensured through the build task's dependencies.

The cache: false setting is appropriate for tests to ensure consistent execution.

tests/bun/package.json (1)

1-11: LGTM!

The package configuration is well-structured for Bun-based e2e tests. The build script properly sequences generation and type-checking, and the test script correctly uses Bun's native test runner.

tests/bun/schemas/models.ts (1)

1-14: LGTM!

This is a correctly structured generated file exporting model types and enum values. The pattern of dual-exporting Role as both a const (runtime) and type (compile-time) is idiomatic TypeScript for enum-like values.

tests/bun/schemas/schema.ts (1)

1-177: LGTM!

This generated schema file correctly defines the ZenStack ORM schema with:

  • User and Post models with proper relations and access control policies
  • CommonFields type definition for shared fields
  • Role enum with ADMIN and USER values
  • Proper use of as const satisfies SchemaDef for type safety while preserving literal types

The schema structure aligns with the SchemaDef type definition and uses ExpressionUtils correctly for policy expressions.

tests/bun/e2e.test.ts (1)

13-42: Good coverage and alignment with policies across sqlite/postgres

The two tests exercise both providers with realistic User/Post flows and validate the policy behavior you defined in the schema (anon → 0 posts, author → 2 posts, other user → 1 published post). Cloning the schema per provider and pushing it before use keeps cross-provider state isolated. This looks solid for a first Bun e2e pass.

Also applies to: 44-81

tests/bun/schemas/input.ts (1)

1-50: Generated input types look consistent with existing patterns

The User/Post arg and payload aliases mirror the existing regression input patterns (including the ClientOptions-aware GetPayload signatures) and the file is clearly generator-owned. No issues here as long as it continues to be maintained via the ZenStack CLI rather than manual edits.

@claude
Copy link

claude bot commented Dec 1, 2025

Claude finished @ymc9's task —— View job


Code Review: Bun E2E Tests

Reviewing PR that adds Bun e2e testing infrastructure to ZenStack v3.

Review Tasks

  • Examine new Bun test directory structure and configuration
  • Review ZModel schema and generated TypeScript files
  • Analyze e2e test implementation and coverage
  • Check workspace and build system integration
  • Evaluate code quality and best practices
  • Assess security and performance considerations
  • Provide comprehensive feedback

Review Summary

This PR adds comprehensive Bun e2e testing infrastructure to ZenStack v3. Overall, the implementation is well-structured and follows good practices. Here's my detailed analysis:

✅ Positive Aspects

Test Structure & Organization

  • Well-organized directory structure: tests/bun/ with clear separation of schemas, scripts, and tests
  • Proper dual database testing: Tests run against both SQLite (in-memory) and PostgreSQL
  • Good test coverage: Tests basic CRUD operations and policy enforcement
  • Follows existing patterns: Mirrors the structure of other test directories in the project

Code Quality

  • Clean test implementation: tests/bun/e2e.test.ts:13-82 uses parameterized tests for both database providers
  • Proper schema generation: Uses automated generation via scripts/generate.ts:17 with bunx --bun zen generate
  • Type safety: Generated TypeScript types are properly imported and used
  • Good error handling: Database creation/cleanup is handled correctly

Integration

  • Proper workspace integration: Added to pnpm-workspace.yaml:4 and turbo.json:18
  • Consistent dependency management: Uses workspace references and catalog versions
  • Build system integration: Proper build, test:generate, and test:typecheck scripts

🔍 Areas for Improvement

Code Quality Issues

  1. Type Casting Safety (tests/bun/e2e.test.ts:88,93)

    (_schema as any).provider.type = 'sqlite';
    (_schema as any).provider.type = 'postgresql';

    Issue: Using any type casting bypasses type safety
    Recommendation: Create a proper type-safe method to update provider type or use structured cloning with proper typing

  2. Missing Error Handling (tests/bun/e2e.test.ts:98-100)

    await pgClient.query(`DROP DATABASE IF EXISTS "${dbName}"`);
    await pgClient.query(`CREATE DATABASE "${dbName}"`);

    Issue: No error handling for database operations that could fail
    Recommendation: Add try-catch blocks and proper error logging

  3. Hardcoded Test Data (tests/bun/e2e.test.ts:17-22)
    Issue: Test uses hardcoded IDs and email addresses
    Recommendation: Use test data generators or factories for more robust testing

Test Coverage Gaps

  1. Limited Policy Testing (tests/bun/e2e.test.ts:44-81)

    • Only tests basic read policies
    • Missing write, update, delete policy validation
    • No testing of complex policy expressions
  2. No Edge Case Testing

    • Missing validation of required fields
    • No testing of constraint violations
    • No concurrent operation testing
  3. No Performance Testing

    • No benchmarking against expected performance baselines
    • Missing stress testing with larger datasets

Configuration Issues

  1. Inconsistent Package Manager (package.json:5)

    "packageManager": "[email protected]"

    Issue: Root package.json uses [email protected] but CLAUDE.md indicates [email protected] is pinned
    Recommendation: Align package manager versions across the project

  2. Missing Test Timeout Configuration
    Issue: No explicit timeout configuration for potentially slow database operations
    Recommendation: Add appropriate timeouts for database setup/teardown

🚨 Security Considerations

  1. SQL Injection Risk (tests/bun/e2e.test.ts:98-99)
    Issue: Database names are interpolated directly into SQL queries
    Current: DROP DATABASE IF EXISTS "${dbName}"
    Recommendation: Use parameterized queries or validate/sanitize database names

  2. Test Database Isolation
    Good: Uses unique database names per test
    Good: Properly cleans up test databases

📈 Performance Considerations

  1. Database Connection Management
    Good: Uses connection pooling for PostgreSQL
    Good: Uses in-memory SQLite for fast testing

  2. Test Efficiency
    Good: Parameterized tests avoid code duplication
    Potential improvement: Consider test parallelization for faster CI runs

🔧 Recommendations

High Priority

  1. Fix type casting in createClient() function - use proper typing instead of any
  2. Add error handling for database operations
  3. Align package manager versions across the project

Medium Priority

  1. Expand policy testing to cover write operations and complex scenarios
  2. Add test data factories for more maintainable tests
  3. Add explicit timeout configuration for database operations

Low Priority

  1. Consider adding performance benchmarks
  2. Add stress testing with larger datasets
  3. Implement test parallelization for faster CI

🎯 Conclusion

This is a high-quality addition that follows ZenStack's patterns and provides valuable testing infrastructure for Bun runtime compatibility. The implementation is solid with only minor improvements needed. The PR successfully:

  • ✅ Adds comprehensive Bun e2e testing
  • ✅ Maintains compatibility with existing test infrastructure
  • ✅ Follows project conventions and patterns
  • ✅ Provides good test coverage for basic functionality

Recommendation: Approve with minor fixes - address the type casting and error handling issues before merging.


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: 0

🧹 Nitpick comments (1)
.github/workflows/build-test.yml (1)

54-57: Pin a specific Bun version instead of "latest" for reproducible CI builds.

Using bun-version: latest means each CI run may use a different version, introducing non-determinism and making it harder to debug failures tied to version changes. Follow the same pinning strategy as the Node.js version (line 48-52).

            - name: Use Bun
              uses: oven-sh/setup-bun@v2
              with:
-                 bun-version: latest
+                 bun-version: 1.x  # or specify a concrete version like 1.2.3

If you prefer to always test against the latest Bun, document this as an intentional choice in a comment.

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5001f00 and f6f1c5c.

📒 Files selected for processing (2)
  • .github/workflows/build-test.yml (1 hunks)
  • tests/bun/e2e.test.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • tests/bun/e2e.test.ts
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: CR
Repo: zenstackhq/zenstack-v3 PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-26T01:55:04.540Z
Learning: Applies to tests/e2e/**/*.{ts,tsx} : E2E tests should validate real-world schema compatibility with established projects
Learnt from: CR
Repo: zenstackhq/zenstack-v3 PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-26T01:55:04.540Z
Learning: Applies to packages/zenstackhq/orm/**/*.test.{ts,tsx} : ORM package tests should include comprehensive client API tests and policy tests
📚 Learning: 2025-11-26T01:55:04.540Z
Learnt from: CR
Repo: zenstackhq/zenstack-v3 PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-26T01:55:04.540Z
Learning: Use Turbo for build orchestration and run `pnpm build`, `pnpm watch`, `pnpm lint`, and `pnpm test` for development tasks

Applied to files:

  • .github/workflows/build-test.yml
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: build-test (20.x, postgresql)
  • GitHub Check: build-test (20.x, sqlite)
🔇 Additional comments (1)
.github/workflows/build-test.yml (1)

54-85: No action needed — Bun e2e tests are already included in the test orchestration.

The tests/bun directory is part of the pnpm workspace and has a test script configured. When pnpm run test executes turbo run test, Turbo automatically discovers and runs the test scripts in all workspace packages, including the bun test command from tests/bun/package.json. The CI workflow is correctly set up to run Bun e2e tests as part of the standard test step.

@claude
Copy link

claude bot commented Dec 1, 2025

Claude finished @ymc9's task —— View job


Code Review: Bun E2E Tests

Reviewing PR that adds Bun e2e testing infrastructure to ZenStack v3.

Review Tasks

  • Examine new Bun test directory structure and configuration
  • Review ZModel schema and generated TypeScript files
  • Analyze e2e test implementation and coverage
  • Check workspace and build system integration
  • Evaluate code quality and best practices
  • Assess security and performance considerations
  • Provide comprehensive feedback

Review Summary

This PR adds comprehensive Bun e2e testing infrastructure to ZenStack v3. Overall, the implementation is well-structured and follows good practices. Here's my detailed analysis:

✅ Positive Aspects

Test Structure & Organization

  • Well-organized directory structure: tests/bun/ with clear separation of schemas, scripts, and tests
  • Proper dual database testing: Tests run against both SQLite (in-memory) and PostgreSQL
  • Good test coverage: Tests basic CRUD operations and policy enforcement
  • Follows existing patterns: Mirrors the structure of other test directories in the project

Code Quality

  • Clean test implementation: tests/bun/e2e.test.ts:13-82 uses parameterized tests for both database providers
  • Proper schema generation: Uses automated generation via scripts/generate.ts:17 with bunx --bun zen generate
  • Type safety: Generated TypeScript types are properly imported and used
  • Good error handling: Database creation/cleanup is handled correctly

Integration

  • Proper workspace integration: Added to pnpm-workspace.yaml:4 and turbo.json:18
  • Consistent dependency management: Uses workspace references and catalog versions
  • Build system integration: Proper build, test:generate, and test:typecheck scripts

🔍 Areas for Improvement

Code Quality Issues

  1. Type Casting Safety (tests/bun/e2e.test.ts:88,93)

    (_schema as any).provider.type = 'sqlite';
    (_schema as any).provider.type = 'postgresql';

    Issue: Using any type casting bypasses type safety
    Recommendation: Create a proper type-safe method to update provider type or use structured cloning with proper typing

  2. Missing Error Handling (tests/bun/e2e.test.ts:98-100)

    await pgClient.query(`DROP DATABASE IF EXISTS "${dbName}"`);
    await pgClient.query(`CREATE DATABASE "${dbName}"`);

    Issue: No error handling for database operations that could fail
    Recommendation: Add try-catch blocks and proper error logging

  3. Hardcoded Test Data (tests/bun/e2e.test.ts:17-22)
    Issue: Test uses hardcoded IDs and email addresses
    Recommendation: Use test data generators or factories for more robust testing

Test Coverage Gaps

  1. Limited Policy Testing (tests/bun/e2e.test.ts:44-81)

    • Only tests basic read policies
    • Missing write, update, delete policy validation
    • No testing of complex policy expressions
  2. No Edge Case Testing

    • Missing validation of required fields
    • No testing of constraint violations
    • No concurrent operation testing
  3. No Performance Testing

    • No benchmarking against expected performance baselines
    • Missing stress testing with larger datasets

Configuration Issues

  1. Inconsistent Package Manager (package.json:5)

    "packageManager": "[email protected]"

    Issue: Root package.json uses [email protected] but CLAUDE.md indicates [email protected] is pinned
    Recommendation: Align package manager versions across the project

  2. Missing Test Timeout Configuration
    Issue: No explicit timeout configuration for potentially slow database operations
    Recommendation: Add appropriate timeouts for database setup/teardown

🚨 Security Considerations

  1. SQL Injection Risk (tests/bun/e2e.test.ts:98-99)
    Issue: Database names are interpolated directly into SQL queries
    Current: DROP DATABASE IF EXISTS "${dbName}"
    Recommendation: Use parameterized queries or validate/sanitize database names

  2. Test Database Isolation
    Good: Uses unique database names per test
    Good: Properly cleans up test databases

📈 Performance Considerations

  1. Database Connection Management
    Good: Uses connection pooling for PostgreSQL
    Good: Uses in-memory SQLite for fast testing

  2. Test Efficiency
    Good: Parameterized tests avoid code duplication
    Potential improvement: Consider test parallelization for faster CI runs

🔧 Recommendations

High Priority

  1. Fix type casting in createClient() function - use proper typing instead of any
  2. Add error handling for database operations
  3. Align package manager versions across the project

Medium Priority

  1. Expand policy testing to cover write operations and complex scenarios
  2. Add test data factories for more maintainable tests
  3. Add explicit timeout configuration for database operations

Low Priority

  1. Consider adding performance benchmarks
  2. Add stress testing with larger datasets
  3. Implement test parallelization for faster CI

🎯 Conclusion

This is a high-quality addition that follows ZenStack's patterns and provides valuable testing infrastructure for Bun runtime compatibility. The implementation is solid with only minor improvements needed. The PR successfully:

  • ✅ Adds comprehensive Bun e2e testing
  • ✅ Maintains compatibility with existing test infrastructure
  • ✅ Follows project conventions and patterns
  • ✅ Provides good test coverage for basic functionality

Recommendation: Approve with minor fixes - address the type casting and error handling issues before merging.


@ymc9 ymc9 merged commit 3c22e34 into dev Dec 1, 2025
5 checks passed
@ymc9 ymc9 deleted the test/bun-e2e branch December 1, 2025 22:42
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