Skip to content

refactor(provider-tck): factories for the backend controls, and keep the gate out of the API - #1925

Merged
toddbaert merged 9 commits into
chore/tck-trimfrom
chore/tck-seams
Oct 19, 2026
Merged

toddbaert merged 9 commits into
chore/tck-trimfrom
chore/tck-seams

Conversation

@aepfli

@aepfli aepfli commented Oct 16, 2026 •

Copy link
Copy Markdown
Member

Stacked on #1923, taking its comment trim and steps/ move. Includes #1926. Nine commits with one aim: the smallest public API that still lets an adopter run the suite and extend it.

The public API

An adopter writes against nine types:

extend one ProviderTckTest (no backend) or ContainerizedProviderTckTest (Docker Compose) — or implement ProviderTckHarness
declare with Capability (four methods), KnownDeviation
get a control BackendControl.overHttp(..) / .inProcess(), returning BackendControl / InProcessControl; BackendType only if you write your own
build a provider BackendEndpoint

An extension author adds four: TckState, FlagUnderTest, ProviderEventRecord, and ProviderTck's three constants.

Nothing else is API. HttpBackendControl, InProcessBackendControl, TckLifecycle, CanonicalFlags and ReportNames are package-private. The eight public types under internal are framework mechanics, not design: Cucumber discovers glue with Class.getMethods(), and ServiceLoader instantiates the listener and the object factory.

What changed

  1. Controls come from factories, and no implementation class is exported. The HTTP one still had to be reachable: an adopter whose backend speaks openapi/control-api.yaml but was not started by the TCK otherwise has no conformant client, and Appendix F makes that the normative path, not the carve-out.
  2. The capability gate leaves the API rather than moving packages. CapabilityGate is gone, its four rules are Capability.requireDeclared(..), and inexpressibleBecause() stays package-private instead of being forced public.
  3. GlueVisibilityTest pins that step classes and their methods are public. Cucumber reports undefined rather than failing when they are not, so demoting glue turns conformance green by deleting the questions — go-sdk#596 had 30 scenarios undefined and a passing test.
  4. One static entry point, ProviderTck: nine public constants down to three, and no instance escapes the class.
  5. feat(provider-tck): inject the harness and backend control through our own ObjectFactory #1926: the harness and backend control are injected into step constructors through our own ObjectFactory; the suite lifecycle becomes a package-private TckLifecycle beside the glue it serves; Capability narrows from eight public members to four.
  6. BackendType replaces ControlApi, with CUSTOM as the default. A control the TCK does not ship reports honestly without being asked, and cannot overstate by guessing HTTP.
  7. A lifecycle per object factory, not a static singleton. Cucumber supplies one factory per run sequentially and one per thread in parallel, so that ownership is what decides whether threads share a backend or each get their own — with parallel enabled, a thread would get its own Compose stack. It stays off: that is a separate decision with an N×Docker cost. Two statics remain, neither holding a harness — a suite-running flag, and the registry @AfterAll drains, since ObjectFactory's only lifecycle hooks are per scenario.

Verification

mvn -pl tools/tck test — 254 tests, 0 failures.

flagd on testbed v3.10.3, tools/tck built in the reactor, clean both sides: both suites 65 scenarios, 59 passed, 2 skipped,
4 failed
, two backends, and the same four named failures — float narrowing, integral-float coercion, large-integer precision,
Example #1.8.

The pre-1925 base gives exactly the same, with the identical flagd commits replayed onto it and run the same way. So these eight
commits are conformance-neutral against a real adoption, not merely green on their own tests.

Open

internal.steps is the only reason requireDeclarable(), requireDeclared(), TckValues.convert() and TckSuiteListener.currentSuite() are public. A module-info.java, or collapsing the package into the one it serves, is the real fix — worth deciding before this merges.

Parallel execution is now the adopter's call. The suite used to pin
cucumber.execution.parallel.enabled=false through a @ConfigurationParameter — a discovery-request
parameter, which beats both -D and their own junit-platform.properties, so they could not turn it
on. That pin is gone; Cucumber's default keeps the suite sequential.

Measured against flagd, with the pool capped to match parallelism, and the same 59 passed, 2 skipped,
4 failed in every configuration:

time stacks
sequential 82.9s 2
2 threads 62.0s 4
4 threads 53.2s 8

Uncapped, ForkJoinPool compensation grew to 18 threads and 18 stacks for a third of the gain, because
each thread starts a backend of its own. ProviderTckTest's javadoc says so, with the numbers. Not
pinned either: a bound we set would be as unoverridable as the one just removed.

@aepfli
aepfli requested a review from a team as a code owner October 16, 2026 20:27
@coderabbitai

coderabbitai Bot commented Oct 16, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 39c388f6-8465-49de-8fcf-db535a6f95ef

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

…t no implementation

One rule instead of a judgement per class: a control is obtained from a
BackendControl factory, never constructed, and no implementation class is
exported.

`BackendControl.overHttp(baseUrl, backendConfiguration)` restores a capability
this branch removed. Making HttpBackendControl package-private is right for the
class and wrong for the capability: an adopter whose backend speaks the canonical
control API but was not started by ContainerizedProviderTckTest -- already
running, brought up by an external orchestrator, CI with no Docker daemon -- had
no way left to reach the one conformant client, and control-api.yaml is a
published contract we should not make anyone re-implement. The failure that
follows is the kind this suite exists to prevent: a hand-rolled client that gets
readiness subtly wrong.

`BackendControl.inProcess()` does the same for the other direction, so the rule
holds both ways. It returns InProcessControl rather than BackendControl because
createProvider() is not on BackendControl and a plain BackendControl would strand
the adopter with no way to obtain the provider -- in-process the flag store and
the provider are one object. InProcessBackendControl is now package-private;
nothing outside this module referenced it.

Signed-off-by: Simon Schrottner <simon.schrottner@flagsmith.com>
…ad of moving it

Moving CapabilityGate to `internal` forced Capability.inexpressibleBecause()
from package-private to public, because the gate reads it across a package
boundary. That trades a class no adopter would ever call -- final, private
constructor, static-only -- for an accessor on the one enum every adopter holds.

Across all three adoptions the only Capability member anyone calls is
declarableExcept(), plus the enum constants. tag(), reserved(), inexpressible(),
inexpressibleBecause(), fromTag(), declarable() and requireDeclarable() have no
caller outside this module.

So the gate goes back beside Capability and becomes package-private, leaving the
API altogether rather than moving to another package while staying public. The
steps reach it through TckRuntime.gateScenario(), already the public entry point
they call for the suite lifecycle, so nothing new is exported -- one fewer public
class and one fewer public method than before.

Also fixes TckRuntime's message, which told the reader to supply an
HttpBackendControl, a class this branch had made unreachable.

Signed-off-by: Simon Schrottner <simon.schrottner@flagsmith.com>
The step classes and their step methods are public because Cucumber requires it,
not as a style choice: PicoFactory.isInstantiable tests Modifier.isPublic and
!isAbstract before registering a component, and MethodScanner enumerates
candidates with Class.getMethods(), which returns public methods only.

Neither complains when it finds nothing. A scenario whose steps cannot be
resolved is reported undefined, and a non-strict run reads as a pass -- so
demoting glue while tidying turns conformance green by removing the questions.
That is the same shape as go-sdk#596, where 30 scenarios reported undefined and
the test passed.

The test reads the glue package from the artifact's code source rather than a
hard-coded list, so a step class added later is covered without anyone
remembering. The extension README now states the requirement too, since that is
where an extension author looks.

Signed-off-by: Simon Schrottner <simon.schrottner@flagsmith.com>
@aepfli
aepfli force-pushed the chore/tck-seams branch 2 times, most recently from 811f477 to 0737475 Compare October 16, 2026 21:14
ProviderTck held nine public String constants, a private constructor and nothing
else. Every reference to them was already inside the tck package -- the
@ConfigurationParameter annotations on ProviderTckTest -- and no adoption names
the class at all, so most of them had no reason to be public.

They move onto what was TckRuntime, which the extension README already sends an
extension author to for the harness and backend control. That makes one class
the thing an extension talks to.

Three constants stay public, the three an extension needs: EXTENSIONS (the
directory its feature files go in), EXTENSION_GLUE (the package its steps go in)
and ALL_GLUE (for ALL_GLUE + ",com.vendor.steps"). FEATURES, GLUE, PLUGINS,
OBJECT_FACTORY, PARALLEL_EXECUTION_ENABLED and FEATURE_EXECUTION_MODE are
package-private; they configure the suite, they do not describe it.
HARNESS_SELECTOR_PROPERTY goes too -- it names a system property, so the contract
is the -Dopenfeature.tck.harness=... flag the README documents, not the Java
constant, which was read only inside the class.

get() is gone with it, and that is a fix rather than a tidy. It had two callers,
both in AbstractSteps, and both dereferenced it immediately -- nobody held the
instance. But stop() nulls the singleton while an instance already handed out
keeps its own harness and backendControl fields, so an extension author who
cached get() in a field -- the obvious thing to do with a getter -- would go on
getting answers from a suite that had already torn down. harness() and
backendControl() are static now and re-read the singleton, so nothing can go
stale; startIfNeeded() returns void, its result never having been used. No
ProviderTck instance escapes the class.

The merged class takes the name ProviderTck rather than keeping TckRuntime,
because the rest of the adopter-facing API is already ProviderTckTest,
ContainerizedProviderTckTest and ProviderTckHarness -- the name was the one
missing from that family, not an addition to it. It also leaves
ProviderTck.ALL_GLUE reading exactly as it did before this PR.

One public type and nine public constants become zero and three, and the entry
point has no instance to misuse.

Signed-off-by: Simon Schrottner <simon.schrottner@flagsmith.com>
…r own ObjectFactory (#1926)

Signed-off-by: Simon Schrottner <simon.schrottner@flagsmith.com>
… default

BackendType gains CUSTOM and backendType() is a default method
returning it, so an implementation the TCK does not ship reports
honestly without being asked, and cannot overstate by guessing HTTP.
One that genuinely drives openapi/control-api.yaml overrides to HTTP
and claims the comparability that goes with it.

Closed set rather than a String: the enum matters only to a custom
control, which owns its own type anyway, and CUSTOM already covers the
case a third value would be invented for -- while a String would be
wider than the vocabulary a report can compare across providers.

DeclarationApiTest previously pinned backendType() as abstract so a
custom control had to state it. That is inverted on purpose: silence
now yields the weaker claim, which the test asserts through an
anonymous BackendControl.

Signed-off-by: Simon Schrottner <simon.schrottner@flagsmith.com>
… singleton

TckLifecycle is an instance owned by TckObjectFactory, started on the
first scenario that factory serves. Cucumber supplies one factory per run
for sequential scenarios and one per thread for parallel ones
(SingletonObjectFactorySupplier against ThreadLocalObjectFactorySupplier),
so that ownership is what decides whether threads share a backend or each
get their own. Enabling parallel execution now gives a thread its own
harness and its own Compose stack. It stays off here: that is a separate
decision with an N-times-Docker cost.

@BeforeAll no longer starts anything. It marks the suite running and keeps
the fail-fast capability check, so a misdeclared suite fails once and
cleanly rather than inside the first scenario of every thread. @afterall
drains a registry, because it runs on one thread and cannot otherwise stop
what another thread started.

Two statics remain, neither holding a harness: the suite-running flag,
which is what stops extension-only glue starting a backend nobody asked
for, and the registry teardown needs. ObjectFactory has no per-run or
per-thread hook -- start() and stop() are per scenario -- so suite-scoped
teardown cannot be done without one.

TckLifecycleTest, in the same package, covers the three properties this
turns on: two lifecycles own separate controls, endSuite stops the ones
other threads started, and a failed start is torn down rather than left
registered. startedCount() exists for those assertions and is
package-private.

Signed-off-by: Simon Schrottner <simon.schrottner@flagsmith.com>
Every port a containerized suite declares is a container port. The stack
must not pin host ports, so Compose maps each to an arbitrary one and
BackendEndpoint resolves the mapping -- which is why
createProvider(BackendEndpoint) is handed an endpoint rather than reading
the declarations back. Dialling a declared port reaches nothing, and the
README example modelled the right thing without saying why.

Also records what a parallel run costs, measured against flagd rather
than reasoned about. Enabling cucumber.execution.parallel.enabled works:
each thread gets its own object factory, so each gets its own harness and
backend, and both suites reported the same 59 passed, 2 skipped, 4 failed
as a serial run. But fixed.parallelism is a ForkJoinPool target, not a
cap, and these steps block on events and control calls -- so the pool
grew to 10 and 8 workers and started 18 Compose stacks for 130 scenarios,
gaining 12% of wall-clock. Pinning fixed.max-pool-size=2 gave 4 stacks,
two per suite, and 24%.

Random host ports are what make this possible at all: two stacks with
pinned ports would collide on bind.

Signed-off-by: Simon Schrottner <simon.schrottner@flagsmith.com>
The suite set cucumber.execution.parallel.enabled=false through a
@ConfigurationParameter, which is a discovery-request parameter and so
beats both -D and an adopter's junit-platform.properties. An adopter
could not turn parallelism on at all.

Cucumber's own default is false, so dropping the annotation and the
PARALLEL_EXECUTION_ENABLED constant leaves the suite sequential while
making the decision theirs. The two test suites that want a deterministic
serial run now say "false" themselves rather than borrowing the constant.

FEATURE_EXECUTION_MODE stays at same_thread, which now means something
useful: an adopter who enables parallelism gets feature-level concurrency
rather than scenario-level, bounding threads by the feature count.

Measured against flagd, with the pool capped to match parallelism: two
threads cut the suites from 82.9s to 62.0s for four stacks, four threads
to 53.2s for eight. Uncapped, ForkJoinPool compensation grew to 18
threads and 18 stacks for a third of that gain. Same 59 passed, 2
skipped, 4 failed in every configuration.

Signed-off-by: Simon Schrottner <simon.schrottner@flagsmith.com>
@toddbaert
toddbaert merged commit 0e36066 into chore/tck-trim Oct 19, 2026
5 checks passed
@toddbaert
toddbaert deleted the chore/tck-seams branch October 19, 2026 17:11
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.

2 participants