Skip to content

Commit ebd416c

Browse files
committed
feat(provider-tck): report an extension under its own uri prefix
The suite can already run an adopter's own scenarios, and already derives the uri each feature file is identified by from where the file is -- `features/` for the packaged assets, `extensions/` for anything under a `tck-extensions` directory. Nothing read that derivation, because the thing it exists for is a report, and the report is here. So the emitter uses it, falling back to what pytest-bdd called a file when the file is neither. pytest-bdd names a feature by its parent directory joined to its own name, which two files can share: an extension at `tck-extensions/features/errors.feature` arrives under exactly the uri the canonical `errors.feature` occupies, and a Messages stream carries one Source per uri -- the canonical source is parsed first, the extension's is never read, and its scenarios are reported against the canonical file's pickles or against none at all. Deriving the uri closes the route an adopter is actually likely to take. It does not close the other two, and those are now refused rather than documented: a feature file of the adopter's own that would reach the reserved `features/` prefix, and two files that would share one uri. Both fail the run and write no report. A document presenting an adopter's feature file as the specification's -- or one file's scenarios against another's source -- is worse than no document, because it is the one thing a consumer cannot check from the outside. Java measured the loud form: a same-named feature file in a second classpath root replaced the canonical one outright and the run went green having asked the adopter's questions. `test_extension_reporting` checks the half of the extension point a consumer reads, and leaves the half that is about running scenarios where it already is: `test_extensions` asks whether an extension runs inside the canonical suite, and answers it out of pytest's own JUnit XML, with no report in sight. Signed-off-by: Simon Schrottner <simon.schrottner@flagsmith.com>
1 parent 795a58a commit ebd416c

3 files changed

Lines changed: 678 additions & 6 deletions

File tree

‎tools/openfeature-provider-tck/README.md‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,12 +124,16 @@ prefix Go and JavaScript mount theirs under too, so a consumer holding conforman
124124
several languages applies one rule. Neither prefix is this package's to choose: Appendix F
125125
identifies a canonical feature by its path *relative to the specification's asset directory*, which
126126
is what makes it `gherkin/`. The prefix is derived from where a file *is*, not from what the runner
127-
called it, and `extensions.py` reports two cases that derivation cannot rule out:
127+
called it, and two cases the derivation cannot rule out are refused outright rather than
128+
documented — **no report is written and the run fails**:
128129

129130
- **A feature file of yours under the reserved `gherkin/` prefix.** Handing `scenarios()` a
130131
directory of your own named `gherkin` is the one route left to a canonical-looking uri.
131-
- **Two feature files that would share one uri.** A record of what ran holds one copy of a feature
132-
file per uri, so the second file's scenarios would be attributed to the first file's.
132+
- **Two feature files that would share one uri.** A Cucumber Messages stream carries one source per
133+
uri, so the second file's scenarios would be reported against the first file's source.
134+
135+
A document presenting your feature file as the specification's is worse than no document, because it
136+
is the one thing a consumer cannot check.
133137

134138
This is not hypothetical. Java's suite found that a same-named feature file in a second classpath
135139
root *replaced* the canonical one, and the run went green having asked the adopter's questions
@@ -510,8 +514,10 @@ the field.
510514
| `test_extensions` | an adopter's own scenarios | an extension runs inside the canonical suite, changes nothing for an adopter who has none, and cannot take a canonical scenario's identity |
511515
| `test_http_control` | `HttpControl` | the `/reset` fallback, the disconnect bookkeeping and the control-API it reports, against a stubbed control API |
512516
| `test_report` | the conformance report | checks the two properties a consumer is entitled to assume, against the emitted Messages stream |
517+
| `test_extension_reporting` | an extension in a report | it is reported under its own prefix, it changes no other field, and the two uris the derivation cannot rule out produce no report at all |
513518

514519
```
520+
| `test_http_control` | `HttpControl` | the `/reset` fallback, the disconnect bookkeeping and the control-API it reports, against a stubbed control API |
515521
PLACEHOLDER passed, 21 skipped, 2 xfailed
516522
```
517523

‎tools/openfeature-provider-tck/src/openfeature/contrib/tools/provider_tck/emitter.py‎

Lines changed: 56 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@
3434
import pytest
3535

3636
from .config import TckConfig
37+
from .extensions import (
38+
collision_problem,
39+
reserved_prefix_problem,
40+
uri_collisions,
41+
uri_for,
42+
)
3743
from .messages import (
3844
FeatureCatalog,
3945
ScenarioIdentity,
@@ -113,11 +119,18 @@ def scenario_identity(node: pytest.Item) -> ScenarioIdentity | None:
113119
tags |= _examples_tags(node, scenario)
114120

115121
filename = str(getattr(feature, "filename", ""))
116-
relative = str(getattr(feature, "rel_filename", "") or Path(filename).name)
122+
path = Path(filename)
123+
relative = str(getattr(feature, "rel_filename", "") or path.name)
117124

118125
return ScenarioIdentity(
119-
uri=feature_uri(relative),
120-
path=Path(filename),
126+
# Derived from where the file is, falling back to what pytest-bdd called
127+
# it. pytest-bdd names a feature by its parent directory joined to its
128+
# own name, which two files can share: an extension at
129+
# tck-extensions/features/errors.feature arrives under exactly the uri
130+
# the canonical errors.feature already occupies, and the payload carries
131+
# one source per uri.
132+
uri=uri_for(path) or feature_uri(relative),
133+
path=path,
121134
name=str(getattr(scenario, "name", "")),
122135
example=_example_of(node),
123136
tags=normalise_tags(tags),
@@ -317,6 +330,13 @@ def _write_suite(
317330
name = suite.config.name
318331
runs = suite.sorted_runs
319332

333+
if not self._identities_are_sound(session, suite):
334+
# Refusing to write is the point: a document that presents an
335+
# adopter's feature file as the specification's -- or reports one
336+
# file's scenarios against another's source -- is worse than no
337+
# document, because it is the one thing a consumer cannot check.
338+
return
339+
320340
catalog = FeatureCatalog()
321341
try:
322342
for run in runs:
@@ -375,6 +395,39 @@ def _write_suite(
375395
if gap:
376396
self._say(session, f"provider-tck [{name}]: {gap}")
377397

398+
def _identities_are_sound(
399+
self, session: pytest.Session, suite: SuiteReport
400+
) -> bool:
401+
"""Whether every feature file this suite ran is named in the payload as itself.
402+
403+
Two ways it might not be, and both are silent without this. A file that
404+
is not one of the packaged assets must not be reported under their uri
405+
prefix, or a consumer reading ``features/errors.feature`` in the stream
406+
has no way to tell that the specification did not write it. And two
407+
files must not share a uri, or the stream carries one source for both
408+
and the second file's scenarios are reported against the first's.
409+
"""
410+
name = suite.config.name
411+
runs = suite.sorted_runs
412+
413+
reserved = [
414+
problem
415+
for run in runs
416+
if (problem := reserved_prefix_problem(run.identity.uri, run.identity.path))
417+
]
418+
for problem in dict.fromkeys(reserved):
419+
self._fail(session, f"provider-tck [{name}]: {problem}")
420+
421+
collisions = uri_collisions(
422+
(run.identity.uri, run.identity.path) for run in runs
423+
)
424+
for uri, paths in sorted(collisions.items()):
425+
self._fail(
426+
session, f"provider-tck [{name}]: {collision_problem(uri, paths)}"
427+
)
428+
429+
return not reserved and not collisions
430+
378431
def _say(self, session: pytest.Session, message: str) -> None:
379432
reporter = session.config.pluginmanager.get_plugin("terminalreporter")
380433
if reporter is not None:

0 commit comments

Comments
 (0)