Skip to content

test(server): cover the feature flag regex helpers - #1056

Open
mariazuheros wants to merge 1 commit into
rybbit-io:masterfrom
mariazuheros:test/feature-flag-regex
Open

test(server): cover the feature flag regex helpers#1056
mariazuheros wants to merge 1 commit into
rybbit-io:masterfrom
mariazuheros:test/feature-flag-regex

Conversation

@mariazuheros

@mariazuheros mariazuheros commented Jul 17, 2026

Copy link
Copy Markdown

The helpers in server/src/services/featureFlags/regex.ts had no direct coverage, so I added tests for the whole module.

What is covered:

  • validateFeatureFlagRegexPattern: an empty pattern, a pattern over the length limit, invalid syntax, a catastrophic backtracking pattern that safe-regex2 flags as too complex, and a safe pattern that returns null.
  • precompileFeatureFlagRegexPattern and getCompiledFeatureFlagRegex: a valid pattern is compiled, cached, and returned on later lookups, the same instance comes back on a second call, and an invalid pattern returns undefined without being cached.
  • precompileFeatureFlagRuleRegexes and precompileFeatureFlagConditionSetRegexes: regex rules are precompiled (including array values), non regex operators are skipped, and a missing list is a no-op.

The module keeps a process wide compile cache, so each test uses a unique pattern to stay independent. Run with cd server && npx vitest run src/services/featureFlags/regex.test.ts (14 tests pass).

Summary by CodeRabbit

  • Tests
    • Added comprehensive coverage for feature-flag regular expression validation and compilation.
    • Verified handling of invalid, unsafe, empty, and overly long patterns.
    • Added tests for compilation caching, invalid-pattern handling, and regex processing across rules and condition sets.

Adds tests for validateFeatureFlagRegexPattern (empty, too long, invalid
syntax, unsafe backtracking, and a safe pattern), the precompile cache, and
the rule and condition set walkers that feed it. Each test uses a unique
pattern so the shared compile cache does not couple them.
@vercel

vercel Bot commented Jul 17, 2026

Copy link
Copy Markdown

@mariazuheros is attempting to deploy a commit to the goldflag's projects Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: b245e861-47a3-4ec7-8a1e-ff4d1c23bc83

📥 Commits

Reviewing files that changed from the base of the PR and between b7a8f86 and 468d48a.

📒 Files selected for processing (1)
  • server/src/services/featureFlags/regex.test.ts

📝 Walkthrough

Walkthrough

Adds Vitest tests covering feature-flag regex validation, compilation caching, invalid-pattern handling, and precompilation across rules and condition sets.

Changes

Feature flag regex tests

Layer / File(s) Summary
Regex validation coverage
server/src/services/featureFlags/regex.test.ts
Tests empty, oversized, invalid, overly complex, and valid regex patterns.
Regex compilation and caching
server/src/services/featureFlags/regex.test.ts
Verifies RegExp compilation, cached instance reuse, and invalid-pattern cache behavior.
Rule and condition-set precompilation
server/src/services/featureFlags/regex.test.ts
Covers regex rules, array-valued patterns, non-regex operators, condition sets, and undefined inputs.

Estimated code review effort: 2 (Simple) | ~10 minutes

🚥 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 clearly matches the change: adding test coverage for feature-flag regex helpers in the server code.
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.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

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.

1 participant