Skip to content

Conversation

@ymc9
Copy link
Member

@ymc9 ymc9 commented Sep 24, 2025

Summary by CodeRabbit

  • Improvements

    • More robust model processing: validation now runs consistently and stops after critical parsing/linking errors to avoid cascading issues.
    • Increased resilience when resolving mixins/base models, reducing crashes from unresolved references.
  • Bug Fixes

    • Fixed policy plugin export resolution for smoother imports in runtime consumers.
  • Chores

    • Version bump to 3.0.0-beta.7 across packages; VS Code extension updated to 3.0.8.

ymc9 and others added 3 commits September 23, 2025 19:18
…269)

* fix(language): ref resolution failure causes exception in validator

* fix lint

* update

* fix tests
* fix(runtime): policy plugin exports

* update
Copilot AI review requested due to automatic review settings September 24, 2025 04:54
@coderabbitai
Copy link

coderabbitai bot commented Sep 24, 2025

Walkthrough

Version updates across multiple packages and samples. Language package adds ZModelDocumentBuilder, adjusts module wiring, relaxes linking assumptions in utils, and runs validators unconditionally. Runtime package adjusts exports paths for policy plugin. Minor test name/content tweaks. VS Code extension version bumped.

Changes

Cohort / File(s) Summary
Language service and validation updates
packages/language/src/module.ts, packages/language/src/utils.ts, packages/language/src/validator.ts, packages/language/src/zmodel-document-builder.ts
Wire a new DocumentBuilder service to use ZModelDocumentBuilder; add ZModelDocumentBuilder overriding build options to stop after errors; update utils to avoid strict linking assumptions and conditionally recurse; remove shouldCheck gating so validators always run.
Language tests adjustments
packages/language/test/expression-validation.test.ts
Rename two tests and add authorId Int to a schema in one test; expectations unchanged.
Runtime exports path update
packages/runtime/package.json
Bump version and change exports["./plugins/policy"] paths to dist/plugins/policy/index.* for import/require/types.
VS Code extension version bump
packages/ide/vscode/package.json
Version updated 3.0.6 → 3.0.8; no other changes.
Repository/package version bumps
package.json, packages/cli/package.json, packages/common-helpers/package.json, packages/create-zenstack/package.json, packages/dialects/sql.js/package.json, packages/eslint-config/package.json, packages/language/package.json, packages/sdk/package.json, packages/tanstack-query/package.json, packages/testtools/package.json, packages/typescript-config/package.json, packages/vitest-config/package.json, packages/zod/package.json
Versions updated to 3.0.0-beta.7 (except VS Code extension as above); no other manifest changes.
Samples and tests version bumps
samples/blog/package.json, tests/e2e/package.json, tests/regression/package.json
Versions updated to 3.0.0-beta.7; no other changes.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Poem

I thump my paw: new versions hop,
A builder burrows, links that stop,
Validators nibble non-stop greens,
Policy paths find index scenes.
With tidy tests and tags anew,
This bunny stamps: release, woo-hoo! 🐇✨

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 "merge dev to main (v3.0.0-beta.7)" is a short, single sentence that clearly describes the branch merge and the release/version bump, which matches the changeset dominated by package version updates and release-related modifications; it is concise and informative for history scanning.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch dev

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 24, 2025

Claude finished @ymc9's task —— View job


PR Review - merge dev to main

I've completed a comprehensive review of this PR. Here's my analysis:

✅ Summary: APPROVED - High Quality Changes

This PR represents a solid merge from dev to main with important bug fixes and proper version management.

📋 Detailed Review

Version ManagementExcellent

  • All packages consistently bumped to 3.0.0-beta.7
  • VSCode extension properly maintains separate versioning (3.0.8) as documented
  • Clean version bump strategy following monorepo best practices

Critical Bug FixesHigh Impact

1. Language Module Robustness (commit 3a2f1f9) ✅ Excellent Fix

Problem Solved: Reference resolution failures causing validator exceptions

Key Improvements:

  • New ZModelDocumentBuilder: Added validation control at document level with proper error stopping flags
  • Validator Simplification: Removed complex shouldCheck() logic, cleaner separation of concerns
  • Defensive Programming: Replaced crashing invariant() calls with null-safe guards in utils.ts
  • Reference Safety: getRecursiveBases() now uses $refText to avoid unresolved references

Code Quality: Follows defensive programming principles, prevents crashes during language server operations

2. Runtime Package Exports Fix (commit 4837cf5) ✅ Good

Problem Solved: Incorrect export paths for policy plugin

Fix: Updated package.json exports to point to correct index.js/index.d.ts files instead of root-level files

  • Affects both ESM and CommonJS imports
  • Critical for proper plugin functionality

Code Quality AssessmentHigh Standards

Strengths:

  • Clean error handling with proper validation stopping
  • Defensive null checking prevents runtime crashes
  • Well-structured inheritance patterns
  • Consistent code style and formatting
  • Good separation of validation concerns

Minor Observations:

  • No unused imports or code left behind
  • Proper TypeScript typing maintained
  • Follows existing architectural patterns

Test CoverageAdequate

  • Runtime package: 72 test files (comprehensive)
  • Language package: 4 test files (focused)
  • E2E/Regression: 16 test files (good coverage)
  • Expression validation tests updated appropriately

Security & PerformanceNo Concerns

  • No security vulnerabilities introduced
  • Changes improve stability and error handling
  • No performance regressions expected
  • Proper resource management maintained

🎯 Recommendation: APPROVE & MERGE

This is a well-executed release preparation with:

  • ✅ Critical stability fixes
  • ✅ Proper version management
  • ✅ Clean code quality
  • ✅ Good test coverage
  • ✅ No breaking changes

The language module fixes are particularly valuable for preventing crashes in development environments.

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 merges changes from the dev branch to main, primarily consisting of version bumps across all packages from 3.0.0-beta.6 to 3.0.0-beta.7, along with several code improvements to the language processing system.

Key changes include:

  • Version updates across all packages and samples
  • Enhanced validation system with custom document builder
  • Improved error handling by removing dependency on invariant assertions
  • Package export path corrections for the policy plugin

Reviewed Changes

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

Show a summary per file
File Description
package.json Root package version bump to 3.0.0-beta.7
packages/*/package.json Version updates across all packages to 3.0.0-beta.7
packages/runtime/package.json Export path fixes for policy plugin and version bump
packages/language/src/zmodel-document-builder.ts New custom document builder with validation options
packages/language/src/validator.ts Simplified validator by removing shouldCheck method
packages/language/src/utils.ts Improved error handling without invariant assertions
packages/language/src/module.ts Integration of new document builder
packages/language/test/expression-validation.test.ts Test improvements with better naming and missing field addition

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

@ymc9 ymc9 changed the title merge dev to main merge dev to main (v3.0.0-beta.7) Sep 24, 2025
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)
packages/language/test/expression-validation.test.ts (2)

5-5: Rename test to be descriptive instead of suffixed numerals.
E.g., “should reject model-to-model comparison (relation field)” for clarity.


26-26: Same here: prefer a descriptive test name.
Avoid numeric suffixes in test titles.

packages/language/src/validator.ts (1)

51-85: Unconditional validations: reuse validator instances and confirm gating by DocumentBuilder.

  • To reduce allocations and allow potential state reuse, instantiate validators once and reuse in methods.
  • Verify that callers always go through the new DocumentBuilder so validation doesn’t run after lexing/parsing/linking errors.

Proposed changes within this file:

 export class ZModelValidator {
-    constructor(protected readonly services: ZModelServices) {}
+    constructor(protected readonly services: ZModelServices) {}
+    private readonly schemaValidator = new SchemaValidator(this.services.shared.workspace.LangiumDocuments);
+    private readonly dataSourceValidator = new DataSourceValidator();
+    private readonly dataModelValidator = new DataModelValidator();
+    private readonly typeDefValidator = new TypeDefValidator();
+    private readonly enumValidator = new EnumValidator();
+    private readonly attributeValidator = new AttributeValidator();
+    private readonly expressionValidator = new ExpressionValidator();
+    private readonly functionInvocationValidator = new FunctionInvocationValidator();
+    private readonly functionDeclValidator = new FunctionDeclValidator();

     checkModel(node: Model, accept: ValidationAcceptor): void {
-        new SchemaValidator(this.services.shared.workspace.LangiumDocuments).validate(node, accept);
+        this.schemaValidator.validate(node, accept);
     }

     checkDataSource(node: DataSource, accept: ValidationAcceptor): void {
-        new DataSourceValidator().validate(node, accept);
+        this.dataSourceValidator.validate(node, accept);
     }

     checkDataModel(node: DataModel, accept: ValidationAcceptor): void {
-        new DataModelValidator().validate(node, accept);
+        this.dataModelValidator.validate(node, accept);
     }

     checkTypeDef(node: TypeDef, accept: ValidationAcceptor): void {
-        new TypeDefValidator().validate(node, accept);
+        this.typeDefValidator.validate(node, accept);
     }

     checkEnum(node: Enum, accept: ValidationAcceptor): void {
-        new EnumValidator().validate(node, accept);
+        this.enumValidator.validate(node, accept);
     }

     checkAttribute(node: Attribute, accept: ValidationAcceptor): void {
-        new AttributeValidator().validate(node, accept);
+        this.attributeValidator.validate(node, accept);
     }

     checkExpression(node: Expression, accept: ValidationAcceptor): void {
-        new ExpressionValidator().validate(node, accept);
+        this.expressionValidator.validate(node, accept);
     }

     checkFunctionInvocation(node: InvocationExpr, accept: ValidationAcceptor): void {
-        new FunctionInvocationValidator().validate(node, accept);
+        this.functionInvocationValidator.validate(node, accept);
     }

     checkFunctionDecl(node: FunctionDecl, accept: ValidationAcceptor): void {
-        new FunctionDeclValidator().validate(node, accept);
+        this.functionDeclValidator.validate(node, accept);
     }
 }

Additionally, please confirm all schema validations are triggered via the new ZModelDocumentBuilder. If there are code paths manually invoking the registry without the builder, they may need guards.

packages/language/src/zmodel-document-builder.ts (2)

9-17: Don’t drop other validation options; merge when validation is an object.
If options.validation is an object, your override replaces any existing flags (e.g., custom checks). Merge instead; for boolean true, synthesize the stopAfter* flags.

Apply:

-                validation:
-                    // force overriding validation options
-                    options.validation === false || options.validation === undefined
-                        ? options.validation
-                        : {
-                              stopAfterLexingErrors: true,
-                              stopAfterParsingErrors: true,
-                              stopAfterLinkingErrors: true,
-                          },
+                validation: (() => {
+                    const v = options.validation;
+                    if (v === false) return v;
+                    const base =
+                        v && typeof v === 'object'
+                            ? v
+                            : { /* boolean true or undefined => start from empty */ };
+                    return {
+                        ...base,
+                        stopAfterLexingErrors: true,
+                        stopAfterParsingErrors: true,
+                        stopAfterLinkingErrors: true,
+                    };
+                })(),

4-4: Type the cancelToken parameter.
Use the proper CancellationToken type instead of any for better type safety.

Example:

import type { CancellationToken } from 'vscode-jsonrpc';
override buildDocuments(documents: LangiumDocument[], options: BuildOptions, cancelToken?: CancellationToken): Promise<void>
packages/language/src/utils.ts (1)

174-178: Fallback to resolved ref when available to include imported mixins.
Using only $refText + local container misses mixins imported from other modules. Prefer mixin.ref when resolved; fall back to container lookup pre-link.

Apply:

-    decl.mixins.forEach((mixin) => {
-        // avoid using mixin.ref since this function can be called before linking
-        const baseDecl = decl.$container.declarations.find(
-            (d): d is TypeDef => isTypeDef(d) && d.name === mixin.$refText,
-        );
+    decl.mixins.forEach((mixin) => {
+        // prefer resolved ref; fallback to same-container lookup pre-link
+        const baseDecl =
+            mixin.ref ??
+            decl.$container.declarations.find(
+                (d): d is TypeDef => isTypeDef(d) && d.name === mixin.$refText,
+            );
📜 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 1770b12 and 4837cf5.

📒 Files selected for processing (23)
  • package.json (1 hunks)
  • packages/cli/package.json (1 hunks)
  • packages/common-helpers/package.json (1 hunks)
  • packages/create-zenstack/package.json (1 hunks)
  • packages/dialects/sql.js/package.json (1 hunks)
  • packages/eslint-config/package.json (1 hunks)
  • packages/ide/vscode/package.json (1 hunks)
  • packages/language/package.json (1 hunks)
  • packages/language/src/module.ts (2 hunks)
  • packages/language/src/utils.ts (3 hunks)
  • packages/language/src/validator.ts (2 hunks)
  • packages/language/src/zmodel-document-builder.ts (1 hunks)
  • packages/language/test/expression-validation.test.ts (2 hunks)
  • packages/runtime/package.json (2 hunks)
  • packages/sdk/package.json (1 hunks)
  • packages/tanstack-query/package.json (1 hunks)
  • packages/testtools/package.json (1 hunks)
  • packages/typescript-config/package.json (1 hunks)
  • packages/vitest-config/package.json (1 hunks)
  • packages/zod/package.json (1 hunks)
  • samples/blog/package.json (1 hunks)
  • tests/e2e/package.json (1 hunks)
  • tests/regression/package.json (1 hunks)
🧰 Additional context used
📓 Path-based instructions (4)
{packages,samples,tests}/**

📄 CodeRabbit inference engine (CLAUDE.md)

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

Files:

  • packages/sdk/package.json
  • tests/e2e/package.json
  • packages/testtools/package.json
  • packages/language/package.json
  • packages/typescript-config/package.json
  • packages/language/src/zmodel-document-builder.ts
  • samples/blog/package.json
  • packages/runtime/package.json
  • packages/zod/package.json
  • packages/language/test/expression-validation.test.ts
  • packages/vitest-config/package.json
  • packages/eslint-config/package.json
  • packages/ide/vscode/package.json
  • tests/regression/package.json
  • packages/common-helpers/package.json
  • packages/cli/package.json
  • packages/language/src/module.ts
  • packages/dialects/sql.js/package.json
  • packages/language/src/utils.ts
  • packages/create-zenstack/package.json
  • packages/tanstack-query/package.json
  • packages/language/src/validator.ts
tests/e2e/**

📄 CodeRabbit inference engine (CLAUDE.md)

End-to-end tests must live under tests/e2e/

Files:

  • tests/e2e/package.json
packages/ide/vscode/package.json

📄 CodeRabbit inference engine (CLAUDE.md)

The ide/vscode package is intentionally versioned differently from other packages

Files:

  • packages/ide/vscode/package.json
package.json

📄 CodeRabbit inference engine (CLAUDE.md)

Pin the repository package manager to [email protected] via the packageManager field

Files:

  • package.json
🧠 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 packages/ide/vscode/package.json : The `ide/vscode` package is intentionally versioned differently from other packages

Applied to files:

  • packages/ide/vscode/package.json
🧬 Code graph analysis (3)
packages/language/src/module.ts (1)
packages/language/src/zmodel-document-builder.ts (1)
  • ZModelDocumentBuilder (3-22)
packages/language/src/utils.ts (1)
packages/language/src/generated/ast.ts (4)
  • TypeDef (725-733)
  • TypeDef (735-735)
  • isTypeDef (737-739)
  • isDataModel (391-393)
packages/language/src/validator.ts (1)
packages/language/src/validators/schema-validator.ts (1)
  • SchemaValidator (10-58)
⏰ 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: build-test (20.x, postgresql)
  • GitHub Check: build-test (20.x, sqlite)
  • GitHub Check: claude-review
🔇 Additional comments (26)
packages/language/package.json (1)

4-4: Version bump looks good.

No issues spotted; aligns with repo-wide beta.7.

packages/testtools/package.json (1)

3-3: Version bump LGTM.

Consistent with workspace-wide update.

packages/sdk/package.json (1)

3-3: Version bump LGTM.

No other changes; consistent with the release.

packages/zod/package.json (1)

3-3: Version bump LGTM.

No functional changes in this file.

packages/tanstack-query/package.json (1)

3-3: Version bump LGTM.

No additional changes detected.

packages/ide/vscode/package.json (1)

4-4: VS Code extension version bump is appropriate.

Per prior guidance, this package is intentionally versioned independently. packageManager is correctly pinned.

tests/regression/package.json (1)

3-3: Version bump LGTM.

Aligned with beta.7 release.

package.json (1)

3-3: Root packageManager pinned; package-version scan incomplete

Root packageManager: [email protected]. The verification script failed while scanning package.json files (shell error: "/bin/bash: line 14: !: command not found"), so I cannot confirm all packages use version 3.0.0-beta.7 — re-run the check with a corrected script or confirm versions manually.

tests/e2e/package.json (1)

3-3: Version bump to 3.0.0-beta.7 looks good; path complies with e2e guideline.
No further action needed.

packages/common-helpers/package.json (1)

3-3: Version bump to 3.0.0-beta.7 looks good.
No other changes detected.

packages/dialects/sql.js/package.json (1)

3-3: Version bump to 3.0.0-beta.7 looks good.
Exports and peers unchanged; OK.

packages/typescript-config/package.json (1)

3-3: Version bump to 3.0.0-beta.7 looks good.
Private config package—no further checks needed here.

samples/blog/package.json (1)

3-3: Version bump to 3.0.0-beta.7 looks good.
Sample remains consistent with workspace dependencies.

packages/create-zenstack/package.json (1)

3-3: Version bump to 3.0.0-beta.7 looks good.
Bin and exports unchanged; OK.

packages/cli/package.json (1)

6-6: Version bump to 3.0.0-beta.7 looks good.
CLI deps are workspace-pinned; alignment looks fine.

packages/vitest-config/package.json (1)

4-4: Version bump to 3.0.0-beta.7 looks good.
No functional changes.

packages/language/test/expression-validation.test.ts (1)

18-18: Good: relation scalar added to back the relation.
Adding authorId Int aligns with the relation definition and prevents invalid schema state.

packages/language/src/zmodel-document-builder.ts (1)

11-13: Confirm intended behavior when validation is undefined.
If Langium defaults validation to on when undefined, current logic may skip the stopAfter* protections. Verify Langium’s default and adjust accordingly (the merge snippet above handles it).

packages/language/src/module.ts (1)

53-55: DocumentBuilder wiring looks correct.
Custom builder is injected under workspace; aligns with validator changes.

packages/runtime/package.json (2)

3-3: Version bump OK.
No concerns.


56-62: Verified — build is configured to emit dist/plugins/policy/index.{js,cjs,d.ts,d.cts}
packages/runtime/tsup.config.ts has an entry for 'plugins/policy/index' with dts:true and formats ['cjs','esm']; src/plugins/policy/index.ts exists and packages/runtime/package.json exports point to the matching dist/plugins/policy/index.* artifacts.

packages/language/src/utils.ts (4)

522-525: Pre-link safety improvement looks good.
Guarding on mixin.ref avoids throwing before linking.


528-531: Pre-link safety for baseModel is good.
Conditional recursion prevents access to unresolved refs.


548-551: Same approval for attributes on mixins.
No issues.


554-557: Same approval for attributes on baseModel.
No issues.

packages/eslint-config/package.json (1)

3-3: Approve — repo-wide version alignment verified.
All @zenstackhq/* packages are at 3.0.0-beta.7; no action needed.

@ymc9 ymc9 added this pull request to the merge queue Sep 24, 2025
Merged via the queue into main with commit 5f639de Sep 24, 2025
9 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