Skip to content

Conversation

@ymc9
Copy link
Member

@ymc9 ymc9 commented Sep 17, 2025

Summary by CodeRabbit

  • Tests

    • Expanded policy test coverage: composite (multi-ID) keys, nested to-one/to-many relations, query reduction scenarios, and a Pet Store sample suite (currently skipped).
    • Added autogenerated schema and type definitions to support the Pet Store sample tests.
    • Enhanced assertions for auth-driven access, nested writes/reads, and partial results across complex relations.
  • Refactor

    • Updated test import paths and suite names for consistency and correct module resolution.
  • Chores

    • Introduced generated test assets (schema, models, input typings) to streamline policy testing.

Copilot AI review requested due to automatic review settings September 17, 2025 05:36
@coderabbitai
Copy link

coderabbitai bot commented Sep 17, 2025

Walkthrough

Multiple migrated policy tests updated import paths. Several new Vitest suites were added for composite IDs, nested to-one/to-many relations, query reduction, and a petstore sample. A set of auto-generated petstore schema/types files were introduced. One existing test also updated a suite title and an additional import.

Changes

Cohort / File(s) Summary
Migrated test import path updates
packages/runtime/test/policy/migrated/auth.test.ts, .../client-extensions.test.ts, .../connect-disconnect.test.ts, .../create-many-and-return.test.ts, .../cross-model-field-comparison.test.ts, .../current-model.test.ts, .../current-operation.test.ts, .../deep-nested.test.ts, .../empty-policy.test.ts, .../field-comparison.test.ts
Adjusted helper import paths (primarily ./utils../utils); no test logic changes.
Client extensions import corrections
packages/runtime/test/policy/migrated/client-extensions.test.ts
Changed definePlugin import path and moved createPolicyTestClient import to parent utils.
Multi-field unique tweaks
packages/runtime/test/policy/migrated/multi-field-unique.test.ts
Updated imports (../utils, ../../../src) and renamed suite description; behavior unchanged.
New policy test suites (complex scenarios)
packages/runtime/test/policy/migrated/multi-id-fields.test.ts, .../nested-to-many.test.ts, .../nested-to-one.test.ts, .../petstore-sample.test.ts, .../query-reduction.test.ts
Added extensive tests covering composite IDs, nested to-many/to-one operations, query reduction, and a skipped petstore sample suite.
Petstore generated schema/types
packages/runtime/test/schemas/petstore/input.ts, .../models.ts, .../schema.ts, .../schema.zmodel
Added auto-generated schema, model result types, and model-specific input/type aliases for User, Pet, Order.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

Poem

A nibble of imports, hop to the parent path,
New warrens of tests where relations do the math.
Composite keys twine like clover vines,
Petstore dreams in generated lines.
I thump approval—queries slim and neat,
Carrots for coverage, a policy treat! 🥕🐇

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title "chore: migrate more v2 tests" succinctly reflects the primary work in the changeset—migrating and updating multiple v2 test files (import path adjustments and new/migrated policy test suites) across the runtime test package. It is concise, actionable for reviewers, and avoids unnecessary detail or noise.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch chore/migrate-more-tests

Tip

👮 Agentic pre-merge checks are now available in preview!

Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.

  • Built-in checks – Quickly apply ready-made checks to enforce title conventions, require pull request descriptions that follow templates, validate linked issues for compliance, and more.
  • Custom agentic checks – Define your own rules using CodeRabbit’s advanced agentic capabilities to enforce organization-specific policies and workflows. For example, you can instruct CodeRabbit’s agent to verify that API documentation is updated whenever API schema files are modified in a PR. Note: Upto 5 custom checks are currently allowed during the preview period. Pricing for this feature will be announced in a few weeks.

Please see the documentation for more information.

Example:

reviews:
  pre_merge_checks:
    custom_checks:
      - name: "Undocumented Breaking Changes"
        mode: "warning"
        instructions: |
          Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal).

Please share your feedback with us on this Discord post.


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 Sep 17, 2025

Claude finished @ymc9's task —— View job


PR Review: Test Migration

Reviewing this test migration PR with focus on:

Review Checklist:

  • Read repository guidelines (CLAUDE.md)
  • Examine petstore schema implementation
  • Review migrated test files structure
  • Check import path updates
  • Assess code quality and best practices
  • Identify potential bugs or issues
  • Evaluate performance considerations
  • Check for security concerns
  • Assess test coverage completeness

Review Summary

This PR successfully migrates v2 tests to the new test structure. The changes are well-organized and follow good migration practices.

Positive Findings

1. Clean Migration Structure

  • Tests properly moved from v2 location to packages/runtime/test/policy/migrated/
  • Import paths consistently updated from ./utils to ../utils
  • No functional changes to test logic, preserving test integrity

2. Petstore Schema Implementation

  • Well-designed ZModel schema at packages/runtime/test/schemas/petstore/schema.zmodel:1-52
  • Proper access control policies with realistic business logic
  • Generated TypeScript files follow expected patterns

3. Code Quality

  • Tests use proper vitest syntax and assertions
  • Good test coverage across different policy scenarios
  • Consistent code style throughout migrated files

🔍 Areas for Attention

1. Skipped Test in Petstore

  • packages/runtime/test/policy/migrated/petstore-sample.test.ts:6 - Test suite is skipped with TODO comment about future() support
  • This indicates incomplete migration pending feature implementation

2. Generated File Management

  • Generated files like schema.ts, models.ts, input.ts are checked into git
  • Consider if these should be gitignored and generated during build process per CLAUDE.md guidelines

🛡️ Security Assessment

No security concerns identified:

  • Test schemas use appropriate validation patterns
  • Access control policies properly implement authorization logic
  • No hardcoded secrets or sensitive data exposure

Performance Considerations

No performance issues:

  • Test structure follows established patterns
  • Schema policies use efficient field comparisons
  • No N+1 query patterns in test data setup

🐛 No Bugs Identified

The migration appears technically sound with no obvious bugs or breaking changes.

📋 Recommendations

  1. Consider build-time generation for generated schema files instead of checking them into git
  2. Complete petstore test migration by implementing future() support or adapting tests
  3. Add migration documentation if this is part of a larger v2 → v3 migration effort

🎯 Conclusion

This is a solid test migration that maintains test integrity while properly organizing code structure. The changes are safe to merge with the minor recommendations noted above.


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 migrates v2 tests to the new test structure as part of a test migration initiative. The changes involve moving test files from a v2-specific directory to a new migrated tests directory structure and updating import paths accordingly.

  • Adds petstore schema files including the ZModel definition and generated TypeScript types
  • Moves multiple test files from v2 test location to the migrated directory under packages/runtime/test/policy/migrated/
  • Updates import paths in all migrated test files to reference the correct utilities location

Reviewed Changes

Copilot reviewed 20 out of 21 changed files in this pull request and generated no comments.

Show a summary per file
File Description
packages/runtime/test/schemas/petstore/schema.zmodel New petstore schema definition with User, Pet, and Order models
packages/runtime/test/schemas/petstore/schema.ts Generated schema definition file for the petstore example
packages/runtime/test/schemas/petstore/models.ts Generated TypeScript model types for petstore schema
packages/runtime/test/schemas/petstore/input.ts Generated TypeScript input types for database operations
Multiple test files Migrated test files with updated import paths to reference ../utils instead of ./utils

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

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 (7)
packages/runtime/test/policy/migrated/multi-id-fields.test.ts (1)

370-373: Type mismatch in skipped test: Int field assigned a string

Even though skipped, y is Int but receives '4'. Keep types consistent to avoid future flakiness when the test is enabled.

-                            create: { x: '4', y: '4', value: 4 },
+                            create: { x: '4', y: 4, value: 4 },
packages/runtime/test/schemas/petstore/schema.zmodel (1)

1-4: Prefer in-memory SQLite for test isolation

A file-backed DB (file:./petstore.db) can leak state across runs/CI shards. Consider an in-memory DSN for hermetic tests.

 datasource db {
     provider = 'sqlite'
-    url = 'file:./petstore.db'
+    // shared in-memory sqlite (works with Prisma/SQLite)
+    url = 'file:petstore?mode=memory&cache=shared'
 }
packages/runtime/test/policy/migrated/petstore-sample.test.ts (1)

5-7: Enable this suite; it doesn’t depend on future().

The test only does create/read; Pet’s future()-gated rule is for update. Safe to unskip to get coverage now.

-// TODO: `future()` support
-describe.skip('Pet Store Policy Tests', () => {
+// TODO: add update tests once `future()` is supported
+describe('Pet Store Policy Tests', () => {
packages/runtime/test/policy/migrated/nested-to-one.test.ts (2)

137-139: Fix typo: “hosting” → “hoisting”.

Minor comment clarity in the skipped test.

-        // including m3 causes m1 to be filtered due to hosting
+        // including m3 causes m1 to be filtered due to hoisting

82-88: Make the assertion explicit for stability.

Instead of truthiness, assert the expected cardinality.

-await expect(db.m2.findMany({ include: { m1: true } })).toResolveTruthy();
+await expect(db.m2.findMany({ include: { m1: true } })).resolves.toHaveLength(1);
packages/runtime/test/policy/migrated/nested-to-many.test.ts (1)

125-130: Fix comment: mentions the wrong relation.

You’re including m4 here, not m3.

-        // including m3 causes m2 to be filtered since m4 is not nullable
+        // including m4 causes m2 to be filtered since m4 is not nullable
packages/runtime/test/schemas/petstore/input.ts (1)

30-30: Confirm GetPayload constraint matches current Select/Include semantics

The constraint Args extends $SelectIncludeOmit<$Schema, "", true> assumes the 3rd generic flag is supported and desired. Please validate against the runtime’s latest definition to avoid overly restrictive payload typing.

You can rely on the script above (last grep) to inspect SelectIncludeOmit’s signature and confirm whether the boolean flag is expected in v3.

Also applies to: 50-50, 70-70

📜 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 75723c7 and 6de78b8.

📒 Files selected for processing (20)
  • packages/runtime/test/policy/migrated/auth.test.ts (1 hunks)
  • packages/runtime/test/policy/migrated/client-extensions.test.ts (1 hunks)
  • packages/runtime/test/policy/migrated/connect-disconnect.test.ts (1 hunks)
  • packages/runtime/test/policy/migrated/create-many-and-return.test.ts (1 hunks)
  • packages/runtime/test/policy/migrated/cross-model-field-comparison.test.ts (1 hunks)
  • packages/runtime/test/policy/migrated/current-model.test.ts (1 hunks)
  • packages/runtime/test/policy/migrated/current-operation.test.ts (1 hunks)
  • packages/runtime/test/policy/migrated/deep-nested.test.ts (1 hunks)
  • packages/runtime/test/policy/migrated/empty-policy.test.ts (1 hunks)
  • packages/runtime/test/policy/migrated/field-comparison.test.ts (1 hunks)
  • packages/runtime/test/policy/migrated/multi-field-unique.test.ts (1 hunks)
  • packages/runtime/test/policy/migrated/multi-id-fields.test.ts (1 hunks)
  • packages/runtime/test/policy/migrated/nested-to-many.test.ts (1 hunks)
  • packages/runtime/test/policy/migrated/nested-to-one.test.ts (1 hunks)
  • packages/runtime/test/policy/migrated/petstore-sample.test.ts (1 hunks)
  • packages/runtime/test/policy/migrated/query-reduction.test.ts (1 hunks)
  • packages/runtime/test/schemas/petstore/input.ts (1 hunks)
  • packages/runtime/test/schemas/petstore/models.ts (1 hunks)
  • packages/runtime/test/schemas/petstore/schema.ts (1 hunks)
  • packages/runtime/test/schemas/petstore/schema.zmodel (1 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
{packages,samples,tests}/**

📄 CodeRabbit inference engine (CLAUDE.md)

Place packages only under packages/, samples/, or tests/

Files:

  • packages/runtime/test/policy/migrated/field-comparison.test.ts
  • packages/runtime/test/policy/migrated/current-operation.test.ts
  • packages/runtime/test/policy/migrated/empty-policy.test.ts
  • packages/runtime/test/policy/migrated/client-extensions.test.ts
  • packages/runtime/test/policy/migrated/petstore-sample.test.ts
  • packages/runtime/test/policy/migrated/auth.test.ts
  • packages/runtime/test/policy/migrated/deep-nested.test.ts
  • packages/runtime/test/policy/migrated/connect-disconnect.test.ts
  • packages/runtime/test/schemas/petstore/models.ts
  • packages/runtime/test/policy/migrated/current-model.test.ts
  • packages/runtime/test/policy/migrated/cross-model-field-comparison.test.ts
  • packages/runtime/test/policy/migrated/create-many-and-return.test.ts
  • packages/runtime/test/policy/migrated/query-reduction.test.ts
  • packages/runtime/test/schemas/petstore/schema.ts
  • packages/runtime/test/policy/migrated/multi-field-unique.test.ts
  • packages/runtime/test/policy/migrated/nested-to-one.test.ts
  • packages/runtime/test/policy/migrated/nested-to-many.test.ts
  • packages/runtime/test/schemas/petstore/input.ts
  • packages/runtime/test/schemas/petstore/schema.zmodel
  • packages/runtime/test/policy/migrated/multi-id-fields.test.ts
**/schema.ts

📄 CodeRabbit inference engine (CLAUDE.md)

The generated TypeScript schema should be named schema.ts

Files:

  • packages/runtime/test/schemas/petstore/schema.ts
**/schema.zmodel

📄 CodeRabbit inference engine (CLAUDE.md)

Name ZModel schema files schema.zmodel

Files:

  • packages/runtime/test/schemas/petstore/schema.zmodel
🧠 Learnings (1)
📚 Learning: 2025-09-04T12:38:14.150Z
Learnt from: CR
PR: zenstackhq/zenstack-v3#0
File: CLAUDE.md:0-0
Timestamp: 2025-09-04T12:38:14.150Z
Learning: Applies to **/schema.ts : The generated TypeScript schema should be named `schema.ts`

Applied to files:

  • packages/runtime/test/schemas/petstore/models.ts
  • packages/runtime/test/schemas/petstore/schema.ts
🧬 Code graph analysis (6)
packages/runtime/test/policy/migrated/petstore-sample.test.ts (2)
packages/runtime/test/policy/utils.ts (1)
  • createPolicyTestClient (14-25)
packages/runtime/test/schemas/petstore/schema.ts (1)
  • schema (9-155)
packages/runtime/test/policy/migrated/query-reduction.test.ts (1)
packages/runtime/test/policy/utils.ts (1)
  • createPolicyTestClient (14-25)
packages/runtime/test/schemas/petstore/schema.ts (2)
packages/runtime/src/schema/expression.ts (1)
  • ExpressionUtils (16-120)
packages/sdk/src/schema/schema.ts (1)
  • SchemaDef (10-18)
packages/runtime/test/policy/migrated/nested-to-one.test.ts (2)
packages/runtime/test/policy/utils.ts (1)
  • createPolicyTestClient (14-25)
packages/runtime/src/client/crud/operations/base.ts (1)
  • read (146-187)
packages/runtime/test/policy/migrated/nested-to-many.test.ts (2)
packages/runtime/test/policy/utils.ts (1)
  • createPolicyTestClient (14-25)
packages/runtime/src/client/crud/operations/base.ts (1)
  • read (146-187)
packages/runtime/test/policy/migrated/multi-id-fields.test.ts (1)
packages/runtime/test/policy/utils.ts (1)
  • createPolicyTestClient (14-25)
⏰ 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). (1)
  • GitHub Check: build-test (20.x)
🔇 Additional comments (20)
packages/runtime/test/policy/migrated/empty-policy.test.ts (1)

2-2: LGTM: shared utils import

Consistent with the reorg to policy/utils.ts.

packages/runtime/test/policy/migrated/auth.test.ts (1)

2-2: LGTM: path fix

Importing from ../utils aligns with other migrated tests.

packages/runtime/test/policy/migrated/create-many-and-return.test.ts (1)

2-2: LGTM: centralizing test util

Correct relative path from migrated/ to policy/utils.ts.

packages/runtime/test/policy/migrated/connect-disconnect.test.ts (1)

2-2: LGTM: utils import

Matches the shared util location; no further changes needed.

packages/runtime/test/policy/migrated/cross-model-field-comparison.test.ts (1)

2-2: LGTM: import path

Consistent with the migration to ../utils.

packages/runtime/test/policy/migrated/deep-nested.test.ts (1)

2-2: LGTM: shared utils

Relative path is correct at this depth.

packages/runtime/test/policy/migrated/field-comparison.test.ts (1)

2-2: Import path update verified

packages/runtime/test/policy/utils.ts exports createPolicyTestClient; all files in packages/runtime/test/policy/migrated/ import from "../utils" and no "./utils" imports remain.

packages/runtime/test/policy/migrated/client-extensions.test.ts (1)

2-3: Imports verified — definePlugin exported & ../utils resolves

definePlugin is exported from packages/runtime/src/client/plugin.ts (export function definePlugin at line ~45) and createPolicyTestClient is exported from packages/runtime/test/policy/utils.ts; the imports in packages/runtime/test/policy/migrated/client-extensions.test.ts are correct.

packages/runtime/test/policy/migrated/multi-id-fields.test.ts (1)

1-58: Strong coverage for composite IDs and nested policy cases

Good end-to-end assertions (CRUD, includes, auth switching, nested writes). The $unuseAll() check validating read filtering is a nice touch.

packages/runtime/test/schemas/petstore/schema.zmodel (1)

14-52: Schema structure and policies look consistent with tests

  • File name and location comply with guidelines.
  • Access rules align with described behaviors (unsold pet visibility; order ownership; restricted updates via future()).
packages/runtime/test/policy/migrated/current-model.test.ts (1)

2-2: Centralized utils import confirmed

Consistent with other migrated tests.

packages/runtime/test/policy/migrated/multi-field-unique.test.ts (1)

3-4: Import paths and suite rename are correct; QueryError is exported.

packages/runtime/src/client/errors.ts exports QueryError (export class QueryError extends Error at line 13).

packages/runtime/test/policy/migrated/current-operation.test.ts (1)

2-2: Centralized utils import confirmed for migrated policy tests

All files in packages/runtime/test/policy/migrated/ import from ../utils; packages/runtime/test/policy/utils.ts also imports ../utils, so migrated tests use the centralized helper. Non-migrated tests still import ./utils (policy-functions.test.ts, todo-sample.test.ts, mixin.test.ts, auth-equality.test.ts).

packages/runtime/test/schemas/petstore/models.ts (1)

8-12: LGTM: generated model result aliases match schema exports.

Types line up with SchemaType from ./schema and ModelResult from @zenstackhq/runtime.

packages/runtime/test/policy/migrated/query-reduction.test.ts (1)

4-136: LGTM: good coverage for AND/OR/NOT and relation filters under policy.

Assertions align with the seeded data and policy semantics.

packages/runtime/test/schemas/petstore/schema.ts (2)

155-156: LGTM: conforms to naming guideline and exports SchemaType.

Generated schema is named schema.ts and provides SchemaType as expected.


8-10: Ensure build runs before tests — dist import missing

File packages/runtime/test/schemas/petstore/schema.ts (lines 8–10): imports "../../../dist/schema" but packages/runtime/dist/schema is absent (fd returned "Search path 'packages/runtime/dist/schema' is not a directory"). Run the build before running tests or change the test to import from source.

packages/runtime/test/policy/migrated/nested-to-many.test.ts (1)

52-61: LGTM: skip retained for v2 semantics check.

Appropriate to keep this isolated until semantics are decided.

packages/runtime/test/schemas/petstore/input.ts (2)

1-7: Generated file header looks good

Clear "do not modify" banner and global eslint-disable are appropriate for generated test artifacts.


8-10: Runtime type exports verified — no action required

packages/runtime/test/schemas/petstore/schema.ts exports SchemaType; all referenced @zenstackhq/runtime types (including CreateManyAndReturnArgs, UpdateManyAndReturnArgs, SelectIncludeOmit) are exported from packages/runtime (e.g., packages/runtime/src/client/crud-types.ts).

@ymc9 ymc9 merged commit b17bf54 into dev Sep 17, 2025
5 checks passed
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