|
| 1 | +# PostHog Elixir SDK Compliance Adapter |
| 2 | + |
| 3 | +This adapter wraps the posthog-elixir SDK for compliance testing with the [PostHog SDK Test Harness](https://github.com/PostHog/posthog-sdk-test-harness). |
| 4 | + |
| 5 | +## Running Tests |
| 6 | + |
| 7 | +Tests run automatically in CI via GitHub Actions. See the test harness repo for details. |
| 8 | + |
| 9 | +### Locally with Docker Compose |
| 10 | + |
| 11 | +```bash |
| 12 | +# From the posthog-elixir/sdk_compliance_adapter directory |
| 13 | +docker-compose up --build --abort-on-container-exit |
| 14 | +``` |
| 15 | + |
| 16 | +This will: |
| 17 | + |
| 18 | +1. Build the Elixir SDK adapter |
| 19 | +2. Pull the test harness image |
| 20 | +3. Run all compliance tests |
| 21 | +4. Show results |
| 22 | + |
| 23 | +### Manually with Docker |
| 24 | + |
| 25 | +```bash |
| 26 | +# Create network |
| 27 | +docker network create test-network |
| 28 | + |
| 29 | +# Build and run adapter |
| 30 | +docker build -f sdk_compliance_adapter/Dockerfile -t posthog-elixir-adapter . |
| 31 | +docker run -d --name sdk-adapter --network test-network -p 8080:8080 posthog-elixir-adapter |
| 32 | + |
| 33 | +# Run test harness |
| 34 | +docker run --rm \ |
| 35 | + --name test-harness \ |
| 36 | + --network test-network \ |
| 37 | + ghcr.io/posthog/sdk-test-harness:latest \ |
| 38 | + run --adapter-url http://sdk-adapter:8080 --mock-url http://test-harness:8081 |
| 39 | + |
| 40 | +# Cleanup |
| 41 | +docker stop sdk-adapter && docker rm sdk-adapter |
| 42 | +docker network rm test-network |
| 43 | +``` |
| 44 | + |
| 45 | +## Implementation |
| 46 | + |
| 47 | +See [lib/sdk_compliance_adapter/](lib/sdk_compliance_adapter/) for the adapter implementation. |
| 48 | + |
| 49 | +The adapter implements the standard SDK adapter interface defined in the [test harness CONTRACT](https://github.com/PostHog/posthog-sdk-test-harness/blob/main/CONTRACT.yaml). |
| 50 | + |
| 51 | +### Architecture |
| 52 | + |
| 53 | +The adapter is a standalone Elixir application that: |
| 54 | + |
| 55 | +1. Starts an HTTP server (using Plug/Cowboy) on port 8080 |
| 56 | +2. Dynamically starts/stops the PostHog SDK based on `/init` and `/reset` requests |
| 57 | +3. Uses a custom `TrackedClient` to intercept HTTP requests and track them for assertions |
| 58 | +4. Maintains state (events captured, sent, retries, etc.) for the test harness to query |
| 59 | + |
| 60 | +### Endpoints |
| 61 | + |
| 62 | +- `GET /health` - Health check, returns SDK name/version |
| 63 | +- `POST /init` - Initialize SDK with configuration |
| 64 | +- `POST /capture` - Capture a single event |
| 65 | +- `POST /flush` - Flush pending events |
| 66 | +- `GET /state` - Get internal state for test assertions |
| 67 | +- `POST /reset` - Reset SDK state |
| 68 | + |
| 69 | +## Documentation |
| 70 | + |
| 71 | +For complete documentation, see: |
| 72 | + |
| 73 | +- [PostHog SDK Test Harness](https://github.com/PostHog/posthog-sdk-test-harness) |
| 74 | +- [Adapter Implementation Guide](https://github.com/PostHog/posthog-sdk-test-harness/blob/main/ADAPTER_GUIDE.md) |
0 commit comments