Skip to content

Commit b518555

Browse files
committed
feat(tck): the resolution reason is a claim a provider declares
Re-pin the spec submodule to c342461a, which moves every resolution-reason assertion out of evaluation.feature, errors.feature and lifecycle.feature -- all thirteen of them -- and into a new gherkin/reason.feature gated as a whole on @standard-reasons. Requirement 2.2.5 is a SHOULD that lets a provider populate `reason` with one of the listed values "or some other string indicating the semantic reason for the returned flag value". Asserting an exact reason in thirteen places narrowed that into a MUST for every adopter, and bought very little: every canonical flag resolves to a value distinct from the caller's default, so a provider that silently falls back was already caught by the value. So @standard-reasons is a claim rather than an exemption -- a provider saying "I use the standard vocabulary with the standard meanings", and reason.feature is what checks it. A provider that does not declare it loses nothing; its values, variants and error codes are asserted everywhere else, on MUSTs. Add the capability, declarable, beside the other twelve. It is the first whose tag is carried at the feature level rather than per scenario, which the gate handles because it reads pytest markers and pytest-bdd marks a scenario from scenario.tags | feature.tags | rule.tags. Verified by running: with the tag undeclared all nine of its scenarios skip in each in-memory suite. Both self-tests declare it, measured before declaring. InMemoryFlag.resolve reports Reason.STATIC for every flag in the decoded set, and a missing flag and a type mismatch both arrive with reason ERROR beside their error code, so the four rule-less rows and the two error scenarios pass in each. The remaining three compose the tag with @targeting and @disabled-flags, neither declared here, so they skip. Self-tests move from 196 passed / 35 skipped to 208 passed / 41 skipped: nine new scenarios in each of the two conformance suites, six running and three skipped. The thirteen removed assertions changed no scenario count -- they were lines inside scenarios that still exist. Signed-off-by: Simon Schrottner <simon.schrottner@flagsmith.com>
1 parent 38909b1 commit b518555

5 files changed

Lines changed: 160 additions & 10 deletions

File tree

‎tools/openfeature-tck/README.md‎

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ SKIPPED provider does not declare capability @stale.
230230
| `Capability.LARGE_INTEGERS` | `@large-integers` | resolves integers up to 2^53 − 1 exactly; undeclarable where the SDK's integer accessor is 32-bit |
231231
| `Capability.REINITIALIZATION` | `@reinitialization` | can be initialised again after `shutdown`, which [Requirement 2.5.2](https://github.com/open-feature/spec/blob/main/specification/sections/02-providers.md) permits rather than requires |
232232
| `Capability.TARGETING` | `@targeting` | resolves a flag differently for a matching evaluation context |
233+
| `Capability.STANDARD_REASONS` | `@standard-reasons` | reports the standard resolution reasons, with the meanings [Appendix F][appendix-f] gives them |
233234
| `Capability.CACHING` | `@caching` | reserved; **not declarable** — no scenarios yet |
234235

235236
`@lifecycle` and `@events` are deliberately separate, and the split matters in both directions. An
@@ -275,8 +276,8 @@ conformant provider for something its author could not fix, and nothing could be
275276
[Requirement 2.2.4](https://github.com/open-feature/spec/blob/main/specification/sections/02-providers.md)
276277
is a **SHOULD** and `types.md` types the field `variant (string, optional)`, so the suite was
277278
asserting a `MUST` neither of them states. Since spec revision `26362f85` the variant assertions
278-
live in one gated Scenario Outline of eight rows; the value and reason assertions stay untagged,
279-
because 2.2.3 makes the value a `MUST`.
279+
live in one gated Scenario Outline of eight rows; the value assertions stay untagged, because 2.2.3
280+
makes the value a `MUST`.
280281

281282
`@targeting` was **reserved and undeclarable** until the same revision, on the reading that targeting
282283
is backend evaluation logic and out of scope. The scope argument still holds — its three scenarios do
@@ -320,8 +321,38 @@ four `disabled-*` flags mirroring `boolean-flag`, `string-flag`, `integer-flag`
320321
exactly, differing only in `state`, and one Scenario Outline of four rows asserts that each resolves
321322
to the caller's default. Each row's default differs from the flag's configured value, so a provider
322323
that ignores the state is caught on the value alone — 2.2.3, a `MUST`. The rows assert neither the
323-
reason, which would rest on 2.2.5's `SHOULD` and its "some other string", nor the variant, since a
324-
disabled flag has resolved none: `@disabled-flags` and `@variants` deliberately do not compose.
324+
reason, which would rest on 2.2.5's `SHOULD` and its "some other string" — it is pinned in
325+
`gherkin/reason.feature` instead, for a provider that opts into the standard meanings — nor the
326+
variant, since a disabled flag has resolved none: `@disabled-flags` and `@variants` deliberately do
327+
not compose.
328+
329+
`@standard-reasons` is **a claim, not an exemption**, and it is the one capability whose tag is
330+
carried at the *feature* level. 2.2.5 is a `SHOULD` that goes further than 2.2.4 does: it lets a
331+
provider populate `reason` with one of the listed values *"or some other string indicating the
332+
semantic reason for the returned flag value"*. A provider whose backend reports vendor-specific
333+
reasons is therefore conformant, and asserting an exact reason against it would fail it for something
334+
the specification permits. The suite did exactly that until spec revision `c342461a`, in thirteen
335+
places across `evaluation.feature`, `errors.feature` and `lifecycle.feature`, and it bought very
336+
little: every canonical flag resolves to a value distinct from the caller's default, so a provider
337+
that silently falls back is already caught by the value.
338+
339+
So the reasons live in `gherkin/reason.feature`, gated as a whole. Declaring the capability is a
340+
provider saying *"I use the standard vocabulary with the standard meanings"*, and that file is what
341+
checks the claim — `STATIC` for a rule-less flag, `TARGETING_MATCH` for a matched rule, `DEFAULT` for
342+
an unmatched one, `DISABLED` for a disabled flag, `ERROR` beside an error code. A provider that does
343+
not declare it **loses nothing**: its values, variants and error codes are asserted everywhere else,
344+
on `MUST` requirements. What the declaration adds is something a report's reader can act on — anyone
345+
building telemetry, dashboards or debugging on `reason` can see that the vocabulary was verified
346+
rather than assumed. `STATIC` for the rule-less rows is the call worth flagging: `types.md` types
347+
`DEFAULT` as *"no dynamic evaluation occurred **or** dynamic evaluation yielded no result"*, so a
348+
provider answering `DEFAULT` there is not defective — it does not use the standard meanings, and
349+
should not declare the tag.
350+
351+
**Tags compose, and here that is load-bearing.** `TARGETING_MATCH` cannot be observed without
352+
targeting and `DISABLED` cannot be observed unless the backend distinguishes a disabled flag, so two
353+
of the file's scenarios also carry `@targeting` and one also carries `@disabled-flags`. Declaring
354+
`@standard-reasons` alone runs the four `STATIC` rows and the two error scenarios, and skips the
355+
other three with their reason.
325356

326357
Untagged scenarios are mandatory and always run. `capabilities` defaults to every *declarable*
327358
capability — `DECLARABLE_CAPABILITIES` — and you should narrow it rather than widen it: start from
@@ -698,7 +729,7 @@ This mirrors what `openfeature-flagd-api-testkit` already does for the flagd tes
698729
| `test_http_control` | `HttpControl` | the `/reset` fallback, the disconnect bookkeeping, the control API it reports and the absence of a `/restart` binding, against a stubbed control API |
699730

700731
```
701-
196 passed, 35 skipped, 2 xfailed
732+
208 passed, 41 skipped, 2 xfailed
702733
```
703734

704735
No Docker and no network beyond loopback. The conformance suites take under a second;
@@ -716,6 +747,14 @@ are skipped as well. Neither declares `@disabled-flags` either, for the reason i
716747
state reaches the flag set and the SDK's provider never reads it — so its four rows are skipped in
717748
both. Both declare `@variants`, since an in-memory flag set is keyed by variant name.
718749

750+
Both declare `@standard-reasons`, and it was measured before it was declared: `InMemoryFlag.resolve`
751+
reports `Reason.STATIC` for every flag in the decoded set, and a missing flag and a type mismatch
752+
both arrive with reason `ERROR` beside their error code, so the four rule-less rows and the two error
753+
scenarios pass in each suite. The remaining three scenarios in `reason.feature` compose the tag with
754+
`@targeting` and `@disabled-flags`, neither of which is declared, so they are skipped in both — which
755+
is the composition working rather than a gap, since a reason cannot be observed without the behaviour
756+
that produces it.
757+
719758
## Known gaps
720759

721760
- **Evaluation context passthrough is verified only for the targeting key.** `targeting-key-flag`

‎tools/openfeature-tck/src/openfeature/contrib/tools/tck/capability.py‎

Lines changed: 98 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ class Capability(str, Enum):
8080
8181
Declaring it runs one Scenario Outline that asserts the variant for each of
8282
the eight flags whose variant name the canonical set fixes. Withholding it
83-
skips those rows with the reason and changes nothing else: the value and
84-
reason assertions live in untagged scenarios, because
83+
skips those rows with the reason and changes nothing else: the value
84+
assertions live in untagged scenarios, because
8585
`Requirement 2.2.3
8686
<https://github.com/open-feature/spec/blob/main/specification/sections/02-providers.md>`_
8787
makes the value a **MUST**.
@@ -143,8 +143,11 @@ class Capability(str, Enum):
143143
alone, which rests on 2.2.3, a **MUST**.
144144
145145
The rows assert the value and the absence of an error, and deliberately
146-
**not** the reason: pinning ``DISABLED`` would rest on 2.2.5, a **SHOULD**
147-
that permits "some other string". No variant is asserted either, because a
146+
**not** the reason: pinning ``DISABLED`` here would rest on 2.2.5, a
147+
**SHOULD** that permits "some other string". It is pinned in
148+
``reason.feature`` instead, which composes this tag with
149+
:attr:`STANDARD_REASONS` so that both must be declared before the reason is
150+
asserted. No variant is asserted either, because a
148151
disabled flag has resolved no variant and there is none to name -- so this
149152
capability and :attr:`VARIANTS` do not compose, which is why the rows are not
150153
part of the variant outline.
@@ -280,13 +283,104 @@ class Capability(str, Enum):
280283
returned the targeted value would pass the first, and one that refuses to
281284
evaluate a rule with no targeting key present is caught by the third.
282285
286+
Two more scenarios carry this tag alongside :attr:`STANDARD_REASONS`, in
287+
``reason.feature``, asserting ``TARGETING_MATCH`` for the hit and
288+
``DEFAULT`` for the miss. They need both: a provider with no targeting has
289+
no rule to match, so there is no ``TARGETING_MATCH`` for it to report and
290+
the scenario would fail it for an absence rather than a defect. Declaring
291+
this capability alone leaves them skipped, and changes nothing about the
292+
three above.
293+
283294
Declare it if the backend under test can express that rule and the provider
284295
forwards the targeting key. A backend with no targeting at all leaves it
285296
undeclared and the three scenarios are skipped with the reason -- which is
286297
also the right answer for an in-memory flag set whose decoder ignores the
287298
``targeting`` member, as this package's own does.
288299
"""
289300

301+
STANDARD_REASONS = "standard-reasons"
302+
"""Provider reports the standard resolution reasons, with the standard meanings.
303+
304+
**A claim, not an exemption.** `Requirement 2.2.5
305+
<https://github.com/open-feature/spec/blob/main/specification/sections/02-providers.md>`_
306+
is a **SHOULD**, and it goes further than 2.2.4 does: it lets a provider
307+
populate ``reason`` with one of the listed values *"or some other string
308+
indicating the semantic reason for the returned flag value"*. A provider
309+
whose backend reports vendor-specific reasons is therefore conformant, and
310+
asserting an exact reason against it would fail it for something the
311+
specification permits.
312+
313+
An earlier revision of the suite did exactly that, in thirteen places across
314+
``evaluation.feature``, ``errors.feature`` and ``lifecycle.feature``, and
315+
Appendix F recorded the narrowing as a deliberate exception. It is not one
316+
any more. It bought very little -- every canonical flag resolves to a value
317+
distinct from the caller's default, so a provider that silently falls back
318+
is already caught by the value assertion, and the reason only said *why* it
319+
failed -- and of the thirteen, five sat beside an error-code assertion that
320+
already carries the **MUST**, while the other eight asserted ``STATIC``, the
321+
one reason the specification genuinely leaves open.
322+
323+
So the reasons now live in ``reason.feature``, gated as a whole at the
324+
feature level. Declaring this capability is a provider saying "I use the
325+
standard vocabulary with the standard meanings", and that file is what
326+
checks the claim. A provider that does not declare it **loses nothing**: its
327+
values, variants and error codes are asserted everywhere else, on **MUST**
328+
requirements. What the declaration adds is something a report's reader can
329+
act on -- anyone building telemetry, dashboards or debugging on ``reason``
330+
can see that the vocabulary was verified rather than assumed.
331+
332+
The meanings are the content of the claim, and they constrain nobody who
333+
does not make it:
334+
335+
* ``STATIC`` -- the flag was resolved from configuration and carries no
336+
targeting rule;
337+
* ``TARGETING_MATCH`` -- a targeting rule matched the evaluation context;
338+
* ``DEFAULT`` -- a targeting rule exists and did not match;
339+
* ``DISABLED`` -- the flag is disabled in the management system;
340+
* ``ERROR`` -- the evaluation failed, and an error code is reported with it.
341+
342+
``STATIC`` for the first row is the call worth flagging. ``types.md`` types
343+
``DEFAULT`` as *"no dynamic evaluation occurred **or** dynamic evaluation
344+
yielded no result"*, which a rule-less flag satisfies as readily as
345+
``STATIC`` does -- two providers can disagree here and both conform. A
346+
provider that answers ``DEFAULT`` for a rule-less flag is not defective; it
347+
does not use the standard meanings, and should not declare the tag.
348+
349+
``ERROR`` is the row where the suite's subject is blurred, and it is
350+
asserted anyway. The other four rest on `Requirement 1.4.7
351+
<https://github.com/open-feature/spec/blob/main/specification/sections/01-flag-evaluation.md>`_,
352+
which makes the SDK propagate the provider's reason -- but only *"in cases of
353+
normal execution"*. Abnormal execution is 1.4.9, a **SHOULD** on the *SDK* to
354+
"indicate an error", and nothing requires the provider's reason to survive.
355+
So a passing ``ERROR`` scenario establishes that what reached the
356+
application is coherent, not that the provider produced it. It is still
357+
worth asserting, because the pair is what carries the meaning: the error
358+
code alone is already covered for every provider by ``errors.feature``,
359+
ungated and on a **MUST**, and the reason alone could have been written by
360+
the SDK. An evaluation reporting ``FLAG_NOT_FOUND`` with reason ``STATIC``
361+
is incoherent whoever wrote it.
362+
363+
``SPLIT``, ``UNKNOWN``, ``CACHED`` and ``STALE`` are not asserted. The first
364+
two have no scenario that produces them; ``CACHED`` needs a repeat
365+
evaluation, which nothing here performs without a configuration change in
366+
between, and belongs behind the reserved :attr:`CACHING`; ``STALE`` needs a
367+
scenario asserting what a provider serves *during* an outage, which is the
368+
same gap.
369+
370+
**Tags compose, and here that is load-bearing.** ``TARGETING_MATCH`` cannot
371+
be observed without targeting and ``DISABLED`` cannot be observed unless the
372+
backend distinguishes a disabled flag, so those scenarios carry
373+
:attr:`TARGETING` and :attr:`DISABLED_FLAGS` as well. A provider declaring
374+
this capability alone runs the four ``STATIC`` rows and the two error
375+
scenarios, and skips the other three with their reason.
376+
377+
This is also the first capability whose tag is carried at the **feature**
378+
level rather than on each scenario. pytest-bdd marks a scenario from
379+
``scenario.tags | feature.tags | rule.tags``, so the gate -- which reads
380+
markers -- sees it on every scenario in the file, and ``Scenario.tags``
381+
alone would not have.
382+
"""
383+
290384
CACHING = "caching"
291385
"""Reserved, and **not declarable**. No scenario carries this tag yet."""
292386

‎tools/openfeature-tck/tests/test_controllable_conformance.py‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ class inherits it rather than choosing it: ``ControllableInMemoryProvider``
5454
changes only how the flag set is *replaced*, and resolution -- including the
5555
fact that ``InMemoryFlag.resolve`` never reads ``state`` -- is still the
5656
SDK's. Measured the same way, with the same four failures.
57+
58+
``STANDARD_REASONS`` is declared, for the reason given there and on the same
59+
measurement: resolution is the SDK's, so the four ``STATIC`` rows and the two
60+
error scenarios pass here identically. The three that compose the tag with
61+
``TARGETING`` or ``DISABLED_FLAGS`` skip, since neither is declared.
5762
"""
5863
control = InProcessControl()
5964
return TckConfig(
@@ -66,6 +71,7 @@ class inherits it rather than choosing it: ``ControllableInMemoryProvider``
6671
Capability.OBJECT,
6772
Capability.VARIANTS,
6873
Capability.LARGE_INTEGERS,
74+
Capability.STANDARD_REASONS,
6975
},
7076
)
7177

‎tools/openfeature-tck/tests/test_in_memory_conformance.py‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,16 @@ def tck_config() -> TckConfig:
136136
in this provider routes a value through a float. ``VARIANTS`` is declared
137137
too: the in-memory flag set is keyed by variant name, so the provider has
138138
one to report for every flag and does.
139+
140+
``STANDARD_REASONS`` is declared, and it was measured before it was: the six
141+
scenarios this provider can reach all pass. ``InMemoryFlag.resolve`` reports
142+
``Reason.STATIC`` for every flag in the decoded set, so the four rule-less
143+
rows hold; a missing flag and a type mismatch both arrive with reason
144+
``ERROR`` beside their error code. The other three scenarios in
145+
``reason.feature`` compose the tag with ``TARGETING`` and ``DISABLED_FLAGS``,
146+
neither of which is declared here, so they skip with that reason -- which is
147+
the capability working as intended rather than a gap: a reason cannot be
148+
observed without the behaviour that produces it.
139149
"""
140150
return TckConfig(
141151
name="in-memory",
@@ -146,6 +156,7 @@ def tck_config() -> TckConfig:
146156
Capability.OBJECT,
147157
Capability.VARIANTS,
148158
Capability.LARGE_INTEGERS,
159+
Capability.STANDARD_REASONS,
149160
},
150161
)
151162

0 commit comments

Comments
 (0)