-
Couldn't load subscription status.
- Fork 10
feat: Add runtime type validation for default values in flag evaluation methods #194
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
@josecolella 👋 This repository doesn't have Copilot instructions. With Copilot instructions, I can understand the repository better, work faster and produce higher quality PRs. I can generate a .github/copilot-instructions.md file for you automatically. Click here to open a pre-filled issue and assign it to me. I'll write the instructions, and then tag you for review. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #194 +/- ##
==========================================
+ Coverage 99.55% 99.57% +0.01%
==========================================
Files 16 16
Lines 226 233 +7
==========================================
+ Hits 225 232 +7
Misses 1 1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Co-authored-by: josecolella <1974588+josecolella@users.noreply.github.com>
There was a problem hiding this comment.
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 adds runtime type validation for default values in flag evaluation methods to prevent unexpected behavior when incorrect types are passed. The validation ensures that default values match the expected types for each flag evaluation method (boolean, string, number, etc.).
- Implements early validation in the
Client#fetch_detailsmethod using the existingTYPE_CLASS_MAP - Adds comprehensive test coverage for both valid and invalid default value scenarios
- Provides descriptive error messages that clearly indicate expected vs actual types
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| lib/open_feature/sdk/client.rb | Adds validation logic to check default value types before provider interaction |
| spec/open_feature/sdk/client_spec.rb | Adds comprehensive test coverage for valid and invalid default value type scenarios |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
|
@copilot There seems to be some failing tests. Ensure that the test suite is passing |
Co-authored-by: josecolella <1974588+josecolella@users.noreply.github.com>
Head branch was pushed to by a user without write access
The test suite is now passing! The failing test was caused by incorrect examples in the README that were using wrong default value types (e.g., All 128 examples are now passing with 0 failures. The runtime type validation is working correctly and catches type mismatches as intended. |
Runtime checks for default value type implementation:
Analysis:
fetch_boolean_valueshould only accepttrueorfalseas default values, but currently accepts any typeImplementation Plan:
fetch_detailsmethod before processingImplementation Details:
✅ Added
validate_default_value_typemethod that checks default value type againstTYPE_CLASS_MAP✅ Method raises
ArgumentErrorwith descriptive message for type mismatches (following codebase patterns)✅ Validation occurs before calling provider, ensuring early error detection
✅ All existing functionality preserved - provider-level type validation still works
✅ Added comprehensive test cases covering all supported types and invalid combinations
✅ Fixed README examples that had incorrect default value types
Changes Made:
Client#fetch_detailsto call validation before provider interactionClient#validate_default_value_typeprivate method with clear error messagesclient_spec.rbcovering both valid and invalid scenariosfetch_string_valuedefault fromfalseto'default'fetch_object_valuedefault fromJSON.dump({...})to{...}Testing Results:
✅ All 128 examples passing (0 failures, 17 pending expected)
✅ All valid default value types work correctly
✅ Invalid types raise appropriate
ArgumentErrorwith helpful messages✅ Existing provider type mismatch detection continues to work
✅ Both value and details methods validate correctly
✅ Error messages are clear and descriptive
✅ README examples now follow correct type usage
Example Usage:
This implementation provides the requested runtime type checking while maintaining full backward compatibility for valid use cases. The failing tests were caused by incorrect examples in the README which have now been fixed.
Fixes #184.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.