Skip to content

Commit 4ca22ec

Browse files
committed
fix(provider-tck): follow the canonical gherkin/ prefix through the report
The reporting half names the canonical prefix in its own right: the emitter refuses a payload whose uris are unsound, the canonical-set guard blames a missing scenario by uri, and the tests assert on both. Those assertions were written as the literal "features/", so the rename on the suite left them pinning a prefix nothing emits any more. The stale assertions fail loudly, which is the good case. The trap was the README, whose worked example of a refused partial run printed two canonical scenarios under features/ -- output no run can produce now, and the one place a reader would have taken the old form from. Test assertions move to CANONICAL_DIRECTORY rather than to a new literal, so a further change to the prefix cannot leave them half-renamed. The single literal pin lives on the suite branch beside the constant it pins, where the reason for it is legible. Two fixtures change shape rather than wording, and both still exercise what they did. The shadowing adoption copies a canonical feature file into extensions/gherkin/ so pytest-bdd names it gherkin/errors.feature -- the canonical uri -- and the derivation has to hold it apart; and the refused adoption hands scenarios() a directory of its own named gherkin, which is the one route left to a canonical-looking uri. Renaming those directories to follow the constant is what keeps them adversarial: pointed at the old name they would now be ordinary extensions, and both tests would pass having examined nothing. Signed-off-by: Simon Schrottner <simon.schrottner@flagsmith.com>
1 parent 4359829 commit 4ca22ec

6 files changed

Lines changed: 55 additions & 40 deletions

File tree

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -449,8 +449,8 @@ execute all of them writes no report:
449449
$ PROVIDER_TCK_REPORT_DIR=./reports pytest -k "unknown_flag_key"
450450
provider-tck [in-memory]: 39 of 40 canonical scenarios did not run, so this run cannot support a
451451
conformance claim and no report is written for it. …
452-
- features/errors.feature: A float flag is not silently narrowed to an integer
453-
- features/errors.feature: An integer requested as a float is widened without loss
452+
- gherkin/errors.feature: A float flag is not silently narrowed to an integer
453+
- gherkin/errors.feature: An integer requested as a float is widened without loss
454454
… and 37 more
455455
```
456456

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ def scenario_identity(node: pytest.Item) -> ScenarioIdentity | None:
141141
# Derived from where the file is, falling back to what pytest-bdd called
142142
# it. pytest-bdd names a feature by its parent directory joined to its
143143
# own name, which two files can share: an extension at
144-
# tck-extensions/features/errors.feature arrives under exactly the uri
144+
# extensions/gherkin/errors.feature arrives under exactly the uri
145145
# the canonical errors.feature already occupies, and the payload carries
146146
# one source per uri.
147147
uri=uri_for(path) or feature_uri(relative),
@@ -486,7 +486,7 @@ def _identities_are_sound(
486486
487487
Two ways it might not be, and both are silent without this. A file that
488488
is not one of the packaged assets must not be reported under their uri
489-
prefix, or a consumer reading ``features/errors.feature`` in the stream
489+
prefix, or a consumer reading ``gherkin/errors.feature`` in the stream
490490
has no way to tell that the specification did not write it. And two
491491
files must not share a uri, or the stream carries one source for both
492492
and the second file's scenarios are reported against the first's.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ class ScenarioIdentity:
139139
"""
140140

141141
uri: str
142-
"""The feature file as Cucumber names it, e.g. ``features/errors.feature``.
142+
"""The feature file as Cucumber names it, e.g. ``gherkin/errors.feature``.
143143
144144
Slash-separated on every platform, and the same string in ``Source``,
145145
``GherkinDocument`` and ``Pickle``, which is what ties the three together.

‎tools/openfeature-provider-tck/tests/test_canonical_set.py‎

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,10 @@
4040
missing_canonical,
4141
partial_run_allowed,
4242
)
43-
from openfeature.contrib.tools.provider_tck.extensions import is_canonical_uri
43+
from openfeature.contrib.tools.provider_tck.extensions import (
44+
CANONICAL_DIRECTORY,
45+
is_canonical_uri,
46+
)
4447
from openfeature.contrib.tools.provider_tck.messages import (
4548
ScenarioIdentity,
4649
ScenarioRun,
@@ -162,9 +165,9 @@ def _run(
162165
(directory / "test_guarded.py").write_text(_SUITE_MODULE, encoding="utf-8")
163166
(directory / "conftest.py").write_text(_CONFTEST_MODULE, encoding="utf-8")
164167
if extension:
165-
features = directory / EXTENSIONS_DIRECTORY
166-
features.mkdir(parents=True, exist_ok=True)
167-
(features / "vendor.feature").write_text(_VENDOR_FEATURE, encoding="utf-8")
168+
extensions = directory / EXTENSIONS_DIRECTORY
169+
extensions.mkdir(parents=True, exist_ok=True)
170+
(extensions / "vendor.feature").write_text(_VENDOR_FEATURE, encoding="utf-8")
168171

169172
reports = tmp_path / "reports"
170173
environment = dict(os.environ)
@@ -274,7 +277,7 @@ def test_an_extension_cannot_close_a_gap(tmp_path: Path) -> None:
274277

275278
assert run.result.returncode != 0, run.stdout
276279
assert f"1 of {CANONICAL_COUNT} canonical scenarios did not run" in run.stdout
277-
assert f"features/errors.feature: {EXCLUDED_SCENARIO}" in run.stdout
280+
assert f"{CANONICAL_DIRECTORY}/errors.feature: {EXCLUDED_SCENARIO}" in run.stdout
278281
assert not run.envelopes
279282

280283

@@ -322,21 +325,21 @@ def test_an_extension_run_is_neither_counted_nor_blamed(tmp_path: Path) -> None:
322325
# separately -- cannot reduce the missing set.
323326
impostor = ScenarioRun(
324327
identity=_identity(
325-
"features/errors.feature",
328+
f"{CANONICAL_DIRECTORY}/errors.feature",
326329
EXCLUDED_SCENARIO,
327-
tmp_path / "features" / "errors.feature",
330+
tmp_path / CANONICAL_DIRECTORY / "errors.feature",
328331
)
329332
)
330333
assert set(missing_canonical([vendor, impostor])) == canonical_scenarios()
331334

332335

333336
def test_a_missing_scenario_is_described_by_its_row() -> None:
334-
assert describe(("features/x.feature", "A scenario", ())) == (
335-
"features/x.feature: A scenario"
336-
)
337-
assert describe(("features/x.feature", "An outline", (("key", "a"),))) == (
338-
"features/x.feature: An outline [key=a]"
337+
assert describe((f"{CANONICAL_DIRECTORY}/x.feature", "A scenario", ())) == (
338+
f"{CANONICAL_DIRECTORY}/x.feature: A scenario"
339339
)
340+
assert describe(
341+
(f"{CANONICAL_DIRECTORY}/x.feature", "An outline", (("key", "a"),))
342+
) == (f"{CANONICAL_DIRECTORY}/x.feature: An outline [key=a]")
340343

341344

342345
@pytest.mark.parametrize(

‎tools/openfeature-provider-tck/tests/test_extension_reporting.py‎

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
which is not presentational -- a report is written per ``TckConfig``, so
1010
appearing in one is appearing in the same provider registration;
1111
* it appears under the ``extensions/`` uri prefix and never the reserved
12-
``features/`` one, which is the only thing telling a consumer whose question a
12+
``gherkin/`` one, which is the only thing telling a consumer whose question a
1313
scenario was;
1414
* an adoption with no extension writes the report it wrote before, field for
1515
field;
@@ -47,7 +47,10 @@
4747
REPORT_DIR_ENV,
4848
features_path,
4949
)
50-
from openfeature.contrib.tools.provider_tck.extensions import is_canonical_uri
50+
from openfeature.contrib.tools.provider_tck.extensions import (
51+
CANONICAL_DIRECTORY,
52+
is_canonical_uri,
53+
)
5154

5255
CANONICAL_FEATURE = "errors.feature"
5356
"""The canonical file the shadowing fixture copies, chosen because it is the one
@@ -146,11 +149,11 @@ def pytest_collection_modifyitems(items):
146149
Then the resolved details value should be "hi"
147150
"""
148151

149-
# An adopter's own directory named `features`, which is the one way a
152+
# An adopter's own directory named `gherkin`, which is the one way a
150153
# non-canonical file can still reach the reserved prefix. Its scenario is
151154
# deliberately trivial: the point is the file name, not what it asks.
152155
_RESERVED_FEATURE = """\
153-
Feature: A feature file in a directory named features
156+
Feature: A feature file in a directory named gherkin
154157
155158
Scenario: A flag resolves
156159
Given a stable provider
@@ -160,7 +163,7 @@ def pytest_collection_modifyitems(items):
160163
"""
161164

162165
_RESERVED_SUITE = '''\
163-
"""An adoption that hands scenarios() a directory of its own named features."""
166+
"""An adoption that hands scenarios() a directory of its own named gherkin."""
164167
165168
import pathlib
166169
@@ -185,7 +188,7 @@ def tck_config():
185188
)
186189
187190
188-
scenarios(str(pathlib.Path(__file__).parent / "features"))
191+
scenarios(str(pathlib.Path(__file__).parent / "gherkin"))
189192
'''
190193

191194

@@ -363,7 +366,7 @@ def _run(
363366
364367
Both mappings are keyed by a path relative to the adoption directory, so a
365368
fixture can put a module or a feature file wherever the property under test
366-
needs it -- including inside a directory named ``features``, which is the
369+
needs it -- including inside a directory named ``gherkin``, which is the
367370
case that has to be refused.
368371
"""
369372
directory = tmp_path_factory.mktemp("adoption")
@@ -385,7 +388,7 @@ def adoption(tmp_path_factory: pytest.TempPathFactory) -> Run:
385388
``scenarios(*feature_paths())`` with an ordinary extension beside it.
386389
``shadowed`` is the same again, in a directory of its own, with an extension
387390
that is a verbatim copy of a canonical feature file placed under a directory
388-
named ``features`` -- so that both routes to a canonical identity, the file's
391+
named ``gherkin`` -- so that both routes to a canonical identity, the file's
389392
own name and its parent's, are taken at once.
390393
391394
One session rather than three, because a subprocess pytest run is by far the
@@ -403,7 +406,8 @@ def adoption(tmp_path_factory: pytest.TempPathFactory) -> Run:
403406
},
404407
{
405408
f"{EXTENSIONS_DIRECTORY}/vendor.feature": _VENDOR_FEATURE,
406-
f"shadow/{EXTENSIONS_DIRECTORY}/features/{CANONICAL_FEATURE}": canonical,
409+
f"shadow/{EXTENSIONS_DIRECTORY}/{CANONICAL_DIRECTORY}/"
410+
f"{CANONICAL_FEATURE}": canonical,
407411
},
408412
)
409413

@@ -443,7 +447,9 @@ def test_the_extension_feature_is_reported_under_its_own_prefix(
443447
report = adoption.report("after")
444448
assert [case.uri for case in report.extensions] == [VENDOR_URI]
445449
assert report.sources[VENDOR_URI] == _VENDOR_FEATURE
446-
assert all(case.uri.startswith("features/") for case in report.canonical)
450+
assert all(
451+
case.uri.startswith(f"{CANONICAL_DIRECTORY}/") for case in report.canonical
452+
)
447453

448454

449455
def test_the_envelope_is_unaffected_by_an_extension(adoption: Run) -> None:
@@ -524,15 +530,15 @@ def test_an_extension_cannot_replace_a_canonical_feature_file(
524530
) -> None:
525531
"""The hazard Java measured, checked at the point it would have bitten.
526532
527-
A verbatim copy of ``errors.feature`` under ``tck-extensions/features/``
528-
reaches pytest-bdd as ``features/errors.feature`` -- the canonical uri. The
533+
A verbatim copy of ``errors.feature`` under ``extensions/gherkin/``
534+
reaches pytest-bdd as ``gherkin/errors.feature`` -- the canonical uri. The
529535
uri the payload reports is derived from where the file is instead, so the
530536
canonical source is still the packaged one, the copy is reported as an
531537
extension, and both ran.
532538
"""
533539
report = adoption.report("shadowed")
534-
canonical_uri = f"features/{CANONICAL_FEATURE}"
535-
extension_uri = f"extensions/features/{CANONICAL_FEATURE}"
540+
canonical_uri = f"{CANONICAL_DIRECTORY}/{CANONICAL_FEATURE}"
541+
extension_uri = f"extensions/{CANONICAL_DIRECTORY}/{CANONICAL_FEATURE}"
536542

537543
packaged = (Path(features_path()) / CANONICAL_FEATURE).read_text(encoding="utf-8")
538544
assert report.sources[canonical_uri] == packaged
@@ -565,24 +571,27 @@ def test_a_shadowing_extension_does_not_disturb_the_canonical_run(
565571
}
566572

567573

568-
def test_a_directory_named_features_is_refused(
574+
def test_a_directory_named_gherkin_is_refused(
569575
tmp_path_factory: pytest.TempPathFactory,
570576
) -> None:
571577
"""The one collision the naming convention cannot rule out on its own.
572578
573579
An adopter can still hand ``scenarios()`` a directory of their own named
574-
``features``, and its files are then named exactly as canonical ones would
580+
``gherkin``, and its files are then named exactly as canonical ones would
575581
be. No report is written for that suite: a document presenting an adopter's
576582
feature file as the specification's is worse than no document, because it is
577583
the one thing a consumer cannot check.
578584
"""
579585
run = _run(
580586
tmp_path_factory,
581587
{"test_reserved.py": _RESERVED_SUITE},
582-
{"features/local.feature": _RESERVED_FEATURE},
588+
{f"{CANONICAL_DIRECTORY}/local.feature": _RESERVED_FEATURE},
583589
)
584590
assert run.result.returncode != 0, run.result.stdout
585-
assert "features/local.feature is not a canonical feature file" in run.result.stdout
591+
assert (
592+
f"{CANONICAL_DIRECTORY}/local.feature is not a canonical feature file"
593+
in run.result.stdout
594+
)
586595
assert EXTENSIONS_DIRECTORY in run.result.stdout, "the message must say the fix"
587596
assert not list(run.reports.glob("*.json")), "no report may be written"
588597

@@ -592,7 +601,7 @@ def test_two_extension_files_cannot_share_one_uri(
592601
) -> None:
593602
"""Deriving the uri from the location narrows the collision; it does not end it.
594603
595-
A ``tck-extensions`` directory nested inside another one reaches the same
604+
An ``extensions`` directory nested inside another one reaches the same
596605
uri as its namesake at the root, and so would two test modules sharing one
597606
``tck_config``. A Messages stream carries one source per uri, so the second
598607
file's scenarios would be reported against the first file's pickles wherever

‎tools/openfeature-provider-tck/tests/test_report.py‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
classify_phase,
5656
scenario_run,
5757
)
58+
from openfeature.contrib.tools.provider_tck.extensions import CANONICAL_DIRECTORY
5859
from openfeature.contrib.tools.provider_tck.messages import (
5960
MESSAGES_FORMAT,
6061
ScenarioIdentity,
@@ -463,7 +464,7 @@ def _config(**overrides: typing.Any) -> TckConfig:
463464

464465
def _identity(*tags: str, name: str = "a scenario") -> ScenarioIdentity:
465466
return ScenarioIdentity(
466-
uri="features/events.feature",
467+
uri=f"{CANONICAL_DIRECTORY}/events.feature",
467468
path=Path(features_path()) / "events.feature",
468469
name=name,
469470
tags=tags,
@@ -1165,9 +1166,11 @@ def test_a_feature_uri_is_slash_separated_on_every_platform() -> None:
11651166
backslash-separated -- and a report emitted there would otherwise not be
11661167
comparable with one emitted on Linux.
11671168
"""
1168-
assert feature_uri("features/errors.feature") == "features/errors.feature"
1169-
assert feature_uri(os.path.join("features", "errors.feature")) == (
1170-
"features/errors.feature"
1169+
assert feature_uri(f"{CANONICAL_DIRECTORY}/errors.feature") == (
1170+
f"{CANONICAL_DIRECTORY}/errors.feature"
1171+
)
1172+
assert feature_uri(os.path.join(CANONICAL_DIRECTORY, "errors.feature")) == (
1173+
f"{CANONICAL_DIRECTORY}/errors.feature"
11711174
)
11721175

11731176

0 commit comments

Comments
 (0)