Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

1.7 KB
Raw Blame

Testing

First, make sure docker compose is running (from main posthog repo), and test database exists:

docker compose -f ../docker-compose.dev.yml up -d
TEST=1 python manage.py setup_test_environment --only-postgres

We only need to run the above once, when the test database is created.

TODO: Would be nice to make the above automatic.

Then, run the tests:

cargo test --package feature-flags

To run against other databases, for example from a second checkout, set TEST_DATABASE_URL, TEST_PERSONS_DATABASE_URL and TEST_REDIS_URL; unset, they default to test_posthog, posthog_persons and Redis database 0 on localhost. Keep TEST_REDIS_URL off Redis database 1, which the dedicated flags cache tests use.

To watch changes

brew install cargo-watch

and then run:

cargo watch -x test --package feature-flags

To run a specific test:

cargo watch -x "test --package feature-flags --lib -- property_matching::tests::test_match_properties_math_operators --exact --show-output"

Running

RUST_LOG=debug cargo run --bin feature-flags

Format code

cargo fmt --package feature-flags

Trying a PR against live traffic

Members of team-feature-flags can comment /pr-canary on an approved PR authored by an active PostHog organization member to build the feature-flags image from the PR head and route a share of traffic to it. The default target is dev. /pr-canary help lists the weight= and env= options. Send a request with the X-PostHog-Fleet: canary header to reach the canary pods, or X-PostHog-Fleet: stable to skip them. The canary stops when the PR closes, or after 48 hours.