Skip to content

Stabilize entitlement calculations - #83

Merged
hosom merged 2 commits into
mainfrom
hosom/calculation-correctness
Sep 22, 2026
Merged

hosom merged 2 commits into
mainfrom
hosom/calculation-correctness

Conversation

@hosom

@hosom hosom commented Sep 22, 2026

Copy link
Copy Markdown
Contributor

We had several bugfixes identified in #74, which I've extracted into this much smaller PR to get them across the finish line sooner.

  • We have moved to using a single, configurable, evaluation timestamp for expiration checks so that we aren't making calculations based on repeated calls to Time.now.
  • Fixed returns to return an empty set for empty and rules.
  • We avoid memoizing the :calculating sentinel in text and YAML groups.

Keep one evaluation timestamp for each run, allow callers to set it explicitly, handle empty AND rules, and avoid caching in-progress calculation sentinels.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 10248eee-e35a-46a7-9705-9bebc7b5318b
Copilot AI balanced review requested due to automatic review settings September 22, 2026 15:04

Copilot AI 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.

Copilot review overview

🟢 Approval recommended

The focused correctness changes are internally consistent and adequately covered by unit tests.

Review effort: Balanced
Findings: None

What changed in this PR

Stabilizes calculated-group entitlement evaluation with consistent expiration timing and safer rule caching.

Changes:

  • Adds a configurable, resettable evaluation timestamp.
  • Handles empty and rules as empty sets.
  • Prevents caching transient :calculating sentinels.
File Description
lib/​entitlements.rb Adds evaluation-time state and reset behavior.
lib/​entitlements/​data/​groups/​calculated/​base.rb Uses fixed time and handles empty conjunctions.
lib/​entitlements/​data/​groups/​calculated/​modifiers/​expiration.rb Uses fixed time for expiration modifiers.
lib/​entitlements/​data/​groups/​calculated/​text.rb Fixes sentinel caching and expiration timing.
lib/​entitlements/​data/​groups/​calculated/​yaml.rb Fixes sentinel caching.
spec/​unit/​entitlements_spec.rb Tests evaluation-time lifecycle.
spec/​unit/​entitlements/​data/​groups/​calculated/​base_spec.rb Tests empty and behavior.
spec/​unit/​entitlements/​data/​groups/​calculated/​modifiers/​expiration_spec.rb Tests configured-time expiration.
spec/​unit/​entitlements/​data/​groups/​calculated/​text_spec.rb Tests text sentinel handling.
spec/​unit/​entitlements/​data/​groups/​calculated/​yaml_spec.rb Tests YAML sentinel handling.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Prepare the entitlement calculation correctness fixes for publication.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 10248eee-e35a-46a7-9705-9bebc7b5318b
nobe4 added a commit that referenced this pull request Sep 22, 2026
to merge after #83
@hosom
hosom merged commit 8e15c14 into main Sep 22, 2026
19 checks passed
@hosom
hosom deleted the hosom/calculation-correctness branch September 22, 2026 15:44
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