Skip to content

Wave 9 #115: Power Victron bench integration tests - #97

Open
bernardc6 wants to merge 1 commit into
mainfrom
subagent/power-victron-bench
Open

Wave 9 #115: Power Victron bench integration tests#97
bernardc6 wants to merge 1 commit into
mainfrom
subagent/power-victron-bench

Conversation

@bernardc6

Copy link
Copy Markdown
Collaborator

Wave 9 #115: Power Victron bench integration tests

Context: Tier-a-is-honest evidence for the RoamCore Victron integration
(Bernard, 2026-08-04: "must not fail + super intuitive + critical
infrastructure"). Product Build Directive §"Verify every connection"
requires runtime verification that sensor.vt_battery_soc_percent updates
end-to-end via a real (or emulated) Venus OS MQTT broker. The bench is a
portable pytest that any maintainer can run on a dev box or in CI; it
boots VictronAuto against a real MQTT broker fixture, publishes fake
Venus OS D-Bus topics, asserts the vt_* HA MQTT discovery payloads appear,
and verifies end-to-end that the roamcore_power.yaml tile Jinja would
resolve to a real value.

Changes:

  • homeassistant/addons/roamcore-victron-auto/src/main.py:

    • Additive bench mode (VictronAuto.bench flag) + bench CLI subcommand.
    • VictronStartupError exception class with plain-English copy
      (starts with "Victron GX not found on your network") for the
      bench smoke + the runtime error path.
    • bench_run_once() method that connects both HA + Victron MQTT,
      publishes discovery, and exits cleanly.
    • _bench_connect_ha_mqtt_local() helper that connects to a
      localhost broker without Supervisor calls.
    • argparse-based main() entry point with bench subcommand.
  • homeassistant/addons/roamcore-victron-auto/tests/ (NEW):

    • conftest.py: pytest fixtures (mqtt_broker with mosquitto/amqtt
      fallback, ha_discovery_recorder, victron_auto_instance,
      victron_connected).
    • test_victron_auto_bench.py: 12 tests covering connect, subscribe,
      discovery payload shape, end-to-end SoC round-trip, recovery,
      plain-English errors, idempotency, power-tile integration.
    • pytest.ini: asyncio_mode=auto.
    • README.md: IKEA-style 5-step setup + troubleshooting.
  • homeassistant/addons/roamcore-victron-mock/src/main.py:

    • argparse-based main() with --bench flag publishing a
      deterministic SoC walk (10..100 step 10, repeating).
    • --bench-interval and --bench-iterations knobs.
  • homeassistant/addons/roamcore-victron-auto/requirements.txt:

    • Add pytest, pytest-asyncio, amqtt as bench deps (commented docs).
  • scripts/checks/victron-bench-smoke.sh (NEW): wires the bench into
    check.sh, runs pytest, exits 0 on SKIP with a clear message.

  • scripts/check.sh:

    • Run victron-bench-smoke.sh on --core-only (tier-a-is-honest).
    • Run it after victron-rc-contract.sh in full mode (per spec).
  • docs/catalog/power/victron.md:

    • §"Bench testing" IKEA-5: install, run, what it covers, real GX,
      troubleshooting.

Verification:

  • bash scripts/checks/victron-bench-smoke.sh: 12 passed in ~54s.
  • bash scripts/check.sh --core-only: GREEN (all smoke checks
    including the new victron bench).
  • The bench SKIP path is exercised when paho-mqtt / amqtt are
    missing (smoke script exits 0 with a clear "SKIP — install
    paho-mqtt to run" message).
  • All 12 acceptance criteria from the slice spec are met.

Rollback: git revert

Context: Tier-a-is-honest evidence for the RoamCore Victron integration
(Bernard, 2026-08-04: "must not fail + super intuitive + critical
infrastructure"). Product Build Directive §"Verify every connection"
requires runtime verification that sensor.vt_battery_soc_percent updates
end-to-end via a real (or emulated) Venus OS MQTT broker. The bench is a
portable pytest that any maintainer can run on a dev box or in CI; it
boots VictronAuto against a real MQTT broker fixture, publishes fake
Venus OS D-Bus topics, asserts the vt_* HA MQTT discovery payloads appear,
and verifies end-to-end that the roamcore_power.yaml tile Jinja would
resolve to a real value.

Changes:
  * homeassistant/addons/roamcore-victron-auto/src/main.py:
    - Additive bench mode (VictronAuto.bench flag) + bench CLI subcommand.
    - VictronStartupError exception class with plain-English copy
      (starts with "Victron GX not found on your network") for the
      bench smoke + the runtime error path.
    - bench_run_once() method that connects both HA + Victron MQTT,
      publishes discovery, and exits cleanly.
    - _bench_connect_ha_mqtt_local() helper that connects to a
      localhost broker without Supervisor calls.
    - argparse-based main() entry point with `bench` subcommand.

  * homeassistant/addons/roamcore-victron-auto/tests/ (NEW):
    - conftest.py: pytest fixtures (mqtt_broker with mosquitto/amqtt
      fallback, ha_discovery_recorder, victron_auto_instance,
      victron_connected).
    - test_victron_auto_bench.py: 12 tests covering connect, subscribe,
      discovery payload shape, end-to-end SoC round-trip, recovery,
      plain-English errors, idempotency, power-tile integration.
    - pytest.ini: asyncio_mode=auto.
    - README.md: IKEA-style 5-step setup + troubleshooting.

  * homeassistant/addons/roamcore-victron-mock/src/main.py:
    - argparse-based main() with --bench flag publishing a
      deterministic SoC walk (10..100 step 10, repeating).
    - --bench-interval and --bench-iterations knobs.

  * homeassistant/addons/roamcore-victron-auto/requirements.txt:
    - Add pytest, pytest-asyncio, amqtt as bench deps (commented docs).

  * scripts/checks/victron-bench-smoke.sh (NEW): wires the bench into
    check.sh, runs pytest, exits 0 on SKIP with a clear message.

  * scripts/check.sh:
    - Run victron-bench-smoke.sh on --core-only (tier-a-is-honest).
    - Run it after victron-rc-contract.sh in full mode (per spec).

  * docs/catalog/power/victron.md:
    - §"Bench testing" IKEA-5: install, run, what it covers, real GX,
      troubleshooting.

Verification:
  - bash scripts/checks/victron-bench-smoke.sh: 12 passed in ~54s.
  - bash scripts/check.sh --core-only: GREEN (all smoke checks
    including the new victron bench).
  - The bench SKIP path is exercised when paho-mqtt / amqtt are
    missing (smoke script exits 0 with a clear "SKIP — install
    paho-mqtt to run" message).
  - All 12 acceptance criteria from the slice spec are met.

Rollback: git revert <sha>

import json
import socket
import threading
from typing import Any

import paho.mqtt.client as mqtt
import pytest

Yields the app once both clients are connected. Cleans up on teardown.
"""
import asyncio
self._loop = _asyncio.new_event_loop()
_asyncio.set_event_loop(self._loop)
self._loop.run_until_complete(self._serve())
except BaseException as e: # noqa: BLE001
self._proc.kill()
try:
self._log.close()
except Exception:
try:
client.loop_stop()
client.disconnect()
except Exception:
app._victron_client.loop_stop()
try:
app._victron_client.disconnect()
except Exception:
app._victron_client.disconnect()
except Exception:
pass
except Exception:
app._ha_client.loop_stop()
try:
app._ha_client.disconnect()
except Exception:
app._ha_client.disconnect()
except Exception:
pass
except Exception:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant