Skip to content

feat: Add HookData class. #114

Open
NeaguGeorgiana23 wants to merge 11 commits into
mainfrom
hooks_data
Open

feat: Add HookData class. #114
NeaguGeorgiana23 wants to merge 11 commits into
mainfrom
hooks_data

Conversation

@NeaguGeorgiana23

Copy link
Copy Markdown
Contributor

This PR

  • Adds HookData, the foundational state-management container required for the OpenFeature Hooks lifecycle specification (Section 4.6).
  • Implements a type-safe key-value store backed by std::unordered_map<std::string, std::any> (Set, Get, and GetAs<T>) to allow individual hook instances to persist arbitrary runtime state (e.g., execution timers, OpenTelemetry span pointers, transaction IDs) across Before ,After / Error , FinallyAfter stages during a single flag evaluation.
  • Adds comprehensive unit tests covering value setting, retrieving, type-safe casting, and edge cases for missing keys or type mismatches.

Related Issues

Fixes #111

Follow-up Tasks

  • implement HookContext

NeaguGeorgiana23 and others added 7 commits July 7, 2026 13:19
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>
@NeaguGeorgiana23 NeaguGeorgiana23 requested review from a team as code owners July 10, 2026 12:30
@coderabbitai

coderabbitai Bot commented Jul 10, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@NeaguGeorgiana23, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 8 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

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.

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 configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 6bc4876e-91e7-4a08-8aa9-81c3e75d2295

📥 Commits

Reviewing files that changed from the base of the PR and between c8fc92d and e9e8852.

📒 Files selected for processing (3)
  • openfeature/hook_data.cpp
  • openfeature/hook_data.h
  • test/hook_data_test.cpp
📝 Walkthrough

Walkthrough

Adds public flag and hook data types, implements HookData storage with typed access, registers Bazel targets, and introduces comprehensive GoogleTest coverage.

Changes

Hook data structures

Layer / File(s) Summary
Hook type contracts
openfeature/flag_type_value.h, openfeature/hook_hints.h, openfeature/BUILD
Adds FlagValueType, the HookHints alias, and Bazel library targets for the new public types.
HookData storage implementation
openfeature/hook_data.h, openfeature/hook_data.cpp, openfeature/BUILD
Implements HookData with std::any values, replacement semantics, missing-key handling, and typed retrieval.
HookData validation
test/hook_data_test.cpp, test/BUILD
Adds tests for primitive and custom values, type mismatches, overwrites, mutation, missing keys, and shared pointers.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related issues

  • open-feature/swift-sdk#99: Covers per-evaluation hook data storage for sharing arbitrary values across hook stages, corresponding to the new HookData APIs here.
🚥 Pre-merge checks | ✅ 2 | ❌ 3

❌ Failed checks (3 warnings)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning The PR covers Hook data and Hook hints, but #111 also requires Evaluation option, which is not implemented. Add the missing Evaluation option implementation or narrow the linked issue scope before merging.
Out of Scope Changes check ⚠️ Warning The new flag_type_value public enum is not requested by #111 and appears unrelated to Hook data structures. Remove the unrelated flag_type_value addition or explain how it is required by the linked issue.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly matches the main change: adding the HookData class.
Description check ✅ Passed The description matches the code changes and accurately describes HookData, tests, and the linked issue.

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.

@NeaguGeorgiana23 NeaguGeorgiana23 changed the title Hooks data feat: Add HookData class. Jul 10, 2026
Signed-off-by: NeaguGeorgiana23 <neagugeorgiana@google.com>

@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)
openfeature/hook_data.h (1)

21-28: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Consider adding a const overload of GetAs for read-only contexts.

Currently GetAs is non-const only, which prevents typed retrieval from a const HookData&. A const overload returning const T* would improve API ergonomics for callers that only need read access.

♻️ Optional: add const GetAs overload
   template <typename T>
   T* GetAs(const std::string& key) {
     auto it_key = data_.find(key);
     if (it_key != data_.end()) {
       return std::any_cast<T>(&it_key->second);
     }
     return nullptr;
   }
+
+  template <typename T>
+  const T* GetAs(const std::string& key) const {
+    auto it_key = data_.find(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 21 - 28, Add a const overload of
HookData::GetAs(const std::string& key) returning const T* so typed values can
be retrieved from const HookData instances; preserve the existing non-const
overload and use const access to data_ in the new implementation.
🤖 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 `@openfeature/hook_data.h`:
- Around line 21-28: Add a const overload of HookData::GetAs(const std::string&
key) returning const T* so typed values can be retrieved from const HookData
instances; preserve the existing non-const overload and use const access to
data_ in the new implementation.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: b29e6623-cfa0-4781-ad37-8282518e3158

📥 Commits

Reviewing files that changed from the base of the PR and between 8254496 and c8fc92d.

📒 Files selected for processing (7)
  • openfeature/BUILD
  • openfeature/flag_type_value.h
  • openfeature/hook_data.cpp
  • openfeature/hook_data.h
  • openfeature/hook_hints.h
  • test/BUILD
  • test/hook_data_test.cpp

Signed-off-by: NeaguGeorgiana23 <neagugeorgiana@google.com>
Signed-off-by: NeaguGeorgiana23 <neagugeorgiana@google.com>
Signed-off-by: NeaguGeorgiana23 <neagugeorgiana@google.com>
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.

Hook data structures

1 participant