Skip to content

04 β€” Patterns and Conventions

Follow these so new tests read like the existing ones and stay easy to map back to behavior.

Coverage-target IDs

Every test file opens with a docstring that enumerates coverage targets β€” short IDs, each naming one behavior, each owned by one test. The prefix is a mnemonic for the file.

"""Phase 4 integration tests β€” rooms service handlers.

Coverage targets
----------------
[SR-1]  save_managed_rooms service persists room config.
[SR-2]  get_vacuum_maps service returns map list for a vacuum.
[SR-3]  update_room_fields service updates a field and returns ok.
[SR-4]  update_room_fields service returns error for unknown room.
"""

Each test then references its target in its own docstring:

async def test_save_managed_rooms_service_persists_rooms(hass, manager_with_services):
    """[SR-1] save_managed_rooms service writes rooms into manager data."""

Why it matters: the target list is the file's table of contents and its contract. When you add a behavior, add a target ID and a test for it. When a test fails, the ID tells you which behavior broke without reading the body.

Established prefixes include LS (learning services), SR (services-rooms), BE (button entity), and so on β€” one per file. Pick a short prefix for a new file, ideally one not already used elsewhere.

IDs are file-scoped, not global. check_legend_drift.py validates each file's legend against its own tests only β€” it does not enforce global uniqueness, and genuine cross-file references are handled inline (prose) plus the checker's CROSSREF_ALLOWLIST. So a [SP-1] in one file is a different behavior than a [SP-1] in another; resolve an ID by the file it lives in. Reusing a prefix across unrelated files is tolerated but discouraged β€” it muddies a global grep, so prefer a fresh prefix. A prefix deliberately shared by a set of files covering one cross-file suite (e.g. LC for lifecycle across the listener + sensor-status tests) is fine and intentional.

Naming

Thing Convention Example
Test file test_<area>.py, grouped by subsystem or platform test_services_queue.py, test_listeners_timers.py
Test function test_<subject>_<expected> test_get_vacuum_maps_service_returns_dict
Module constants _VAC, _MAP at top of file _VAC = "vacuum.alfred"
Private helpers leading underscore, module scope _seed_active_job, _make_manager

vacuum.alfred is the standard test vacuum across the suite. Reuse it.

Calling a service

result = await hass.services.async_call(
    DOMAIN,
    "service_name",
    {"vacuum_entity_id": _VAC, "map_id": _MAP},
    blocking=True,
    return_response=True,   # only for services that return data
)
  • blocking=True β€” wait for completion before asserting.
  • return_response=True β€” required for services that return a payload (the read/snapshot services). Omit it for fire-and-forget services, which return None.

After a service that schedules background work, drain the loop before asserting:

await hass.async_block_till_done()

Sync manager methods: run them in the executor

Many manager methods are synchronous and do blocking file I/O through the store (finalize_completed_job, the rebuilders, snapshot writes). HA forbids blocking the event loop, so call them through the executor:

result = await hass.async_add_executor_job(
    lambda: learning.finalize_completed_job(
        manager=core_manager,
        vacuum_entity_id=_VAC,
        map_id=_MAP,
        battery_start=85, battery_end=60,
        started_at="2026-01-01T09:00:00+00:00",
        ended_at="2026-01-01T09:30:00+00:00",
        used_for_learning=False,
        rebuild_stats=False,
    )
)

The async wrappers (e.g. async_finalize_completed_job) do this internally β€” prefer them when one exists. Drop to the sync method + executor only when you are specifically testing the sync path.

Unit tests: mock the manager

Entity and platform unit tests do not need a real manager β€” they need an object that records calls. Build a MagicMock, with AsyncMock for the async methods:

from unittest.mock import AsyncMock, MagicMock

def _make_manager(*, run_profile_data=None):
    manager = MagicMock()
    manager.async_save = AsyncMock()          # awaited by the entity
    manager.reset_maintenance = MagicMock()   # sync
    manager.get_saved_run_profiles.return_value = {"library": run_profile_data or {}}
    return manager

Then assert on the recorded interaction:

manager = _make_manager()
button = _make_reset_button(manager)
await button.async_press()
manager.reset_maintenance.assert_called_once()
manager.async_save.assert_awaited_once()

Use this for anything whose logic is "translate an HA call into a manager call" β€” buttons, switches, numbers, sensors. It is faster and more precise than standing up the full manager.

…but use spec_manager() when the mock is handed to OUR code

The pattern above is right for driving a platform entity against a deliberately partial stub. It is the wrong tool when the mock is passed into our own code as a manager β€” PhaseRunner(manager=mgr), RoomMapManager(mgr), finalizer._collect_finalization_inputs(manager=mgr, …) β€” because a bare MagicMock agrees with the caller, not the callee:

  • it answers to any attribute name, whether or not the real class has one. mgr.learning does not exist on EufyVacuumManager (it is _get_learning_manager()), and a mock inventing it made a dead path look exercised;
  • it accepts any argument list. _collect_finalization_inputs was called without three required keyword-only args; the permissive stub swallowed the TypeError and two live runs wrote no child records while the suite stayed green.
from tests._factories import spec_manager

mgr = spec_manager()                       # autospec'd against EufyVacuumManager
mgr.get_active_job.return_value = {...}    # stub what the test needs
runner = PhaseRunner(manager=mgr)

spec_manager builds create_autospec(EufyVacuumManager, instance=True), so call signatures are checked against the real functions and unknown names raise. Instance attributes (data, hass, active_job, …) are invisible to autospec because they are assigned at runtime, so they are scraped from core/manager.py and attached β€” not hand-listed, because a hand list is a second source of truth that goes stale silently (the first draft of the helper proved it, failing 17 tests that had nothing wrong with them).

One consequence worth knowing: autospec makes the manager's async def methods AsyncMocks, so hass.async_create_task(mgr._async_save_logged()) now builds a real coroutine. spec_manager closes it, or Python reports "coroutine … was never awaited" against whichever test the GC happened to interrupt.

tests/unit/test_factories_spec_surface.py is the guard on the guard β€” it pins that unknown attributes raise, that bad signatures raise, and (as a control) that a bare MagicMock accepts both.

Pin discipline: test the contract, not the shape

The mirror image of the mock rule above, discovered by the CAL-23 blind-reconstruction calibration (2026-08-07). The two diseases:

what lies failure mode constrains
Mock disease a fake collaborator agrees with the caller test PASSES while the code is broken under-constrains behavior
Pin disease a real-code test asserts private internals by name test FAILS while the code is correct over-constrains implementation

A test that drives t._record_rising_edge(...) or asserts t._grace_cancels == {} is pinning the implementation's shape: any correct reimplementation that names or structures its internals differently fails, while behaving identically. The acid question for every new test: would this test accept a correct reimplementation? If no, it asserts the wrong contract. Prefer the public surface β€” the constructor, the public methods, the emitted state/attributes, the injected-closure seams β€” and treat any direct ._name access as a deliberate exception that needs a comment saying why the public surface can't force the behavior.

Over-pinning also steers production: core/error_tracker.py keeps the deprecated harvest_active_run alive solely because tests assert its semantic (its docstring says so) β€” the suite driving the code instead of guarding it.

Current, honestly stated: tests/integration/test_core_error_tracker.py is the known worst case β€” 35 of its 43 tests touch private names (census 2026-08-07). They guard real behavior today and are NOT being rewritten opportunistically (suite-freeze ruling); they are quarantined from blind-reconstruction verdicts and queued as a hardening class. New tests follow this section from now on β€” the ratchet direction is: white-box count may only shrink.

Assertions: prefer presence over exact equality

Because the integration hass shares its config_dir across tests in a run (see 05), seeded jobs and stats accumulate. Assert on what your test added, not on totals:

# Good β€” robust to accumulation
assert result.get("available") is True
assert result["overview"]["job_stats"]["total_jobs"] >= 1
assert any(j["job_id"] == "j-flt-001" for j in jobs)

# Fragile β€” breaks when another test seeds a job
assert result["overview"]["job_stats"]["total_jobs"] == 1

What not to test

The suite deliberately skips:

  • Pure log-only / best-effort except blocks β€” a block whose only effect is a log line (best-effort I/O writes, listener teardown). These carry # pragma: no cover instead (see below).
  • Inactive / dead code paths β€” functions that currently always return early, or guards whose conditions are mutually exclusive (e.g. the documented dead branch in core/manager.py's progress snapshot).
  • A real device or live HA entity setup β€” e.g. the live-entity path of the discover_rooms service, which drives real adapter entities. The handler itself is covered with a mock manager (test_services_rooms.py test_discover_handler_success / test_discover_handler_raises, SR-5/SR-6); only the live-entity path is left to a full integration boot, the same place async_setup_entry boot wiring runs.
  • Defensive continue / return [] normalization guards β€” left as honest misses (real control flow, so not pragma'd), since a test that feeds garbage to assert it's skipped asserts plumbing, not behavior.

Coverage of those costs more than it protects. Spend the effort on real behavior.

But DO test an except that changes the surfaced result

The opposite of the first bullet: an except block is behavior β€” and worth a test β€” when it does more than log. Test it when the failure path:

  • wraps the error as HomeAssistantError / ServiceValidationError (the HA Silver action-exception contract) β€” monkeypatch the manager method to raise, then assert the wrapped type (see test_services_run_profiles.py SRN-11, test_services_maintenance_reset.py MR-4/5);
  • returns a degraded field the caller sees (e.g. start_selected_rooms' learning_snapshot: {saved: False, reason: snapshot_error}, SS-7);
  • skips one item and continues a fan-out loop (a failing update callback must not block the rest β€” MD-7).

The rule of thumb: if removing the except would change what a caller observes, it's behavior; if it would only change the logs, it's a # pragma: no cover.

Coverage exclusions (# pragma: no cover)

.coveragerc excludes pragma: no cover lines. Put it on the except line itself (not the log line) so the whole branch drops, and append a short reason:

except OSError as err:  # pragma: no cover - best-effort I/O, logs and swallows
    _LOGGER.debug("…failed to write %s: %s", path, err)

Use it surgically, one audited block at a time β€” never a blanket _LOGGER.* regex, which would also silence the behavioral excepts above and leave half-excluded branches under --cov-branch. The full convention is in subsystems/README.

100.00% is LINE coverage β€” a multi-condition if hides inside it

coverage.py records lines and arcs, not conditions. A one-line or chain reads fully covered as soon as either arc out of it is taken, so a module can publish 100.00% with conditions that were never evaluated β€” Python short-circuits the rest of the chain, so they are not merely untested, they did not run.

Measured in user_fonts.py's build_catalog, which this release range took from 88.64% to 100.00%. Its symlink containment rule is written three times β€” about the drop-in directory, about font.json, and about each face file β€” and deleting either of the first two left tests/unit/test_user_fonts.py at 30 passed, exit 0. What made that null robust was the denominator rather than the two runs: os.symlink appeared exactly once in the whole test tree, and it linked a descriptor, so no test anywhere could reach the other two arms. UF-11 is now parametrised over all three sites, one cell each, and each cell reddens only on its own.

So a 100.00% over a predicate with several conditions is not evidence about any one of them. The instrument that answers is still an ablation per clause β€” one per condition, not one per line.

Standing gates on things that are not code

Nine committed gates, holding ground that no ordinary test can. They divide into two kinds, and the distinction matters when you touch one:

Ratchets β€” mock debt, pragmas, the register, annotations and documentation β€” are SHRINK-ONLY: the number may fall freely, and raising it is meant to be harder than fixing the thing it measures.

Absolute gates β€” front-page links, screenshot freshness, covers and shipped texture references β€” have no allowance. They pass or they do not.

This heading read "The two ratchets (mock debt, doc coverage)" and opened "Two committed gates" while three were listed beneath it. Each new gate was appended without touching the frame above, so the count was wrong for as long as the section had been growing β€” the same accretion failure the register ratchet exists to catch, in the prose describing it.

It then happened again. The count read five with eight gates listed below it, and both kind-lists were short: the register was filed as absolute while its own heading calls it a ratchet, and pragmas, annotations and covers appeared in neither. Corrected 2026-11-12 when the texture gate became the ninth. If you add a tenth, the count and the two lists above are the thing to touch, not just a new ### below.

Mock ratchet β€” tests/test_mock_ratchet.py

A bare MagicMock() / AsyncMock() agrees with the caller, not the callee: every attribute exists, every method returns another mock, every shape assertion passes. Audit 1 traced four live failures to exactly that, green all the way to hardware. spec_manager() and create_autospec are the cure (see spec_manager); this gate measures where they are not yet used.

tests/mock_allowlist.json records a per-file CEILING for the 40 files that currently carry bare mocks. A file not on that list may have zero β€” that is the half that matters, because the debt is concentrated and what must be prevented is it reappearing in the ~145 files that are clean.

This is not a ban. Entity-driving partial stubs are correct and stay (above). The doctrine's line is a mock handed INTO production code must be spec'd, which needs per-site judgement; the gate only holds the total steady while that happens.

python scripts/mock_census.py                     # the current profile, worst first
python scripts/mock_census.py --write-allowlist   # bank progress AFTER converting

Pragma ratchet β€” tests/test_pragma_ratchet.py

The programme allows # pragma: no cover for a logger line only. Every other excluded line leaves the arithmetic as well as the report, so a pragma elsewhere makes a file's percentage flattering by exactly as much as it hides β€” and that percentage is what the 95%-per-file campaign is measured on.

Audited 2026-11-08: 224 pragma sites, 103 within the rule, 121 outside it across 39 files, concentrated in diagnostics.py (21) and core/manager.py (20).

A pragma on a compound statement suppresses the whole statement, not its own line, and that is the part that surprises. Of the 189 pragmas sitting on an except clause, 97 handlers contain no logger call at all β€” mostly pass, continue, and real returns like return (entities, report). A pragma written to skip one _LOGGER.exception(...) can be excluding control flow nobody meant to waive, which is why scripts/pragma_census.py classifies the handler BODY rather than the comment.

Not a ban, and not a verdict on any one site. An except Exception: # pragma: no cover whose body is a log line plus a bare return None is the allowance in substance and is not counted β€” proven by ablation, along with both failing halves. 121 sites is not one commit's work and should not be: several are genuinely unreachable handlers whose right answer is a recorded classification (the shape used for room_discovery.py's non-convergence arm and switch.py's two remaining arms) rather than a pragma, and a few are real gaps. The gate holds the total steady while that judgement happens β€” deliberately the same shape as the mock ratchet above.

id what it holds
PR-1 a file not on the allowlist may have zero
PR-2 a listed file may not exceed its ceiling
PR-3 slack is reported, not enforced; a drained or deleted file must lose its row
PR-4 the census can tell the two shapes apart β€” the ablation PR-1/PR-2 cannot do on themselves
python scripts/pragma_census.py            # the profile, worst first
python scripts/pragma_census.py --json     # {path: count} for the allowlist

mkdocs.yml sets docs_dir: docs and builds --strict, so every link inside docs/ is validated on each Pages build. README.md sits at the repository ROOT, which puts it outside that gate entirely β€” no CI job reads it at all.

The gap was not theoretical. The README pointed at …/docs/dev/27-render-harness/ after that file was renamed to docs/dev/frontend/render-harness.md. There is no redirects plugin and the Pages deploy replaces the whole artifact, so it had been a hard 404 since the rename, found eventually by a hand audit.

Four checks, all offline: every repo-relative path exists on disk; every published docs-site URL maps to a real source file under docs/ (including the section landings, which are README.md, not index.md); every in-page anchor matches a heading that still exists; and reference-style definitions and uses match in both directions. External URLs are deliberately NOT checked β€” they need the network and other people's repos are allowed to move.

Retiring a screenshot or renaming a docs page now fails here instead of on the front page.

Register ratchet β€” tests/test_replica_ratchet.py

A notation anchor and its registry must not drift apart. Three checks, each ablated and confirmed to go red on its own and nothing else:

[RR-1] an anchor declared in source has a ### \TOKEN`entry in00b(IN) or00c` (RN)
[RR-2] a registry entry names a real anchor site β€” 00b's own standard, enforced
[RR-3] each RN set has exactly one anchor: primary and at least one REPLICA

The hole it closes is specific and was live. On 2026-08-18 seven RN anchors were declared, marked at both members, and present in no document at all, while doc_anchor --check reported 0 problems and --orphans reported 0 orphans. --orphans asks "does any document cite this anchor?", and a REPLICA marker in source satisfies it β€” so a set can be fully wired in code and invisible in the register, permanently, with every shipped gate green.

[RR-3] covers the other invisible state: three placements during the census briefly left a primary with no replica. A set of one is not a set, and nothing else can see it.

It imports doc_anchor.scan() rather than re-scanning. A second parser is a second answer to "what counts as declared" and will diverge β€” while writing this, a hand-rolled regex requiring a #////* prefix reported INMKEHPQ and INSJM6KC as unregistered. Both were fine; INSJM6KC is declared inside a docstring. A ratchet that cries wolf gets deleted, so the tool owns the question and the test owns only the comparison.

CN is deliberately exempt β€” 00b indexes IN and 00c indexes RN; code notation has no registry by design.

Screenshot freshness β€” scripts/check-screenshot-freshness.test.mjs

A committed screenshot is a claim about the product that no test reads. docs/screenshots/translations-hero-profile-card.png rendered "RUNS AS"; run_profiles.runs_as became "Runs in this order" three days after that image was committed. The README carried the outdated wording for six weeks and shipped it in v2.1.0. Every gate here checks code, and a screenshot is not code.

Note how it differs from the front-page link gate above, which is the closest thing: that one proves the image path resolves. This proves the pixels still match the product. A retired screenshot fails there; a stale one fails here.

Not OCR. scripts/screenshot-i18n-manifest.json declares which i18n keys each family renders and fingerprints their English values; the check fails when one moves and names the key, the new value, and the files to re-shoot. It cannot say an image is wrong β€” only that the strings under it changed, which is the signal a human needs.

Key sets are derived, not hand-listed: static t("…") literals are extracted from each card's own source, so a card that starts using a new string is covered without anyone remembering to edit the manifest β€” "remember to update the manifest" being the same failure mode as "remember to re-shoot". The one unextractable case is the dynamic t(`vocab.${field}.${slug}`); those four fields are declared literally at the chipRow() call sites, so the manifest names them rather than sweeping all 682 vocab.* keys and flagging every image on an unrelated fault-vocabulary edit.

node scripts/check-screenshot-freshness.mjs            # the gate
node scripts/check-screenshot-freshness.mjs --update   # AFTER re-shooting, never before

⚠ --update before re-shooting silently disarms it forever. It re-records whatever is in en.js now, so it will happily bless images that are still stale, and read green from then on.

Declared blind spot: the maintenance guide prose inside Filter_*.png is model-aware content that does not live in en.js, so only that card's chrome is fingerprinted. A guide rewrite will not flag those images. Layout, theme, font and non-English values are all out of scope too β€” this watches English string values only.

Re-shooting is cheap by design: the shots come from a permanent dashboard with one card pinned per language. See .claude/notes/WORKFLOW-screenshots-and-languages.md.

Annotation ratchet β€” tests/test_annotation_ratchet.py

Nothing in this repo type-checks β€” no mypy/pyright step in .github/workflows/, no .pre-commit-config.yaml β€” so a return annotation is prose that happens to be parsed. It can drift arbitrarily far from the code and no gate, test or runtime notices.

Found 2026-11-11: segmentor.py::_split_suspicious_component declared tuple[list[Any], str | None] against eight return statements that every one returned a 3-tuple, with its docstring already saying three. That is the tell β€” the docstring was updated when the third element was added and the annotation beside it was not, so the two sat contradicting each other in one function header. A sweep then found a second, in an unrelated subsystem: __init__.py::_prepare_static_dirs declared a 4-tuple and returned five directories. Both call sites were already correct, so both fixes were behaviour-neutral. One is a slip; two is a class of defect with nothing watching for it.

ARITY ONLY, deliberately. Element types need real inference and a ratchet that guesses is worse than none, so it is blind to a wrong element type at the right arity, to return result (a name carries no arity at the return site), and to tuple[X, ...]. [AR-3] pins that last exclusion specifically: read naively tuple[int, ...] has two subscript elements, so a len(elts) implementation would call every variadic in the package an arity-2 annotation and the gate would become a wall of false positives β€” the failure mode that gets a gate deleted rather than obeyed.

[AR-2] is the bite test on the detector itself. [AR-1] asserts an empty list, and an empty list is also what a broken walker returns β€” a bad glob, a renamed package, a swallowed exception β€” which reads identically to a clean tree; [AR-2] injects the exact defect found here and confirms the analysis reports it. [AR-4] asserts the walk is non-empty and reaches both fixed files, because the denominator is the claim.

⚠ This is not a step towards a type checker. The repo has deliberately not got one; that is the owner's call, not a side effect of a bug fix.

Documentation ratchet β€” tests/test_docs_ratchet.py

A test file that appears nowhere in docs/testing/ produces no findings and reads exactly like a well-covered one β€” the same shape of lie as the mock, one level up. tests/undocumented_tests.json lists the current backlog; a new test file must be mentioned in its subsystem page in the same commit that creates it.

python scripts/mock_docs.py --undocumented   # what is still missing

⚠ It sees Python only. census() walks tests/, so harness/tests/*.spec.mjs, harness/lib/*.test.mjs and scripts/*.test.mjs are outside the ratchet entirely β€” a node test file can be created undocumented and nothing says so. Measured 2026-08-25: of 31 node-side test files, 22 are mentioned somewhere under docs/, 9 are mentioned nowhere:

harness/lib/animal-gallery-html, harness/lib/landing-html, scripts/animal-js-to-descriptor, scripts/bundled-animals, scripts/check-animal-pr, scripts/gen-theme-token-docs, scripts/process-animal-submission, scripts/sanitize-animal-svg, scripts/svg-to-descriptor.

(It was 10 when first measured. Documenting the screenshot gate above moved it off the list β€” which is exactly how small this fix is per file, and why nine of them have sat there unnoticed.)

That is the ratchet's own stated blind spot β€” "an undocumented subsystem and a clean one read identically" β€” reproduced one level up, in the scope of the gate rather than inside it. The bar also differs: Python is enforced against docs/testing/ specifically, while the node figures above count a mention anywhere under docs/, which is the more generous test.

Covers gate β€” scripts/check_covers.py, tests/test_covers_gate.py

A test may name the symbol it covers, and this gate proves it does:

@pytest.mark.covers("custom_components/eufy_vacuum/mapping/tracker.py::MappingTracker._compact_dock_drift")
def test_mt6_compaction_keeps_the_meta_header_and_the_newest_entries(tracker, tmp_path):
python scripts/check_covers.py          # every marker in tests/ (also a CI step)
python scripts/check_covers.py --list   # just show what is declared

It exists because of a count, not an incident. On 2026-11-07 six tests in this repo passed without exercising what they named β€” four of them written that same day, by the same author, while closing coverage gaps:

the test why it was worthless
LID-11 / LID-12 rooms/room_discovery.py already renamed the duplicate slug and already dropped the bad id, so each assertion held for a reason other than the one it named β€” and the lines they claimed stayed missed
a staleness boundary pair fixtures built from the constant under test, so 30 β†’ 31 and 30 β†’ 29 both left the suite green
test_harvest_units.py imported the unit table it was meant to be checking
a rect-shape guard subsumed by the except below it; ablating the guard changed nothing
MTE-15 asserted on a counter that only moves once a room is current, so it measured 0 == 0

What caught each one was a second instrument β€” coverage disagreeing with a green test, a declared-empty red set, or a control assertion. The suite alone never caught one. This closes the commonest of those shapes unattended: the test passes and the line it claims is still uncovered.

Two checks, and they are not the same claim:

  • REACH, per test β€” every test naming a symbol must itself execute at least one line inside it.
  • SPAN, per symbol β€” the declaring tests together must leave no line of it uncovered. Several tests legitimately share one symbol, one per branch, so this half stays collective. It is the half that catches LID-11's shape, where the test does enter but its named lines stay missed.

⚠ REACH was missing from v1, and an ablation on the real repo is what found it. v1 ran every test naming a symbol in one coverage run and asked whether the span came out covered. Repointing a real marker at a symbol its test never calls β€” MTE-18 at _compact_dock_drift β€” left the gate green, because the four genuine compaction tests were in the same run and answered for the liar. The hole sat one level below the one v1's own grouping comment already warned about, written by the same hand that then shipped it. CG-1 could not see it: its lying test was alone in its group, so the missing red input was the mixed group, now CG-7.

⚠ Contexts need a non-default measurement core. REACH is attributed with coverage's own per-test contexts (--cov-context=test), and on python 3.14 coverage defaults to core=sysmon, which warns "Dynamic contexts aren't supported … context data may be incomplete". It is not cosmetic: under sysmon a two-test probe reported four context names, under COVERAGE_CORE=ctrace the same two tests reported five β€” the missing one a setup phase. Incomplete attribution makes REACH fail tests that do reach, so the gate pins ctrace and then fails loudly if the warning appears anyway rather than reading a half-populated report as a verdict.

What it deliberately does not do. It catches one of the six shapes. A fixture derived from its own constant, a self-referential import, a subsumed guard and a vacuous assertion all cover their target lines perfectly well β€” coverage cannot see any of them, and ablation is still the only instrument that can. This is not a substitute for declaring a red set; it is the cheap half that runs unattended.

No line numbers, on purpose. Targets are file.py::symbol, never file.py:120. Line citations rot: inserting 21 comment lines into dispatch/manager.py on the day this was written moved its guards from 669/706 to 727/730, and every line citation from that morning was wrong by the afternoon. scripts/check_doc_citations.py reached the same conclusion for docs and calls a line citation "a defect by rule".

Its own coverage run. The CI behaviour gate is deliberately --no-cov (coverage is inspection-only there), so this cannot read a shared report. It runs the declaring tests only, scoped to the target's package directory β€” one pytest subprocess per declared symbol, not per marker. Markers inside a test class are reported MALFORMED rather than skipped, because a declaration nothing can parse is invisible and invisible reads as clean.

tests/test_covers_gate.py drives the real script as a subprocess against synthetic trees in tmp_path (via the COVERS_ROOT override) β€” the lying test cannot live in the real suite, which is why that override exists. CG-1 is the bite; CG-2 is the control, and without it CG-1 would pass just as happily if the gate failed on everything.

⚠ CG-1 is a DISJUNCTIVE detector, and the SPAN half shipped with no test that could see it go. CG-1's lying test trips both halves at once, so ablating either one alone leaves it green β€” measured: replacing the SPAN verdict (if uncovered:) with if False: left every one of this file's eleven cases green at exit 0, while the same edit on REACH (if not hit:) reddened CG-7 alone. The string CG-1 asserts, UNCOVERED, comes from a print the gate emits unconditionally two lines above the failure it appends, so it fenced the diagnostic and not the verdict: with SPAN disabled the gate printed UNCOVERED [...] and then all 1 declaration(s) hold … together they leave no line of it uncovered underneath it β€” a false all-clear below the evidence against it. CG-9 closes that: a declaring test that enters its symbol and leaves one arm unrun, the shape only SPAN can fail. All three cells are measured β€” SPAN reddens CG-9 alone, REACH reddens CG-7 alone, and CG-1 goes red only under the double mutant. Its fixture needs an explicit else arm, because a bare if with no else leaves missing_lines empty and SPAN reads only missing_lines, never the arcs.

Shipped texture references β€” scripts/check-texture-assets.test.mjs

custom_components/eufy_vacuum/textures/ is inside the release payload: release.yml zips the contents of custom_components/eufy_vacuum/ whole, minus bytecode. So a file parked in that directory is downloaded by every user whether or not any renderer asks for it, and until 2026-11-12 nothing checked.

It had already happened, for four months. The commit that re-authored carpet and granite as split base+detail masks moved rendering onto the masks and left the three full-colour source photographs behind: 20,002,815 bytes, 78.1% of all texture bytes and ~68% of the 29,462,699-byte 2.6.1 download, referenced by nothing in the package β€” the only consumer is scripts/gen_floor_masks.py, which is not shipped either. Rendering was never affected, which is why it produced no symptom for anyone to report: the 18 greyscale masks all shipped and all worked. The sources now live under authoring/texture-sources/.

The gate is bidirectional, and the second half is worth as much as the first:

finding meaning
unreferenced ships to every user, no renderer loads it β€” the defect above
missing the registry names a mask that is not on disk β€” that material renders as nothing

The registry is imported, not parsed. A regex over src/textures/floor-texture-registry.js would drift from it silently, which is the same failure shape as the thing being guarded; importing makes the expectation the real closed set (layers[].url, masks[].url, baseTexture, with the module's own ?v= cache-bust suffix stripped β€” CTA-4 is the cell that fails if the stripping goes, and it would otherwise fire on all 18 masks at once, which is the shape of a gate that gets deleted rather than fixed).

CTA-1 runs against the real tracked tree and is the gate; CTA-2..CTA-7 are synthetic and exist because a gate nobody has reddened is a preference. CTA-1 was ablation-proven on the actual historical defect β€” copying texture-floor-granite-light.png back into textures/granite/ took the CLI to exit 1 naming that file, and reddened CTA-1 alone while the other six stayed green.

npm run check:textures      # 18 file(s) on disk, 18 referenced by the registry

It runs in node-tests.yml (whose path filter now includes custom_components/eufy_vacuum/textures/**, or a stray PNG added there alone would not have triggered it) and again in release.yml before the zip is built.

Drop-in floor materials β€” tests/unit/test_user_materials.py

A drop-in material is user-supplied content that reaches the renderer, so custom_components/eufy_vacuum/user_materials.py is the only thing between a stranger's directory and the card. Two of its failure modes are SILENT, and they are what the tests are built around:

failure why nothing would complain
wrong canvas the per-type feature scales are tuned to 2048Γ—2048 and the decode path never reads the bitmap's own width, so another size MISALIGNS rather than erroring
RGB instead of greyscale the compositor reads luminance only, so a colour mask costs ~3Γ— the bytes and renders identically β€” which is how 20 MB of unreferenced RGB shipped inert for four months until d902c5af

Both are readable from 26 bytes of PNG IHDR, so refusing them needs no decoder and no Pillow (which is an optional dependency here β€” the manifest declares none). That is png_header(), pinned by UMAT-20. UMAT-25 pins the one optional BOOLEAN, tileable, which is strict where declared_number is forgiving: only the JSON literal true makes the claim, because falling back to art always renders as something while wrongly tiling a non-seamless mask puts a seam on every floor that uses it.

The file is the evidence, never the descriptor. That is user_fonts.py's governing sentence applied to masks, and the parametrised cases build a REAL PNG differing in exactly one property each, so a refusal cannot come from the file being unreadable for some unrelated reason.

The id is a namespace, and containment is the point. Token names are minted --evcc-floor-<id>-<suffix>, so an id equal to a shipped floor type mints keys that already exist and assertUniqueTokenKeys throws β€” with the initial rebuild() unguarded, which takes the card down. A PREFIX is worse and less obvious: the scoped-theme import clears by raw prefix, so a material called carpet would wipe carpet-high's and carpet-low's tokens on import. UMAT-10..12 cover equal, prefixes, and prefixed-by.

Containment, not pattern-matching. contained_path() resolves the path and tests where it LANDS, then walks every component refusing symlinks β€” a symlinked directory defeats a check on the leaf alone, which is why user_fonts.py refuses islink at three separate places. A regex is a denylist of spellings; it cannot see a symlink and it cannot see whatever it is later loosened to admit.

The card half is covered separately and does NOT re-validate β€” the backend already did, against the files, and two validators drifting apart is worse than one: src/textures/user-materials.test.mjs (UM-1..10) for catalogue-row β†’ registry entry, including UM-10, which pins that a drop-in is ART unless its descriptor claims tileable: true β€” the default is decided once, on the Python side, and this hop only carries it, so a catalogue written before the key existed must read as art rather than start tiling every pack on the box, and src/theme-tokens/user-floors.test.mjs (UF-FLOOR-1..7) for the minted editor controls. UM-5 and UF-FLOOR-3 both exist for one trap: no per-material -opacity-card token may be emitted, because it sits above the global --evcc-floor-texture-opacity-card master in the render's var() fallback chain and would shadow it for anyone who set it.

The generated Mocking column

Each subsystem coverage table carries a Mocking cell derived from the same census that feeds the ratchet β€” so the docs and the gate cannot disagree. It aggregates a row's test files and reports the risk (bare xN), not the pedigree: clean means nothing in that row constructs an unspec'd mock. The Layer column says unit-vs-integration, which is not the axis that bites.

Generated, so hand edits are overwritten:

python scripts/mock_docs.py            # rewrite the column
python scripts/mock_docs.py --check    # CI-style staleness check, writes nothing

Both ratchets and the column live in tests/test_mock_ratchet.py, tests/test_docs_ratchet.py, scripts/mock_census.py and scripts/mock_docs.py.

Generated documentation β€” the staleness gate

A generated document cannot drift the way prose does. It drifts by not being regenerated, and that is indistinguishable from being correct: the file is well-formed, the numbers are specific, and nothing about it looks old.

Both generated surfaces in this repo were stale when the gate was written, and neither had ever failed anything:

surface state found why nothing caught it
docs/dev/reference/THEME_TOKEN_USAGE.md 651 lines out of date after 31 commits to src/styles/; every file:line citation wrong (index.js:324 had become :393) the generator was run by hand, last on 2026-08-11
the Mocking column in subsystems/15-adapters.md, 17-services.md two rows stale mock_docs.py --check existed, documented as "CI: fail if stale", and was wired into nothing

The second one is the sharper lesson: the check was already written and already correct. Writing a checker is not the same as running one.

scripts/check_generated_docs.py holds a registry of every generator and compares what is in the tree against what the generator emits now.

python scripts/check_generated_docs.py          # check
python scripts/check_generated_docs.py --fix    # regenerate everything, then re-check

Five findings, each ablated in tests/unit/test_generated_doc_gate.py (GDG-1..GDG-16) β€” a clean run against a clean tree proves nothing about a detector that is silently dead:

STALE the generator now emits something else
MISSING a registered file is not in the tree
SILENT the generator exited 0 and wrote nothing, or wrote the wrong name
BROKEN it could not be run, timed out, or failed
UNGATED a file carrying the GENERATED FILE banner that no registry entry claims β€” the omission failure, so adding a generator and forgetting to register it fails here rather than nowhere

Entries come in two shapes. Whole-file generators write complete documents and name an env var this gate sets to redirect them into a scratch tree, so the check never touches the working copy β€” one that wrote over the tracked files and restored them would leave the tree dirty on exactly the run that failed. Region generators rewrite a block inside a hand-written page (the Mocking column), so there is nothing to redirect; they bring their own --check and a non-zero exit means stale. A command that cannot be run at all is BROKEN, never STALE β€” those are opposite instructions, and reporting a missing node as "your docs are stale" sends the reader to regenerate a document that was already current.

This one IS a CI gate, unlike check_docs_index.py, and the difference is not an inconsistency. That script is a doc-commit rule because a new document legitimately lands before the index pass that files it, so gating on it would fail pushes for work that is not yet due β€” the 2026-06-12 check_legend_drift.py ruling. Staleness here is the opposite shape: it is caused by a code change, the fix is one command with no editorial judgement in it, and there is no later pass that is supposed to catch up. Same reason check-styles.mjs gates the build. It runs as the generated docs job in tests.yml.

Line-precise citations are what a generated doc is FOR, and this gate is what makes them safe. The standing rule that prose cites symbols rather than line numbers exists because prose has no mechanism to stay current. A generator does β€” provided something runs it.

Line-number citations are banned β€” scripts/check_doc_citations.py

A file.py:187 citation is the cheapest claim a doc can make and the only one that rots without anyone touching the document: one import added at the top of a module invalidates every citation below it, everywhere.

What makes it a trap rather than a nuisance is that a rotted line number still resolves. A rotted citation into core/manager.py::_find_button_entity_by_tokens lands on return entry_.entity_id β€” real code, in the right file, plausible. A broken link announces itself; this reads as correct.

This example used to name a _find_registry_entity_by_tokens helper in the core capabilities module, DELETED on 2026-11-09 as a zero-call-site orphan β€” so the illustration would have quietly stopped illustrating, which is this same failure one layer up. Replaced with the live twin that outlived it.

Measured across docs/ on 2026-08-15:

file.py:N citations 664
file.py::symbol citations 6
line citations that could be verified (a symbol was named beside them) 41
…of those, wrong 36 (88%)
line citations with nothing naming what they point at β€” unverifiable 623

Three of the failures were broken that same morning, by commits to the code the doc describes.

So the rule is the form, not the correctness: prose cites symbols, never line numbers. file.py::symbol survives any refactor that does not rename the thing, and the checker prints the replacement for every citation it can resolve. Where nothing names the target, degrade to the bare file.py rather than reverse-engineer a pointer that may already be wrong β€” a file-level citation cannot rot, and the precision being given up was fictional.

python scripts/check_doc_citations.py --summary

Gated in CI since 2026-11-07, and until then it was the half of a pair that ran nowhere. The two citation gates divide the work deliberately:

form validated by failure it reports
ID-form anchor β€” CN…, IN…, written file.py#ID doc_anchor.py --check MOVED / BROKEN, resolved repo-wide
file.py::symbol check_doc_citations.py NO-SYMBOL
any other #name fragment check_doc_citations.py NO-ANCHOR, substring in that one file

⚠ The forms in that table are spelled oddly on purpose: an example citation IS a citation. Both gates match a backticked file.py immediately followed by #token, and doc_anchor's BARE_RE matches a well-formed anchor id anywhere β€” backticks, prose, a table cell illustrating the syntax. Writing this section the natural way failed both gates on the commit that added them: a quoted example of the broken citation was reported NO-ANCHOR, and a plausible-looking placeholder id was reported BROKEN … defined nowhere. Use CN… with an ellipsis for a specimen id, and keep the file and the # fragment out of one code span.

check_doc_citations.py explicitly skips ID-form anchors (if ANCHOR_ID_RE.match(anchor): continue) so that two tools never render opposite verdicts on one citation β€” a moved but valid anchor is doc_anchor's business. The consequence of gating only doc_anchor was that the whole symbol-and-name half went unchecked, and it was not hypothetical: two citations in docs/retired/dev/25-eufy-adapter.md pointed at adapters/eufy/adapter.py with an #eufy_room_pixels_v1 fragment β€” a map format key that lives in mapping/map_source_coordinator.py and was never an anchor at all β€” pasted onto two unrelated capability claims, while CI stayed green.

⚠ The line-citation tally above is advisory, which is what makes gating it safe. main ends return 1 if all_problems else 0, so the 109 surviving file.py:N citations (100 of them unverifiable) are printed and never fail the run. Clearing that backlog is therefore not a precondition for the gate, and the gate did not need narrowing to one defect class β€” both of which looked true before the exit path was read. It is stdlib-only and ~1.2 s, so it rides in the generated-docs job beside its sibling rather than paying for a runner.

Testing a generator: assert on the DOCUMENT

EVT-1..EVT-3 in the same file cover scripts/gen_event_docs.py, and they read the emitted markdown rather than anything the generator printed about itself. That distinction is the whole point. The bug they pin had reached the output: where two fire sites built a payload key differently, only the first expression survived, so 17 slots printed one expression as though it were the only one β€” source and trigger among them, the keys an automation actually branches on. Every count the generator reported was correct while the document was wrong, so no stdout assertion could have seen it.

They run against a synthetic three-file package via EVCC_EVT_ROOT, not the real integration, so ordinary churn cannot fail them for an unrelated reason. EVT-3 asserts the blind-spot ledger is present and non-empty: a generated page that declares no blind spots reads as one that has none, which is how THEME_TOKEN_USAGE.md once reported 135 live theme tokens as dead.