Repository navigation
hardening: critical fixes + edge-case guards + tests + docs - #52
Conversation
Add three tests for the fsnotify config watcher: - TestWatcherFiresOnChange: verifies the applier callback fires with the updated config after modifying config.yaml on disk - TestWatcherIgnoresInvalidYAML: verifies invalid YAML is rejected silently (applier not called, old config preserved) - TestWatcherStopIsIdempotent: verifies Stop() can be called twice without panic The idempotent-stop test exposed a real bug: Stop() did a bare close(w.stop) which panics on double-close. Fixed by wrapping the close+fsw.Close in sync.Once. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Comprehensive quality pass across the codebase:
Critical fixes:
- currency.go: guard division-by-zero when FX rate is missing
- mpc/service.go: guard NaN/Inf in both forecastPVW and predictedPVW
- api.go: log.Warn on SaveConfig/SaveBatteryModel failures (was silent)
- dispatch.go: safer SoC default (0.1 not 0.5) when battery never reports
- dispatch.go: log.Warn when MPC plan goes stale
Hardening:
- mpc.go: defensive η check in forward-simulation loop
- telemetry/store.go: clamp negative rawLoad to 0 in UpdateLoad
- ocpp/server.go: 5s shutdown timeout prevents deadlock
- prices.go: ENTSOE stub returns explicit error instead of empty slice
New tests:
- telemetry: TestUpdateLoadClampsNegative
- mpc: TestOptimizeWithNaNPVW, TestOptimizeZeroCapacity,
TestOptimizeZeroActionLevels, TestBuildSlotsEmptyForecast,
TestSelectPlannerPVWBothNaN
Documentation:
- docs/api.md: document energy.today nested structure
- docs/driver-catalog.md: add solaredge_pv.lua (18th driver)
- docs/host-api.md: clarify covers both Lua + WASM
- control/CLAUDE.md: add PlanStale, PlanTargetFunc signature, holdoff
- docs/battery-models.md: document saturation curve seed guard
Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e9674b860e
ℹ️ 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".
| state.SetGridTarget(gridW) | ||
| state.PlanStale = false | ||
| } else { | ||
| slog.Warn("mpc plan stale — falling back to self_consumption") |
There was a problem hiding this comment.
Rate-limit stale-plan warning in dispatch loop
This warning is emitted on every control-cycle when planner mode has no current plan (PlanTarget is nil or returns ok=false), which is common during startup or extended price/forecast gaps; with the default 5s loop this produces continuous warn-level spam and can drown out actionable alerts while growing logs unnecessarily. Consider logging only on the PlanStale state transition (false→true) or adding throttling.
Useful? React with 👍 / 👎.
|
🎉 This PR is included in version 2.0.1 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
Systematic quality pass: 3 critical fixes, 4 medium hardening guards, 6 new tests, 5 doc updates. go test ./... green.