From 68ffd3b22125ab0c9ed75e14893bf633dbeff0c3 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sat, 25 Apr 2026 04:36:32 -0500 Subject: [PATCH] [api] Fix CI errors in MAC varint unit tests - Test file: declare proto_debug_end_ locally instead of misusing PROTO_ENCODE_DEBUG_INIT (which expands to a comma+expression for appending to a function call, not a standalone statement). Add NOLINTNEXTLINE on the deterministic mt19937_64 seed so clang-tidy cert-msc32-c stops failing the build (the seed is intentional for reproducible test runs). - socket FILTER_SOURCE_FILES: tolerate non-dict CORE.config['socket'] (e.g. C++ unit-test builds where socket isn't validated as a mapping). Returning [] is safe -- all impl files are guarded by USE_SOCKET_IMPL_* defines so only the selected one contributes code. --- esphome/components/socket/__init__.py | 9 ++++++++- tests/components/api/test_proto_mac_varint.cpp | 6 +++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/esphome/components/socket/__init__.py b/esphome/components/socket/__init__.py index abbbb0f056..c7b2fec35f 100644 --- a/esphome/components/socket/__init__.py +++ b/esphome/components/socket/__init__.py @@ -177,7 +177,14 @@ async def to_code(config): def FILTER_SOURCE_FILES() -> list[str]: """Return list of socket implementation files that aren't selected by the user.""" - impl = CORE.config["socket"][CONF_IMPLEMENTATION] + socket_config = CORE.config.get("socket") + if not isinstance(socket_config, dict): + # Config has not been validated yet (or socket isn't configured as a + # mapping for this build, e.g. a C++ unit test build that skips config + # validation). Don't filter -- all impl files are guarded by USE_* + # defines so only the selected implementation contributes code anyway. + return [] + impl = socket_config[CONF_IMPLEMENTATION] # Build list of files to exclude based on selected implementation excluded = [] diff --git a/tests/components/api/test_proto_mac_varint.cpp b/tests/components/api/test_proto_mac_varint.cpp index 7597c89806..317a6fb9d6 100644 --- a/tests/components/api/test_proto_mac_varint.cpp +++ b/tests/components/api/test_proto_mac_varint.cpp @@ -1,6 +1,7 @@ #include #include +#include #include #include "esphome/components/api/api_buffer.h" @@ -55,7 +56,9 @@ static void verify_mac(uint64_t mac, size_t expected_bytes) { APIBuffer api_buf; api_buf.resize(16); uint8_t *pos = api_buf.data(); - PROTO_ENCODE_DEBUG_INIT(&api_buf); +#ifdef ESPHOME_DEBUG_API + uint8_t *proto_debug_end_ = api_buf.data() + api_buf.size(); +#endif ProtoEncode::encode_varint_raw_48bit(pos PROTO_ENCODE_DEBUG_ARG, mac); size_t new_len = pos - api_buf.data(); @@ -109,6 +112,7 @@ TEST(ProtoMacVarint, AllOnes) { verify_mac(0xFFFFFFFFFFFFULL, 7); } // F // 100 deterministic-random 48-bit MACs to catch regressions across the space. TEST(ProtoMacVarint, RandomSample) { + // NOLINTNEXTLINE(cert-msc32-c,cert-msc51-cpp) -- intentional fixed seed for reproducibility. std::mt19937_64 rng(0xC0FFEE); for (int i = 0; i < 100; i++) { uint64_t mac = rng() & 0xFFFFFFFFFFFFULL;