zenstack/packages/language/test
Yiming Cao ab9535ea90
fix(language): resolve mixin fields from imported files in scope (#598) (#632)
Fixed issue where access policy rules couldn't reference fields inherited from mixins defined in separate imported files. The language service now correctly resolves these fields during scope computation.

## Root Cause

The `getRecursiveBases()` function only searched for mixin declarations in the current document (`decl.$container.declarations`), which failed for imported mixins.

## Solution

- Modified `getRecursiveBases()` to accept optional `LangiumDocuments` parameter
- Implemented two-strategy approach:
  1. Use resolved reference if available (post-linking)
  2. Search by name across all documents including imports (pre-linking)
- Updated `ZModelScopeComputation.processNode()` to pass `LangiumDocuments`
- Leverages existing `getAllDeclarationsIncludingImports()` helper

## Changes

- **packages/language/src/utils.ts**: Fixed `getRecursiveBases()` to search imported documents
- **packages/language/src/zmodel-scope.ts**: Pass LangiumDocuments to scope computation
- **packages/language/test/mixin.test.ts**: Added tests for imported mixin field resolution
- **packages/testtools**: Added `extraZModelFiles` option for multi-file test schemas
- **tests/regression/test/issue-598.test.ts**: Regression test for the issue

## Test Results

 All language package tests pass (65 tests)
 Regression test validates policy rules can access imported mixin fields
 Handles edge cases: cyclic imports, nested mixins, transitive imports

Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-30 13:38:10 +08:00
..
attribute-application.test.ts feat: field-level access control (#557) 2026-01-05 18:14:23 +08:00
delegate.test.ts fix(zmodel): rejects delegate models with missing opposite relation (#490) 2025-12-14 10:23:00 +08:00
expression-validation.test.ts feat(zmodel): collection predicate binding (#548) 2026-01-18 14:08:10 +08:00
function-invocation.test.ts fix(orm): cuid() generator should respect version argument (#547) 2025-12-29 23:18:35 +08:00
import.test.ts fix(policy): run pg/sqlite tests, misc dual db compatibility fixes (#260) 2025-09-22 16:16:15 -07:00
mixin.test.ts fix(language): resolve mixin fields from imported files in scope (#598) (#632) 2026-01-30 13:38:10 +08:00
procedure-validation.test.ts custom procedures (#551) 2026-01-08 11:21:51 +08:00
this-resolution.test.ts test(zmodel): more validation tests (#459) 2025-12-02 10:27:11 +08:00
utils.ts refactor: move policy attributes to its own zmodel (#307) 2025-10-16 21:52:22 -07:00
view.test.ts fix(zmodel): more validation about "view" (#526) 2025-12-23 12:40:17 +08:00