Skip to content

fix(openfeature): compute correct reason from allocation structure#224

Draft
leoromanovsky wants to merge 2 commits intomainfrom
leo.romanovsky/fix-openfeature-reason
Draft

fix(openfeature): compute correct reason from allocation structure#224
leoromanovsky wants to merge 2 commits intomainfrom
leo.romanovsky/fix-openfeature-reason

Conversation

@leoromanovsky
Copy link
Copy Markdown
Collaborator

Motivation

The evaluator hardcodes TARGETING_MATCH as the reason for all successful flag evaluations. The correct reason depends on the allocation structure:

  • STATIC: empty rules, no shards (catch-all override/kill-switch path)
  • SPLIT: empty rules, shards present (percentage rollout)
  • TARGETING_MATCH: non-empty rules (rule-based targeting)

This aligns with the Go reference implementation in dd-trace-go and the OpenFeature spec.

Changes

  • evaluateForSubject.ts: Replace hardcoded TARGETING_MATCH with inline three-way reason computation based on allocation.rules and split.shards
  • TestCaseResult.types.ts: Make reason a required field (was optional) — every evaluation path returns a reason
  • flags-v1.spec.ts: Remove conditional if (testCase.result.reason) guard — always assert reason unconditionally

Decisions

  • Reason is computed inline at the return site (no helper function) — mirrors Go's switch block
  • allocation.rules?.length is checked directly, not the result of containsMatchingRule (which returns true for empty rules)
  • startAt/endAt are NOT reason signals — they are time-window pre-filters only
  • One fixture auto-fix: test-flag-that-does-not-exist.json reason changed from DEFAULT to ERROR to match the provider's actual FLAG_NOT_FOUND behavior

…oding TARGETING_MATCH

- Three-way reason: rules?.length -> TARGETING_MATCH, shards.length -> SPLIT, else -> STATIC
- Fix test-flag-that-does-not-exist fixture: reason should be ERROR (FLAG_NOT_FOUND), not DEFAULT
…ssertions

- Remove optional marker from reason field in TestCaseResult interface
- Remove conditional guard around reason assertion in flags-v1.spec.ts
- Add reason field to all test fixture JSON files
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.

1 participant