From ebe6e54017edb8ed1dda8f648bd7955d26fb2616 Mon Sep 17 00:00:00 2001 From: Anders Asheim Hennum Date: Wed, 4 Nov 2026 09:18:23 +0100 Subject: [PATCH 1/3] test(compliance): expose the legacy payload accessor to the harness Declare feature_flag_payloads and add /get_feature_flag_payload, which reads a flag's payload remotely with get_feature_flag_payload. The harness uses it to check payloads read from /flags?v=4 records. --- sdk_compliance_adapter/README.md | 1 + sdk_compliance_adapter/adapter.py | 28 ++++++++++++++++++++++++++ sdk_compliance_adapter/test_adapter.py | 25 +++++++++++++++++++++++ 3 files changed, 54 insertions(+) diff --git a/sdk_compliance_adapter/README.md b/sdk_compliance_adapter/README.md index eae25916b..79285792d 100644 --- a/sdk_compliance_adapter/README.md +++ b/sdk_compliance_adapter/README.md @@ -25,6 +25,7 @@ The adapter implements the standard SDK adapter interface defined in the [test h - `POST /flush` - Flush pending events - `GET /state` - Return internal state - `POST /get_feature_flag` - Evaluate a flag locally or remotely +- `POST /get_feature_flag_payload` - Read a flag payload remotely with the legacy payload accessor - `POST /reload_feature_flag_definitions` - Fresh, bounded definitions readiness barrier - `POST /reset` - Reset SDK state diff --git a/sdk_compliance_adapter/adapter.py b/sdk_compliance_adapter/adapter.py index d205d1792..1e197d758 100644 --- a/sdk_compliance_adapter/adapter.py +++ b/sdk_compliance_adapter/adapter.py @@ -313,6 +313,8 @@ def health(): capabilities.append("feature_flags_local_evaluation_v1") # Remote /flags requests send ?v=4 and read the v4 flag record. capabilities.append("flags_response_v4") + # The legacy payload accessor is exposed on /get_feature_flag_payload. + capabilities.append("feature_flag_payloads") return jsonify( { "sdk_name": "posthog-python", @@ -710,6 +712,32 @@ def get_feature_flag(): return jsonify({"error": str(e)}), 500 +@app.route("/get_feature_flag_payload", methods=["POST"]) +def get_feature_flag_payload(): + """Read a flag's payload with the legacy payload accessor (remote evaluation).""" + try: + if not state.client: + return jsonify({"error": "SDK not initialized"}), 400 + data = request.json or {} + if not data.get("key") or not data.get("distinct_id"): + return jsonify({"error": "key and distinct_id are required"}), 400 + client = state.remote_client or state.client + payload = client.get_feature_flag_payload( + data["key"], + data["distinct_id"], + person_properties=data.get("person_properties"), + groups=data.get("groups"), + group_properties=data.get("group_properties"), + disable_geoip=data.get("disable_geoip"), + only_evaluate_locally=False, + ) + client.flush() + return jsonify({"success": True, "value": payload}) + except Exception as e: + logger.exception("Error reading feature flag payload") + return jsonify({"error": str(e)}), 500 + + @app.route("/reset", methods=["POST"]) def reset(): """Reset SDK state""" diff --git a/sdk_compliance_adapter/test_adapter.py b/sdk_compliance_adapter/test_adapter.py index 0f40f20fc..514963aa9 100644 --- a/sdk_compliance_adapter/test_adapter.py +++ b/sdk_compliance_adapter/test_adapter.py @@ -87,6 +87,7 @@ def test_health_opts_into_local_evaluation_without_losing_capture( capabilities = adapter.app.test_client().get("/health").json["capabilities"] assert "feature_flags_local_evaluation_v1" in capabilities assert "flags_response_v4" in capabilities + assert "feature_flag_payloads" in capabilities assert capability in capabilities assert "capture_ai_v0" in capabilities @@ -181,6 +182,30 @@ def test_force_remote_bypasses_loaded_local_definitions(adapter, monkeypatch): remote.assert_called_once() +def test_payload_route_reads_remotely_and_returns_the_parsed_payload( + adapter, monkeypatch +): + client = initialize(adapter) + remote = Mock( + return_value=posthog.client.normalize_flags_response( + { + "featureFlags": {"flag": True}, + "featureFlagPayloads": {"flag": '{"columns": 2}'}, + } + ) + ) + monkeypatch.setattr(adapter.state.remote_client, "_get_flags_decision", remote) + response = client.post( + "/get_feature_flag_payload", json={"key": "flag", "distinct_id": "user"} + ) + assert response.json == {"success": True, "value": {"columns": 2}} + remote.assert_called_once() + assert ( + client.post("/get_feature_flag_payload", json={"key": "flag"}).status_code + == 400 + ) + + def test_rejects_conflicting_evaluation_modes(adapter): client = initialize(adapter) response = client.post( From 717d352932d3c8051aca59ba9c71bb4ffa8a3b79 Mon Sep 17 00:00:00 2001 From: Anders Asheim Hennum Date: Mon, 9 Nov 2026 09:35:18 +0100 Subject: [PATCH 2/3] ci(compliance): run harness 1.28.0 Move the SDK compliance pin from 1.23.0 to 1.28.0, so CI runs the feature_flags_v4 suite and the capture v1 404/429 retry tests. Point the local docker examples at the same image. --- .github/workflows/sdk-compliance.yml | 4 ++-- sdk_compliance_adapter/CONTRIBUTING.md | 2 +- sdk_compliance_adapter/docker-compose.yml | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/sdk-compliance.yml b/.github/workflows/sdk-compliance.yml index 2df4d111c..99cf7aa6c 100644 --- a/.github/workflows/sdk-compliance.yml +++ b/.github/workflows/sdk-compliance.yml @@ -33,7 +33,7 @@ jobs: with: adapter-dockerfile: "sdk_compliance_adapter/Dockerfile" adapter-context: "." - test-harness-version: "1.23.0" + test-harness-version: "1.28.0" continue-on-error: false report-name: "sdk-compliance-report-v0" @@ -43,6 +43,6 @@ jobs: with: adapter-dockerfile: "sdk_compliance_adapter/Dockerfile.v1" adapter-context: "." - test-harness-version: "1.23.0" + test-harness-version: "1.28.0" continue-on-error: false report-name: "sdk-compliance-report-v1" diff --git a/sdk_compliance_adapter/CONTRIBUTING.md b/sdk_compliance_adapter/CONTRIBUTING.md index 3033609b3..8514a342c 100644 --- a/sdk_compliance_adapter/CONTRIBUTING.md +++ b/sdk_compliance_adapter/CONTRIBUTING.md @@ -44,7 +44,7 @@ docker run -d --name sdk-adapter --network test-network -p 8080:8080 posthog-pyt docker run --rm \ --name test-harness \ --network test-network \ - ghcr.io/posthog/sdk-test-harness:1.1.1 \ + ghcr.io/posthog/sdk-test-harness:1.28.0 \ run --adapter-url http://sdk-adapter:8080 --mock-url http://test-harness:8081 # Cleanup diff --git a/sdk_compliance_adapter/docker-compose.yml b/sdk_compliance_adapter/docker-compose.yml index c679f5c4f..dcbd677de 100644 --- a/sdk_compliance_adapter/docker-compose.yml +++ b/sdk_compliance_adapter/docker-compose.yml @@ -23,7 +23,7 @@ services: # Test harness test-harness: - image: ghcr.io/posthog/sdk-test-harness:1.1.1 + image: ghcr.io/posthog/sdk-test-harness:1.28.0 command: ["run", "--adapter-url", "http://sdk-adapter:8080", "--mock-url", "http://test-harness:8081"] networks: - test-network From 1f710f080f0fda6feeca6cdf230a46651aee534a Mon Sep 17 00:00:00 2001 From: Anders Asheim Hennum Date: Mon, 9 Nov 2026 14:02:40 +0100 Subject: [PATCH 3/3] fix(compliance): honor only_evaluate_locally on the payload route The harness contract gives /get_feature_flag_payload the same fields as /get_feature_flag. The route ignored only_evaluate_locally and always read remotely. It now selects the client and evaluation mode the same way as /get_feature_flag, and rejects only_evaluate_locally with force_remote. --- sdk_compliance_adapter/README.md | 2 +- sdk_compliance_adapter/adapter.py | 15 ++++++++++--- sdk_compliance_adapter/test_adapter.py | 29 ++++++++++++++++++++++++-- 3 files changed, 40 insertions(+), 6 deletions(-) diff --git a/sdk_compliance_adapter/README.md b/sdk_compliance_adapter/README.md index 79285792d..b35a0b1f7 100644 --- a/sdk_compliance_adapter/README.md +++ b/sdk_compliance_adapter/README.md @@ -25,7 +25,7 @@ The adapter implements the standard SDK adapter interface defined in the [test h - `POST /flush` - Flush pending events - `GET /state` - Return internal state - `POST /get_feature_flag` - Evaluate a flag locally or remotely -- `POST /get_feature_flag_payload` - Read a flag payload remotely with the legacy payload accessor +- `POST /get_feature_flag_payload` - Read a flag payload locally or remotely with the legacy payload accessor - `POST /reload_feature_flag_definitions` - Fresh, bounded definitions readiness barrier - `POST /reset` - Reset SDK state diff --git a/sdk_compliance_adapter/adapter.py b/sdk_compliance_adapter/adapter.py index 1e197d758..4dd0c25b3 100644 --- a/sdk_compliance_adapter/adapter.py +++ b/sdk_compliance_adapter/adapter.py @@ -714,14 +714,23 @@ def get_feature_flag(): @app.route("/get_feature_flag_payload", methods=["POST"]) def get_feature_flag_payload(): - """Read a flag's payload with the legacy payload accessor (remote evaluation).""" + """Read a flag's payload with the legacy payload accessor. + + Takes the same evaluation modes as /get_feature_flag; remote by default. + """ try: if not state.client: return jsonify({"error": "SDK not initialized"}), 400 data = request.json or {} + only_evaluate_locally = data.get("only_evaluate_locally", False) + force_remote = data.get("force_remote", not only_evaluate_locally) + if only_evaluate_locally and force_remote: + return jsonify( + {"error": "only_evaluate_locally conflicts with force_remote"} + ), 400 if not data.get("key") or not data.get("distinct_id"): return jsonify({"error": "key and distinct_id are required"}), 400 - client = state.remote_client or state.client + client = (state.remote_client or state.client) if force_remote else state.client payload = client.get_feature_flag_payload( data["key"], data["distinct_id"], @@ -729,7 +738,7 @@ def get_feature_flag_payload(): groups=data.get("groups"), group_properties=data.get("group_properties"), disable_geoip=data.get("disable_geoip"), - only_evaluate_locally=False, + only_evaluate_locally=not force_remote, ) client.flush() return jsonify({"success": True, "value": payload}) diff --git a/sdk_compliance_adapter/test_adapter.py b/sdk_compliance_adapter/test_adapter.py index 514963aa9..8867b6ae9 100644 --- a/sdk_compliance_adapter/test_adapter.py +++ b/sdk_compliance_adapter/test_adapter.py @@ -206,10 +206,35 @@ def test_payload_route_reads_remotely_and_returns_the_parsed_payload( ) -def test_rejects_conflicting_evaluation_modes(adapter): +def test_payload_route_honors_local_only_evaluation(adapter, monkeypatch): client = initialize(adapter) + local = definitions() + local["flags"][0]["filters"]["payloads"] = {"true": '{"columns": 2}'} + monkeypatch.setattr( + posthog.client, "get", Mock(return_value=GetResponse(data=local)) + ) + client.post("/reload_feature_flag_definitions", json={}) + remote = Mock(side_effect=AssertionError("Local-only must never request /flags")) + monkeypatch.setattr(adapter.state.client, "_get_flags_decision", remote) + monkeypatch.setattr(adapter.state.remote_client, "_get_flags_decision", remote) response = client.post( - "/get_feature_flag", + "/get_feature_flag_payload", + json={ + "key": "flag", + "distinct_id": "user", + "person_properties": {"plan": "banana"}, + "only_evaluate_locally": True, + }, + ) + assert response.json == {"success": True, "value": {"columns": 2}} + remote.assert_not_called() + + +@pytest.mark.parametrize("route", ["/get_feature_flag", "/get_feature_flag_payload"]) +def test_rejects_conflicting_evaluation_modes(adapter, route): + client = initialize(adapter) + response = client.post( + route, json={ "key": "flag", "distinct_id": "user",