test: pin the behavior 100% coverage was not pinning - #1404
Open
raman325 wants to merge 1 commit into
Open
Conversation
Line coverage hit 100% in #1403, which is exactly the point at which it stops being informative. Branch coverage is 99% (57 partial branches), and a mutation-testing sample over four pure-logic modules scored 76.2% -- meaning roughly a quarter of deliberately-introduced defects were executed by the tests without being detected. Three functions turned out to have NO direct assertions at all, reaching 100% line coverage purely through their callers: - `LockCapabilities.bounded_slot_count` -- the gate for the out-of-range slot check. Every mutation of its condition survived. Getting it wrong either blocks legitimate writes or admits an impossible slot. - `WriteResult.changed` -- decides whether the seam refreshes the coordinator. Its truth table was never asserted. - `build_slot_unique_id` -- produces the entity registry key. No test referenced it, so the pipe separator that every existing entity depends on was unpinned. Also adds property tests for the two identifier codecs in `config.py`. Their sibling in `providers/_util.py` has had round-trip properties since the property suite was created; these had none, and that asymmetry cost a real bug -- #1402's parser gated on `str.isdigit()` and so rejected the negative slot its own builder emits. Reverting that fix makes the new round-trip property fail in under a second with the minimal counterexample `slot=-1`; the example-based tests that shipped with the builder do not notice, because nobody writes slot -1 down by hand. PIN masking gets properties too. It is a round trip over secret material: the mask has to be deterministic (one PIN reads as one token across a log), constant-width (a variable-width token discloses PIN length), salted per slot (so a log cannot reveal two slots share a PIN), and total on arbitrary pasted text. Mutation score over the sampled modules: 76.2% -> 92.6%. Every remaining survivor is a `slots=True` dataclass toggle with no observable effect under `frozen=True`, or an error-message string. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Entire-Checkpoint: 9d178f84aeb0
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1404 +/- ##
=======================================
Coverage 98.95% 98.95%
=======================================
Files 53 53
Lines 6598 6598
Branches 470 470
=======================================
Hits 6529 6529
Misses 69 69
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Proposed change
Line coverage reached 100% in #1403, which is exactly the point at which it stops telling you anything. Two harder measurements say otherwise:
resilience.py,credentials.py,_util.py,config.py). Roughly a quarter of deliberately-introduced defects were executed by the tests without being detected.resilience.pyand_util.pyboth scored 100% — their assertions are genuinely strong.credentials.pyscored 41.7%.Three functions had no direct assertions at all
Each reached 100% line coverage purely through its callers:
LockCapabilities.bounded_slot_countor→and,is→is not,<=→>,0→1). Wrong here either blocks legitimate writes or admits an impossible slot.WriteResult.changedbuild_slot_unique_id|separator every existing entity depends on was unpinned.EntryConfigDiff.has_changeswas tested only at the extremes — every existing test changes slots and locks together, or neither — so mutating any individualortoandsurvived. It gates the Lovelace re-render, so a collapsed disjunct means a user who only adds a slot silently gets a stale dashboard.Property tests for the identifier codecs
The tag codec in
providers/_util.pyhas had round-trip and totality properties since the property suite was created. The structurally identical codec indomain/config.pyhad none — and that asymmetry cost a real bug: #1402'sparse_slot_device_identifiergated onstr.isdigit(), rejecting the negative slot its own builder emits, which made the device invisible to both the orphan sweep and the removal hook.Reverting that fix against the new property:
Under a second, minimal counterexample. The example-based tests that shipped alongside the builder do not notice, because nobody writes slot
-1down by hand. That is the whole argument for the property.PIN masking
A round trip over secret material, previously covered only by examples. The properties pin what actually matters: the mask is deterministic (one PIN reads as one token throughout a log), constant-width (a variable-width token discloses PIN length, meaningful for a 4–8 digit code), salted per slot (a log cannot reveal that two slots share a PIN), and
deobfuscate_pinsis total on arbitrary pasted text.Deliberately not asserted: that the token never contains the PIN as a substring. An 8-hex-char token can contain
1234by chance, so that property would flake — the sound formulation is the constant-width one above.Type of change
Additional information
Mutation score over the sampled modules: 76.2% → 92.6% (
credentials.py41.7% → 80.6%,config.py79.5% → 94.9%), re-measured with the same harness after these tests. Every remaining survivor is either aslots=Truedataclass toggle — no observable effect whenfrozen=Truealready blocks the writes the tests attempt — or an error-message string.Tests only; no production code touched. Suite: 1457 passed, 100% line coverage retained, ~59s. Verified at
HYPOTHESIS_PROFILE=ci(200 examples) as well as the dev default.🤖 Generated with Claude Code