When adding or modifying tests, favor behavioral contract coverage over brittle implementation/shape checks.
Apply these rules:
Example pattern (deterministic time):
class FakeTime:
def __init__(self, real_time, start=1000.0):
self._real = real_time
self._now = start
def monotonic(self):
return self._now
def advance(self, seconds):
self._now += seconds
def __getattr__(self, name):
return getattr(self._real, name)
def test_silence_threshold(monkeypatch):
import time as real_time
fake = FakeTime(real_time)
monkeypatch.setattr("tools.voice_mode.time", fake)
# drive the timeline deterministically
fake.advance(0.05)
# assert state transitions...
This approach makes tests resilient to harmless refactors while still catching real regressions in control flow, branching, and platform-dependent behavior.