Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion providers/flagsmith/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,21 @@ Options can be defined using the FlagsmithProviderOptions builder. Below are all
| trustManager | X509TrustManager | | X509TrustManager used when overriding the sslSocketFactory.
| httpInterceptor | Interceptor | | Add a custom HTTP interceptor in the form of an okhttp3.Interceptor object.
| retries | int | 3 | Add a custom com.flagsmith.config.Retry object to configure the backoff / retry configuration.
| usingBooleanConfigValue | boolean | false | Determines whether to resolve a feature value as a boolean or use the isFeatureEnabled as the flag itself. These values will be false and true respectively.
| usingBooleanConfigValue | boolean | false | Determines whether to resolve a feature value as a boolean or use the isFeatureEnabled as the flag itself. These values will be false and true respectively.

## Provider conformance (TCK)

This provider adopts the [OpenFeature Provider TCK](../../tools/tck/README.md) as a single suite,
`FlagsmithProviderTckTest`, in `src/test/java/.../flagsmith/tck/`. That class records which
capabilities are declared, which are withheld and why, and every known deviation. The backend is the
[Flagsmith TCK testbed](https://github.com/aepfli/flagsmith-tck-testbed).

```bash
mvn -Ptck -pl providers/flagsmith -am test
```

The suite is Docker-gated. The root pom excludes every provider's `tck` package from the default
build and its `tck` profile runs only that package, so `-am` adds no other module's tests.

**CI runs it** in the `Provider TCK` job, apart from the main matrix. Set
`tck.testFailureIgnore` to `true` in this module's pom to report the failures without failing it.
39 changes: 39 additions & 0 deletions providers/flagsmith/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,46 @@
</developer>
</developers>

<properties>
<!-- Match any provider-tck version locally; CI resolves it from the reactor -->
<provider-tck.version>[0.0.1,)</provider-tck.version>
<!-- The tck package runs only under the root pom's `tck` profile; set true to report failures without failing. -->
<tck.testFailureIgnore>false</tck.testFailureIgnore>
</properties>

<dependencies>
<!-- Jackson alignment.
tools/tck brings jackson-databind 2.22.1, while flagsmith-java-client 7.4.3 pins
jackson-annotations and jackson-core at 2.15.2. Maven's nearest-wins then assembles
databind 2.22 against annotations 2.15, and the Flagsmith client's ObjectMapper dies
with ClassNotFoundException on com.fasterxml.jackson.annotation.JsonSerializeAs.

The provider's own 35 tests pass without the TCK on the classpath, so this is a
conflict the TCK introduces rather than a defect in the provider. Still present after
the TCK moved testcontainers to provided/optional, so it wants its own fix upstream:
shade Jackson, or stop exporting a hard databind version.

Aligned DOWN to the client's 2.15.2 rather than up, because jackson-annotations has no
2.22.1 release at all (it tracks its own version line), so aligning upward needs the
Jackson BOM. Compile scope, not test: the provider's own main source imports
com.fasterxml.jackson.databind. -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.15.2</version>
</dependency>
<dependency>
<groupId>dev.openfeature.contrib.tools</groupId>
<artifactId>tck</artifactId>
<version>${provider-tck.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers</artifactId>
<version>2.0.4</version>
<scope>test</scope>
</dependency>
<!-- Inherits dev.openfeature.javasdk and the test dependencies from the parent pom -->
<dependency>
<groupId>com.flagsmith</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,14 @@ private <T> T convertValue(Object value, Class<?> expectedType) {
|| expectedType == String.class
|| expectedType == Integer.class
|| expectedType == Double.class;
// Flagsmith has no float type: a float is stored as its string form.
if (expectedType == Double.class && value instanceof String) {
try {
return (T) Double.valueOf((String) value);
} catch (NumberFormatException e) {
throw new TypeMismatchError("Flag value " + value + " is not a valid float.");
}
}
T flagValue = isPrimitive ? (T) value : (T) objectToValue(value);

if (flagValue.getClass() != expectedType) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,23 @@ void shouldNotResolveFlagValueIfFlagsmithErrorThrown() {
() -> booleanFlagsmithProvider.getBooleanEvaluation("true_key", false, new MutableContext()));
}

@Test
void shouldResolveFloatStoredAsString() {
// Flagsmith has no float type, so a float flag is stored as its string form
ProviderEvaluation<Double> evaluation =
flagsmithProvider.getDoubleEvaluation("float_string_key", 0.1, new MutableContext());

assertEquals(0.5, evaluation.getValue());
assertNull(evaluation.getErrorCode());
}

@Test
void shouldReportTypeMismatchForNonNumericStringRequestedAsFloat() {
assertThrows(
dev.openfeature.sdk.exceptions.TypeMismatchError.class,
() -> flagsmithProvider.getDoubleEvaluation("float_invalid_key", 0.1, new MutableContext()));
}

private String readMockResponse(String filename) throws IOException {
String file = getClass()
.getClassLoader()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
package dev.openfeature.contrib.providers.flagsmith.tck;

import dev.openfeature.contrib.providers.flagsmith.FlagsmithProvider;
import dev.openfeature.contrib.providers.flagsmith.FlagsmithProviderOptions;
import dev.openfeature.contrib.tools.tck.BackendEndpoint;
import dev.openfeature.contrib.tools.tck.Capability;
import dev.openfeature.contrib.tools.tck.ContainerizedProviderTckTest;
import dev.openfeature.sdk.FeatureProvider;
import java.io.File;
import java.util.Arrays;
import java.util.EnumSet;
import java.util.List;
import java.util.Set;

/**
* The OpenFeature Provider Conformance Suite against the Flagsmith <b>Java</b> provider.
*
* <p>The backend, and how the four language adoptions compare against it, are documented once in
* <a href="https://github.com/aepfli/flagsmith-tck-testbed">aepfli/flagsmith-tck-testbed</a> rather
* than restated in each adoption.
*/
public class FlagsmithProviderTckTest extends ContainerizedProviderTckTest {

/** Fixed by the testbed, because the control API cannot hand connection parameters to a provider. */
private static final String SERVER_SIDE_KEY = "ser.provider-tck-server-key";

private static final int PROXY_PORT = 8000;

@Override
public File composeFile() {
return new File("src/test/resources/tck/docker-compose.yaml");
}

@Override
public List<Integer> backendPorts() {
return Arrays.asList(PROXY_PORT);
}

@Override
public FeatureProvider createProvider(BackendEndpoint endpoint) {
// The Flagsmith SDK appends its own path segments, so baseUri is the API root with a
// trailing slash: remote evaluation requests "flags/" beneath it.
String baseUri = String.format("http://%s:%d/api/v1/", endpoint.host(), endpoint.port(PROXY_PORT));

FlagsmithProviderOptions options = FlagsmithProviderOptions.builder()
.apiKey(SERVER_SIDE_KEY)
.baseUri(baseUri)
// Set explicitly, not left to the default: every canonical flag is seeded enabled,
// so reading `enabled` instead of feature_state_value would resolve
// boolean-zero-flag to true -- exactly what the falsy-value scenario catches.
.usingBooleanConfigValue(true)
.build();
return new FlagsmithProvider(options);
}

@Override
public FeatureProvider createUnavailableProvider() {
// Pointed at a closed port on localhost, never at the backend under test -- that has to
// stay up, and simulated outages belong to the control API.
FlagsmithProviderOptions options = FlagsmithProviderOptions.builder()
.apiKey(SERVER_SIDE_KEY)
.baseUri("http://localhost:9999/api/v1/")
.usingBooleanConfigValue(true)
.build();
return new FlagsmithProvider(options);
}

/**
* {@inheritDoc}
*
* <p>{@code VARIANTS} is withheld because Flagsmith has no variant concept for a plain feature:
* the evaluation response carries no variant key and no seeding can produce one. Permitted rather
* than defective, so it carries no deviation entry.
*
* <p>{@code LARGE_INTEGERS} is withheld because Java's integer accessor is a 32-bit
* {@code Integer}, so 2^53-1 cannot be asked for at all. Go declares it; the difference is real
* rather than an oversight.
*
* <p>{@code STANDARD_REASONS} is withheld: {@code resolveFlagsmithEvaluation} sets
* {@code Reason.DISABLED} for a disabled flag and leaves the reason null on every successful
* resolution, so STATIC, TARGETING_MATCH and DEFAULT are never reported. The Go Flagsmith provider
* reports all three against the same backend.
*
* <p>{@code NUMERIC_COERCION} is withheld: this provider does not coerce between Integer and Float
* requests.
*
* <p>{@code OBJECT} is withheld: Flagsmith has no structured type and stores the JSON document as
* text, which this provider does not parse into a structure.
*
* <p>{@code STRING_TYPING} is declared and {@code FULLY_TYPED_VALUES} withheld, which is the split
* this backend motivated. {@code feature_state_value} is natively boolean, integer or string, so
* a boolean and an integer both report {@code TYPE_MISMATCH} through the String accessor, while a
* float and a structure have no native type, are stored as text, and are correctly returned.
* Withheld rather than deviated because nothing obliges a provider to report a type its store does
* not have.
*
* <p>{@code DISABLED_FLAGS} is declared: Flagsmith's native model is {@code enabled} plus a value,
* so the canonical set's four disabled-* flags map straight onto it.
*
* <p>The lifecycle and event capabilities are withheld: this provider has no observable
* initialisation for the suite to assert against.
*/
@Override
public Set<Capability> capabilities() {
return EnumSet.of(Capability.TARGETING, Capability.DISABLED_FLAGS, Capability.STRING_TYPING);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,24 @@
},
"feature_state_value": 3.141
},
{
"enabled": true,
"feature": {
"id": 1460,
"type": "STANDARD",
"name": "float_string_key"
},
"feature_state_value": "0.5"
},
{
"enabled": true,
"feature": {
"id": 1461,
"type": "STANDARD",
"name": "float_invalid_key"
},
"feature_state_value": "abc"
},
{
"enabled": true,
"feature": {
Expand Down
17 changes: 17 additions & 0 deletions providers/flagsmith/src/test/resources/tck/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# The Flagsmith provider-TCK backend: the Flagsmith Edge Proxy with a launchpad implementing the
# control API as its upstream. https://github.com/aepfli/flagsmith-tck-testbed
#
# The service is named "backend" because that is ContainerizedProviderTckTest's default.
#
# The image is PINNED, not :latest. Four language adoptions pull this image, and a mutable tag lets
# a push to the testbed change four pull requests' results with no diff anywhere to explain it.
#
# Ports are never pinned. The TCK reads the dynamically mapped host ports after the stack is up,
# and POST /stop deliberately never restarts the container precisely so those mappings survive an
# outage scenario.
services:
backend:
image: ${FLAGSMITH_TESTBED_IMAGE:-ghcr.io/aepfli/flagsmith-tck-testbed:0.1.0}
ports:
- 8000 # Edge Proxy -- what the provider under test talks to
- 8080 # launchpad -- control API
Loading