chore: unify HA manufacturer and add refactor guards

This commit is contained in:
2026-02-18 02:25:07 +01:00
parent 00b2eb859a
commit 9495e7e8de
6 changed files with 171 additions and 2 deletions

View File

@@ -0,0 +1,37 @@
Set-StrictMode -Version Latest
$ErrorActionPreference = "Stop"
$repoRoot = (Resolve-Path (Join-Path $PSScriptRoot "..")).ProviderPath
$configPath = (Resolve-Path (Join-Path $repoRoot "include/config.h")).ProviderPath
$mqttPath = (Resolve-Path (Join-Path $repoRoot "src/mqtt_client.cpp")).ProviderPath
$configText = Get-Content -Raw -Path $configPath
if ($configText -notmatch 'HA_MANUFACTURER\[\]\s*=\s*"AcidBurns"\s*;') {
throw "include/config.h must define HA_MANUFACTURER as exactly ""AcidBurns""."
}
$mqttText = Get-Content -Raw -Path $mqttPath
if ($mqttText -notmatch 'device\["manufacturer"\]\s*=\s*HA_MANUFACTURER\s*;') {
throw "src/mqtt_client.cpp must assign device[""manufacturer""] from HA_MANUFACTURER."
}
if ($mqttText -match 'device\["manufacturer"\]\s*=\s*"[^"]+"\s*;') {
throw "src/mqtt_client.cpp must not hardcode manufacturer string literals."
}
$roots = @(
Join-Path $repoRoot "src"
Join-Path $repoRoot "include"
)
$literalHits = Get-ChildItem -Path $roots -Recurse -File -Include *.c,*.cc,*.cpp,*.h,*.hpp |
Select-String -Pattern '"AcidBurns"' |
Where-Object { (Resolve-Path $_.Path).ProviderPath -ne $configPath }
if ($literalHits) {
$details = $literalHits | ForEach-Object {
"$($_.Path):$($_.LineNumber)"
}
throw "Unexpected hardcoded ""AcidBurns"" literal(s) outside include/config.h:`n$($details -join "`n")"
}
Write-Host "HA manufacturer drift check passed."

View File

@@ -0,0 +1,41 @@
#include <Arduino.h>
#include <unity.h>
#include "../../src/app_context.h"
#include "../../src/receiver_pipeline.h"
#include "../../src/sender_state_machine.h"
#include "config.h"
static void test_refactor_headers_and_types() {
SenderStateMachineConfig sender_cfg = {};
sender_cfg.short_id = 0xF19C;
sender_cfg.device_id = "dd3-F19C";
ReceiverSharedState shared = {};
ReceiverPipelineConfig receiver_cfg = {};
receiver_cfg.short_id = 0xF19C;
receiver_cfg.device_id = "dd3-F19C";
receiver_cfg.shared = &shared;
SenderStateMachine sender_sm;
ReceiverPipeline receiver_pipe;
TEST_ASSERT_EQUAL_UINT16(0xF19C, sender_cfg.short_id);
TEST_ASSERT_NOT_NULL(receiver_cfg.shared);
(void)sender_sm;
(void)receiver_pipe;
}
static void test_ha_manufacturer_constant() {
TEST_ASSERT_EQUAL_STRING("AcidBurns", HA_MANUFACTURER);
}
void setup() {
UNITY_BEGIN();
RUN_TEST(test_refactor_headers_and_types);
RUN_TEST(test_ha_manufacturer_constant);
UNITY_END();
}
void loop() {}