diff --git a/.gherkin-lintrc b/.gherkin-lintrc index 36b2d0ca..5679dc51 100644 --- a/.gherkin-lintrc +++ b/.gherkin-lintrc @@ -49,8 +49,8 @@ "on", { "steps-length": { - "Background": 3, - "Scenario": 16 + "Background": 4, + "Scenario": 17 } } ] diff --git a/README.md b/README.md index 9b39897d..5677d7ce 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Flagd Test Harness -This repository contains a Docker image to support the [Gherkin test suites](https://github.com/open-feature/spec/blob/main/specification/appendix-b-gherkin-suites.md) defined in the OpenFeature specification. +This repository contains a Docker image and flagd's [Provider TCK](https://github.com/open-feature/spec/issues/417) extension scenarios, which flagd providers run to check their behaviour. ## `flagd-testbed` Container @@ -40,24 +40,16 @@ This file is generated when flagd is started and can be used to test all flags i --- -## Gherkin Test Suite +## TCK Extensions -The [`gherkin`](./gherkin) directory contains [*Gherkin*](https://cucumber.io/docs/gherkin/) tests that validate behavior for the configurations defined in the flagd-testbed (see [Flag Files](#flag-files)). -Combined with the appropriate SDK and provider, these tests form a complete integration suite. +The [`tck-extensions`](./tck-extensions) directory holds flagd's scenarios as extensions for the +[OpenFeature Provider TCK](https://github.com/open-feature/spec/issues/417): a flagd provider runs +them alongside the TCK's own scenarios, against the image above. Its +[README](./tck-extensions/README.md) covers the tags, the extension steps and how to consume it. -### Tagging - -Tests are tagged to support selective execution, as not all providers or SDKs support all features. Tags can be applied at both the suite and individual test case level. - -Currently supported "provider-tags": - -* `@file` -* `@rpc` -* `@in-process` - -For example, to run a test in RPC mode, tag the suite or test case with `@rpc`. - -Tag-based filtering enables incremental migration and test execution, allowing individual features to be validated progressively rather than all at once. +The legacy `gherkin/` suite was removed in 4.0. SDKs that still run it pin a 3.x release, which +keeps being cut from the [`release/v3`](https://github.com/open-feature/flagd-testbed/tree/release/v3) +branch. --- @@ -67,7 +59,7 @@ This repository should be included as a submodule within your sdk which should b We recommend: - to setup renovate to automatically update your submodule, always pointing to version tags and not branches -- to load all gherkin files, and eliminate tests via tag exclusions +- to load all extension feature files, and eliminate tests via tag exclusions - to utilize testcontainers for easier test setup - to use the version.txt within this repository to load the appropriate docker image diff --git a/agents.md b/agents.md index 7360f520..96037750 100644 --- a/agents.md +++ b/agents.md @@ -10,7 +10,7 @@ This file provides guidance for AI agents (such as GitHub Copilot) working in th It ships: - A Docker image (`flagd-testbed`) bundling [flagd](https://flagd.dev/) and a control server called **Launchpad**. -- [Gherkin](https://cucumber.io/docs/gherkin/) feature files (in `gherkin/`) that define the expected behaviour of flagd providers. +- [Gherkin](https://cucumber.io/docs/gherkin/) feature files (in `tck-extensions/`) that define the expected behaviour of flagd providers, as Provider TCK extensions. The legacy `gherkin/` suite lives on the `release/v3` branch only. - Flag definition JSON files (in `flags/`) that back the test scenarios. SDK teams include this repo as a **git submodule**, spin up the Docker image via [Testcontainers](https://testcontainers.com/) or Docker Compose, then run the Gherkin scenarios against their provider implementation. @@ -23,7 +23,8 @@ SDK teams include this repo as a **git submodule**, spin up the Docker image via | Path | Description | |------|-------------| -| `gherkin/` | Cucumber/Gherkin `.feature` files — the primary test contracts | +| `tck-extensions/` | Provider TCK extension `.feature` files — the primary test contracts; also a Go module | +| `evaluator/` | Evaluator testkit features and flags for flagd's in-process evaluators | | `flags/` | flagd flag definition JSON files backing the scenarios | | `flagd/` | Dockerfile and build assets for the `flagd-testbed` Docker image | | `launchpad/` | Go HTTP server that controls flagd lifecycle during tests (start/stop/restart/change) | @@ -37,7 +38,7 @@ This repo uses [Conventional Commits](https://www.conventionalcommits.org/) enfo ### ⚠️ Important: Gherkin and Flag Changes Are `feat:` -Changes to `gherkin/` feature files and `flags/` JSON files **must** use the `feat:` prefix (not `test:` or `chore:`). +Changes to `tck-extensions/` feature files and `flags/` JSON files **must** use the `feat:` prefix (not `test:` or `chore:`). **Why:** The Gherkin scenarios and flag definitions are **the product** of this repository. They define the test contract behaviour that every provider SDK must implement. Adding or changing a scenario or flag definition is adding or changing a feature of the contract — it has downstream impact on SDK teams and triggers a version bump. @@ -222,7 +223,7 @@ This applies to fixup commits, merge-conflict resolutions, and co-authored commi When adding a new test scenario, **always provide both artefacts together**: 1. **Flag definition** — add the flag key and its variants/targeting to the appropriate `flags/*.json` file (or create a new one if it belongs to a new category). -2. **Gherkin scenario** — add the scenario to the appropriate `gherkin/*.feature` file (or create a new one). +2. **Gherkin scenario** — add the scenario to the appropriate `tck-extensions/*.feature` file (or create a new one). A PR that adds only one of the two will be incomplete — the scenario will fail in all SDK test suites because either the flag or the step is missing. diff --git a/gherkin/connection.feature b/gherkin/connection.feature deleted file mode 100644 index a75b4d05..00000000 --- a/gherkin/connection.feature +++ /dev/null @@ -1,100 +0,0 @@ -Feature: flagd provider disconnect and reconnect functionality - - @rpc @in-process @file - Scenario Outline: Connection - Given a flagd provider - And a Boolean-flag with key "boolean-flag" and a default value "false" - When the flag was evaluated with details - Then the resolved details value should be "true" - - Scenarios: Stable - | name | - | stable | - @customCert - Scenarios: Certificates - | name | - | ssl | - @unixsocket @os.linux - Scenarios: Unixsocket - | name | - | socket | - - @rpc @in-process @file @reconnect - # This test suite tests the reconnection functionality of flagd providers - Scenario Outline: Provider reconnection - Given a flagd provider - And a ready event handler - And a error event handler - When a ready event was fired - When the connection is lost for 8s - Then the error event handler should have been executed - Then the ready event handler should have been executed - - Scenarios: Stable - | name | - | stable | - @customCert - Scenarios: Certificates - | name | - | ssl | - # unix sockets and reconnects is a strange topic and not as easily handled as like tcp reconnects - # @unixsocket @os.linux - # Scenarios: Unixsocket - # | name | - # | socket | - - @rpc @in-process @file @unavailable - Scenario: Provider unavailable - Given an option "deadlineMs" of type "Integer" with value "1000" - And a unavailable flagd provider - And a error event handler - Then the error event handler should have been executed within 3000ms - - @rpc @in-process @forbidden - # This test ensures that a forbidden response from flagd results in a fatal client state - Scenario: Provider forbidden - Given an option "fatalStatusCodes" of type "StringList" with value "PERMISSION_DENIED" - And a forbidden flagd provider - And a error event handler - Then the error event handler should have been executed within 5000ms - And the client should be in fatal state - - @targetURI @rpc - Scenario: Connection via TargetUri rpc - Given an option "targetUri" of type "String" with value "envoy://localhost:/rpc.service" - And a stable flagd provider - And a Boolean-flag with key "boolean-flag" and a default value "false" - When the flag was evaluated with details - Then the resolved details value should be "true" - - @targetURI @in-process - Scenario: Connection via TargetUri in-process - Given an option "targetUri" of type "String" with value "envoy://localhost:/sync.service" - And a stable flagd provider - And a Boolean-flag with key "boolean-flag" and a default value "false" - When the flag was evaluated with details - Then the resolved details value should be "true" - - @targetURI @in-process @reconnect - Scenario: Re-Connection via TargetUri in-process - Given an option "targetUri" of type "String" with value "envoy://localhost:/sync.service" - And a stable flagd provider - And a ready event handler - And a error event handler - When a ready event was fired - When the connection is lost for 8s - Then the error event handler should have been executed - Then the ready event handler should have been executed - - @targetURI @in-process @reconnect @grace - Scenario: Re-Connection via TargetUri in-process with grace period - Given an option "targetUri" of type "String" with value "envoy://localhost:/sync.service" - And a stable flagd provider - And a ready event handler - And a stale event handler - And a error event handler - When a ready event was fired - When the connection is lost for 8s - Then the stale event handler should have been executed - Then the error event handler should have been executed - Then the ready event handler should have been executed diff --git a/gherkin/contextEnrichment.feature b/gherkin/contextEnrichment.feature deleted file mode 100644 index fc6d5ba9..00000000 --- a/gherkin/contextEnrichment.feature +++ /dev/null @@ -1,50 +0,0 @@ -@contextEnrichment -Feature: Context Enrichment - - Background: - Given a stable flagd provider - - @in-process @rpc - Scenario: Use enriched context - Given a String-flag with key "flagd-context-aware" and a default value "not" - When the flag was evaluated with details - Then the resolved details value should be "INTERNAL" - - @grace @in-process - Scenario: Use enriched context on connection error for IN-PROCESS - Given a String-flag with key "flagd-context-aware" and a default value "not" - And a stale event handler - And a ready event handler - When the flag was evaluated with details - Then the resolved details value should be "INTERNAL" - When the connection is lost for 6s - And a stale event was fired - When the flag was evaluated with details - Then the resolved details value should be "INTERNAL" - When a ready event was fired - - @grace @rpc - Scenario: Use enriched context on connection error for RPC - Given a String-flag with key "flagd-context-aware" and a default value "not" - And a stale event handler - And a ready event handler - When the flag was evaluated with details - Then the resolved details value should be "INTERNAL" - When the connection is lost for 6s - And a stale event was fired - When the flag was evaluated with details - Then the resolved details value should be "not" - When a ready event was fired - - @rpc @caching - Scenario: Use enriched context on RPC connection will not cache the value - Given a String-flag with key "flagd-context-aware" and a default value "not" - And a change event handler - And a ready event handler - When the flag was modified - And a change event was fired - And the flag was evaluated with details - Then the reason should be "TARGETING_MATCH" - # ensure that we do not cache a "TARGETING_MATCH", we should only cache evaluation with a "STATIC" reason - When the flag was evaluated with details - Then the reason should be "TARGETING_MATCH" diff --git a/gherkin/evaluation.feature b/gherkin/evaluation.feature deleted file mode 100644 index 04cac474..00000000 --- a/gherkin/evaluation.feature +++ /dev/null @@ -1,134 +0,0 @@ -@rpc @in-process @file -Feature: flagd evaluations - - # This test suite contains scenarios to test flagd providers. - # It's associated with the flags configured in flags. - # It should be used in conjunction with the suites supplied by the OpenFeature specification. - - Background: - Given an option "cache" of type "CacheType" with value "disabled" - And a stable flagd provider - - Scenario Outline: Resolve values - Given a -flag with key "" and a default value "" - When the flag was evaluated with details - Then the resolved details value should be "" - - Examples: - | key | type | default | resolved_value | - | boolean-flag | Boolean | false | true | - | string-flag | String | bye | hi | - | integer-flag | Integer | 1 | 10 | - | float-flag | Float | 0.1 | 0.5 | - - Scenario Outline: Resolves zero value - Given a -flag with key "" and a default value "" - When the flag was evaluated with details - Then the resolved details value should be "" - And the reason should be "STATIC" - - Examples: - | key | type | default | resolved_value | - | boolean-zero-flag | Boolean | true | false | - | string-zero-flag | String | hi | | - | integer-zero-flag | Integer | 1 | 0 | - | float-zero-flag | Float | 0.1 | 0.0 | - - @precision - Scenario Outline: Resolves numeric values without loss of precision - # 2147483647 is 2^31 - 1. It is outside the range a 32-bit float represents exactly, so a - # provider or transport that routes integers through a float and back returns 2147483648. - # 10.0 is the mirror case: a float whose value happens to be integral, which must stay a - # float rather than arriving as the integer 10. - Given a -flag with key "" and a default value "" - When the flag was evaluated with details - Then the resolved details value should be "" - And the variant should be "" - And the reason should be "STATIC" - - Examples: - | key | type | default | resolved_value | variant | - | large-integer-flag | Integer | 1 | 2147483647 | max-int32 | - | integral-float-flag | Float | 0.1 | 10.0 | ten | - - @precision @large-integers - Scenario: Resolves an integer beyond 32 bits without loss of precision - # 9007199254740991 is 2^53 - 1, the largest integer a double represents exactly. Separate - # from the scenario above, and separately tagged, because a language whose integer type is - # 32 bits cannot ask for it at all -- excluding @large-integers is the honest answer there, - # not failing it. - Given a Integer-flag with key "huge-integer-flag" and a default value "1" - When the flag was evaluated with details - Then the resolved details value should be "9007199254740991" - And the variant should be "max-safe" - And the reason should be "STATIC" - - @targeting - Scenario Outline: Resolves zero value with targeting - Given a -flag with key "" and a default value "" - And a context containing a key "email", with type "String" and with value "ballmer@macrosoft.com" - When the flag was evaluated with details - Then the resolved details value should be "" - And the reason should be "TARGETING_MATCH" - - Examples: - | key | type | default | resolved_value | - | boolean-targeted-zero-flag | Boolean | true | false | - | string-targeted-zero-flag | String | hi | | - | integer-targeted-zero-flag | Integer | 1 | 0 | - | float-targeted-zero-flag | Float | 0.1 | 0.0 | - - @targeting - Scenario Outline: Resolves zero value with targeting using default - Given a -flag with key "" and a default value "" - And a context containing a key "email", with type "String" and with value "ballmer@none.com" - When the flag was evaluated with details - Then the resolved details value should be "" - And the reason should be "DEFAULT" - - Examples: - | key | type | default | resolved_value | - | boolean-targeted-zero-flag | Boolean | true | false | - | string-targeted-zero-flag | String | hi | | - | integer-targeted-zero-flag | Integer | 1 | 0 | - | float-targeted-zero-flag | Float | 0.1 | 0.0 | - - # This suite is deprecated and @no-default-variant should be used instead - @no-default @deprecated - Scenario Outline: Resolves flag with no defaultValue correctly - Given a -flag with key "" and a default value "" - And a context containing a key "email", with type "String" and with value "" - When the flag was evaluated with details - Then the resolved details value should be "" - And the reason should be "" - And the error-code should be "" - - # For now, no defaultValue is resolved as FLAG_NOT_FOUND to result in a code default. - # This may be handled more gracefully in the future. - Examples: - | key | type | email | default | resolved_value | reason | error_code | - | null-default-flag | Boolean | | true | true | ERROR | FLAG_NOT_FOUND | - | null-default-flag | Boolean | | false | false | ERROR | FLAG_NOT_FOUND | - | undefined-default-flag | Integer | | 100 | 100 | ERROR | FLAG_NOT_FOUND | - | no-default-flag-null-targeting-variant | String | wozniak@orange.com | Inventor | Inventor | ERROR | FLAG_NOT_FOUND | - | no-default-flag-null-targeting-variant | String | wozniak@orange.com | Founder | Founder | ERROR | FLAG_NOT_FOUND | - | no-default-flag-null-targeting-variant | String | jobs@orange.com | CEO | CEO | TARGETING_MATCH | | - | no-default-flag-undefined-targeting-variant | String | wozniak@orange.com | Retired | Retired | ERROR | FLAG_NOT_FOUND | - - @no-default-variant - Scenario Outline: Resolves flag with no default variant correctly - Given a -flag with key "" and a default value "" - And a context containing a key "email", with type "String" and with value "" - When the flag was evaluated with details - Then the resolved details value should be "" - And the reason should be "" - - Examples: - | key | type | email | code_default | resolved_value | reason | - | null-default-flag | Boolean | | true | true | DEFAULT | - | null-default-flag | Boolean | | false | false | DEFAULT | - | undefined-default-flag | Integer | | 100 | 100 | DEFAULT | - | no-default-flag-null-targeting-variant | String | wozniak@orange.com | Inventor | Inventor | DEFAULT | - | no-default-flag-null-targeting-variant | String | wozniak@orange.com | Founder | Founder | DEFAULT | - | no-default-flag-null-targeting-variant | String | jobs@orange.com | CEO | CEO | TARGETING_MATCH | - | no-default-flag-undefined-targeting-variant | String | wozniak@orange.com | Retired | Retired | DEFAULT | diff --git a/gherkin/events.feature b/gherkin/events.feature deleted file mode 100644 index 677b1469..00000000 --- a/gherkin/events.feature +++ /dev/null @@ -1,50 +0,0 @@ -@rpc @in-process @file @events -Feature: Flagd Provider State Changes - - Background: - Given a stable flagd provider - - Scenario: Provider events chain ready -> error -> ready - Given a ready event handler - And a error event handler - Then the ready event handler should have been executed - When the connection is lost for 8s - Then the error event handler should have been executed - Then the ready event handler should have been executed - - @grace - Scenario: Provider events chain ready -> stale -> error -> ready - Given a ready event handler - And a error event handler - And a stale event handler - Then the ready event handler should have been executed - When the connection is lost for 8s - Then the stale event handler should have been executed - Then the error event handler should have been executed - Then the ready event handler should have been executed - - @grace - Scenario: Provider events chain ready -> stale -> ready - Given a ready event handler - And a error event handler - And a stale event handler - Then the ready event handler should have been executed - When the connection is lost for 1s - Then the stale event handler should have been executed - Then the ready event handler should have been executed - And the error event handler should not have been executed - - Scenario: Flag change event - Given a String-flag with key "changing-flag" and a default value "false" - And a change event handler - When the flag was modified - And a change event was fired - Then the flag should be part of the event payload - - @change-event-excludes-unchanged - Scenario: Unchanged flag is not part of the change event payload - Given a String-flag with key "unchanging-flag" and a default value "false" - And a change event handler - When the flag was modified - And a change event was fired - Then the flag with key "unchanging-flag" should not be part of the event payload diff --git a/gherkin/sync-payload.feature b/gherkin/sync-payload.feature deleted file mode 100644 index c9ae2ff2..00000000 --- a/gherkin/sync-payload.feature +++ /dev/null @@ -1,28 +0,0 @@ -@in-process @sync-payload -Feature: Disabled Sync Metadata - - Background: - Given a syncpayload flagd provider - - Scenario: Use enriched context - Given a String-flag with key "flagd-context-aware" and a default value "not" - When the flag was evaluated with details - Then the resolved details value should be "INTERNAL" - - @grace - Scenario: Use enriched context on connection error for IN-PROCESS - Given a String-flag with key "flagd-context-aware" and a default value "not" - And a stale event handler - And a ready event handler - When the flag was evaluated with details - Then the resolved details value should be "INTERNAL" - When the connection is lost for 6s - And a stale event was fired - When the flag was evaluated with details - Then the resolved details value should be "INTERNAL" - When a ready event was fired - - Scenario: Resolve value independent of context - Given a Boolean-flag with key "boolean-flag" and a default value "false" - When the flag was evaluated with details - Then the resolved details value should be "true" diff --git a/tck-extensions/.gitattributes b/tck-extensions/.gitattributes new file mode 100644 index 00000000..8bb653ed --- /dev/null +++ b/tck-extensions/.gitattributes @@ -0,0 +1,5 @@ +# Every language reads these files byte for byte, and the Go module zip is checksummed, so +# normalise to LF whichever platform they are committed from. +*.feature text eol=lf +*.go text eol=lf +go.mod text eol=lf diff --git a/tck-extensions/README.md b/tck-extensions/README.md new file mode 100644 index 00000000..dcab31e5 --- /dev/null +++ b/tck-extensions/README.md @@ -0,0 +1,24 @@ +# TCK extensions + +flagd's scenarios as extensions for the +[OpenFeature Provider TCK](https://github.com/open-feature/spec/issues/417). A flagd provider that +adopts the TCK runs these alongside the TCK's own scenarios. They replace the `gherkin/` suite, +which 4.0 removed; it lives on in the 3.x releases cut from `release/v3`. + +They ask only what the TCK's canonical scenarios do not. Each file's header names its source feature, +the scenarios it leaves out, and why; most of those the TCK already asks. One source feature has no +extension at all: `errors.feature` is the TCK's own `errors.feature` matrix, its String rows behind +`@string-typing`, and its `ERROR` reason is asked by `reason.feature`. + +They are written in the TCK's step vocabulary (`a stable provider`, `a context with the following +keys:`), plus flagd-specific steps an adopter supplies as extension glue: provider options +(`an option "" of type "" with value ""`), connection control, the configuration +steps of `config.feature`, and `the flag should not be part of the event payload`. Feature tags +name the resolvers a scenario applies to (`@rpc`, `@in-process`, `@file`). + +Java, JavaScript, Python and .NET read this directory through the `test-harness` submodule. Go +depends on it as a module, `github.com/open-feature/flagd-testbed/tck-extensions`, whose `FS` +embeds the feature files, because a Go module zip carries a submodule without its files. + +A scenario fixed or added on `release/v3` should be added here too, or listed as not ported in the +matching file's header. diff --git a/gherkin/config.feature b/tck-extensions/config.feature similarity index 98% rename from gherkin/config.feature rename to tck-extensions/config.feature index 8024e22a..597eb2a7 100644 --- a/gherkin/config.feature +++ b/tck-extensions/config.feature @@ -1,4 +1,5 @@ -Feature: Configuration Test +@ext-config +Feature: TCK extension: flagd provider configuration """markdown This is the official option configuration table | Option name | Environment variable name | Explanation | Type & Values | Default | Compatible resolver | @@ -25,6 +26,10 @@ Feature: Configuration Test | fatalStatusCodes | FLAGD_FATAL_STATUS_CODES | a list of gRPC status codes, which will cause streams to give up and put the provider in a PROVIDER_FATAL state | array | [] | rpc & in-process | """ + # Ported from gherkin/config.feature unchanged. It asks how a flagd provider reads its options and + # environment variables, which no TCK scenario asks: it creates no provider and reaches no backend, + # so every step here is flagd extension glue, worded as the testbed worded it. + Scenario Outline: Default Config When a config was initialized Then the option "