Skip to content

Commit 38909b1

Browse files
committed
feat(tck): check every scenario the run collects for a reserved tag
The check landed canonical-only, on the reasoning that only the specification can expire a reservation -- an adopter's own feature reaching for a reserved tag is a mistake in that file rather than news about the specification. That reasoning is sound and it answers the wrong question. A reserved capability cannot be declared, because TckConfig refuses it, so the capability gate skips every scenario carrying its tag whichever file the tag is in. An extension scenario tagged @caching is therefore unclaimable from the day it is written: it can never run, it can never be claimed, and the report shows a gap the provider may not have. That is the unclaimable-capability failure Appendix F describes, and it is the failure this check exists to surface. It arrives from the adopter's side instead of from upstream and the consequence is identical, so one check covers both causes as long as the message names both remedies -- drop the tag from RESERVED_CAPABILITIES because the specification has given it scenarios, or rename a tag of your own that reached for a reserved name. Go and Java check every scenario the run collected. This is Python coming into line rather than a local judgement: the divergence was put up for a ruling and the broader rule is what it settled on. Two things stay as they were and both are Python's alone. The canonical half is still read off the packaged feature files rather than off the collected items, because an adopter's selection must not be able to narrow a run past the specification's half; an extension has no equivalent source, since its directory is found from the adopter's own test module, so that half comes from the collection as it does in every other language. And the check still waits for a canonical scenario to be collected before it looks at anything: this package is a pytest11 plugin, so the hook fires for every pytest run in an environment that merely has it installed, and an unrelated test suite has no business failing over the contents of these feature files. Tags are read only from scenarios the uri derivation in extensions claims, so a pytest-bdd suite of the adopter's own sharing the session is left alone too. The tags are the markers pytest-bdd derives from the parsed Gherkin, which is what the capability gate itself reads, so the check and the gate cannot disagree about which scenarios are unclaimable -- and a tag inherited from the feature or the rule is included, where Scenario.tags would miss it. Still never the file text: gherkin/events.feature names @caching inside a Gherkin comment, and a text scan would fail every adoption over a sentence. Verified against a real collection rather than only the stubbed items. An adopter suite whose extensions/vendor.feature carries @caching aborts at collection with exit 4 and that message; renaming the tag collects the same 58 scenarios clean; moving @caching into a Gherkin comment collects clean. Narrowing the check back to the canonical set fails exactly one test, the one that covers the widening. Signed-off-by: Simon Schrottner <simon.schrottner@flagsmith.com>
1 parent 6d5eaa1 commit 38909b1

5 files changed

Lines changed: 226 additions & 78 deletions

File tree

‎tools/openfeature-tck/README.md‎

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -347,17 +347,25 @@ reason, back when both were reserved.
347347
mirror of the mistake the set exists to prevent — a capability that can be verified, refused the
348348
chance — so `@targeting` moved out of it the moment the specification gave it three.
349349

350-
**A reservation this package has outgrown fails the run.** The reservation expires in the
351-
specification repository and `RESERVED_CAPABILITIES` lives here, so on every run the plugin reads the
352-
tags the packaged feature files actually carry and refuses to continue if one of them is still listed
353-
as reserved. Without that, re-pinning the assets onto a revision that gave `@caching` scenarios would
354-
skip them — for a capability `TckConfig` refuses to let anyone declare — and the only visible trace
355-
would be a few more skips. Appendix F calls that the unclaimable capability. The fix when it fires is
356-
to take the tag out of `RESERVED_CAPABILITIES` and decide, per adoption, whether to declare it.
357-
358-
Only the canonical set can expire a reservation. A feature file of your own reaching for a reserved
359-
tag is a mistake in that file, not news about the specification, so the check reads the packaged
360-
assets — which also means a `-k` or `--deselect` cannot narrow the run past it.
350+
**A scenario carrying a reserved tag fails the run.** `TckConfig` refuses to let anyone declare a
351+
reserved capability, so the gate skips every scenario carrying one — for a capability nobody is
352+
permitted to claim, which leaves a gap in the report that the provider may not have. Appendix F calls
353+
that the unclaimable capability, and nothing else notices it: the run is green and the report is
354+
well-formed. So the plugin refuses to continue, naming the tags.
355+
356+
Two mistakes end there and the message names both remedies. Either the tag arrived with the canonical
357+
feature files, because the specification wrote the scenarios the reservation was held open for and
358+
this package has not followed — take the tag out of `RESERVED_CAPABILITIES` and decide, per adoption,
359+
whether to declare it. Or it arrived from a feature file of your own under `extensions/`, in which
360+
case pick a tag of your own: a reserved tag gates nothing and can never be declared, so a scenario
361+
carrying one can never run.
362+
363+
The two halves are read differently, and that is deliberate. The canonical tags come from the
364+
packaged files rather than from the collected run, so a `-k` or `--deselect` cannot narrow a run past
365+
the specification's half; your extensions have no such source — the directory is found from your test
366+
module — so those tags come from what was collected. Both are the parsed Gherkin tags, never the file
367+
text: `gherkin/events.feature` names `@caching` in a `#` comment saying where those scenarios will go
368+
once they exist, and a text scan would fail every adoption over a sentence.
361369

362370
`@numeric-coercion` deserves a note, because it is the one capability here that **the specification
363371
does not define**. OpenFeature has a single numeric type on purpose — `number` is "a numeric value of
@@ -690,7 +698,7 @@ This mirrors what `openfeature-flagd-api-testkit` already does for the flagd tes
690698
| `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 |
691699

692700
```
693-
194 passed, 35 skipped, 2 xfailed
701+
196 passed, 35 skipped, 2 xfailed
694702
```
695703

696704
No Docker and no network beyond loopback. The conformance suites take under a second;

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

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -369,22 +369,25 @@ def capability_for_tag(tag: str) -> Capability | None:
369369
def expired_reservations(tags: typing.Iterable[str]) -> tuple[Capability, ...]:
370370
"""Reserved capabilities that the tags handed in turn out to carry.
371371
372-
A non-empty answer means :data:`RESERVED_CAPABILITIES` is out of date: the
373-
scenarios the tag was being held open for now exist, so the capability can
374-
be verified and an adoption should be allowed -- and required -- to say
375-
whether it has it.
376-
377-
Leaving the reservation in place instead is the mirror of declaring an
378-
unverified capability, and it is the quieter mistake of the two. Declaring
379-
a reserved capability is refused, so nobody can claim it; the new scenarios
380-
are therefore skipped for a capability an adopter has no way to declare,
381-
and the report says a gap exists where the provider may well have none.
382-
Appendix F names that the unclaimable capability.
383-
384-
Read off the feature files rather than compared against a second list,
385-
because a reservation expires in the specification repository while this
386-
set lives here. Deduplicated and ordered by tag: the tags arrive from every
387-
scenario of every feature file, and one carried twice is not two expiries.
372+
A non-empty answer means some scenario is both unrunnable and unclaimable.
373+
Declaring a reserved capability is refused, so the capability gate skips
374+
every scenario carrying its tag, and the report says a gap exists where the
375+
provider may well have none. Appendix F names that the unclaimable
376+
capability, and it is the quieter mirror of declaring a capability nothing
377+
verifies: nobody can claim the tag, so nothing else about the run changes.
378+
379+
Two things put a reserved tag on a scenario and this reports only that one
380+
of them happened. Either :data:`RESERVED_CAPABILITIES` is out of date --
381+
the scenarios the tag was held open for now exist, so the capability can be
382+
verified and an adoption should be allowed, and required, to say whether it
383+
has it -- or an adopter has used a reserved name for a tag of their own.
384+
Telling the two apart is the caller's, because the caller is what knows
385+
where the tags came from: the remedies differ and the consequence does not.
386+
387+
Compared against tags rather than against a second list, because a
388+
reservation expires in the specification repository while this set lives
389+
here. Deduplicated and ordered by tag: the tags arrive from every scenario
390+
of every feature file, and one carried twice is not two expiries.
388391
"""
389392
carried = set(tags)
390393
expired = (c for c in RESERVED_CAPABILITIES if c.tag in carried)

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,9 +193,14 @@ def canonical_root() -> Path | None:
193193
def canonical_tags() -> frozenset[str]:
194194
"""Every Gherkin tag the packaged canonical feature files carry.
195195
196-
What a reservation is checked against: a tag is reserved because no
197-
canonical scenario carries it, and this is the set that says whether that
198-
is still true. See :func:`~.capability.expired_reservations`.
196+
The specification's half of what a reservation is checked against: a tag is
197+
reserved because no canonical scenario carries it, and this is the set that
198+
says whether that is still true. Read off the packaged files rather than
199+
off a collected run, so a ``-k`` or a ``--deselect`` cannot narrow a run
200+
past it. An adopter's own features have no equivalent source -- the
201+
directory is found from their test module -- so the other half of the check
202+
reads them from what was collected. See
203+
:func:`~.capability.expired_reservations`.
199204
200205
**Tag lines only**, which is what tells a tag apart from the same word
201206
written in prose. ``events.feature`` mentions ``@caching`` in a comment,

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

Lines changed: 89 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
1414
It is also where the two things a run must refuse to do quietly are checked:
1515
skipping a scenario whose capability was not declared happens loudly, with the
16-
reason, and a reservation the canonical assets have outgrown fails the run
17-
outright rather than skipping scenarios for a capability nobody may claim.
16+
reason, and a scenario carrying a tag this package still calls reserved fails
17+
the run outright rather than being skipped for a capability nobody may claim.
1818
"""
1919

2020
from __future__ import annotations
@@ -29,7 +29,7 @@
2929
from .capability import Capability, capability_for_marker, expired_reservations
3030
from .compose import ComposeBackend, RunningBackend, run_compose_backend
3131
from .config import TckConfig
32-
from .extensions import canonical_tags, is_canonical
32+
from .extensions import canonical_tags, is_canonical, uri_for
3333
from .state import TckState
3434

3535
# The step modules are registered as plugins in their own right, not merely
@@ -60,60 +60,110 @@ def pytest_configure(config: pytest.Config) -> None:
6060

6161

6262
def pytest_collection_modifyitems(items: list[pytest.Item]) -> None:
63-
"""Fail the run if a canonical feature carries a tag still called reserved.
63+
"""Fail the run if any scenario it collected carries a reserved tag.
6464
6565
A reservation is a name held open for scenarios that do not exist yet, and
66-
it is only ever temporary: the specification writes them, the tag starts
67-
gating something, and the capability becomes declarable. Until this package
68-
follows, declaring it is refused -- so those scenarios are skipped for a
69-
capability an adopter cannot claim, and the report shows a gap the provider
70-
may not have. Appendix F calls that the unclaimable capability, and it has
71-
no local symptom at all, which is why it is checked rather than watched
72-
for: ``@targeting`` was reserved until spec revision ``26362f85`` gave it
73-
three scenarios.
74-
75-
Refused rather than worked around. Dropping the reservation here instead
76-
would let a run declare a capability against a package that does not know
77-
the tag exists, and the point of the check is that a human re-reads
78-
:data:`~.capability.RESERVED_CAPABILITIES` against the specification.
79-
80-
Only the canonical set can expire a reservation. An adopter's own feature
81-
reaching for a reserved tag is a mistake in that file rather than news
82-
about the specification, so the tags come from the packaged assets and not
83-
from what was collected -- which also means a narrowed run cannot select
84-
its way past the check. What *is* read off the collection is whether this
85-
session runs the conformance suite at all: the plugin is installed for
86-
every pytest run in the environment, and an unrelated test suite has no
87-
business failing over the contents of these feature files.
66+
a reserved capability cannot be declared -- :class:`~.config.TckConfig`
67+
refuses it. So a scenario carrying one reaches the capability gate below
68+
and is skipped, for a capability nobody is permitted to claim: a question
69+
put and silently withdrawn. Appendix F calls that the unclaimable
70+
capability. The run stays green, the report stays well-formed, and nothing
71+
else here notices, which is why it is checked rather than watched for.
72+
73+
Two different mistakes end there. The check does not tell them apart,
74+
because the consequence is identical and the message names both remedies:
75+
76+
* the specification wrote the scenarios the tag was held open for and
77+
:data:`~.capability.RESERVED_CAPABILITIES` has not followed --
78+
``@targeting`` was reserved until spec revision ``26362f85`` gave it
79+
three scenarios;
80+
* an extension of the adopter's own used a reserved name for a tag of its
81+
own, which is unclaimable from the day the file is written.
82+
83+
This once fired for the canonical set alone, on the reasoning that only the
84+
specification can expire a reservation. That much is true and it is beside
85+
the point: an extension scenario carrying a reserved tag can never run and
86+
can never be claimed either, which is exactly the failure being surfaced.
87+
It arrives from the adopter rather than from upstream; the consequence does
88+
not care. Go and Java check every scenario the run collected, and so does
89+
this.
90+
91+
Refused rather than worked around. Treating the tag as declarable here
92+
would let a run claim a capability against a package that does not know the
93+
tag exists, and the point of the check is that a human re-reads that set
94+
against the specification -- or renames their own tag.
95+
96+
**The two halves have different sources, and only one of them is
97+
collected.** The canonical tags are read off the packaged files rather than
98+
off the items, so a ``-k`` or a ``--deselect`` cannot narrow a run past the
99+
specification's half. An extension's tags have no such source -- the
100+
directory is found from the adopter's own test module, at the moment
101+
:func:`~.extensions.feature_paths` is called -- so they come from what was
102+
collected, as they do in every other language. In practice this hook is
103+
handed the whole collection before anything is deselected, so a selection
104+
does not narrow that half either; that is pytest's hook order rather than a
105+
promise, and the half that must not be narrowable does not lean on it.
106+
107+
What is read off the collection either way is whether this session runs the
108+
conformance suite at all. This package is a ``pytest11`` plugin, so the
109+
hook fires for every pytest run in an environment that merely has it
110+
installed, and an unrelated test suite has no business failing over the
111+
contents of these feature files. So the check waits for a canonical
112+
scenario, which nothing but :func:`~.extensions.feature_paths` produces,
113+
and it reads tags only from scenarios this suite is running. Go, Java and
114+
JS have an explicit entry point and no equivalent problem.
88115
"""
89-
if not any(_is_canonical_scenario(item) for item in items):
116+
running = False
117+
carried: set[str] = set()
118+
for item in items:
119+
feature = _suite_feature(item)
120+
if feature is None:
121+
continue
122+
running = running or is_canonical(feature)
123+
carried.update(f"@{marker.name}" for marker in item.iter_markers())
124+
125+
if not running:
90126
return
91127

92-
expired = expired_reservations(canonical_tags())
128+
expired = expired_reservations(carried | canonical_tags())
93129
if not expired:
94130
return
95131

96132
named = " ".join(capability.tag for capability in expired)
97133
raise pytest.UsageError(
98-
f"reserved capabilities {named} are carried by the canonical feature "
99-
f"files, so the scenarios they were held open for now exist. Remove "
100-
f"them from RESERVED_CAPABILITIES, so an adoption can declare them and "
101-
f"be held to them -- until then those scenarios are skipped for a "
102-
f"capability nobody is allowed to claim."
134+
f"reserved capabilities {named} are carried by scenarios this run "
135+
f"collected, and a reserved capability cannot be declared -- so every "
136+
f"scenario carrying one is skipped for a capability nobody is allowed "
137+
f"to claim, and the report shows a gap the provider may not have. "
138+
f"Either they came with the canonical feature files, and the scenarios "
139+
f"they were held open for now exist: remove them from "
140+
f"RESERVED_CAPABILITIES, so an adoption can declare them and be held "
141+
f"to them. Or they came from a feature file of your own under "
142+
f"extensions/, in which case pick tags of your own: a reserved tag "
143+
f"gates nothing and can never be declared."
103144
)
104145

105146

106-
def _is_canonical_scenario(item: pytest.Item) -> bool:
107-
"""Whether a collected node is a scenario from the packaged feature files.
147+
def _suite_feature(item: pytest.Item) -> Path | None:
148+
"""The feature file behind a collected node, when this suite is what runs it.
108149
109150
``__scenario__`` is what pytest-bdd hangs on the function it generates, and
110-
it is readable at collection without running a fixture. The feature file is
111-
then matched by path rather than by the uri it reports, so the check does
112-
not rest on the derivation in :mod:`~.extensions`.
151+
it is readable at collection without running a fixture. ``None`` for a node
152+
that is not a scenario at all, and for a pytest-bdd scenario belonging to
153+
some other suite that happens to share the session -- neither is this
154+
suite's to fail.
155+
156+
Which scenarios are this suite's is decided by
157+
:func:`~.extensions.uri_for`, the same derivation a report identifies a
158+
scenario by, so what is checked and what is recorded cannot disagree about
159+
what the run consisted of.
113160
"""
114161
scenario = getattr(getattr(item, "function", None), "__scenario__", None)
115162
filename = getattr(getattr(scenario, "feature", None), "filename", None)
116-
return bool(filename) and is_canonical(Path(str(filename)))
163+
if not filename:
164+
return None
165+
feature = Path(str(filename))
166+
return feature if uri_for(feature) is not None else None
117167

118168

119169
@pytest.fixture(scope="session")

0 commit comments

Comments
 (0)