flagcov 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. flagcov-0.1.0/.github/workflows/ci.yml +52 -0
  2. flagcov-0.1.0/.github/workflows/dogfood-flagsmith.yml +79 -0
  3. flagcov-0.1.0/.github/workflows/release.yml +23 -0
  4. flagcov-0.1.0/.github/workflows/selfhosted-e2e.yml +81 -0
  5. flagcov-0.1.0/.gitignore +12 -0
  6. flagcov-0.1.0/LICENSE +21 -0
  7. flagcov-0.1.0/PKG-INFO +248 -0
  8. flagcov-0.1.0/README.md +221 -0
  9. flagcov-0.1.0/action.yml +128 -0
  10. flagcov-0.1.0/docs/DEMO.md +116 -0
  11. flagcov-0.1.0/docs/demo.gif +0 -0
  12. flagcov-0.1.0/docs/flagcov-demo.mp4 +0 -0
  13. flagcov-0.1.0/docs/tools/make_gif.py +151 -0
  14. flagcov-0.1.0/docs/tools/make_video.py +574 -0
  15. flagcov-0.1.0/examples/demo_shop/conftest.py +33 -0
  16. flagcov-0.1.0/examples/demo_shop/environment.json +79 -0
  17. flagcov-0.1.0/examples/demo_shop/shop.py +45 -0
  18. flagcov-0.1.0/examples/demo_shop/test_shop.py +29 -0
  19. flagcov-0.1.0/examples/selfhosted/docker-compose.yml +99 -0
  20. flagcov-0.1.0/examples/selfhosted/run.sh +33 -0
  21. flagcov-0.1.0/examples/selfhosted/seed.py +142 -0
  22. flagcov-0.1.0/pyproject.toml +40 -0
  23. flagcov-0.1.0/src/flagcov/__init__.py +9 -0
  24. flagcov-0.1.0/src/flagcov/analyze.py +395 -0
  25. flagcov-0.1.0/src/flagcov/cli.py +115 -0
  26. flagcov-0.1.0/src/flagcov/environment.py +72 -0
  27. flagcov-0.1.0/src/flagcov/override.py +76 -0
  28. flagcov-0.1.0/src/flagcov/pytest_plugin.py +136 -0
  29. flagcov-0.1.0/src/flagcov/recorder.py +184 -0
  30. flagcov-0.1.0/src/flagcov/report.py +201 -0
  31. flagcov-0.1.0/src/flagcov/scan.py +104 -0
  32. flagcov-0.1.0/tests/conftest.py +18 -0
  33. flagcov-0.1.0/tests/test_analyze.py +144 -0
  34. flagcov-0.1.0/tests/test_environment_and_cli.py +118 -0
  35. flagcov-0.1.0/tests/test_flagsmith_sdk.py +46 -0
  36. flagcov-0.1.0/tests/test_plugin.py +113 -0
  37. flagcov-0.1.0/tests/test_report.py +81 -0
  38. flagcov-0.1.0/tests/test_scan.py +83 -0
  39. flagcov-0.1.0/tests/test_states.py +98 -0
@@ -0,0 +1,52 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+
8
+ permissions:
9
+ contents: read
10
+
11
+ jobs:
12
+ test:
13
+ name: Tests (Python ${{ matrix.python }}, ${{ matrix.os }})
14
+ runs-on: ${{ matrix.os }}
15
+ strategy:
16
+ fail-fast: false
17
+ matrix:
18
+ os: [ubuntu-latest]
19
+ python: ["3.10", "3.11", "3.12", "3.13"]
20
+ include:
21
+ - os: windows-latest
22
+ python: "3.13"
23
+ - os: macos-latest
24
+ python: "3.13"
25
+ steps:
26
+ - uses: actions/checkout@v4
27
+ - uses: actions/setup-python@v5
28
+ with:
29
+ python-version: ${{ matrix.python }}
30
+ - run: python -m pip install -e ".[dev]"
31
+ - run: python -m pytest --cov=flagcov --cov-report=term-missing
32
+
33
+ build:
34
+ name: Build package
35
+ runs-on: ubuntu-latest
36
+ steps:
37
+ - uses: actions/checkout@v4
38
+ - uses: actions/setup-python@v5
39
+ with:
40
+ python-version: "3.13"
41
+ - run: python -m pip install build twine
42
+ - run: python -m build
43
+ - run: python -m twine check dist/*
44
+ - name: Install the wheel and run the CLI
45
+ run: |
46
+ python -m pip install dist/*.whl
47
+ flagcov --version
48
+ flagcov report --env examples/demo_shop/environment.json --evaluations none.json --untested-only
49
+ - uses: actions/upload-artifact@v4
50
+ with:
51
+ name: dist
52
+ path: dist/
@@ -0,0 +1,79 @@
1
+ name: Dogfood - FlagCov on Flagsmith's own test suite
2
+
3
+ # Runs a slice of Flagsmith's open-source API test suite (the tests around code
4
+ # that reads flags) with FlagCov, against the environment document Flagsmith
5
+ # commits for its own flags (api/integrations/flagsmith/data/environment.json).
6
+
7
+ on:
8
+ workflow_dispatch:
9
+ schedule:
10
+ - cron: "0 6 * * 1"
11
+ push:
12
+ branches: [main]
13
+ paths: [".github/workflows/dogfood-flagsmith.yml", "src/**"]
14
+
15
+ permissions:
16
+ contents: read
17
+
18
+ jobs:
19
+ flagsmith:
20
+ runs-on: ubuntu-latest
21
+ timeout-minutes: 40
22
+ services:
23
+ postgres:
24
+ image: postgres:15.5-alpine
25
+ env: { POSTGRES_PASSWORD: password, POSTGRES_DB: flagsmith }
26
+ ports: ["5432:5432"]
27
+ options: --health-cmd "pg_isready -U postgres" --health-interval 5s --health-retries 20
28
+ analytics:
29
+ image: postgres:15.5-alpine
30
+ env: { POSTGRES_PASSWORD: password, POSTGRES_DB: analytics }
31
+ ports: ["5433:5432"]
32
+ options: --health-cmd "pg_isready -U postgres" --health-interval 5s --health-retries 20
33
+ defaults:
34
+ run:
35
+ working-directory: flagsmith/api
36
+ env:
37
+ DOTENV_OVERRIDE_FILE: .env-ci
38
+ # Flagsmith's settings only define DATABASES when DATABASE_URL is in the real environment.
39
+ DATABASE_URL: postgresql://postgres:password@localhost:5432/flagsmith
40
+ ANALYTICS_DATABASE_URL: postgresql://postgres:password@localhost:5433/analytics
41
+ steps:
42
+ - uses: actions/checkout@v4
43
+ with:
44
+ path: flagcov
45
+ - uses: actions/checkout@v4
46
+ with:
47
+ repository: Flagsmith/flagsmith
48
+ path: flagsmith
49
+ - uses: astral-sh/setup-uv@v6
50
+ with:
51
+ python-version: "3.13"
52
+ - name: Install Flagsmith API dependencies
53
+ run: uv sync --frozen --extra dev
54
+ - name: Install FlagCov into Flagsmith's environment
55
+ run: uv pip install -e ../../flagcov
56
+ - name: Run Flagsmith's flag-related unit tests with FlagCov
57
+ run: |
58
+ set +e
59
+ uv run pytest -n 0 -p no:cacheprovider \
60
+ tests/unit/organisations tests/unit/custom_auth tests/unit/segment_membership \
61
+ tests/unit/environments/onboarding tests/unit/integrations/flagsmith tests/unit/app_analytics \
62
+ -k "not clickhouse and not influx" \
63
+ --flagcov --flagcov-env integrations/flagsmith/data/environment.json \
64
+ --flagcov-scan . --flagcov-out "$GITHUB_WORKSPACE/flagcov-flagsmith" -q
65
+ echo "pytest exit code: $?"
66
+ exit 0
67
+ - name: Report
68
+ if: always()
69
+ run: |
70
+ if [ -f "$GITHUB_WORKSPACE/flagcov-flagsmith/report.md" ]; then
71
+ cat "$GITHUB_WORKSPACE/flagcov-flagsmith/report.md" >> "$GITHUB_STEP_SUMMARY"
72
+ else
73
+ echo "No report produced" >> "$GITHUB_STEP_SUMMARY"
74
+ fi
75
+ - uses: actions/upload-artifact@v4
76
+ if: always()
77
+ with:
78
+ name: flagcov-on-flagsmith
79
+ path: flagcov-flagsmith/
@@ -0,0 +1,23 @@
1
+ name: Release to PyPI
2
+
3
+ # Publishes with PyPI trusted publishing (no API token stored in GitHub).
4
+ # One-time setup on pypi.org: add a "pending publisher" for project "flagcov",
5
+ # this repository, workflow "release.yml", environment "pypi".
6
+
7
+ on:
8
+ release:
9
+ types: [published]
10
+
11
+ jobs:
12
+ publish:
13
+ runs-on: ubuntu-latest
14
+ environment: pypi
15
+ permissions:
16
+ id-token: write
17
+ steps:
18
+ - uses: actions/checkout@v4
19
+ - uses: actions/setup-python@v5
20
+ with:
21
+ python-version: "3.13"
22
+ - run: python -m pip install build && python -m build
23
+ - uses: pypa/gh-action-pypi-publish@release/v1
@@ -0,0 +1,81 @@
1
+ name: Self-hosted Flagsmith end-to-end
2
+
3
+ # Boots the official open-source Flagsmith image, seeds it through its REST API,
4
+ # then runs the demo shop's tests with FlagCov against the LIVE self-hosted
5
+ # environment document, using this repository's own GitHub Action.
6
+
7
+ on:
8
+ push:
9
+ branches: [main]
10
+ pull_request:
11
+ workflow_dispatch:
12
+
13
+ permissions:
14
+ contents: read
15
+ pull-requests: write
16
+
17
+ jobs:
18
+ e2e:
19
+ runs-on: ubuntu-latest
20
+ timeout-minutes: 25
21
+ steps:
22
+ - uses: actions/checkout@v4
23
+ with:
24
+ fetch-depth: 0
25
+ - uses: actions/setup-python@v5
26
+ with:
27
+ python-version: "3.13"
28
+
29
+ - name: Start self-hosted Flagsmith (official docker-compose)
30
+ run: docker compose -f examples/selfhosted/docker-compose.yml up -d
31
+
32
+ - name: Seed flags, variants, segment and a server-side key
33
+ run: |
34
+ python examples/selfhosted/seed.py --api-url http://localhost:8000/api/v1/ --out .selfhosted.env
35
+ grep -E '^FLAGSMITH_(API_URL|SERVER_KEY)=' .selfhosted.env >> "$GITHUB_ENV"
36
+ echo "::add-mask::$(grep FLAGSMITH_SERVER_KEY .selfhosted.env | cut -d= -f2)"
37
+
38
+ - name: Download the live environment document
39
+ run: |
40
+ python -m pip install --quiet ".[flagsmith]"
41
+ flagcov fetch -o examples/demo_shop/environment.live.json
42
+ python - <<'PY'
43
+ import json
44
+ doc = json.load(open("examples/demo_shop/environment.live.json"))
45
+ print("environment:", doc["name"])
46
+ for fs in doc["feature_states"]:
47
+ mv = [(v["multivariate_feature_option"]["value"], v["percentage_allocation"]) for v in fs.get("multivariate_feature_state_values") or []]
48
+ print(f" {fs['feature']['name']}: enabled={fs['enabled']} value={fs['feature_state_value']!r} variants={mv}")
49
+ print("segments:", [s["name"] for s in doc["project"]["segments"]])
50
+ PY
51
+
52
+ - name: FlagCov (this repository's action) against live self-hosted Flagsmith
53
+ uses: ./
54
+ with:
55
+ working-directory: examples/demo_shop
56
+ api-url: ${{ env.FLAGSMITH_API_URL }}
57
+ server-key: ${{ env.FLAGSMITH_SERVER_KEY }}
58
+ pytest-args: -p no:cacheprovider
59
+ scan: "."
60
+ env:
61
+ FLAGCOV_ENV_DOCUMENT: ${{ github.workspace }}/examples/demo_shop/environment.live.json
62
+
63
+ - name: Check the report found what it should
64
+ working-directory: examples/demo_shop
65
+ run: |
66
+ python - <<'PY'
67
+ import json
68
+ r = json.load(open(".flagcov/report.json"))
69
+ states = {(f["flag"], s["label"]): s for f in r["flags"] for s in f["states"]}
70
+ assert states[("checkout_flow", "express")]["covered"] is False, "express should be untested"
71
+ assert states[("checkout_flow", "express")]["weight"] == 10
72
+ assert states[("checkout_flow", "one_page")]["weight"] == 30
73
+ assert any(s["segment"] == "enterprise" for s in states.values()), "segment override missing"
74
+ assert "recommendation_v2" in r["unknown_flags"]
75
+ assert "legacy_promo_banner" in r["unreferenced_flags"]
76
+ print("Live self-hosted report verified:", r["state_coverage"], "% states covered")
77
+ PY
78
+
79
+ - name: Flagsmith logs on failure
80
+ if: failure()
81
+ run: docker compose -f examples/selfhosted/docker-compose.yml logs --tail=200 flagsmith
@@ -0,0 +1,12 @@
1
+ .venv/
2
+ __pycache__/
3
+ *.pyc
4
+ .flagcov/
5
+ .pytest_cache/
6
+ dist/
7
+ build/
8
+ *.egg-info/
9
+ .coverage
10
+ .selfhosted.env
11
+ environment.live.json
12
+ docs/tools/.voice-cache/
flagcov-0.1.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 FlagCov contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
flagcov-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,248 @@
1
+ Metadata-Version: 2.5
2
+ Name: flagcov
3
+ Version: 0.1.0
4
+ Summary: Code coverage for feature flags: find the Flagsmith flag states your tests never ran, weighted by real production traffic.
5
+ Project-URL: Homepage, https://github.com/AryanMashalkar/flagcov
6
+ Author: FlagCov contributors
7
+ License-Expression: MIT
8
+ License-File: LICENSE
9
+ Keywords: coverage,feature-flags,flagsmith,openfeature,pytest,testing
10
+ Classifier: Framework :: Pytest
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Topic :: Software Development :: Testing
13
+ Requires-Python: >=3.10
14
+ Requires-Dist: pytest>=7
15
+ Provides-Extra: dev
16
+ Requires-Dist: flagsmith>=5; extra == 'dev'
17
+ Requires-Dist: openfeature-provider-flagsmith>=1.0; extra == 'dev'
18
+ Requires-Dist: openfeature-sdk>=0.8; extra == 'dev'
19
+ Requires-Dist: pytest-cov; extra == 'dev'
20
+ Requires-Dist: pytest-xdist; extra == 'dev'
21
+ Provides-Extra: flagsmith
22
+ Requires-Dist: flagsmith>=5; extra == 'flagsmith'
23
+ Requires-Dist: openfeature-provider-flagsmith>=1.0; extra == 'flagsmith'
24
+ Provides-Extra: openfeature
25
+ Requires-Dist: openfeature-sdk>=0.8; extra == 'openfeature'
26
+ Description-Content-Type: text/markdown
27
+
28
+ # FlagCov 🚩
29
+
30
+ **Code coverage for feature flags.**
31
+ Your tests are green. But are they testing what Flagsmith is actually serving your users?
32
+
33
+ [![CI](https://github.com/AryanMashalkar/flagcov/actions/workflows/ci.yml/badge.svg)](https://github.com/AryanMashalkar/flagcov/actions/workflows/ci.yml)
34
+ [![Self-hosted Flagsmith e2e](https://github.com/AryanMashalkar/flagcov/actions/workflows/selfhosted-e2e.yml/badge.svg)](https://github.com/AryanMashalkar/flagcov/actions/workflows/selfhosted-e2e.yml)
35
+ [![Dogfood on Flagsmith](https://github.com/AryanMashalkar/flagcov/actions/workflows/dogfood-flagsmith.yml/badge.svg)](https://github.com/AryanMashalkar/flagcov/actions/workflows/dogfood-flagsmith.yml)
36
+ ![License: MIT](https://img.shields.io/badge/license-MIT-blue)
37
+
38
+ ![FlagCov finds the 10% of checkouts no test has ever run, then writes the test that exposes the crash](https://raw.githubusercontent.com/AryanMashalkar/flagcov/main/docs/demo.gif)
39
+
40
+ *Every line in that GIF is real output from [`examples/demo_shop`](examples/demo_shop). The GIF is regenerated by [`docs/tools/make_gif.py`](docs/tools/make_gif.py).*
41
+
42
+ Built for **Toggle Wars 2026 · Track 03: Build on Open Source Flagsmith**.
43
+
44
+ ---
45
+
46
+ ## The problem, in one story
47
+
48
+ On 1 August 2012, Knight Capital deployed new trading code. One of eight servers still had old code on it, and the new release reused a flag that, on that server, switched on a dead feature nobody had tested in years. In 45 minutes the firm lost about **$440 million**.
49
+
50
+ That's the extreme version of something every team with feature flags lives with:
51
+
52
+ - We measure **line coverage** obsessively.
53
+ - We never measure **flag coverage**.
54
+ - And flags change **outside code review**. Someone adds a 10% variant in a dashboard on a Friday, and no pull request, no CI run, no new test ever sees it.
55
+
56
+ I wanted one number that answers: *of everything Flagsmith can serve in production right now, how much have my tests actually run?*
57
+
58
+ ## What FlagCov does
59
+
60
+ ```bash
61
+ pip install "flagcov[flagsmith]"
62
+ pytest --flagcov --flagcov-env environment.json --flagcov-scan .
63
+ ```
64
+
65
+ ```
66
+ flag state status who gets it
67
+ checkout_flow classic tested 60% of prod traffic
68
+ checkout_flow one_page tested 30% of prod traffic
69
+ checkout_flow express NOT TESTED 10% of prod traffic
70
+ checkout_flow invoice NOT TESTED segment "enterprise" (plan == enterprise)
71
+ legacy_promo_banner on STALE (no code reads it)
72
+
73
+ Riskiest flag: checkout_flow (10% of its production traffic hits untested code)
74
+ Read in code but missing from Flagsmith: recommendation_v2
75
+ ```
76
+
77
+ 1. **It records every flag your tests read.** Through an OpenFeature hook (works with any provider) or the native Flagsmith Python SDK. No code changes.
78
+ 2. **It reads what production actually serves** from Flagsmith's environment document: every flag, every multivariate weight, every segment rule and override, every identity override. The document comes from a file or straight from your **self-hosted** Flagsmith's API.
79
+ 3. **It compares the two** and tells you, per flag, how much production traffic lands on code your tests have never executed.
80
+ 4. **It writes the missing tests for you**: a parametrised pytest per untested state, using a `flag_override` fixture that forces any variant, or the "flag turned off" path.
81
+ 5. **It comments on your pull request** (GitHub Action), focused on the flags that PR touches.
82
+
83
+ ### Things it catches that nothing else does
84
+
85
+ | Finding | Why it matters |
86
+ |---|---|
87
+ | **Untested variant, weighted by real traffic** | "express is 10% of checkouts and 0 tests" is a number a team can act on. |
88
+ | **Untested segment override**, shown as its rule | Enterprise customers get different code. Did any test run it? |
89
+ | **Targeting never verified** | The test forced the "enterprise" value, but no test used traits that actually *match* the rule. FlagCov checks with Flagsmith's own evaluation engine. |
90
+ | **Kill switch never tested** | During an incident you turn the flag off. Has that path ever run? |
91
+ | **Flag read in code but missing in Flagsmith** | A typo like `recommendation_v2` silently returns the default forever. |
92
+ | **Stale flag** | In Flagsmith, but no code reads it any more. Time to clean up. |
93
+
94
+ ## Honest numbers, no made-up maths
95
+
96
+ - **Variant percentages are exact.** They come straight from `percentage_allocation` in Flagsmith.
97
+ - **Segments never get a fake percentage.** Flagsmith knows the rule (`plan == enterprise`), not how many users match it, so FlagCov shows the rule.
98
+ - **The headline is the worst case.** "Riskiest flag: 10% of its traffic is untested" is more useful than an average that hides it.
99
+
100
+ ## Quick start
101
+
102
+ ### 1. Run it locally
103
+
104
+ ```bash
105
+ pip install "flagcov[flagsmith]"
106
+
107
+ # Use a saved environment document...
108
+ pytest --flagcov --flagcov-env environment.json
109
+
110
+ # ...or fetch it live from your self-hosted Flagsmith (server-side key)
111
+ export FLAGSMITH_API_URL=http://localhost:8000/api/v1/
112
+ export FLAGSMITH_SERVER_KEY=ser.xxxxxxxx
113
+ pytest --flagcov --flagcov-scan src/
114
+
115
+ # Fail CI if any flag sends more than 5% of its traffic to untested code
116
+ pytest --flagcov --flagcov-fail-untested 5
117
+ ```
118
+
119
+ Reports land in `.flagcov/`: `report.md` (the PR comment), `report.json`, `badge.svg`, `evaluations.json` and `test_flagcov_stubs.py` (the generated tests).
120
+
121
+ ### 2. Force a variant in a test
122
+
123
+ ```python
124
+ from flagcov import OFF
125
+
126
+ def test_express_checkout(flag_override):
127
+ flag_override("checkout_flow", "express") # or OFF for the kill-switch path
128
+ assert checkout(650, "user-1", city="delhi")["eta_days"] > 0
129
+ ```
130
+
131
+ ### 3. Add it to your pull requests
132
+
133
+ ```yaml
134
+ # .github/workflows/flagcov.yml
135
+ on: pull_request
136
+ permissions: { contents: read, pull-requests: write }
137
+ jobs:
138
+ flagcov:
139
+ runs-on: ubuntu-latest
140
+ steps:
141
+ - uses: actions/checkout@v4
142
+ with: { fetch-depth: 0 }
143
+ - uses: actions/setup-python@v5
144
+ with: { python-version: "3.13" }
145
+ - run: pip install -e .
146
+ - uses: AryanMashalkar/flagcov@main
147
+ with:
148
+ api-url: https://flagsmith.example.com/api/v1/
149
+ server-key: ${{ secrets.FLAGSMITH_SERVER_KEY }}
150
+ scan: src
151
+ fail-untested: "5"
152
+ ```
153
+
154
+ You get one comment per PR, updated on every push, listing the untested states for the flags that PR touches, plus the tests to paste.
155
+
156
+ ### 4. Try the whole thing with self-hosted Flagsmith
157
+
158
+ ```bash
159
+ ./examples/selfhosted/run.sh
160
+ ```
161
+
162
+ This starts the official open-source Flagsmith image with Docker Compose and seeds a demo project through Flagsmith's REST API: flags, a 60/30/10 multivariate split, an `enterprise` segment with an override, and a server-side key. It then runs the demo shop's tests against the **live** environment document. Change a weight in the dashboard at <http://localhost:8000>, run it again, and watch the report change.
163
+
164
+ ## How Flagsmith is used
165
+
166
+ FlagCov is built on Flagsmith. Take Flagsmith away and there's nothing to measure.
167
+
168
+ | Flagsmith piece | What FlagCov does with it |
169
+ |---|---|
170
+ | **Environment document** (`GET /api/v1/environment-document/`, server-side key) | The source of truth for what production serves: flags, `percentage_allocation`, variant keys, segments, segment overrides, identity overrides. |
171
+ | **Self-hosted Flagsmith** | `flagcov fetch` / `--flagcov-api-url` talk to any instance. CI boots the official image and checks the report against it on every push. |
172
+ | **Flagsmith's evaluation engine** (`flag-engine`) | Checks whether the traits your tests used actually match each segment rule, the same way Flagsmith would. |
173
+ | **OpenFeature + the Flagsmith provider** | The recording hook sits at the OpenFeature API level, so it sees every evaluation, including `variant` and `reason`. |
174
+ | **Native Flagsmith Python SDK** | `Flags.is_feature_enabled` / `get_feature_value` are recorded too, with the identity and traits used. |
175
+ | **Flagsmith's own codebase** | We run FlagCov on part of Flagsmith's open-source test suite every week. See [Dogfooding](#dogfooding-flagcov-on-flagsmiths-own-tests). |
176
+
177
+ ## Proof it works
178
+
179
+ - **79 tests**, run on Python 3.10–3.13 on Linux, plus Windows and macOS ([CI](.github/workflows/ci.yml)).
180
+ - **Real self-hosted Flagsmith in CI** ([workflow](.github/workflows/selfhosted-e2e.yml)): boots the official Docker image, seeds it through the REST API, fetches the live document, runs the demo with **this repo's own GitHub Action**, and asserts that the report found the untested 10% variant, the segment, the missing flag and the stale flag.
181
+ - **A real pull request** with FlagCov's comment on it: see [the demo PR](https://github.com/AryanMashalkar/flagcov/pulls?q=is%3Apr).
182
+
183
+ ## Dogfooding: FlagCov on Flagsmith's own tests
184
+
185
+ Flagsmith's API evaluates its own flags through OpenFeature and the Flagsmith provider, reading a committed environment document (`api/integrations/flagsmith/data/environment.json`). That's exactly FlagCov's setup, so the [dogfood workflow](.github/workflows/dogfood-flagsmith.yml) checks out Flagsmith, runs the unit tests around flag-reading code with `--flagcov`, and publishes the report.
186
+
187
+ **What it found** ([run](https://github.com/AryanMashalkar/flagcov/actions/runs/45968631712)). 690 Flagsmith tests passed with FlagCov on. They read flags 102 times:
188
+
189
+ | Flag | Value in the committed document | What Flagsmith's tests read | FlagCov says |
190
+ |---|---|---|---|
191
+ | `api_usage_alerting` | **off** | `True`, 7 times | the **off** path is never run |
192
+ | `sdk_metrics_labels` | **off** | `True`, 18 times | the **off** path is never run |
193
+ | `segment_membership_inspection` | **off** | `True`, 23 times | the **off** path is never run |
194
+ | `api_limiting_*`, `api_usage_overage_charges` | on | `True` | ✅ tested |
195
+ | `experimental_flags`, `feature_lifecycle`, `onboarding_quickstart_flow`, `experimentation_warehouse_connection` | off | nothing | not read anywhere in the API code (probably frontend flags) |
196
+
197
+ So in this slice of the suite, those three flags are only ever tested **switched on**, while the document Flagsmith ships has them **switched off**. That's the configuration an instance falls back to when it isn't connected to Flagsmith's own flag service.
198
+
199
+ To be fair to Flagsmith: this is a slice of the suite (organisations, auth, segment membership, onboarding, analytics and the Flagsmith integration), not the whole thing, and other tests may well cover those paths. But that's exactly the point. Without a tool like this, nobody can tell.
200
+
201
+ ## How it works
202
+
203
+ ```mermaid
204
+ flowchart LR
205
+ T[Your pytest suite] -->|every flag read| H[OpenFeature hook / Flagsmith SDK wrapper]
206
+ H --> E[(evaluations.json)]
207
+ F[Self-hosted Flagsmith] -->|environment document| D[(flags · weights · segments · overrides)]
208
+ S[Your source code] -->|flagcov scan| R[(flag keys read in code)]
209
+ E --> A{FlagCov analyser}
210
+ D --> A
211
+ R --> A
212
+ A --> O1[Terminal table]
213
+ A --> O2[PR comment + badge]
214
+ A --> O3[Generated tests]
215
+ A --> O4[CI gate]
216
+ ```
217
+
218
+ Each flag state Flagsmith can serve (the control value, each variant, each segment override, each identity override, and the "turned off" path) is matched against the recorded evaluations. A boolean read only proves the flag was on, so it never counts as covering a multivariate value. Disabled paths are covered when the code falls back to its default.
219
+
220
+ ## Limitations (being upfront)
221
+
222
+ - **Python and pytest only for now.** JavaScript/TypeScript (Jest/Vitest) is next. The OpenFeature JS SDK has the same hook model, so the analyser and reports carry over.
223
+ - **Segment traffic isn't measured.** We show the rule, not a guessed percentage. Flagsmith's analytics could fill this in later.
224
+ - **The code scanner is pattern-based.** It finds string-literal flag keys. A key built at runtime (`f"flag_{name}"`) won't be found.
225
+ - **Overrides of the same value can be ambiguous.** If a segment serves the same value as the control, testing the value covers both, because it's the same code path.
226
+
227
+ ## Project layout
228
+
229
+ ```
230
+ src/flagcov/ analyser, recorder, pytest plugin, reports, scanner, CLI
231
+ action.yml GitHub Action (PR comment, job summary, CI gate)
232
+ examples/demo_shop the demo: a tiny shop with a hidden bug behind a 10% variant
233
+ examples/selfhosted official Flagsmith docker-compose + REST seeding script
234
+ docs/ demo GIF, video script, GIF generator
235
+ tests/ 79 tests (unit, pytester end-to-end, xdist, live HTTP)
236
+ ```
237
+
238
+ ## Contributing
239
+
240
+ ```bash
241
+ python -m venv .venv && . .venv/bin/activate
242
+ pip install -e ".[dev]"
243
+ pytest
244
+ ```
245
+
246
+ Issues and PRs welcome, especially for JS/TS support.
247
+
248
+ MIT licensed.