chore: add targeted utils mutation tests#576
Conversation
posthog-python Compliance ReportDate: 2026-05-26 10:10:43 UTC ✅ All Tests Passed!45/45 tests passed Capture Tests✅ 29/29 tests passed View Details
Feature_Flags Tests✅ 16/16 tests passed View Details
|
|
Warning Review the following alerts detected in dependencies. According to your organization's Security Policy, it is recommended to resolve "Warn" alerts. Learn more about Socket for GitHub.
|
Prompt To Fix All With AIFix the following 2 code review issues. Work through them one at a time, proposing concise fixes.
---
### Issue 1 of 2
posthog/test/test_utils.py:297-343
**Non-parameterised test for OS platform branches**
`test_get_os_info_branches` contains six independent platform scenarios (win32 with version, win32 without version, darwin, linux, freebsd, and a generic fallback) each written as a separate `with` block inside a single method. Per the team convention, these should each be a row in a `@parameterized.expand` table — as used elsewhere in this file — so that failures point to the exact platform case and each scenario is independently named and runnable.
### Issue 2 of 2
posthog/utils.py:202-204
**`# fmt: off` directives leak mutation-test infrastructure into production code**
Both occurrences of `# fmt: off` / `# fmt: on` (here and in `set_cached_flag` around the `FlagCacheEntry(…)` call) exist solely because the constant reference makes the line exceed the formatter's line-length limit. Suppressing the formatter in production source to satisfy mutmut's single-line requirement violates the "no superfluous parts" rule. A cleaner alternative would be to introduce a short local alias (e.g. `_STALE = CACHE_STALE_TTL`) at the call site, or to rename the constant to something shorter so the line fits naturally without bypassing `black`.
Reviews (1): Last reviewed commit: "Merge branch 'main' into chore/add-utils..." | Re-trigger Greptile |
💡 Motivation and Context
Add targeted mutation testing coverage for
posthog/utils.pyso regressions in utility helpers and flag cache behavior are caught by tests.This adds a focused mutmut configuration and CI job that only runs when the targeted mutation inputs change, with
mutants/cached across CI runs. The targeted utils tests now cover all statements inposthog/utils.py.💚 How did you test it?
uv run --extra test pytest posthog/test/test_utils.py posthog/test/test_size_limited_dict.py --timeout=30 -quv run --extra test coverage run -m pytest posthog/test/test_utils.py posthog/test/test_size_limited_dict.py --timeout=30 -q && uv run --extra test coverage report -m posthog/utils.pyrm -rf mutants && uv run --extra test --with mutmut mutmut run --max-children 1 && uv run --extra test --with mutmut mutmut resultsuv run --extra test pytest --timeout=30 -q.github/workflows/ci.ymlas YAML📝 Checklist
If releasing new changes
sampo addto generate a changeset file