Skip to content

test(drivers): let a driver report metrics, and a topic carry a configurable prefix - #59

Merged
frahlg merged 3 commits into
mainfrom
mqtt-topic-and-metrics-only-checks
Aug 7, 2026
Merged

test(drivers): let a driver report metrics, and a topic carry a configurable prefix#59
frahlg merged 3 commits into
mainfrom
mqtt-topic-and-metrics-only-checks

Conversation

@frahlg

@frahlg frahlg commented Jul 31, 2026

Copy link
Copy Markdown
Member

Two catalog conventions only held because every driver that breaks them is byte-identical to its FTW baseline and therefore skipped. Editing one for any reason fails on a rule it never had to meet. Neither rule was right, so this fixes the rules rather than adding an exemption.

test_calls_emit_in_poll required host.emit, which carries a DER reading and needs a DER type the host understands. VALID_DERS has had heatpump since the FTW promotion, but no host has a heat-pump reading type yet, so a heat-pump driver has nothing to emit and reports temperatures and power through host.emit_metric. The rule left an author two options: emit nothing, or claim to be a battery. It now accepts either call.

test_subscription_topics_are_strings required a literal, while heishamon and ctek_hybrid both build the topic from a file-local set in driver_init — the broker prefix is the operator's to choose. Renamed to test_subscription_topics_are_static and rewritten to ask for what it actually wants: a topic decidable without running the driver. Literals and file-local names concatenate; an index, a field or a call does not, which is how a driver ends up subscribing to whatever a message told it to.

make check is green: 3148 passed, 1323 skipped.

Found while making heishamon report hp_power_w (srcfl/ftw#520). That change is #NEXT, based on this branch.

🤖 Generated with Claude Code

…gurable prefix

Two catalog conventions only held because every driver that breaks them is
byte-identical to its FTW baseline and therefore skipped. Editing one for any
reason fails on a rule it never had to meet, and neither rule was right.

test_calls_emit_in_poll required host.emit, which carries a DER reading and
needs a DER type the host understands. VALID_DERS has had `heatpump` since the
FTW promotion, but no host has a heat-pump reading type, so a heat-pump driver
has nothing to emit and reports through host.emit_metric. The rule left an
author two options: emit nothing, or claim to be a battery.

test_subscription_topics_are_strings required a literal, while heishamon and
ctek_hybrid both build the topic from a file-local set in driver_init — the
broker prefix is the operator's to choose. The check now asks for what it
actually wants: a topic decidable without running the driver. Literals and
file-local names concatenate; an index, a field or a call does not, which is
how a driver ends up subscribing to whatever a message told it to.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Signed-off-by: Fredrik Ahlgren <fredrik@sourceful-labs.com>

@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: 79132d07a7

ℹ️ 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 thread drivers/tests/test_driver_contract.py Outdated
Comment thread drivers/tests/test_mqtt_drivers.py Outdated

@frahlg frahlg left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Automated maintenance pass.

(Can't formally approve — this PR's author is the same account this pass posts as.)

Reviewed against AGENTS.md and CONTRIBUTING.md. This is a test-convention fix only — no driver source or manifest touched, so no version bump or CHANGELOG entry is owed here. Both changes are narrowing/correcting existing rules rather than loosening safety-relevant checks:

  • test_calls_emit_in_poll now accepts host.emit_metric alongside host.emit, which matches reality: heatpump has been in VALID_DERS since the FTW promotion but no host has a heat-pump host.emit reading type yet, so a heat-pump driver reporting through emit_metric was never actually wrong.
  • test_subscription_topics_are_static (renamed from test_subscription_topics_are_strings) still rejects a topic built from runtime data (index/field/call) — it only additionally accepts concatenation of string literals and file-local names, which is what heishamon and ctek_hybrid already do in driver_init. Reviewable, not a relaxation of the security-relevant property (topic decidable without running the driver).

All 6 CI checks are green (dco, packages, signed channel accepts this tree, history-secret-scan, drivers, public-boundary). Looks ready to merge.

Flagging rather than merging: the merge API refuses with 403 Merging stacked PRs via this API is not supported. Use the web interface instead because #60 is stacked on this branch. A maintainer needs to merge this one from the web UI.


Generated by Claude Code

frahlg commented Jul 31, 2026

Copy link
Copy Markdown
Member Author

Automated maintenance pass: reviewed and this looks ready.

  • CI green across all 6 checks (dco, packages, signed-channel, history-secret-scan, drivers, public-boundary).
  • Test-only change, no driver source touched, no version bump needed.
  • Both edits are sound: test_calls_emit_in_poll was requiring host.emit(), which needs a host DER type — heat-pump drivers have none and legitimately report via host.emit_metric() instead. test_subscription_topics_are_static (renamed from ..._are_strings) correctly still rejects a runtime-derived topic (index/field/call) while allowing the literal + file-local-name concatenation that heishamon and ctek_hybrid already use for a configurable broker prefix.

I attempted to merge this but the GitHub API refused: "Merging stacked PRs via this API is not supported. Use the web interface instead." — because #60 is branched from this PR's branch. A maintainer will need to merge this one from the web UI. Once it's in, #60's diff will collapse down to just its own heishamon commit automatically.


Generated by Claude Code

@miravoss26 miravoss26 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.

Read the whole diff — two test-contract loosenings, both well-argued.

  • test_calls_emit_in_poll now accepts host.emit_metric( alongside host.emit(. Right call: a heat-pump driver has no DER reading type to emit yet, so metrics are its honest output — the alternative was "emit nothing or claim to be a battery." The docstring captures the why.
  • test_subscription_topics_are_static swaps the literal-only rule for literal-or-concatenation-of-file-local-names. The re.fullmatch correctly rejects runtime-derived topics (index/field/call) while allowing PREFIX .. "/status".

One note, not a blocker: the check is syntactic — a bare identifier passes even if it held runtime data. In practice the sandbox keeps those file-local so this matches intent; just flagging that the guarantee is "looks static," not "is constant."

Security screen: no secrets, no new deps, no network — this tightens a subscribe-injection guard, doesn't widen it. CI green. Safe to merge from my read; leaving the merge to a human (device-drivers isn't on my auto-merge allowlist).

frahlg added 2 commits August 7, 2026 09:59
Signed-off-by: Fredrik Ahlgren <fredrik@sourceful-labs.com>
Signed-off-by: Fredrik Ahlgren <fredrik@sourceful-labs.com>
@frahlg
frahlg merged commit fb18dd9 into main Aug 7, 2026
6 checks passed
@frahlg
frahlg deleted the mqtt-topic-and-metrics-only-checks branch August 7, 2026 08:02
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