A unit test for your production experiment.
On every pull request, a real, throwaway Flagsmith boots in CI, runs your app's own tests against the change, and becomes the merge oracle: if your experiment stops counting users, the pull request fails and names the line.
Your coding agent renamed checkout_completed. Your tests passed. Headcount didn't.
Every Flagsmith user
headcount lint, about one second, no tests, no Docker, no Flagsmith, catches 9 of 13.Teams with end-to-end tests
The full check, real Flagsmith in CI, catches 13 of 13 and names the line.
- uses: ayushagarwalhere/headcount/action@v1
with:
experiment: .headcount/experiment.json
test-command: npx playwright testWhat only Headcount does
Names the broken line.
Not just a red check: the file and line that stopped the count, such as
public/app.mjs:68.Suggests the fix.
A one-click suggestion on the pull request. The author clicks Commit suggestion and the experiment counts again.
Catches dashboard drift.
A rollout change made in Flagsmith becomes a pull request against the committed experiment file, which Headcount then checks. Experiments as code, both ways.
Watch it count
FAIL
control: 29 exposures counted of 29 sent, 0 of 23 Checkout Completion counted.
Cause The event name does not match the metric exactly public/lib/store.mjs:5
- Stock pipeline
- unit tests pass / dashboard running
- Headcount
- Fails the PR
- Boot to verdict
- 45.2 s
- Tracers
- 52
Lab run of the Kiln & Co. sample against Flagsmith 2.295.2 with synthetic tracer identities, recorded by node faults/bench.mjs.
That case's data could not be read. The table below still has its row.
How it works
- 1
Boot
Pinned open-source Flagsmith 2.295.2 from one compose file.
docker compose
- 2
Recreate
Your committed export, rebuilt through the Admin API and started.
POST …/experiments/ · …/start/
- 3
Drive tracers
Your own tests, as hc-‹run›-‹n› identities, 15 per arm by default.
POST /api/v1/identities/ · /api/v1/events
- 4
Refresh
Exposures refresh and results refresh, once.
…/exposures/refresh/ · …/results/refresh/
- 5
Judge
Four checks, each a number Flagsmith returned against a number Headcount sent.
GET …/exposures/ · …/results/
Proof · planted-fault benchmark
Each row is one small pull request against the Kiln & Co. sample, run through the stock pipeline and through Headcount. Rows come from node faults/bench.mjs; synthetic tracer identities against a throwaway Flagsmith.
| Wheel | Planted pull request | Cause it plants | Path | Stock pipeline | Lint (static) | Headcount | Cause named | Boot to verdict |
|---|---|---|---|---|---|---|---|---|
| No change (baseline) | none | browser | unit tests pass / dashboard running | clean | PASSES | none | 55.9 s | |
| No change (baseline), checkout API | none | server, local eval | unit tests pass / dashboard running | clean | PASSES | none | 40.4 s | |
| Use camelCase for analytics event names #1 | Event names match your metrics exactly, including case. | browser | unit tests pass / dashboard running | error: event-name | FAILS THE PR | The event name does not match the metric exactly | 45.2 s | |
| Report PayPal orders with their own completion event #2 | Event names match your metrics exactly, including case (here in one arm only). | browser | unit tests pass / dashboard running | error: event-name | FAILS THE PR | The event name does not match the metric exactly | 49.5 s | |
| Forget the shopper as soon as the order is placed #3 | The user is identified. | browser | unit tests pass / dashboard running | error: unidentified | FAILS THE PR | The user is not identified | 45.3 s | |
| Identify the shopper lazily, at checkout #4 | The user is identified (before the experiment flag is read). | browser | unit tests pass / dashboard running | error: identified-late | FAILS THE PR | The user is identified after the flag lookup | 44.9 s | |
| Re-export the experiment after the variation was recreated through the API #5 | Every variation of the flag has a label. | browser | unit tests pass / dashboard running | error: unkeyed-variation | FAILS THE PR | A variation has no key | 48.2 s | |
| Rename the country trait to shipping_country #6 | The identity is inside the experiment's rollout (and its audience). | browser | unit tests pass / dashboard running | error: outside-rollout | FAILS THE PR | The identity is outside the rollout or the audience | 59.3 s | |
| Let the SDK batch events on its own timer #7 | Buffered events were sent before your application exited. | browser | unit tests pass / dashboard running | error: not-flushed | FAILS THE PR | Events were still buffered when the app exited | 1 min 30 s | |
| Record the conversion on the server, where ad blockers cannot drop it #8 | Event timestamps are within the accepted window. | browser | unit tests pass / dashboard running | error: timestamp | FAILS THE PR | Event timestamps are outside the accepted window | 1 min 11 s | |
| Attach the receipt image to checkout_completed for the analytics team #9 | A batch over 2 MiB is rejected whole. | browser | unit tests pass / dashboard running | error: batch-size | FAILS THE PR | An event batch is over 2 MiB | 2 min 02 s | |
| Read server-side analytics event names from the tracking plan file #10 | Event names match your metrics exactly, including case (the name is read from a JSON file at run time). | server, local eval | unit tests pass / dashboard running | clean | FAILS THE PR | The event name does not match the metric exactly | 39.3 s | |
| Batch server events every five minutes and flush them in one exit hook #11 | Buffered events were sent before your application exited (close() is called, on a path the process never takes). | server, local eval | unit tests pass / dashboard running | clean | FAILS THE PR | Events were still buffered when the app exited | 29.9 s | |
| Quote shipping on the checkout options, with country codes in lower case #12 | The identity is inside the experiment's rollout (and its audience): the trait is set, with a value the segment does not match. | server, local eval | unit tests pass / dashboard running | clean | FAILS THE PR | The identity is outside the rollout or the audience | 38.9 s | |
| Create Flagsmith identities only for shoppers who place an order #13 | The user is identified (before the experiment flag is read; here identify() moved to another module). | browser | unit tests pass / dashboard running | clean | FAILS THE PR | The user is identified after the flag lookup | 44.3 s | |
| Wait for consent before identifying shoppers in Germany #14 | Not catchable here: the tests only ship to GB, so the broken path never runs in CI. | browser | unit tests pass / dashboard running | warning only: unidentified | PASSES | none | 57.5 s |
- Cause it plants
- none
- Path
- browser
- Stock pipeline
- unit tests pass / dashboard running
- Lint (static)
- clean
- Headcount
- PASSES
- Cause named
- none
- Boot to verdict
- 55.9 s
- Cause it plants
- none
- Path
- server, local eval
- Stock pipeline
- unit tests pass / dashboard running
- Lint (static)
- clean
- Headcount
- PASSES
- Cause named
- none
- Boot to verdict
- 40.4 s
- Cause it plants
- Event names match your metrics exactly, including case.
- Path
- browser
- Stock pipeline
- unit tests pass / dashboard running
- Lint (static)
- error: event-name
- Headcount
- FAILS THE PR
- Cause named
- The event name does not match the metric exactly
- Boot to verdict
- 45.2 s
- Cause it plants
- Event names match your metrics exactly, including case (here in one arm only).
- Path
- browser
- Stock pipeline
- unit tests pass / dashboard running
- Lint (static)
- error: event-name
- Headcount
- FAILS THE PR
- Cause named
- The event name does not match the metric exactly
- Boot to verdict
- 49.5 s
- Cause it plants
- The user is identified.
- Path
- browser
- Stock pipeline
- unit tests pass / dashboard running
- Lint (static)
- error: unidentified
- Headcount
- FAILS THE PR
- Cause named
- The user is not identified
- Boot to verdict
- 45.3 s
- Cause it plants
- The user is identified (before the experiment flag is read).
- Path
- browser
- Stock pipeline
- unit tests pass / dashboard running
- Lint (static)
- error: identified-late
- Headcount
- FAILS THE PR
- Cause named
- The user is identified after the flag lookup
- Boot to verdict
- 44.9 s
- Cause it plants
- Every variation of the flag has a label.
- Path
- browser
- Stock pipeline
- unit tests pass / dashboard running
- Lint (static)
- error: unkeyed-variation
- Headcount
- FAILS THE PR
- Cause named
- A variation has no key
- Boot to verdict
- 48.2 s
- Cause it plants
- The identity is inside the experiment's rollout (and its audience).
- Path
- browser
- Stock pipeline
- unit tests pass / dashboard running
- Lint (static)
- error: outside-rollout
- Headcount
- FAILS THE PR
- Cause named
- The identity is outside the rollout or the audience
- Boot to verdict
- 59.3 s
- Cause it plants
- Buffered events were sent before your application exited.
- Path
- browser
- Stock pipeline
- unit tests pass / dashboard running
- Lint (static)
- error: not-flushed
- Headcount
- FAILS THE PR
- Cause named
- Events were still buffered when the app exited
- Boot to verdict
- 1 min 30 s
- Cause it plants
- Event timestamps are within the accepted window.
- Path
- browser
- Stock pipeline
- unit tests pass / dashboard running
- Lint (static)
- error: timestamp
- Headcount
- FAILS THE PR
- Cause named
- Event timestamps are outside the accepted window
- Boot to verdict
- 1 min 11 s
- Cause it plants
- A batch over 2 MiB is rejected whole.
- Path
- browser
- Stock pipeline
- unit tests pass / dashboard running
- Lint (static)
- error: batch-size
- Headcount
- FAILS THE PR
- Cause named
- An event batch is over 2 MiB
- Boot to verdict
- 2 min 02 s
- Cause it plants
- Event names match your metrics exactly, including case (the name is read from a JSON file at run time).
- Path
- server, local eval
- Stock pipeline
- unit tests pass / dashboard running
- Lint (static)
- clean
- Headcount
- FAILS THE PR
- Cause named
- The event name does not match the metric exactly
- Boot to verdict
- 39.3 s
- Cause it plants
- Buffered events were sent before your application exited (close() is called, on a path the process never takes).
- Path
- server, local eval
- Stock pipeline
- unit tests pass / dashboard running
- Lint (static)
- clean
- Headcount
- FAILS THE PR
- Cause named
- Events were still buffered when the app exited
- Boot to verdict
- 29.9 s
- Cause it plants
- The identity is inside the experiment's rollout (and its audience): the trait is set, with a value the segment does not match.
- Path
- server, local eval
- Stock pipeline
- unit tests pass / dashboard running
- Lint (static)
- clean
- Headcount
- FAILS THE PR
- Cause named
- The identity is outside the rollout or the audience
- Boot to verdict
- 38.9 s
- Cause it plants
- The user is identified (before the experiment flag is read; here identify() moved to another module).
- Path
- browser
- Stock pipeline
- unit tests pass / dashboard running
- Lint (static)
- clean
- Headcount
- FAILS THE PR
- Cause named
- The user is identified after the flag lookup
- Boot to verdict
- 44.3 s
- Cause it plants
- Not catchable here: the tests only ship to GB, so the broken path never runs in CI.
- Path
- browser
- Stock pipeline
- unit tests pass / dashboard running
- Lint (static)
- warning only: unidentified
- Headcount
- PASSES
- Cause named
- none
- Boot to verdict
- 57.5 s
Planted faults with a cause from the list: 13.
Stock pipeline caught before merge: 0 of 13.
Lint (static, no Flagsmith) failed the pull request: 9 of 13.
Headcount failed the pull request: 13 of 13; named the planted cause: 13 of 13.
Reading the wheel
- Incised ticks
- One per tracer Headcount sent into that arm. Cut into the clay: Headcount's own record.
- Glaze
- One stroke per ring, as long as the count Flagsmith returned for that arm. Flagsmith reports counts per arm, not per tracer.
- Brass pin
- Where the glaze should stop: what was sent. A green cap means that check passed.
- Red hatch and flag
- Sent, but not counted. The check failed for that arm.
- Grey hatch
- Unfinished journeys, accepted either way, or a value Flagsmith did not return: no reading, never a zero.
- Tray
- Chips for tracers Flagsmith quarantined because they saw more than one arm.
Limits
- Sample ratio is reported, never asserted. Flagsmith leaves
srm_p_valueempty for experiments with a rollout (upstream Flagsmith/flagsmith#8798), so the row is informational. - Only what your tests reach. A fault on a path the tests never take cannot fail the check. The consent-gate case shows it: the tests ship to GB only, so Germany's broken path never runs in CI, and Headcount passes it.
- Causes that only show in production, such as an ad blocker or a real traffic mix, are outside a CI check.
Set it up
Export the experiment once with headcount export; the admin credential stays on your machine. headcount export --check exits 1 when the live experiment has drifted from the committed file. Locally, the same check runs with node bin/headcount.mjs run --test-command "npx playwright test". GitLab: include gitlab/headcount.gitlab-ci.yml.
headcount lint is a static pre-flight that reads the source and the experiment file, with no Docker and no Flagsmith, and annotates the pull request before the full check has booted. It is a first opinion; the full run is the verdict. Measured by node faults/lint-bench.mjs: Lint flagged 9 of 13 (at error level, failing the lint step: 9 of 13); named the planted cause: 9 of 13. Findings on the unchanged baseline (false positives): 0.
| Input | Default | What it does |
|---|---|---|
test-command | none | Command that runs the tracer journey spec (for example npx playwright test tests/e2e/checkout.spec.mjs). Not needed with the http driver. |
experiment | .headcount/experiment.json | Path to the committed experiment export. |
working-directory | . | Directory of the app under test. |
driver | tests | tests (default) runs test-command; http repeats .headcount/journey.json against a service. |
min-per-arm | 15 | Tracer identities per arm. 15 is enough for the verdict, which reads Flagsmith's per-arm counts. |
full-results | false | true sends 60 tracers per arm (above Flagsmith's 50-identity floor) so the summary also shows lift and chance to win. |
workers | 2 | Parallel test workers. |
port | 8300 | Host port for the throwaway Flagsmith (the recording proxy uses port + 1). |
cache-image | true | Cache the pre-migrated Flagsmith database image between runs. |
artifact-name | none | Name for the uploaded run record. Set it per matrix leg if the Action runs more than once in one job name. |
base | none | Git ref the pull request is compared with, for file and line in causes. Defaults to the PR base branch. |
lint | true | true (default) runs headcount lint first, a static pre-flight that annotates the PR in seconds while the full check runs; its findings do not decide the job. only runs lint alone (no Docker; the job fails on lint errors). false skips it. |
lint-src | none | Comma-separated folders or files lint reads (default everything except node_modules, tests and build output). |
lint-sarif | none | A path (for example headcount-lint.sarif) where lint also writes its findings as SARIF 2.1.0, for github/codeql-action/upload-sarif. Empty (default) writes none. See docs/lint-quickstart.md. |
dashboard-screenshot | true | true (default) screenshots Flagsmith's own results page for the experiment before teardown (flagsmith-results.png in the report artifact), using the app's Playwright; skipped with a note when Playwright is not installed. Never changes the verdict. false skips it. |
flagsmith-patches | none | srm boots the pinned Flagsmith with one patched file mounted (a draft upstream fix), so Flagsmith returns srm_p_value and the sample-ratio row becomes a fifth check that fails below 0.001. Runs at least 120 tracers. Empty (default) runs stock Flagsmith, where that row is informational. |
weekly-traffic | none | Users a week who reach the code that reads the experiment's flag in production and match its audience segment, if it has one (for example 4000). On a red check the summary then says about how many users a week in each failing arm would go uncounted: this number x the committed rollout x the arm's split x the share the tracer run lost. Empty (default) adds no line. A value that is not a positive number adds a note and no line; it never fails the job. See docs/impact.md. |
suggestions | true | true (default) posts a one-click fix (a review comment with a suggestion block) when a cause sits on a line the pull request added and the fix is an exact edit of that line; pull_request events only. Needs permissions: pull-requests: write; without it the fix is still shown in the job summary. false turns it off. |
pr-comment | true | true (default) keeps one comment in the pull request conversation with the verdict (headline, cause with a link to the line, impact, per-variant counts, a link to the run), edited in place on every run; one comment per job leg, keyed on artifact-name. pull_request events only. Needs permissions: pull-requests: write; without it a note goes in the job summary and the job is unaffected. false turns it off. |
github-token | ${{ github.token }} | Token for posting suggestion review comments and the pull request comment. |
How this differs from Flagsmith's sdk-spec
Flagsmith's sdk-spec also boots Flagsmith in CI and seeds it through the Admin API, to test that the SDKs behave. Headcount tests that your app, after this pull request, still produces events the engine counts for your experiment, and it reads the exposures and results endpoints to say so.