feat: add constructor validation checks to BasePolicy - #333855
Open
Deniz Güney Yıldırım (denizguney) wants to merge 2 commits into
Open
feat: add constructor validation checks to BasePolicy#333855Deniz Güney Yıldırım (denizguney) wants to merge 2 commits into
Deniz Güney Yıldırım (denizguney) wants to merge 2 commits into
Conversation
Copilot started reviewing on behalf of
Deniz Güney Yıldırım (denizguney)
September 1, 2026 20:05
View session
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Empty module names now break every policy factory, and validation remains incomplete and insufficiently tested.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
Adds defensive constructor validation to BasePolicy.
Changes:
- Validates required policy metadata.
- Checks
minimumVersionformatting. - Adds descriptive constructor errors.
File summaries
| File | Description |
|---|---|
build/lib/policies/basePolicy.ts |
Adds constructor validation for policy fields. |
Review details
Suppressed comments (4)
build/lib/policies/basePolicy.ts:41
- This rejects every policy created by the existing factories:
BooleanPolicy.from,NumberPolicy.from,ObjectPolicy.from,StringPolicy.from, andStringEnumPolicy.fromall intentionally pass''because translations are flattened into the empty-string module namespace. Consequently, parsing the checked-in policy catalog now throws before rendering. Keep the empty namespace valid while still rejecting non-string values.
if (!moduleName || typeof moduleName !== 'string' || moduleName.trim() === '') {
throw new Error("BasePolicy: Geçerli bir 'moduleName' değeri gereklidir.");
build/lib/policies/basePolicy.ts:35
- This pattern accepts values such as
"1"and"1.2.3.4", althoughPolicyDto.minimumVersionis defined as a two-componentmajor.minorvalue and the renderer's supported-version identifiers follow that convention. Require exactly two numeric components so the new check actually rejects malformed policy versions.
if (!minimumVersion || typeof minimumVersion !== 'string' || !/^\d+(\.\d+)*$/.test(minimumVersion)) {
throw new Error(`BasePolicy: Geçersiz 'minimumVersion' formatı (${minimumVersion}). Sürüm numarası sayısal değerlerden oluşmalıdır (örn. '1.0.0').`);
build/lib/policies/basePolicy.ts:26
- The newly thrown diagnostics are in Turkish while the surrounding build tooling reports errors in English. These messages will be exposed to all contributors running policy generation, so rewrite all of the new constructor errors in English to keep failures understandable and consistent.
throw new Error("BasePolicy: 'type' parametresi zorunludur ve boş bırakılamaz.");
build/lib/policies/basePolicy.ts:25
- None of the new validation branches has a targeted test. Add BasePolicy test coverage for each required field and version boundary, including the valid empty module namespace used by every concrete factory; this would catch both over-rejection and under-validation regressions.
if (!type) {
- Files reviewed: 1/1 changed files
- Comments generated: 1
- Review effort level: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+25
to
+32
| if (!type) { | ||
| throw new Error("BasePolicy: 'type' parametresi zorunludur ve boş bırakılamaz."); | ||
| } | ||
| if (!name || typeof name !== 'string' || name.trim() === '') { | ||
| throw new Error("BasePolicy: Geçerli bir 'name' değeri gereklidir."); | ||
| } | ||
| if (!category) { | ||
| throw new Error("BasePolicy: 'category' parametresi zorunludur."); |
Refine validation to support empty moduleName, enforce major.minor version format, use English error messages, and add structured type/category checks.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #333852
Summary
BasePolicyconstructor to ensure robust error handling.type,name,category,description,moduleName).minimumVersion.