Skip to content

feat: Update global api#123

Open
NeaguGeorgiana23 wants to merge 30 commits into
mainfrom
update_global_api
Open

feat: Update global api#123
NeaguGeorgiana23 wants to merge 30 commits into
mainfrom
update_global_api

Conversation

@NeaguGeorgiana23

Copy link
Copy Markdown
Contributor

This PR

  • Adds getter and setter methods for Hooks in the global API.
  • Updates the Shutdown method to also clean hooks when it is called.
  • Adds unit test for these new getters and setters.
  • Adds unit tests for SetEvaluationContext and GetEvaluationContext since they were missing.

Fixes #122

NeaguGeorgiana23 and others added 28 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>
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>
Signed-off-by: NeaguGeorgiana23 <neagugeorgiana@google.com>
Signed-off-by: NeaguGeorgiana23 <neagugeorgiana@google.com>
Signed-off-by: NeaguGeorgiana23 <115723925+NeaguGeorgiana23@users.noreply.github.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>
@NeaguGeorgiana23
NeaguGeorgiana23 requested review from a team as code owners July 15, 2026 21:28
@coderabbitai

coderabbitai Bot commented Jul 15, 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: 46 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: 52b25c9b-0346-46fb-8b61-89a562e2250f

📥 Commits

Reviewing files that changed from the base of the PR and between 665914a and 0bd0f58.

📒 Files selected for processing (2)
  • openfeature/openfeature_api.cpp
  • test/openfeature_api_test.cpp
📝 Walkthrough

Walkthrough

Adds C++ hook contracts, evaluation detail types, provider hook access, and global hook management. New Bazel targets and tests cover lifecycle callbacks, hook hints, polymorphism, evaluation details, and API registration behavior.

Changes

Hook infrastructure

Layer / File(s) Summary
Hook and evaluation contracts
openfeature/base_hook.h, openfeature/hook.*, openfeature/evaluation_options.h, openfeature/flag_evaluation_details.*
Adds polymorphic hook contracts, lifecycle callbacks, evaluation options, flag evaluation details, common type aliases, and Bazel targets.
Provider hook contract
openfeature/provider.h, openfeature/noop_provider.*, openfeature/memory_provider/*
Adds FeatureProvider::GetHooks() and empty implementations for the built-in providers, with updated dependencies.
Global hook management
openfeature/openfeature.h, openfeature/openfeature_api.*
Adds batch and single-hook registration, retrieval with shared synchronization, null filtering, provider overloads, and shutdown cleanup.
Hook behavior validation
test/*, test/mocks/mock_feature_provider.h
Adds tests for evaluation options, evaluation details, hook callbacks, provider mocks, global context, and global hook registration.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant OpenFeatureAPI
  participant HookStorage
  Client->>OpenFeatureAPI: AddHook or AddHooks
  OpenFeatureAPI->>HookStorage: append non-null hooks
  Client->>OpenFeatureAPI: GetHooks
  OpenFeatureAPI->>HookStorage: read hooks under shared lock
  HookStorage-->>OpenFeatureAPI: hook snapshot
  OpenFeatureAPI-->>Client: return hook list
  Client->>OpenFeatureAPI: Shutdown
  OpenFeatureAPI->>HookStorage: clear hooks under exclusive lock
Loading

Possibly related PRs

Suggested reviewers: oxddr

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 27.94% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title is related, but it's too generic to clearly reflect the hook-management changes. Use a more specific title like 'Add global hook management to the OpenFeature API'.
✅ Passed checks (3 passed)
Check name Status Explanation
Description check ✅ Passed The description matches the changeset by describing hook APIs, shutdown cleanup, and tests.
Linked Issues check ✅ Passed The PR implements global hook management and cleanup, which matches issue #122.
Out of Scope Changes check ✅ Passed I don't see clear unrelated code changes beyond the hook API work and its supporting 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.

@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.

Actionable comments posted: 3

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
test/openfeature_api_test.cpp (1)

19-25: 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Ensure test isolation matches the comment.

The comment indicates that the singleton is shut down before and after each test to reset its state. However, SetUp() is currently empty. To prevent potential state leakage from other test suites that might run beforehand in the same process, consider applying the cleanup logic in SetUp() as well.

🛠️ Proposed fix
   // To ensure test isolation for the singleton, we shut it down before and
   // after each test, to reset it to its default state.
-  void SetUp() override {}
+  void SetUp() override {
+    api.Shutdown();
+    api.SetEvaluationContext(EvaluationContext::Builder().build());
+  }
   void TearDown() override {
     api.Shutdown();
     api.SetEvaluationContext(EvaluationContext::Builder().build());
   }
🤖 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/openfeature_api_test.cpp` around lines 19 - 25, Update the test
fixture’s SetUp method to perform the same singleton cleanup as TearDown: call
api.Shutdown() and reset the evaluation context with a newly built default
EvaluationContext. Keep the existing TearDown cleanup unchanged so isolation
occurs both before and after each test.
🤖 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 `@openfeature/flag_evaluation_details.cpp`:
- Around line 3-5: Add a direct <utility> include in flag_evaluation_details.cpp
alongside the existing standard-library includes so the translation unit
explicitly provides std::move without relying on transitive includes.

In `@openfeature/openfeature_api.cpp`:
- Around line 80-84: Update OpenFeatureAPI::AddHooks to skip null shared
pointers before inserting elements into hooks_, matching the validation
performed by AddHook. Preserve moving valid hooks into the collection while
ensuring nullptr entries are never stored.

In `@openfeature/provider.h`:
- Line 28: Update FeatureProvider::GetHooks() to provide a default empty
implementation instead of remaining pure virtual, preserving source
compatibility for downstream providers while allowing providers to override it
when needed.

---

Outside diff comments:
In `@test/openfeature_api_test.cpp`:
- Around line 19-25: Update the test fixture’s SetUp method to perform the same
singleton cleanup as TearDown: call api.Shutdown() and reset the evaluation
context with a newly built default EvaluationContext. Keep the existing TearDown
cleanup unchanged so isolation occurs both before and after each test.
🪄 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: a865e274-ec3d-4840-9f04-56e938238aab

📥 Commits

Reviewing files that changed from the base of the PR and between b7e65b5 and ea6a463.

📒 Files selected for processing (22)
  • openfeature/BUILD
  • openfeature/base_hook.h
  • openfeature/evaluation_options.h
  • openfeature/flag_evaluation_details.cpp
  • openfeature/flag_evaluation_details.h
  • openfeature/hook.cpp
  • openfeature/hook.h
  • openfeature/memory_provider/BUILD
  • openfeature/memory_provider/in_memory_provider.cpp
  • openfeature/memory_provider/in_memory_provider.h
  • openfeature/noop_provider.cpp
  • openfeature/noop_provider.h
  • openfeature/openfeature.h
  • openfeature/openfeature_api.cpp
  • openfeature/openfeature_api.h
  • openfeature/provider.h
  • test/BUILD
  • test/evaluation_options_test.cpp
  • test/flag_evaluation_details_test.cpp
  • test/hook_test.cpp
  • test/mocks/mock_feature_provider.h
  • test/openfeature_api_test.cpp

Comment on lines +3 to +5
#include <optional>
#include <string>
#include <string_view>

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

ast-grep outline openfeature/flag_evaluation_details.cpp --view expanded

Repository: open-feature/cpp-sdk

Length of output: 575


🏁 Script executed:

sed -n '1,120p' openfeature/flag_evaluation_details.cpp

Repository: open-feature/cpp-sdk

Length of output: 1561


🏁 Script executed:

sed -n '1,200p' openfeature/flag_evaluation_details.h && printf '\n---\n' && sed -n '1,200p' openfeature/resolution_details.h

Repository: open-feature/cpp-sdk

Length of output: 3727


Include <utility> for std::move. This translation unit depends on transitive includes here; add the direct include so it stays portable.

Proposed fix
 `#include` <string_view>
+#include <utility>
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
#include <optional>
#include <string>
#include <string_view>
`#include` <optional>
`#include` <string>
`#include` <string_view>
`#include` <utility>
🤖 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/flag_evaluation_details.cpp` around lines 3 - 5, Add a direct
<utility> include in flag_evaluation_details.cpp alongside the existing
standard-library includes so the translation unit explicitly provides std::move
without relying on transitive includes.

Comment thread openfeature/provider.h
public:
virtual ~FeatureProvider() = default;
virtual Metadata GetMetadata() const = 0;
virtual std::vector<std::shared_ptr<BaseHook>> GetHooks() const = 0;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf 'Repo root: '; pwd
printf '\nFiles of interest:\n'
git ls-files | rg '^openfeature/(provider\.h|.*provider.*|.*hook.*|.*mock.*|.*test.*|README|CHANGELOG|VERSION|docs/)'

printf '\n--- openfeature/provider.h (numbered) ---\n'
cat -n openfeature/provider.h

printf '\n--- Search for FeatureProvider implementations / subclasses ---\n'
rg -n "class\s+\w+\s*:\s*public\s+FeatureProvider|struct\s+\w+\s*:\s*public\s+FeatureProvider|FeatureProvider\s*{" openfeature . --glob '!**/build/**' --glob '!**/dist/**' --glob '!**/node_modules/**'

printf '\n--- Search for GetHooks usage/overrides ---\n'
rg -n "GetHooks\s*\(" openfeature .

printf '\n--- Search for version / breaking-change notes ---\n'
rg -n "breaking change|major version|semver|compatib|migration|GetHooks|hooks" README* CHANGELOG* docs openfeature . --glob '!**/build/**' --glob '!**/dist/**' --glob '!**/node_modules/**'

Repository: open-feature/cpp-sdk

Length of output: 3873


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '\n--- FeatureProvider subclasses in repo ---\n'
rg -n "public FeatureProvider" openfeature

printf '\n--- GetHooks overrides/usages ---\n'
rg -n "GetHooks\s*\(" openfeature

printf '\n--- Provider implementations ---\n'
sed -n '1,220p' openfeature/noop_provider.h
printf '\n--- openfeature/noop_provider.cpp ---\n'
sed -n '1,240p' openfeature/noop_provider.cpp
printf '\n--- openfeature/memory_provider/in_memory_provider.h ---\n'
sed -n '1,220p' openfeature/memory_provider/in_memory_provider.h
printf '\n--- openfeature/memory_provider/in_memory_provider.cpp ---\n'
sed -n '1,260p' openfeature/memory_provider/in_memory_provider.cpp

printf '\n--- Docs mentioning compatibility / breaking changes / hooks ---\n'
rg -n "breaking change|major version|semver|compatib|migration|hooks" README* CHANGELOG* docs openfeature .

Repository: open-feature/cpp-sdk

Length of output: 25219


Avoid a breaking FeatureProvider change.
Adding GetHooks() as pure virtual makes downstream FeatureProvider implementations abstract and breaks source compatibility. If that break is intentional, document it as a major API change and add migration guidance; otherwise provide a default empty implementation.

🤖 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/provider.h` at line 28, Update FeatureProvider::GetHooks() to
provide a default empty implementation instead of remaining pure virtual,
preserving source compatibility for downstream providers while allowing
providers to override it when needed.

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.

Actionable comments posted: 1

🤖 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 `@openfeature/openfeature_api.cpp`:
- Around line 88-95: Update OpenFeatureAPI::AddHooks to acquire hooks_mutex_
with a std::unique_lock before reserving or appending to hooks_, matching the
synchronization used by AddHook; keep the existing null filtering and move
behavior unchanged.
🪄 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: a729b14d-7df5-4c6e-aedb-9f2fd1dbdc86

📥 Commits

Reviewing files that changed from the base of the PR and between ea6a463 and 665914a.

📒 Files selected for processing (4)
  • openfeature/openfeature.h
  • openfeature/openfeature_api.cpp
  • openfeature/openfeature_api.h
  • test/openfeature_api_test.cpp
🚧 Files skipped from review as they are similar to previous changes (1)
  • openfeature/openfeature.h

Comment thread openfeature/openfeature_api.cpp
Signed-off-by: NeaguGeorgiana23 <neagugeorgiana@google.com>
@NeaguGeorgiana23
NeaguGeorgiana23 requested a review from oxddr July 16, 2026 08:35
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.

Update Global API to manage hooks.

1 participant