Skip to content

Fix single-value explicit enum handling (#181)#192

Merged
eviltester merged 5 commits into
masterfrom
181-single-value-enums
Jun 12, 2026
Merged

Fix single-value explicit enum handling (#181)#192
eviltester merged 5 commits into
masterfrom
181-single-value-enums

Conversation

@eviltester

@eviltester eviltester commented Jun 12, 2026

Copy link
Copy Markdown
Owner

Summary

  • allow explicit enum syntax like enum("Open") and enum(10) to validate as enums with a single value
  • keep implicit comma-separated enum detection requiring at least two values so plain single values still do not become enums
  • add validator, compiler, and end-to-end regression coverage for single-value explicit enums

Root 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:local

Summary by CodeRabbit

  • New Features

    • Single-value enums using explicit enum(...) syntax are now supported, removing the previous minimum value requirement for explicit enum definitions.
  • Tests

    • Added comprehensive test coverage for single-value enum validation, compilation, and end-to-end scenarios to ensure correct handling and output.

Copilot AI review requested due to automatic review settings June 12, 2026 11:58
@coderabbitai

coderabbitai Bot commented Jun 12, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@eviltester, we couldn't start this review because you've reached your PR review rate limit.

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 @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 37411be6-aa72-4c61-bf92-499545f2f443

📥 Commits

Reviewing files that changed from the base of the PR and between 1e161b7 and 6ddf8d4.

📒 Files selected for processing (4)
  • .github/workflows/node.js.yml
  • packages/core/js/data_generation/enum/enumTestDataRuleValidator.js
  • packages/core/js/data_generation/utils/enumParser.js
  • packages/core/src/tests/data_generation/unit/enum/enumTestDataRuleValidator.test.js
📝 Walkthrough

Walkthrough

Enum validation now supports single-value explicit enums using enum(...) syntax. The validator dynamically sets minimumValues to 1 for explicit enums or 2 for CSV-style, with updated error messages. Unit, integration, and end-to-end tests verify the feature.

Changes

Single-Value Explicit Enum Support

Layer / File(s) Summary
Validator logic for single-value enums
packages/core/js/data_generation/enum/enumTestDataRuleValidator.js
Validator imports isExplicitEnumRule and updates enum value count validation to compute minimumValues dynamically: 1 for explicit enum(...) syntax, 2 otherwise. Error messages reflect the threshold.
Unit tests for validator and parser
packages/core/src/tests/data_generation/unit/enum/enumTestDataRuleValidator.test.js
Tests confirm that explicit single-value syntax enum("OnlyOne") passes validation and that enum("Open") is correctly extracted as ['Open'] by the parser.
Compiler integration tests
packages/core/src/tests/data_generation/enum-compiler-integration.test.js
Assertions verify that enum("A") is recognized as a valid enum pattern and that enum("Open") compiles with type === 'enum' and reports compiler validity.
End-to-end enum generation test
packages/core/src/tests/data_generation/enum-integration-e2e.test.js
E2E test builds a schema with enum("Open"), generates 5 rows with JSON output, and asserts every row's Status column is exactly "Open".

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 A single value now stands tall,
No need for pairs to pass the call,
Explicit enums, one and true,
The tests confirm what validation knew!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Fix single-value explicit enum handling' clearly and specifically summarizes the main change, which is enabling single-value explicit enum syntax like enum("Open") to be recognized and validated as enums.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch 181-single-value-enums

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread packages/core/js/data_generation/enum/enumTestDataRuleValidator.js

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 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-apps

greptile-apps Bot commented Jun 12, 2026

Copy link
Copy Markdown

Greptile Summary

This PR fixes single-value explicit enum handling so that enum("Open") and enum(10) are accepted by the validator, while implicit comma-separated enums still require at least two values. It also hardens the Docker smoke-test steps in CI with retry logic and container-exit detection.

  • Validator change: isExplicitEnumRule is now consulted to set minimumValues to 1 for explicit enum(...) (and shorthand enum <value>) forms, and 2 for plain CSV enums.
  • Parser change: extractAwdEnumValues now preserves empty strings from trailing/double commas so the downstream validator can emit a precise "cannot be empty" error instead of silently dropping them.
  • Test coverage: New unit, compiler-integration, and end-to-end tests cover the single-value quoted and numeric paths, as well as trailing-comma and double-comma rejection.

Confidence Score: 5/5

Safe 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 enum active form also now accepts a single value — is not tested and not mentioned in the PR description, but it is an edge case unlikely to cause user-visible regressions in practice.

packages/core/js/data_generation/enum/enumTestDataRuleValidator.js — worth confirming whether the shorthand single-value relaxation is intentional.

Important Files Changed

Filename Overview
packages/core/js/data_generation/enum/enumTestDataRuleValidator.js Uses isExplicitEnumRule to lower the minimum-value threshold to 1 for explicit enums; works correctly for enum(...) but also silently lowers the bar for the shorthand enum <value> form as an unintended side effect.
packages/core/js/data_generation/utils/enumParser.js Removes the empty-string guard on push so trailing/double commas produce empty strings that the validator can reject with a clear message; the sentinel check is updated to values.every(v => v.length === 0) to still throw on fully-empty input.
.github/workflows/node.js.yml Adds retry helpers (web_curl / site_curl), container-exit detection, and an explicit ready-flag check to the Docker smoke tests to make flaky curl failures more resilient and diagnostic.
packages/core/src/tests/data_generation/unit/enum/enumTestDataRuleValidator.test.js Adds tests for single-value quoted and numeric explicit enums, trailing-comma rejection, and double-comma rejection; covers all new validator paths introduced by this PR.
packages/core/src/tests/data_generation/enum-compiler-integration.test.js Adds compiler-level test confirming enum("A") is detected as an enum pattern and compiles to type enum.
packages/core/src/tests/data_generation/enum-integration-e2e.test.js End-to-end regression for single-value explicit enum: generates 5 rows and asserts every value equals the sole enum member.

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]
Loading

Reviews (5): Last reviewed commit: "Harden docker smoke test readiness check..." | Re-trigger Greptile

Comment thread packages/core/js/data_generation/enum/enumTestDataRuleValidator.js

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
packages/core/src/tests/data_generation/unit/enum/enumTestDataRuleValidator.test.js (1)

121-125: ⚡ Quick win

Consider 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

📥 Commits

Reviewing files that changed from the base of the PR and between 09538e5 and 1e161b7.

📒 Files selected for processing (4)
  • packages/core/js/data_generation/enum/enumTestDataRuleValidator.js
  • packages/core/src/tests/data_generation/enum-compiler-integration.test.js
  • packages/core/src/tests/data_generation/enum-integration-e2e.test.js
  • packages/core/src/tests/data_generation/unit/enum/enumTestDataRuleValidator.test.js

@eviltester eviltester merged commit 6cf4512 into master Jun 12, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants