CASE STUDY –- OPEN SOURCE PRODUCT ANALYTICS

Case study: PostHog Analytics

Kerno indexed PostHog's Django REST codebase and analysed all 2,386 endpoints in under 10 minutes. It then launched a PostHog environment with its real dependencies, including Kafka, ZooKeeper and Postgres, and generated white-box tests against two endpoints.
COPY SETUP PROMPT
Get started for free | Works with your AI stack
COMPANY
PostHog
LANGAUGE
Python 3.11+
FRAMEWORK
Django REST
LINES OF CODE
6.4M
ENDPOINTS
2, 386
ABOUT POSTHOG

What is PostHog

PostHog is an open-source product analytics platform built for engineers and technical product teams. It bundles product analytics, session replay, feature flags, experimentation, surveys, error tracking, LLM observability and a built-in data warehouse into a single product.

The API is large: 2,386 endpoints, with authorization, billing gates and multi-tenant scoping present in most read paths. Testing it accurately requires access to the data layer, not only the route.
KERNO SETUP

What Kerno did

Full Codebase Indexation

Kerno indexed the PostHog codebase and completed endpoint analysis across all 2,386 routes. This index is the foundation for test generation

Live Environment

A PostHog environment was launched with access to its real dependencies, including Kafka, ZooKeeper and Postgres. Tests therefore run against the same behaviour as production

Data Layer Control

Kerno handles the data layer itself. It seeds tenants, reads rows back and cleans up afterwards, so it can create high fidelity tests and runtime scenarios that mimic production.

Baseline Test

Kerno generated, executed and verified baseline tests on two endpoints, covering validation and security scenarios.

Verified execution

Kerno verified the execution of the tests through a two implementation strategy, running each scenario twice to confirm the result. It produced reusable artifacts, so these tests persist if the baseline moves.

OVERVIEW

Results

ABOUT POSTHOG

2,386

CODEBASE INDEXING TIME

<10 mins

TEST SCENARIOS CREATED

16

ENDPOINTS TESTED

2

Two endpoints were taken end to end as an experiment. The first is a read path guarded by multi-tenant RBAC. The second is a write path with payload validation. Both were run at medium effort, white_box access, intent [validation, security].
EXPERIMENT -- ENDPOINT 1

GET/api/0/organizations/{organization_id_or_slug}/projects/

What the endpoint does

It lists the projects inside one organisation, but only the ones the caller is allowed to see. PostHog starts from every project, then narrows the list to the teams the user is a member of. That filter is the real permission check, so getting it wrong would leak another company's projects.

If the caller used a scoped API key or OAuth token, the list is narrowed again to the organisations that key is scoped to. The response uses a lighter serializer that also copies a few fields from each project's team record for backward compatibility.

Access Control

Caller must be signed in, hold the project:read scope, and be on a plan that allows multiple projects. Six auth methods are accepted, and role-based rules are checked per project before anything is returned.

Postgres Tables

Read-only, across seven tables: the organisation and its memberships, teams and projects, the API key or OAuth token used, and the access control rules. Team membership is where the real permission decision is made.

Side Effects

None. Nothing is written and no events are fired, so the risk here is leakage rather than corruption.
EXPERIMENT -- ENDPOINT 2

POST/api/projects/{project_id}/feature_flags/

What the endpoint does

It creates a feature flag in one project. PostHog first checks the whole payload is valid: the flag key, its release conditions, any multivariate split and payloads, tags and the dashboards it should link to.

It then stamps the record with who created it, which project it belongs to and version 1, fills in default release conditions, and encrypts payload values if the flag is set up to hold secrets.

Key reuse is handled carefully. A key still held by a deleted flag is freed, and a genuine duplicate returns a clear validation error rather than a database crash.Once the flag is saved, PostHog does the follow-up work: attaching tags and evaluation contexts, creating a usage dashboard by default, linking any analytics dashboards, and recording that a flag was created.

Access Control

Caller must be signed in, hold the feature_flag:write scope, and pass role-based and project membership checks. Six auth methods are accepted, with rate limits per key type.

Postgres Tables

One request can write to eleven tables: the flag itself, tags, evaluation contexts, dashboard links, a usage dashboard with its tiles and insights, the sidebar index and the activity log. It reads teams, cohorts, experiments, properties and early access features while validating.

Encryption and Side Effects

Secret payloads are encrypted before saving, a usage telemetry event is sent, and writes are attributed correctly when an admin is impersonating a user.
VERDICT

Claude’s Review of Kerno

The Bottom Line

Kerno delivers real value for a specific job: characterizing untested endpoints and locking their observed contract, including the error shapes and authz behaviour people forget, as a regression net. In this case it added meaningful coverage to endpoints that had zero tests, and the generated code is high quality and honest about what it is asserting.It creates a feature flag in one project. PostHog first checks the whole payload is valid: the flag key, its release conditions, any multivariate split and payloads, tags and the dashboards it should link to.

The framing of working purely from the codebase oversells the autonomy. The interesting truth of a running system lives in the environment, not the repo, and Kerno needs a knowledgeable operator to hand it that truth. Think of it as a very good, reality-grounded test writer that needs a well-briefed pairing partner rather than a fire-and-forget generator. Used selectively, on important endpoints, with a human reviewing actual against intended, it is worth the setup.
COPY SETUP PROMPT
Install in 5 mins | No credit card required