feat: Add HookContext class#115
Conversation
Signed-off-by: NeaguGeorgiana23 <neagugeorgiana@google.com>
Signed-off-by: NeaguGeorgiana23 <neagugeorgiana@google.com>
Signed-off-by: NeaguGeorgiana23 <neagugeorgiana@google.com>
Signed-off-by: NeaguGeorgiana23 <neagugeorgiana@google.com>
Signed-off-by: NeaguGeorgiana23 <neagugeorgiana@google.com>
Signed-off-by: NeaguGeorgiana23 <neagugeorgiana@google.com>
Signed-off-by: NeaguGeorgiana23 <neagugeorgiana@google.com>
Signed-off-by: NeaguGeorgiana23 <neagugeorgiana@google.com>
Signed-off-by: NeaguGeorgiana23 <neagugeorgiana@google.com>
Signed-off-by: NeaguGeorgiana23 <neagugeorgiana@google.com>
Signed-off-by: NeaguGeorgiana23 <neagugeorgiana@google.com>
|
Warning Review limit reached
Next review available in: 44 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughAdds public hook data structures, typed hook contexts, flag value types, hook hints, Bazel targets, and GoogleTest coverage for storage, context updates, metadata, and shared state. ChangesHook data structures
Estimated code review effort: 3 (Moderate) | ~20 minutes 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
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 |
Signed-off-by: NeaguGeorgiana23 <neagugeorgiana@google.com>
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (2)
openfeature/hook_data.h (1)
22-29: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd a
constoverload forGetAs.
GetAsis non-const only, so callers with aconst HookData&must fall back toGet+ manualstd::any_cast. Adding a const overload is straightforward and improves API ergonomics for read-only contexts.♻️ Proposed const overload
template <typename T> T* GetAs(std::string_view key) { auto it_key = data_.find(std::string(key)); if (it_key != data_.end()) { return std::any_cast<T>(&it_key->second); } return nullptr; } + + template <typename T> + const T* GetAs(std::string_view key) const { + auto it_key = data_.find(std::string(key)); + if (it_key != data_.end()) { + return std::any_cast<T>(&it_key->second); + } + return nullptr; + }🤖 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 `@openfeature/hook_data.h` around lines 22 - 29, Add a const overload of HookData::GetAs alongside the existing non-const template, accepting the same key and returning a const T pointer. Implement it using the const data_ lookup and std::any_cast<const T> semantics, while preserving the current nullptr behavior for missing keys.test/hook_context_test.cpp (1)
34-133: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueConsider typed/parameterized tests to reduce repetition.
The five
ConstructorAndAccessorsFor*tests follow an identical assertion pattern, differing only in type, flag key, and default value. GoogleTest'sTYPED_TEST_SUITE/TYPED_TESTwould consolidate these into a single test body, reducing duplication and making it easier to add new types.🤖 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 `@test/hook_context_test.cpp` around lines 34 - 133, Consolidate the five duplicated ConstructorAndAccessorsForBool, ConstructorAndAccessorsForString, ConstructorAndAccessorsForInteger, ConstructorAndAccessorsForDouble, and ConstructorAndAccessorsForObject tests into a GoogleTest typed or parameterized test. Define per-type test data for the flag type, key, default value, and expected value access, then reuse one shared assertion body while preserving all existing coverage.
🤖 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.
Inline comments:
In `@test/hook_context_test.cpp`:
- Around line 1-13: Update the cc_test target in test/BUILD that compiles
hook_context_test.cpp to add direct dependencies on //openfeature:flag_metadata,
//openfeature:flag_type_value, and //openfeature:metadata, matching the directly
included headers while preserving the existing hook_context dependency.
---
Nitpick comments:
In `@openfeature/hook_data.h`:
- Around line 22-29: Add a const overload of HookData::GetAs alongside the
existing non-const template, accepting the same key and returning a const T
pointer. Implement it using the const data_ lookup and std::any_cast<const T>
semantics, while preserving the current nullptr behavior for missing keys.
In `@test/hook_context_test.cpp`:
- Around line 34-133: Consolidate the five duplicated
ConstructorAndAccessorsForBool, ConstructorAndAccessorsForString,
ConstructorAndAccessorsForInteger, ConstructorAndAccessorsForDouble, and
ConstructorAndAccessorsForObject tests into a GoogleTest typed or parameterized
test. Define per-type test data for the flag type, key, default value, and
expected value access, then reuse one shared assertion body while preserving all
existing coverage.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 284b5272-5b48-4c42-9d9a-13e771dfa8d6
📒 Files selected for processing (10)
openfeature/BUILDopenfeature/flag_type_value.hopenfeature/hook_context.cppopenfeature/hook_context.hopenfeature/hook_data.cppopenfeature/hook_data.hopenfeature/hook_hints.htest/BUILDtest/hook_context_test.cpptest/hook_data_test.cpp
| #include "openfeature/hook_context.h" | ||
|
|
||
| #include <gtest/gtest.h> | ||
|
|
||
| #include <memory> | ||
| #include <string> | ||
|
|
||
| #include "openfeature/evaluation_context.h" | ||
| #include "openfeature/flag_metadata.h" | ||
| #include "openfeature/flag_type_value.h" | ||
| #include "openfeature/hook_data.h" | ||
| #include "openfeature/metadata.h" | ||
| #include "openfeature/value.h" |
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Declare direct Bazel deps for all directly-included headers.
The test file directly includes openfeature/flag_metadata.h, openfeature/flag_type_value.h, and openfeature/metadata.h, but the cc_test target in test/BUILD does not list //openfeature:flag_metadata, //openfeature:flag_type_value, or //openfeature:metadata as direct deps. They are only available transitively through //openfeature:hook_context. This works today but will break under strict dependency checking.
🔧 Add missing deps to test/BUILD
cc_test(
name = "hook_context_test",
srcs = ["hook_context_test.cpp"],
deps = [
"//openfeature:evaluation_context",
+ "//openfeature:flag_metadata",
+ "//openfeature:flag_type_value",
"//openfeature:hook_context",
"//openfeature:hook_data",
+ "//openfeature:metadata",
"//openfeature:value",
"`@googletest//`:gtest_main",
],
)🤖 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 `@test/hook_context_test.cpp` around lines 1 - 13, Update the cc_test target in
test/BUILD that compiles hook_context_test.cpp to add direct dependencies on
//openfeature:flag_metadata, //openfeature:flag_type_value, and
//openfeature:metadata, matching the directly included headers while preserving
the existing hook_context dependency.
There was a problem hiding this comment.
@oxddr Sure, fixing this now.
- Add missing direct Bazel dependencies (
//openfeature:flag_metadata,//openfeature:flag_type_value,//openfeature:metadata) to thehook_context_testtarget intest/BUILD.
The requested changes have been implemented and a pull request has been created: View PR
Signed-off-by: NeaguGeorgiana23 <neagugeorgiana@google.com>
| #include "openfeature/hook_context.h" | ||
|
|
||
| #include <gtest/gtest.h> | ||
|
|
||
| #include <memory> | ||
| #include <string> | ||
|
|
||
| #include "openfeature/evaluation_context.h" | ||
| #include "openfeature/flag_metadata.h" | ||
| #include "openfeature/flag_type_value.h" | ||
| #include "openfeature/hook_data.h" | ||
| #include "openfeature/metadata.h" | ||
| #include "openfeature/value.h" |
This PR
Implements the
HookContext<T>template class and unit tests to support the OpenFeature flag evaluation lifecycle hooks specification.HookContext<T>Implementation:HookContexttemplate class encapsulating flag evaluation state (flag_key,type,default_value,EvaluationContext, client/providerMetadata, andHookData).SetEvaluationContext(ctx)to allow hook mutations.BoolHookContext,StringHookContext,IntHookContext,DoubleHookContext, andObjectHookContext).bool,std::string,int64_t,double,Value).Related Issues
Fixes #111