Skip to content

Test: add HA bridge nil-safety and diagnostic method tests - #48

Merged
frahlg merged 1 commit into
masterfrom
6-ha-bridge-tests
Apr 16, 2026
Merged

frahlg merged 1 commit into
masterfrom
6-ha-bridge-tests

Conversation

@frahlg

@frahlg frahlg commented Apr 16, 2026

Copy link
Copy Markdown
Member

Summary

  • Add go/internal/ha/bridge_test.go with 6 test functions (7 sub-tests) covering all public diagnostic methods on the HA bridge
  • Tests verify nil-safety (nil *Bridge), zero-value safety (&Bridge{}), BrokerAddr formatting (IP + hostname), SensorsAnnounced pre-discovery state and formula, and LastPublishMs mutex round-trip
  • No MQTT broker needed -- all tests are lightweight and run in microseconds

Test plan

  • go test -v ./internal/ha/ passes (7/7)
  • go test ./... passes (pre-existing configreload failure is unrelated)

🤖 Generated with Claude Code

The HA bridge had zero test coverage. Add tests for all public
diagnostic methods (IsConnected, BrokerAddr, LastPublishMs,
SensorsAnnounced) on nil, zero-value, and configured Bridge
instances. No MQTT broker needed — tests exercise the code paths
the API layer relies on without network I/O.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@frahlg
frahlg merged commit dee4ccd into master Apr 16, 2026
@frahlg
frahlg deleted the 6-ha-bridge-tests branch April 16, 2026 05:14

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ab296e9bbb

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +99 to +101
b.mu.Lock()
b.sensorsAnnounced = expected
b.mu.Unlock()

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Invoke production path for sensor-count formula test

This test never exercises publishDiscovery; it computes expected and then writes b.sensorsAnnounced directly, so it can pass even if the production formula or assignment in publishDiscovery regresses. In practice, any future bug where discovery publishes a different number of sensors (or forgets to update the field) would not be caught, despite the test name/comment claiming it validates that behavior.

Useful? React with 👍 / 👎.

@github-actions

Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 2.0.1 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

frahlg added a commit that referenced this pull request Sep 27, 2026
…overs (#1456)

* refactor(state,mpc,api): remove dead storage, planner and backup leftovers

- #49 Keep on a driver draft now takes the driver update lock and removes
  the record before the saved original, so an expiry already in flight
  finishes first and Keep answers 409 instead of "kept" for a reverted draft.
- #20 History maintenance runs only the plain SQLite stages. Remove the
  Parquet archive pipeline (rolloff, aggregate/sample archive, legacy
  compaction, cold/diagnostic Parquet pruning, Store.Prune) and the unused
  retentionDays closure of rolloffLoop; keep the Parquet readers.
- #40 Drop the hot-history alias (s.hot, hotPath, hotWriteMu), dead
  hot-only branches and readers, forceRotate, heldBytes, RotateHistory and
  the test-only historyWriter.maintainHistory.
- #41 Remove the always-empty ImportedHistoryFiles filter, the unused
  coldDir parameter of legacyHistoryIdle and the test-only backup.Restore;
  round-trip tests now use RestoreContents.
- #29 Remove the recourse/multistage challenger, unix and auto transports,
  transport Health and the stateful shadow evaluator. The worker request
  keeps the same solver settings as constants; the Energyplan process
  transport and Core DP shadow are unchanged.
- #47 Remove the always-zero PV nameplate and load caps (Service fields,
  Plan.pv_nameplate_w/load_max_w, forecast ACLimitW/ClampForecasts and
  their web chart caps), the load rain-check and test-only wrappers. A
  single sanitiser still maps NaN or negative load to 0 W.
- #48 Handshake errors now say the bundled Energyplan worker does not match
  Core and to run `ftw update` or reinstall. Drop PYTHONPATH and fix stale
  Update Center, CVXPY, Python shadow and scenario comments.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01MuerPFZFG88kgu8sWVHeq7

* test(mpc): the native contract test no longer expects a scenario model

The shared PV scenarios in buildRequest were reachable only by calling
ExternalOptimizer directly with a risk margin; production runs through
EnergyplanOptimizer, which applies the margin to the slots and zeroes it
before the request. Removing that dead block left the native contract
test asking for three scenarios. It now checks that a margin never
builds a scenario model.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01MuerPFZFG88kgu8sWVHeq7

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant