Fix single-value explicit enum handling (#181)#192
Conversation
|
Warning Review limit reached
More reviews will be available in 14 minutes and 14 seconds. Learn how PR review limits work. Your organization has run out of usage credits. Purchase more credits in the billing tab to continue. ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (4)
📝 WalkthroughWalkthroughEnum validation now supports single-value explicit enums using ChangesSingle-Value Explicit Enum Support
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 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.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1e161b7299
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
Pull request overview
This PR fixes enum handling in the core data-generation pipeline so explicit enum function syntax (e.g. enum("Open")) is treated as an enum even when it contains only a single value, instead of falling back to a literal.
Changes:
- Update enum validation to allow a minimum of 1 value for explicit
enum(...)-style rules while keeping implicit CSV enums requiring 2+ values. - Add/extend unit and integration tests covering single-value explicit enum parsing, compilation, and end-to-end generation.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| packages/core/js/data_generation/enum/enumTestDataRuleValidator.js | Adjusts enum minimum-value validation based on whether the rule is explicit enum(...) syntax. |
| packages/core/src/tests/data_generation/unit/enum/enumTestDataRuleValidator.test.js | Adds unit coverage for validating and parsing single-value explicit enums. |
| packages/core/src/tests/data_generation/enum-compiler-integration.test.js | Extends compiler tests to detect/compile enum("A") as an enum. |
| packages/core/src/tests/data_generation/enum-integration-e2e.test.js | Adds E2E regression test ensuring single-value explicit enum generates the expected constant value. |
Greptile SummaryThis PR fixes single-value explicit enum handling so that
Confidence Score: 5/5Safe to merge; the core logic is correct and well-tested for all explicitly targeted paths. The explicit enum(...) single-value path is implemented correctly end-to-end and covered by unit, integration, and e2e tests. The one noteworthy side effect — that the shorthand packages/core/js/data_generation/enum/enumTestDataRuleValidator.js — worth confirming whether the shorthand single-value relaxation is intentional. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[ruleSpec input] --> B{isAwdEnumFormat?}
B -- yes --> C[extractAwdEnumValues]
B -- no --> D{isShorthandEnumFormat?}
D -- yes --> E[strip prefix, recurse]
D -- no --> F[split on comma CSV path]
C --> G[preserve empty slots from commas]
G --> H[strip surrounding quotes]
H --> I[return values array]
E --> I
F --> I
I --> J{isExplicitEnumRule?}
J -- yes --> K[minimumValues = 1]
J -- no --> L[minimumValues = 2]
K --> M{length < minimumValues?}
L --> M
M -- yes --> N[❌ Enum must have at least N value/s]
M -- no --> O{any empty string?}
O -- yes --> P[❌ Enum values cannot be empty]
O -- no --> Q[✅ valid]
Reviews (5): Last reviewed commit: "Harden docker smoke test readiness check..." | Re-trigger Greptile |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages/core/src/tests/data_generation/unit/enum/enumTestDataRuleValidator.test.js (1)
121-125: ⚡ Quick winConsider adding test coverage for unquoted single-value enums.
The PR objectives mention
enum(10)as an example, but there's no test for unquoted single-value enums. Consider adding test cases for:
- Unquoted string:
enum(Open)- Unquoted numeric:
enum(10)This would provide more comprehensive coverage and align with the stated PR objectives.
📋 Suggested additional test cases
test('extracts a single explicit enum value', () => { const values = EnumParser.extractAwdEnumValues('enum("Open")'); expect(values).toEqual(['Open']); }); + + test('extracts a single unquoted string explicit enum value', () => { + const values = EnumParser.extractAwdEnumValues('enum(Open)'); + + expect(values).toEqual(['Open']); + }); + + test('extracts a single numeric explicit enum value', () => { + const values = EnumParser.extractAwdEnumValues('enum(10)'); + + expect(values).toEqual(['10']); + });And in the validator test section:
test('accepts explicit enum syntax with one value', () => { const rule = new TestDataRule('Single', 'enum("OnlyOne")'); rule.type = 'enum'; const validator = new EnumTestDataRuleValidator(); const isValid = validator.validate(rule); expect(isValid).toBe(true); expect(validator.isValid()).toBe(true); }); + + test('accepts explicit enum syntax with one unquoted value', () => { + const rule = new TestDataRule('Status', 'enum(10)'); + rule.type = 'enum'; + + const validator = new EnumTestDataRuleValidator(); + const isValid = validator.validate(rule); + + expect(isValid).toBe(true); + expect(validator.isValid()).toBe(true); + });🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/core/src/tests/data_generation/unit/enum/enumTestDataRuleValidator.test.js` around lines 121 - 125, Add tests covering unquoted single-value enums to match the PR objectives: create unit tests that call EnumParser.extractAwdEnumValues with unquoted string and numeric inputs (e.g., 'enum(Open)' and 'enum(10)') and assert the returned arrays equal ['Open'] and ['10'] (or numeric 10 if parser returns numbers); add these alongside the existing 'enum("Open")' test in enumTestDataRuleValidator.test.js to ensure extractAwdEnumValues handles unquoted values correctly.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In
`@packages/core/src/tests/data_generation/unit/enum/enumTestDataRuleValidator.test.js`:
- Around line 121-125: Add tests covering unquoted single-value enums to match
the PR objectives: create unit tests that call EnumParser.extractAwdEnumValues
with unquoted string and numeric inputs (e.g., 'enum(Open)' and 'enum(10)') and
assert the returned arrays equal ['Open'] and ['10'] (or numeric 10 if parser
returns numbers); add these alongside the existing 'enum("Open")' test in
enumTestDataRuleValidator.test.js to ensure extractAwdEnumValues handles
unquoted values correctly.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 89c9be6a-8e4f-440d-8d80-f1e5ac31c1a6
📒 Files selected for processing (4)
packages/core/js/data_generation/enum/enumTestDataRuleValidator.jspackages/core/src/tests/data_generation/enum-compiler-integration.test.jspackages/core/src/tests/data_generation/enum-integration-e2e.test.jspackages/core/src/tests/data_generation/unit/enum/enumTestDataRuleValidator.test.js
Summary
enum("Open")andenum(10)to validate as enums with a single valueRoot cause
Explicit enum syntax was detected correctly, but enum validation still enforced a minimum of two values for every enum form. That caused
enum(...)with a single value to fall back to a literal.Validation
pnpm run verify:localSummary by CodeRabbit
New Features
enum(...)syntax are now supported, removing the previous minimum value requirement for explicit enum definitions.Tests