Skip to content

ci: run ct002 codegen unit tests in the host-e2e job#398

Open
tomquist wants to merge 1 commit into
developfrom
claude/modest-goldberg-9bvas
Open

ci: run ct002 codegen unit tests in the host-e2e job#398
tomquist wants to merge 1 commit into
developfrom
claude/modest-goldberg-9bvas

Conversation

@tomquist
Copy link
Copy Markdown
Owner

@tomquist tomquist commented May 28, 2026

Problem

The codegen schema-validator tests in tests/components/ct002/test_codegen.py importorskip("esphome") — they import the esphome Python module to exercise the ct002 schema validators (MAC normalization, three-phase sensor validation) directly. That means they need the esphome module importable in the venv that runs pytest.

They ran nowhere in CI:

  • validate job — esphome isn't installed → importorskip skips them (this is the ESPHome not installed; skipping codegen unit tests / SKIPPED line seen in CI logs).
  • ct002-host-e2e job — only puts the esphome CLI on PATH (via uv tool install, which is an isolated env, not importable), and selects -m esphome_e2e, which these tests aren't marked with.
  • No other job touches them.

So 8 unit tests were silently dead. (The ESPHome E2E tests — the esphome_e2e-marked suites — do run correctly in ct002-host-e2e; they detect esphome via shutil.which("esphome"), so they were unaffected.)

Fix

Run the codegen tests in the ct002-host-e2e job, which already has the esphome toolchain:

- name: Install esphome into venv for codegen tests
  run: uv pip install esphome
- name: Run ct002 codegen unit tests (esphome schema validators)
  run: uv run --no-sync pytest tests/components/ct002/test_codegen.py -v
  • --no-sync — esphome isn't in uv.lock, so a normal uv run would re-sync and drop it; --no-sync preserves the pip-installed module.
  • Ordered last — the venv mutation happens after the E2E run, so it can't perturb it.

Verification

Locally: uv pip install esphome + uv run --no-sync pytest test_codegen.py8 passed.

CI/tooling-only change; no CHANGELOG.md entry (no user-visible behavior change).

https://claude.ai/code/session_01EmFCdUKkFS5gp87kkjr5t1


Generated by Claude Code

Summary by CodeRabbit

Release Notes

  • New Features

    • ESPHome external component for running CT002/CT003 emulator on ESP32
    • Modbus UDP transport support (TCP remains default)
    • MQTT Insights integration for Home Assistant discovery and monitoring
    • Marstek cloud device registration
    • DC battery input support with passthrough control
  • Bug Fixes

    • Home Assistant powermeter startup timeout handling
    • Fixed invalid device ID generation for Shelly Pro 3EM variants
    • Multi-Venus setup PV passthrough no longer misinterpreted as discharge
  • Documentation

    • Added comprehensive ESPHome and Python powermeter configuration guides
    • Updated troubleshooting with oscillation handling and battery behavior guidance
    • New efficiency warnings for DC batteries

Review Change Stack

The codegen schema-validator tests in tests/components/ct002/test_codegen.py
importorskip("esphome"), so they need the esphome Python module importable
in the venv that runs pytest. Previously they ran nowhere: the validate job
has no esphome installed, the ct002-host-e2e job only puts the esphome CLI on
PATH (via uv tool install) and selects -m esphome_e2e (which these aren't),
and no other job touches them.

Install esphome into the project venv at the end of the host-e2e job and run
the codegen tests with uv run --no-sync (esphome isn't in uv.lock, so a sync
would drop it). Ordered after the e2e run so the venv mutation can't perturb
it.
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 28, 2026

Caution

Review failed

Failed to post review comments

Walkthrough

Introduces an ESPHome ct002 external component with filters, balancer, protocol, MQTT/HA/Marstek integrations; adds host/CMake tests, E2E backends and YAML configs; updates Python ct002 aggregation, simulator with DC input, Modbus UDP, HomeAssistant REST bootstrap; updates docs, CI, and release tooling.

Changes

CT002 ESPHome feature and cross-backend updates

Layer / File(s) Summary
CI, CMake host build, pytest marker, add-on version, release tooling
.github/workflows/ci.yml, pyproject.toml, tests/components/ct002/CMakeLists.txt, release.sh, tests/test_release.py, ha_addon/config.yaml
Adds ct002 CI jobs, host GTest builds, pytest marker, add-on version bump, and release ref pin/reset with tests.
Documentation and examples
AGENTS.md, CONTRIBUTING.md, README.md, CHANGELOG.md, config.ini.example, docs/*, esphome.example.yaml
Adds ESPHome/Python powermeter docs, README updates, changelog entries, Modbus TRANSPORT example, and example ESPHome config.
ESPHome ct002 component core and wrappers
esphome/components/ct002/{ct002.h,ct002.cpp,wrapper_base.h,sensor_backed.*,hampel.*,smoothing.*,pid.*}
Implements ct002 core with powermeter pipeline and wrappers (sensor-backed, Hampel, smoothing, PID).
Load balancer and saturation tracker
esphome/components/ct002/balancer.*
Adds LoadBalancer and SaturationTracker with probe/efficiency/rotation logic.
Protocol, MQTT insights, HA discovery, Marstek registration/responder, test hooks
esphome/components/ct002/{protocol.*,mqtt_insights.*,ha_discovery.*,marstek_registration.*,marstek_responder.*,test_hooks.cpp}
Implements protocol encode/decode, MQTT insights with HA discovery and Marstek MQTT, cloud registration, responder helpers, and test control server.
ESPHome codegen, YAML configs, protocol vectors, and C++ host tests
esphome/components/ct002/__init__.py, tests/components/ct002/*
Adds codegen schemas, multiple ESPHome YAML test configs, protocol golden vectors/generator, and host GTest suites.
Python ct002 instructed-power and related tests
src/astrameter/ct002/ct002.py, tests/test_ct002_*
Tracks last instructed power and updates aggregation; adds unit and protocol parity tests.
Simulator DC input, E2E backends and scenarios
src/astrameter/simulator/*, tests/_ct002_e2e_backend.py, tests/test_*e2e*, tests/test_issue376_pv_passthrough.py
Adds DC input/passthrough, runner/config/HTTP control, shared E2E backend, and backend-agnostic E2E scenarios.
HomeAssistant powermeter REST bootstrap and tests
src/astrameter/powermeter/homeassistant.py, src/astrameter/powermeter/homeassistant_test.py
Seeds entity cache via REST when WS snapshot missing; manages task lifecycle; adds tests.
Modbus UDP transport and tests; config wiring
src/astrameter/powermeter/modbus.py, src/astrameter/config/config_loader.py, src/astrameter/powermeter/modbus_test.py
Adds UDP transport option, config wiring, unit and E2E UDP tests.
Shelly device id prefix fix and tests
src/astrameter/main.py, src/astrameter/main_test.py
Fixes generated device IDs for Shelly variants with tests.

Estimated code review effort

🎯 5 (Critical) | ⏱️ ~150 minutes

Possibly related PRs

  • tomquist/AstraMeter#385 — Introduces the ct002 ESPHome external component and related CI/test wiring similar to this PR’s ct002 C++/codegen work.
  • tomquist/AstraMeter#387 — Adds Modbus UDP transport and config wiring overlapping with this PR’s ModbusPowermeter and config_loader changes.
  • tomquist/AstraMeter#384 — Implements ct002 instructed-power aggregation updates in Python mirroring this PR’s last_instructed_power behavior and tests.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/modest-goldberg-9bvas

@tomquist tomquist changed the base branch from main to develop May 28, 2026 18:20
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.

2 participants