Skip to content

Conversation

@jose-sequeira
Copy link

@jose-sequeira jose-sequeira commented Jan 2, 2026

💡 Motivation and Context

We need a language-agnostic way to verify that all PostHog SDKs implement the capture API correctly. The SDK Test Harness provides a shared contract and test runner. This PR integrates it into this SDK.

This adds:

  • An SDK adapter that wraps this SDK and exposes the standard REST interface for the test harness
  • A CI workflow that runs compliance tests on every PR and push to the default branch
  • A Dockerfile for running the adapter in the test harness environment

The test harness runs a mock PostHog server, exercises the SDK through the adapter, and verifies behavior matches the contract defined in CONTRACT.yaml (event format, retries, compression, deduplication, etc.).

#skip-changelog

💚 How did you test it?

The compliance tests run as part of this PR's CI. The adapter was also tested locally via docker-compose.

📝 Checklist

  • I reviewed the submitted code.
  • I added tests to verify the changes.
  • I updated the docs if needed.
  • No breaking change or entry added to the changelog.
  • If there are related changes in the core package, I've already released them, or I'll release them before this one.

@github-actions
Copy link

github-actions bot commented Jan 28, 2026

posthog-android Compliance Report

Date: 2026-01-28 11:01:29 UTC
Duration: 147105ms

⚠️ Some Tests Failed

18/29 tests passed, 11 failed


Capture Tests

⚠️ 18/29 tests passed, 11 failed

View Details
Test Status Duration
Format Validation.Event Has Required Fields 2358ms
Format Validation.Event Has Uuid 2023ms
Format Validation.Event Has Lib Properties 2023ms
Format Validation.Distinct Id Is String 2020ms
Format Validation.Token Is Present 2020ms
Format Validation.Custom Properties Preserved 2020ms
Format Validation.Event Has Timestamp 2024ms
Retry Behavior.Retries On 503 7027ms
Retry Behavior.Does Not Retry On 400 4024ms
Retry Behavior.Does Not Retry On 401 4022ms
Retry Behavior.Respects Retry After Header 7023ms
Retry Behavior.Implements Backoff 17022ms
Retry Behavior.Retries On 500 7026ms
Retry Behavior.Retries On 502 7023ms
Retry Behavior.Retries On 504 7027ms
Retry Behavior.Max Retries Respected 17023ms
Deduplication.Generates Unique Uuids 2041ms
Deduplication.Preserves Uuid On Retry 7023ms
Deduplication.Preserves Uuid And Timestamp On Retry 12032ms
Deduplication.Preserves Uuid And Timestamp On Batch Retry 7032ms
Deduplication.No Duplicate Events In Batch 2029ms
Deduplication.Different Events Have Different Uuids 2020ms
Compression.Sends Gzip When Enabled 2016ms
Batch Format.Uses Proper Batch Structure 2017ms
Batch Format.Flush With No Events Sends Nothing 2012ms
Batch Format.Multiple Events Batched Together 2027ms
Error Handling.Does Not Retry On 403 4021ms
Error Handling.Does Not Retry On 413 4020ms
Error Handling.Retries On 408 7019ms

Failures

retry_behavior.retries_on_503

Expected at least 3 requests, got 1

retry_behavior.respects_retry_after_header

Expected at least 2 requests, got 1

retry_behavior.implements_backoff

Expected at least 3 requests, got 1

retry_behavior.retries_on_500

Expected at least 2 requests, got 1

retry_behavior.retries_on_502

Expected at least 2 requests, got 1

retry_behavior.retries_on_504

Expected at least 2 requests, got 1

retry_behavior.max_retries_respected

Expected 4 requests, got 1

deduplication.preserves_uuid_on_retry

Need at least 2 requests to check retry

deduplication.preserves_uuid_and_timestamp_on_retry

Expected at least 3 requests, got 1

deduplication.preserves_uuid_and_timestamp_on_batch_retry

Expected at least 2 requests, got 1

error_handling.does_not_retry_on_413

Expected 1 requests, got 2

@PostHog PostHog deleted a comment from github-actions bot Jan 28, 2026
@jose-sequeira jose-sequeira marked this pull request as ready for review January 28, 2026 13:42
@jose-sequeira jose-sequeira requested a review from a team as a code owner January 28, 2026 13:42
Comment on lines +5 to +11
branches: [ main, master ]
paths:
- 'posthog/**'
- 'sdk_compliance_adapter/**'
- '.github/workflows/sdk-compliance-tests.yml'
pull_request:
branches: [ main, master ]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
branches: [ main, master ]
paths:
- 'posthog/**'
- 'sdk_compliance_adapter/**'
- '.github/workflows/sdk-compliance-tests.yml'
pull_request:
branches: [ main, master ]
branches: [ main ]
paths:
- 'posthog/**'
- 'sdk_compliance_adapter/**'
- '.github/workflows/sdk-compliance-tests.yml'
pull_request:
branches: [ main ]

we dont have master

* Default: `null` (SDK creates its own client).
*/
@PostHogInternal
public var httpClient: okhttp3.OkHttpClient? = null
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public var httpClient: okhttp3.OkHttpClient? = null
public var httpClient: OkHttpClient? = null

then just import okhttp3.OkHttpClient

* @property config The Config
*/
internal class GzipRequestInterceptor(private val config: PostHogConfig) : Interceptor {
public class GzipRequestInterceptor(private val config: PostHogConfig) : Interceptor {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public class GzipRequestInterceptor(private val config: PostHogConfig) : Interceptor {
internal class GzipRequestInterceptor(private val config: PostHogConfig) : Interceptor {

we can revert this i assume? and run make api again

Comment on lines +147 to +148
println("[ADAPTER] Error parsing request body: ${e.message}")
e.printStackTrace()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think we can clear all println and printStackTrace?

@marandaneto
Copy link
Member

i can see the tests:

Total: 29 | 18 passed | 11 failed | Duration: 147105ms

11 test(s) failed

but CI didnt fail, is that expected @jose-sequeira ?

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.

3 participants