fix(tests): F2 — the voluptuous mirror compares fields, not marker classes (t35)

real voluptuous 0.16.0 implements ``Marker.__eq__`` as ``self.schema ==
other`` — a field-name comparison with no class check, so
``Optional("x") == Required("x")`` is True (verified against the library
source, not just the audit note). The mirror compared class + field, which
kept two dict entries for one field: a ``Required(field, default=...)`` after
``Optional(field)`` LOOKED like it applied the default, while real voluptuous
keeps the first (defaultless) key object and silently drops it — the exact
t33 F-A failure mode the mirror exists to catch, i.e. the harness could mask
the bug it was built to see.

``Marker.__eq__`` is now the library's comparison and the contract tests gained
both pins: field-only equality (with equal hashes) and the mixed-marker
re-declaration that used to be masked. Reverting only ``__eq__`` makes those
two fail, which is the red proof recorded for t35.

Verified: uvx --with pytest-asyncio pytest tests -q → 276 passed, 1 skipped;
uvx ruff check custom_components tests → clean.
This commit is contained in:
James Mackay committed 2026-10-10 21:04:34 +01:00
1 parent 186e5c1935
commit 7a0152e6b5
2 files changed
+42 -6

No files matched your search

+31
View File
@@ -424,6 +424,37 @@ class TestVoluptuousMirrorContract:
vol_mirror.declared_fields({CONF_ADB_HOST: str})
def test_marker_equality_is_field_only_like_voluptuous(self):
"""t35 F2: real ``Marker.__eq__`` is ``self.schema == other``.
No class check: ``Optional("x") == Required("x")`` on voluptuous 0.16.0.
"""
vol = sys.modules["voluptuous"]
assert vol.Optional(CONF_ADB_HOST) == vol.Required(CONF_ADB_HOST)
assert hash(vol.Optional(CONF_ADB_HOST)) == hash(
vol.Required(CONF_ADB_HOST)
)
# the real implementation compares the field name to the other value
assert vol.Optional(CONF_ADB_HOST) == CONF_ADB_HOST
def test_a_mixed_marker_redeclaration_drops_the_default(self):
"""The case a class-comparing mirror masks (t35 F2).
``Required(field, default=...)`` after ``Optional(field)`` collides on
the field name, so the FIRST key object (no default) survives — the
schema silently loses the default, exactly like the Optional case.
"""
vol = sys.modules["voluptuous"]
schema = {vol.Optional(CONF_ADB_HOST): str}
schema[vol.Required(CONF_ADB_HOST, default=DISCOVERED_HOST)] = str
assert (
vol_mirror.defaults_by_key(schema)[CONF_ADB_HOST]
is vol_mirror.UNDEFINED
)
class TestDiscoveryPrefill:
"""F-A / F-A2 / F-D: the discovered address reaches the rendered FORM."""