test(templates): cover instance_seed helper and update service tests

Add tests/service_testing/test_instance_seed.py — pins NODE_NAME to assert
determinism of seeded functions and sweeps NODE_NAMEs to assert cross-fleet
divergence. Conftest gains load_real_instance_seed() so template tests see
the real seeding behavior instead of a stub. Existing template tests updated
to pin NODE_NAME and match seeded outputs.
This commit is contained in:
2026-04-22 09:24:28 -04:00
parent 3fb84ac5d0
commit a63708a3d1
10 changed files with 302 additions and 78 deletions

View File

@@ -33,15 +33,16 @@ def _load_mqtt(accept_all: bool = True, custom_topics: str = "", persona: str =
"MQTT_PERSONA": persona,
"MQTT_CUSTOM_TOPICS": custom_topics,
}
for key in list(sys.modules):
if key in ("mqtt_server", "syslog_bridge"):
del sys.modules[key]
for key in ("mqtt_server", "syslog_bridge", "instance_seed"):
sys.modules.pop(key, None)
sys.modules["syslog_bridge"] = _make_fake_syslog_bridge()
spec = importlib.util.spec_from_file_location("mqtt_server", "decnet/templates/mqtt/server.py")
mod = importlib.util.module_from_spec(spec)
with patch.dict("os.environ", env, clear=False):
from .conftest import load_real_instance_seed
sys.modules["instance_seed"] = load_real_instance_seed()
spec.loader.exec_module(mod)
return mod
@@ -127,14 +128,18 @@ def test_subscribe_wildcard_retained(mqtt_mod):
_send(proto, _connect_packet())
written.clear()
_send(proto, _subscribe_packet("plant/#"))
# The water_plant persona now picks a per-instance site prefix (north,
# south, plant-a, etc.) instead of hardcoding "plant/". Use the top-level
# wildcard so the test doesn't depend on which site this decky rolled.
_send(proto, _subscribe_packet("#"))
assert len(written) >= 2 # At least SUBACK + some publishes
assert written[0].startswith(b"\x90") # SUBACK
assert len(written) >= 2 # At least SUBACK + some publishes
assert written[0].startswith(b"\x90") # SUBACK
combined = b"".join(written[1:])
# Should contain some water plant topics
assert b"plant/water/tank1/level" in combined
# The identifying tail of water-plant topics is stable regardless of
# which site prefix was chosen at instance boot.
assert b"water/tank1/level" in combined
def test_publish_qos1_returns_puback(mqtt_mod):
proto, _, written = _make_protocol(mqtt_mod)