Iter 24. Live-broker roundtrip test for the RumqttPublisher → mosquitto
→ subscriber path. CI-safe: silently skips when BFLD_MQTT_BROKER is
unset; opt-in locally with:
scoop install mosquitto
mosquitto -v -c mosquitto-allow-anon.conf &
BFLD_MQTT_BROKER=tcp://localhost:1883 cargo test \
-p wifi-densepose-bfld --features mqtt --test mosquitto_integration
Added (gated on `feature = "mqtt"`):
- tests/mosquitto_integration.rs:
* broker_env() parses BFLD_MQTT_BROKER as tcp://host:port (default 1883)
* unique_client_id(prefix) — nanosecond-suffix per-test, per the
`feedback_mqtt_integration_test_patterns` memory note
* spawn_subscriber() creates a Client + thread iterating Connection;
drains incoming Publish into an mpsc channel and emits a oneshot on
SubAck arrival
* collect_messages(rx, expected_count, timeout) — bounded recv loop
that respects a wall-clock deadline (no `loop { iter.recv() }`)
* Two named tests:
live_broker_anonymous_event_roundtrips_all_six_topics
Subscribe to ruview/<node>/bfld/+/state with the wildcard, await
SubAck, publish an Anonymous event with zone, collect 6 messages,
assert every expected entity name appears exactly once.
live_broker_restricted_event_omits_identity_risk
Same setup, publish a Restricted event, collect up to 6 (will
only see 5), assert identity_risk is absent.
Test discipline (per the workspace memory):
- per-test unique client_id (prevents broker session collisions)
- subscriber eventloop pumped until SubAck BEFORE publishing
- explicit timeout instead of infinite recv (no test hangs on misconfig)
- publisher Connection drained in its own thread (rumqttc requirement)
- 200ms sleep between publisher construction and first publish to let
CONNECT complete (otherwise messages are queued before the session
is open, and mosquitto silently drops them in some configurations)
When BFLD_MQTT_BROKER is unset:
- broker_env() returns None
- Test prints a one-line skip message to stderr and returns Ok(())
- Both tests show as passing in cargo output
ACs progressed:
- ADR-122 AC1 end-to-end demonstrable — when a broker is available,
the test proves a BfldEvent traverses RumqttPublisher, the network,
and an MQTT subscriber, arriving with the correct topic shape and
payload encoding.
- ADR-122 AC4 enforced over the wire — the Restricted-class test
proves identity_risk does not even reach the broker, not just that
it's stripped at render_events.
Test config:
- cargo test --no-default-features → 72 passed
- cargo test → 169 passed
- cargo test --features mqtt → 178 passed (176 + 2 skip-mode tests)
Out of scope (next iter target):
- BfldPipelineHandle: Arc<Mutex<BfldPipeline>> + a worker thread that
pumps inbound (SensingInputs, IdentityEmbedding) channel into MQTT.
Single-call "set up publisher and walk away" API for operators.
- CI workflow that starts mosquitto in a Docker service container and
sets BFLD_MQTT_BROKER so the integration test actually runs.
Co-Authored-By: claude-flow <ruv@ruv.net>