Skip to content

Implement class Evaluation Context#56

Merged
NeaguGeorgiana23 merged 4 commits into
mainfrom
eval_context
Feb 2, 2026
Merged

Implement class Evaluation Context#56
NeaguGeorgiana23 merged 4 commits into
mainfrom
eval_context

Conversation

@NeaguGeorgiana23

Copy link
Copy Markdown
Contributor

This PR

Implements the EvaluationContext class and its associated Builder. The EvaluationContext is immutable and represents a container for contextual information used during flag evaluation, such as a targeting key and custom attributes.

  • Includes a static merge method that combines multiple contexts. Here, the attributes are merged with higher precedence overwrites and the targeting key is resolved by selecting the first valid key found in order of precedence (highest to lowest).

  • Builder Pattern was used to make the EvaluationContext immutable

Related Issues

Fixes #55

Signed-off-by: NeaguGeorgiana23 <neagugeorgiana@google.com>
@NeaguGeorgiana23 NeaguGeorgiana23 requested review from a team as code owners January 28, 2026 15:21
@gemini-code-assist

Copy link
Copy Markdown

Summary of Changes

Hello @NeaguGeorgiana23, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces the foundational EvaluationContext class, a critical component for managing contextual information during feature flag evaluation. By leveraging the Builder pattern, it ensures that context objects are immutable and consistently constructed. The implementation also includes a sophisticated merge mechanism, allowing for the composition of multiple contexts while respecting defined precedence rules for both attributes and targeting keys. This enhancement provides a robust and predictable way to handle dynamic evaluation environments.

Highlights

  • New Class Implementation: Introduced the EvaluationContext class and its associated Builder pattern for creating immutable context objects.
  • Immutability and Builder Pattern: The EvaluationContext is designed to be immutable, with its construction strictly managed through a Builder to ensure consistent state.
  • Contextual Data Storage: The EvaluationContext serves as a container for a targeting key and custom attributes, essential for flag evaluation.
  • Context Merging Logic: A static merge method has been implemented to combine multiple EvaluationContext instances. This method handles attribute merging with higher precedence overwriting lower, and resolves the targeting key by selecting the first valid key based on precedence.
  • Comprehensive Unit Tests: A new test file, evaluation_context_test.cpp, has been added with extensive unit tests covering the EvaluationContext's functionality, including attribute handling, targeting key management, and the complex merge logic.
  • Build System Updates: The openfeature/BUILD and test/BUILD files have been updated to include the new evaluation_context.cpp source file and the evaluation_context_test target, respectively.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request implements the EvaluationContext class and its builder, which is a great addition. The implementation is solid, but I have a few suggestions to improve performance, API safety, and design clarity. Specifically, I've recommended using heterogeneous lookup for the attributes map to avoid unnecessary string allocations. I've also suggested a change to how a missing targeting_key is represented, using std::nullopt instead of an empty string to better align with the concept of an "undefined" value. Finally, I've pointed out a potential API safety issue with storing const char* in attributes and suggested standardizing on std::string.

Comment thread openfeature/evaluation_context.cpp
Comment thread openfeature/evaluation_context.cpp Outdated
}

EvaluationContext EvaluationContext::Builder::build() const {
return EvaluationContext(targeting_key_.value_or(""), attributes_);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Using an empty string to represent a missing targeting key can be ambiguous. The OpenFeature specification says the key should be "undefined" if not set. Using std::optional throughout (from builder to the context object) by passing targeting_key_ directly to the constructor would better represent this "undefined" state as std::nullopt. This makes the implementation cleaner and less ambiguous. The corresponding test DefaultBuilderCreatesEmptyContext will need to be updated to expect std::nullopt.

Suggested change
return EvaluationContext(targeting_key_.value_or(""), attributes_);
return EvaluationContext(targeting_key_, attributes_);

Comment thread openfeature/evaluation_context.h
Comment thread test/evaluation_context_test.cpp Outdated
Comment thread test/evaluation_context_test.cpp Outdated

@oxddr oxddr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please have a look at suggestions from Gemini and apply whenever they make sense.

NeaguGeorgiana23 and others added 2 commits January 30, 2026 09:41
Signed-off-by: NeaguGeorgiana23 <115723925+NeaguGeorgiana23@users.noreply.github.com>
…ult constructor.

Signed-off-by: NeaguGeorgiana23 <neagugeorgiana@google.com>
Comment thread openfeature/evaluation_context.h Outdated
Comment thread openfeature/evaluation_context.cpp Outdated
Comment thread openfeature/evaluation_context.cpp Outdated
Signed-off-by: NeaguGeorgiana23 <neagugeorgiana@google.com>
@NeaguGeorgiana23 NeaguGeorgiana23 merged commit 511a899 into main Feb 2, 2026
2 checks passed
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.

Implement Evaluation Context

3 participants