validate computed field configuration on startup#653
validate computed field configuration on startup#653lsmith77 wants to merge 1 commit intozenstackhq:devfrom
Conversation
📝 WalkthroughWalkthroughAdded root-client validation that every computed field declared in the schema has a corresponding Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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 |
There was a problem hiding this comment.
Pull request overview
Adds runtime validation to ensure all @computed fields declared in the schema have corresponding computedFields implementations configured when the ORM client starts.
Changes:
- Add startup-time validation in
ClientImplconstructor to verify computed field config completeness. - Add E2E tests covering missing computed field configuration scenarios.
- Update existing type-checking computed-field tests to include runtime
computedFieldsconfig required by the new validation.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| tests/e2e/orm/client-api/computed-fields.test.ts | Adds new negative tests for missing computedFields config and updates type-checking cases to satisfy new startup validation. |
| packages/orm/src/client/client-impl.ts | Introduces validateComputedFieldsConfig() and invokes it during client construction to fail fast on misconfiguration. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
feaecb9 to
1212adc
Compare
1212adc to
5d8b09a
Compare
5d8b09a to
5aee416
Compare
There was a problem hiding this comment.
Actionable comments posted: 0
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
tests/e2e/orm/client-api/computed-fields.test.ts (2)
183-226:⚠️ Potential issue | 🔴 CriticalPipeline failure: TS2769 at line 184 — the added
computedFieldsoption breaks thecreateTestClientoverload resolution.The CI reports
TS2769: No overload matches this callat line 184. The newly added outercomputedFields(lines 193–197) doesn't have anas anycast on the options object, unlike the error-handling tests above. Since the schema is passed as a raw string, TypeScript can't infer the correctcomputedFieldsshape and the call doesn't match anycreateTestClientoverload.Add
as anyto the options object (consistent with lines 110, 243, 326, 359) or type-assert just thecomputedFieldsproperty.Proposed fix
{ + computedFields: { + User: { + upperName: (eb: any) => eb.fn('upper', ['name']), + }, + }, extraSourceFiles: { main: ` - computedFields: { - User: { - upperName: (eb: any) => eb.fn('upper', ['name']), - }, - },The simplest fix is to add
as anyto the entire options argument, matching the pattern used by the other tests:}, - }, + } as any, );
255-297:⚠️ Potential issue | 🔴 CriticalSame
as anyissue likely applies here for the optional-fields type-checking test.Lines 264–269 add the outer
computedFieldswithout anas anyon the options object. This will likely cause the same TS2769 overload error as line 184. Apply the same fix.Proposed fix
}, - }, + } as any, );
|
Hi @lsmith77 , it seems the updated test file is failing type checking. |
Note on the changes to the existing tests:
The type-checking tests contain duplicate configurations:
Outer config (required by createTestClient): Needed to instantiate the actual client. Without it, the new runtime validation throws an error before the test can run.
Inner config (in extraSourceFiles): Example code that demonstrates proper usage and ensures the generated TypeScript file compiles with correct type hints.
This duplication is a consequence of using createTestClient for type-checking. The outer config satisfies the runtime validation, while the inner config serves as realistic documentation of how users should structure their code.
Let me know if you would prefer adding a helper to side-step createTestClient for these cases.
Summary by CodeRabbit
Bug Fixes
Tests