Skip to content

Conversation

@Zaimwa9
Copy link
Contributor

@Zaimwa9 Zaimwa9 commented Oct 23, 2025

Thanks for submitting a PR! Please check the boxes below:

  • I have added information to docs/ if required so people know about the feature!
  • I have filled in the "Changes" section below?
  • I have filled in the "How did you test this code" section below?
  • I have used a Conventional Commit title for this Pull Request

Changes

Contributes to #81

This is pass 1 of 4.

  • Implement document to evaluation context mappers (map_environment_model_to_evaluation_context, map_identity_overrides_to_segments, map_segment_rule_to_model, map_identity_model_to_identity_context)
  • Metadata consistently added to features and segment overrides
  • Add tests around the mappers
  • Preparation to implement evaluationResult
  • Tests inspired from PHP

How did you test this code?

  • Added tests

@Zaimwa9 Zaimwa9 requested a review from a team as a code owner October 23, 2025 09:29
@Zaimwa9 Zaimwa9 requested review from gagantrivedi and removed request for a team October 23, 2025 09:29
Copy link
Member

@khvn26 khvn26 left a comment

Choose a reason for hiding this comment

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

Looks good, with a handful of comments.

module EvaluationContext
module Mappers
# Using integer constant instead of -Float::INFINITY because the JSON serializer rejects infinity values
HIGHEST_PRIORITY = 0
Copy link
Member

Choose a reason for hiding this comment

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

Just for safety, I'd prefer this to be lower than 0. Also, our naming convention for these constants is strongest-weakest:

Suggested change
HIGHEST_PRIORITY = 0
STRONGEST_PRIORITY = -99_999_999

end

# Create hash of the overrides to group identities with same overrides
overrides_hash = Digest::SHA1.hexdigest(overrides_key.to_json)
Copy link
Member

Choose a reason for hiding this comment

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

Consider one of the following alternatives.

  1. Using inspect instead of to_json might be more performant, and doesn't require us to avoid Inf:
Suggested change
overrides_hash = Digest::SHA1.hexdigest(overrides_key.to_json)
overrides_hash = Digest::SHA1.hexdigest(overrides_key.inspect)
  1. I'm not too familiar with Ruby's Object::hash, but it could be sufficient in our case. We could drop the digest dependency that way:
Suggested change
overrides_hash = Digest::SHA1.hexdigest(overrides_key.to_json)
overrides_hash = overrides_key.hash

Copy link
Contributor Author

@Zaimwa9 Zaimwa9 Oct 28, 2025

Choose a reason for hiding this comment

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

I'm actually reverting this change to inspect as I discovered that the hash is not consistent over application restarts

Copy link
Member

Choose a reason for hiding this comment

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

We're not persisting this hash anywhere, so I don't think it's a requirement for it to be consistent across runtimes? Am I missing something?

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.

3 participants