-
-
Notifications
You must be signed in to change notification settings - Fork 12
fix(delegate,policy): several issues due to interaction between delegate and policy #299
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
WalkthroughImplements delegate base-field selection for relation access, replacing direct FK references with subselects when fields originate from delegated base models; refactors join construction to aggregate multi-path conditions; adds guards in policy handling; adjusts testtools build to copy types via tsup hook; introduces new e2e and regression tests for delegated policies. Changes
Estimated code review effort🎯 4 (Complex) | ⏱️ ~70 minutes Possibly related PRs
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
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. Comment |
|
Claude finished @ymc9's task —— View job PR Review AnalysisCompleted comprehensive review of this PR that fixes delegate/policy interaction issues. Todo List:
SummaryThis PR fixes several important issues with the interaction between delegate models and policy enforcement in ZenStack. The changes primarily focus on ensuring that policies are correctly evaluated when delegate models are involved, particularly handling cases where relation fields originate from delegate base models. Key Changes Analysis1. Expression Transformer (
|
There was a problem hiding this 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 fixes several issues related to the interaction between delegate models and policy enforcement. The changes ensure that policies defined on base models are correctly inherited and enforced on delegate models, and that policy checks properly handle fields and relations defined in delegate base models.
Key Changes:
- Enhanced policy handling to correctly reference fields from delegate base models using nested select queries
- Added comprehensive test coverage for delegate-policy interactions including inheritance, field references, and relation checks
- Refactored build tooling to use tsup's onSuccess hook instead of copyfiles dependency
Reviewed Changes
Copilot reviewed 7 out of 8 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| tests/regression/test/v2-migrated/issue-1930.test.ts | Adds regression test verifying policy check on delegate relation fields |
| tests/e2e/orm/policy/delegate.test.ts | Adds comprehensive test suite for delegate-policy interactions |
| packages/testtools/tsup.config.ts | Replaces copyfiles with tsup onSuccess hook for file copying |
| packages/testtools/package.json | Removes copyfiles dependency from build script and devDependencies |
| packages/plugins/policy/src/policy-handler.ts | Adds null check for node.from before policy filter transformation |
| packages/plugins/policy/src/functions.ts | Refactors check function to handle delegate base model fields using nested selects |
| packages/plugins/policy/src/expression-transformer.ts | Updates column reference creation and relation joins to handle delegate base models |
Files not reviewed (1)
- pnpm-lock.yaml: Language not supported
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Nitpick comments (1)
packages/testtools/package.json (1)
7-7: Build flow change is fine, but ensure types emission mapping is correct.
- tsup often emits only index.d.ts; your exports.require.types points to index.d.cts, which may not exist. Align it or configure generation accordingly.
- Also make sure the types copy step actually runs (see tsup.config.ts review).
Suggested change for types mapping if .d.cts is not emitted:
- "types": "./dist/index.d.cts", + "types": "./dist/index.d.ts",
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
pnpm-lock.yamlis excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (7)
packages/plugins/policy/src/expression-transformer.ts(2 hunks)packages/plugins/policy/src/functions.ts(1 hunks)packages/plugins/policy/src/policy-handler.ts(2 hunks)packages/testtools/package.json(1 hunks)packages/testtools/tsup.config.ts(2 hunks)tests/e2e/orm/policy/delegate.test.ts(1 hunks)tests/regression/test/v2-migrated/issue-1930.test.ts(1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
{packages,samples,tests}/**
📄 CodeRabbit inference engine (CLAUDE.md)
Place packages only under
packages/,samples/, ortests/
Files:
packages/testtools/tsup.config.tspackages/plugins/policy/src/functions.tstests/regression/test/v2-migrated/issue-1930.test.tspackages/plugins/policy/src/expression-transformer.tspackages/testtools/package.jsontests/e2e/orm/policy/delegate.test.tspackages/plugins/policy/src/policy-handler.ts
tests/e2e/**
📄 CodeRabbit inference engine (CLAUDE.md)
End-to-end tests must live under
tests/e2e/
Files:
tests/e2e/orm/policy/delegate.test.ts
🧬 Code graph analysis (3)
tests/regression/test/v2-migrated/issue-1930.test.ts (1)
packages/testtools/src/client.ts (1)
createPolicyTestClient(176-187)
packages/plugins/policy/src/expression-transformer.ts (1)
packages/plugins/policy/src/utils.ts (1)
conjunction(49-67)
tests/e2e/orm/policy/delegate.test.ts (1)
packages/testtools/src/client.ts (1)
createPolicyTestClient(176-187)
⏰ 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, sqlite)
- GitHub Check: build-test (20.x, postgresql)
- GitHub Check: claude-review
🔇 Additional comments (3)
packages/plugins/policy/src/policy-handler.ts (1)
300-303: Good guard for select without FROM.Prevents applying policy filters to subquery-only selects. LGTM.
tests/regression/test/v2-migrated/issue-1930.test.ts (1)
1-76: No action needed; custom matchers are registered
vitest.config.ts’s setupFiles include '@zenstackhq/testtools', which via expect.extend in packages/testtools/src/vitest-ext.ts defines toResolveTruthy/toResolveNull.packages/testtools/tsup.config.ts (1)
13-15: onSuccess callback functions are supported
Tsup’s onSuccess option accepts both shell-command strings and JS callbacks; yourasync onSuccess()will run as intended and copytypes.d.ts. No change required.Likely an incorrect or invalid review comment.
Summary by CodeRabbit
New Features
Bug Fixes
Tests
Chores