Skip to content

Implementing a Flagnetic SDK against the conformance suite

A Flagnetic SDK in a new language is right when it passes conformance/ with no file, case or scenario skipped. Behaviour two SDKs must agree on is pinned there, never left to a judgement call: drift between SDKs does not fail loudly, it silently serves different values to the same user and biases experiments. This page is the order to work through it.

1. The evaluator

Port the evaluation algorithm documented on eval (go doc github.com/azverinus/flagnetic/eval), then run the evaluator suite:

  • Fixtures (conformance/fixtures/<topic>/<name>.json): decode ruleset, evaluate flag for context and compare with expect exactly, key for key, with no key missing and none extra. conformance/README.md lists every result key and when it is present. The evaluator always returns the true reason.
  • murmur3 (conformance/fixtures/murmur3.json): MurmurHash3 x86 32-bit, seed 0, over UTF-8 bytes, read unsigned; bucket = hash % 10000, and Bucket(salt, unit_id) hashes "{salt}.{unit_id}". Hashing UTF-16 or reading the hash as signed fails these vectors.
  • RE2 vectors (conformance/fixtures/regex.json): a matches condition must match, not match or refuse the pattern ("invalid", evaluated as inconsistent_ruleset) exactly as Go regexp does. A pattern Go accepts must be accepted. If your platform’s engine is not RE2, translate patterns or bring an RE2 implementation; a skip list is not an option.
  • Unsupported rules: an operator, condition kind, serve kind or attribute type your evaluator does not know is found when the ruleset is decoded and reported per flag, as {kind, name}. A fixture’s unsupported key is the report it expects; without the key, the report must be empty. Evaluating such a flag is inconsistent_ruleset where evaluation reaches the construct.

2. The SDK surface

Wrap the evaluator in getters that never throw or panic: a missing flag, a type mismatch, an evaluator error or no ruleset at all serves the built-in default the caller passed, with reason fallback and an error code. Put every evaluator fixture through your getters too, as the Go SDK’s conformance_test.go does, so the SDK layer cannot distort what the evaluator computed. Log rule_unsupported once per flag and ruleset version, naming the flag and its constructs.

3. The protocol

conformance/protocol holds the documents of /sdk/v1 in exactly the shapes the server serves (their contract is api/sdk.yaml), and a step language a mock server in any language can script:

  • Degradation cases (degradation/cases.json): what the fallback chain does with an empty, truncated, newer, lower-versioned or otherwise wrong document, and the answers served afterwards; logs names what must have been logged.
  • Scenarios (scenarios.json, versioning-scenarios.json, experiment-scenarios.json, stream-stability-scenarios.json, foreground-scenarios.json for client SDKs on devices, and page-scenarios.json for client SDKs in a browser page): the fallback chain, the store, a revoked key, the ruleset stream and when it counts as stable, local overrides, offline mode, the events retry policy, evaluation summaries, schema versions, running experiments with explicit and automatic exposures, the foreground stream of a device (the random wait before evaluating, the background close, the resume refetch), and a browser page (no poll while hidden, the refetch on becoming visible or back online, the beacon of a hidden or closing page). Run every scenario of every mode your SDK supports; server mode evaluates locally from the ruleset, client mode reads evaluate answers.
  • A client key’s answers carry targeting_match in place of the reasons targeting decided, and no rule identifier. A client-mode SDK reads and reports them as they are.
  • Errors are problem documents in the management API’s shape (server/problems/): type, title, status, a stable code, detail, the request_id of the request, and for a refused body errors, each with a JSON Pointer into the body, a code and the rule’s params. Act on the status and Retry-After (and the code where it helps a log line), never on title or detail.
  • Events answers list each refused event in rejected with a code. The exposure exchanges show both sides: an exposure of an experiment the server has, accepted, and exposures refused unknown_experiment and unit_type_mismatch. The codes are an open set: treat a code you do not know like any other rejection and never send that event again.

Your runner should fail when a scenario of a mode you support runs nowhere, as the Go SDK’s TestEveryServerScenarioIsCovered does, and write the scenarios that passed to a report from which .github/scripts/behaviour-matrix.sh builds your column of the behaviour matrix.

Log names

The logger hook receives named events, and operators alert on those names, so every SDK uses the same ones. An SDK exports them in its own style (Go Event constants, Ruby Flagnetic::EVENTS, the JavaScript LogEvent union, Dart LogEvents, Python module constants) but the strings are these, and no SDK logs a name outside this list for the same concept:

Name When
events_failed A batch of events failed and is sent again with the same event IDs.
exposures_off send_exposures is off, so no exposure or alias leaves the client.
evaluation_failed An internal failure was caught at the API boundary.
queue_dropped Events or summary rows were given up on; cause names why. A summary window older than one hour has the cause window_too_old.
stream_connected The ruleset stream is open.
stream_dropped The ruleset stream ended.
operation_deprecated An answer carried a Deprecation header. Logged once per operation for each client, at warning level, with the fields operation (ruleset, stream, events, or evaluate in a client SDK), deprecation (the header as received) and, when the answer carries one, sunset (the header as received); the call is never failed for it.

The protocol option that switches the ruleset stream on or off is stream. Each SDK’s tests check that its exported names are the ones in this table and that none of the names it replaced is still logged.

4. OpenFeature

A provider maps Flagnetic reasons to OpenFeature reasons by conformance/openfeature/reasons.json, and carries the Flagnetic reason in the flag metadata under the key the file names, so dashboards agree across languages.

5. Compatibility

Declare the schema_version range your SDK reads and the SDK API path it speaks, send Flagnetic-Schema-Version on every document and events request, and add your row to the compatibility table.