Skip to content

Bump HMTL for the COLOR wire-range widening - #35

Merged
aphelps-claude-bot merged 10 commits into
mainfrom
bump-hmtl-color-wire-range
Aug 20, 2026
Merged

aphelps-claude-bot merged 10 commits into
mainfrom
bump-hmtl-color-wire-range

Conversation

@aphelps-claude-bot

Copy link
Copy Markdown
Collaborator

Parent PR for aphelps/HMTL#9 — pointer bump only, one line of diff.

Why this PR exists at all

make test STRICT=1 here is what runs HMTL's four-ABI × two-flag layout sweep and its negative control. The WLED firmware build never reaches those headers — rs485_bridge_protocol.h imports only HMTLprotocol/HMTLWireFormat.h, and the bridge reads PROGRAM_COLOR as d.programVals[0..2], the RGB triple at offset 0, which no range width can move. So the firmware is genuinely unaffected, and carrying the pointer is the only thing that puts the new asserts in super-repo CI.

What HMTL#9 does

hmtl_program_color_t embedded pixel_range_t, whose width follows -DBIG_PIXELS, so the struct was 5 bytes on some shipped modules and 7 on others — two ATMega328s already disagreed. It now carries a fixed-width wire_pixel_range_t: 7 bytes with range at 3 everywhere, and the size assert drops from 3 + 2 * sizeof(PIXEL_ADDR_TYPE) to a literal.

Full reasoning, the negative controls, and the fleet-migration note are on HMTL#9.

Verified on this exact combination

  • make test STRICT=1 — sweep covered host / host-avr-proxy / avr-g++ / xtensa under both flag settings; 484/484 perturbations broke the build as required; esp-now-router relay + election + attach all passed.
  • cd WLED && rm -rf .pio/libdeps/ampworks && pio run -e ampworks — SUCCESS. (The rm -rf is not ceremony: PlatformIO copies path-based lib_deps into .pio/libdeps/ and does not reliably re-sync them, which has previously made a build report success against a stale copy.)

Merge order

⚠️ HMTL#9 must merge first, and this pointer then needs repointing. HMTL merges are squashed, so the branch SHA this commit records (a1a1e0c) will not exist on HMTL main afterwards — a fresh git submodule update --init would fail to fetch it. Same chore as WLED_dev#33; flagging it here so it is not missed again.

🤖 Generated with Claude Code

https://claude.ai/code/session_013HqzdRdTRnreSvevaQGQSJ

aphelps/HMTL#9 gives hmtl_program_color_t a fixed-width range so its wire
layout no longer follows -DBIG_PIXELS. Nothing on the WLED build path
changes: rs485_bridge_protocol.h imports only HMTLprotocol/HMTLWireFormat.h,
and the bridge reads PROGRAM_COLOR's payload as d.programVals[0..2] — the
RGB triple at offset 0, which no range width can move.

Carrying the pointer here is what puts the new asserts in super-repo CI:
`make test STRICT=1` runs HMTL's four-ABI x two-flag layout sweep and its
negative control, neither of which the WLED firmware build would reach.

Verified on this combination:
  make test STRICT=1  — 484/484 perturbations broke the build as required,
                        sweep covered host/host-avr-proxy/avr/xtensa,
                        esp-now-router relay+election+attach all passed
  pio run -e ampworks — SUCCESS after rm -rf .pio/libdeps/ampworks

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_013HqzdRdTRnreSvevaQGQSJ

@aphelps-reviewer-bot aphelps-reviewer-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Adjacent-context review — informed by WLED_dev/pack-hmtlprograms-and-timesync-payloads-so-avr-and-esp32-agree-on-the-wire (shares cross-abi, struct-packing; partially touches hmtl-protocol, wire-format)

Reviewed the bump against HMTL#9 at a1a1e0c (current head of both). The layout work itself reads correctly and I am not repeating the generic pass. What the earlier packing round in this workstream kept tripping over was never the struct definitions — it was which target actually compiles the guard: a desktop stub that had quietly drifted from the shipped header, an assert living in a header no toolchain in the matrix included, and a negative-control loop that reported on a variant it had never run. All three notes below are that same shape, and all three are actionable at this layer rather than inside HMTL#9. The diff here is a single gitlink line, so everything is top-level.

1. Suggested test: the new behavioural tests are invoked by no automation, in either repo.

HMTL#9 is careful to wire test_protocol.py into HMTL's own test-python recipe, with a comment to the effect that a guard no target invokes is as dead as an assert no toolchain compiles. That is true of the recipe, but the recipe has no caller: aphelps/HMTL has no .github/workflows at all, and this repo's test-hmtl (Makefile:131-141) delegates only to HMTL/tests/layout/ — the sweep, packed-access, and negative. So make test STRICT=1 here does carry the new static_asserts into CI, as the PR body says, but not the six new program_color unit tests and not the six Python encoder tests. The parts of HMTL#9 that CI never sees are exactly the parts covering new runtime behaviour: the start/length bounding, the rejection of the stale five-byte invocation, and "length 0 still means whole strip". Since this repo is the only one of the two with CI, widening test-hmtl to also run make -C HMTL test-python (and test-native, if the runner cost is acceptable), behind the same missing_tests guard used elsewhere so an older pointer still skips cleanly, is what would close it.

2. Suggested test: the -DBIG_PIXELS half of test_color_start_beyond_a_byte_is_not_truncated is compiled by nothing.

At a1a1e0c, platformio/HMTL_Test/platformio.ini defines only native and native_coverage, neither of which sets the flag, and no target passes it to pio test. So the #ifdef BIG_PIXELS branch — the one asserting that a start of 300 actually lands on pixels 300-301, i.e. the payoff the widening was for — is never built. The #else branch is the only one that ever runs, and it asserts the opposite outcome (rejection). To be precise about what is covered: tests/layout's packed-access syntax-checks HMTLPrograms.cpp under both flag settings, so the clamp code does compile under -DBIG_PIXELS; nothing executes it. A native_big_pixels env extending native with the flag, run alongside native, would make that branch real. Otherwise it is a comment shaped like a test, and replacing it with a plain note would at least be honest about the coverage.

3. Suggested post-merge check: the new pixel_range_t asserts pin the stub, and this repo is the only place that can bind the stub to the real header.

HMTL#9 states this scope itself, so it is not an oversight — the sweep puts -I$(STUBS) on the include path and HMTL does not vendor ArduinoLibs, so sizeof(pixel_range_t) == 2 / 4 constrains platformio/HMTL_Test/stubs/PixelUtil.h, not ArduinoLibs/PixelUtil/PixelUtil.h. It is worth a line here rather than there for two reasons. That stub having drifted from the real header — it hard-coded the wide type regardless of the flag — is what led an earlier round of this same workstream to record the wrong widths as confirmed. And the width is now load-bearing at runtime rather than only at layout time: program_color() derives addr_max from PIXEL_ADDR_TYPE, so a stub that is wrong in the other direction would hide a truncation the shipped build has. This super-repo is the only checkout where both trees exist, so it is the only place a check can confirm they still agree. A full compile is not free (the real header pulls FastLED, which is not vendored outside PlatformIO here), so the cheap form is a guard in test-hmtl that the flag block in the stub still matches the shipped one.

None of this blocks the bump — the pointer and the merge-order note look right.

@aphelps-reviewer-bot aphelps-reviewer-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Self-review of the COLOR wire-range widening.

Everything is in this top-level body rather than inline. PR #35's diff is the HMTL
gitlink and nothing else, so GitHub has no hunks to hang comments on; inline comments on
submodule paths would 422 the whole review. All references below are to the submodule PR
aphelps/HMTL#9 at a1a1e0c.

Checked before reviewing, so the findings are read in proportion. The WLED side really is
unaffected: usermods/rs485_bridge/usermod_rs485_bridge.cpp:432 consumes PROGRAM_COLOR
behind a programLen < 3 guard and reads only programVals[0..2], never the range, and
nothing on the WLED build path includes HMTLPrograms.h. And PixelUtil::numPixels() returns
uint16_t in both the shipped header and the stub — which is what makes the new addr_max
check load-bearing rather than dead: a 400-pixel strip on a default-flag build is
representable, so "inside the strip" and "survives the narrowing" genuinely are two questions.


1. The -DBIG_PIXELS half of the new native test is compiled by nothing

platformio/HMTL_Test/test/test_pixel_programs/test_pixel_programs.cpp:446 splits
test_color_start_beyond_a_byte_is_not_truncated on #ifdef BIG_PIXELS. But
platformio/HMTL_Test/platformio.ini defines only native and native_coverage, neither
of which sets the flag, and tests/layout/ sweeps -DBIG_PIXELS over layout asserts only —
it never builds the unit tests. So the branch asserting the thing this entire task bought
(start=300 actually painting pixels 300 and 301) has never been compiled, let alone run. The
branch that does run asserts rejection, which is the opposite behaviour.

That is the same defect the PR's own Makefile comment names one screen earlier: "a guard no
target invokes is the same defect as a static_assert no toolchain compiles". Here it is an
assertion no toolchain compiles, added in the same change.

Suggested test: add [env:native_big_pixels] (extends = env:native, plus -DBIG_PIXELS)
to platformio/HMTL_Test/platformio.ini and run it from HMTL/Makefile's test-native, so
both halves of every #ifdef BIG_PIXELS in the native suite are actually built. Without it,
delete the #ifdef and keep only the branch that runs — the same "add the guard or drop the
axis" choice the plan already made for tests/layout/.

2. The stale-invocation guard is strip-length dependent, and fails open on exactly the fleet the widening was for

In program_color() (Libraries/HMTLMessaging/HMTLPrograms.cpp), the stale five-byte form
decodes as start=2560, length=0 and is refused only if start >= num or
start > addr_max. On a default build addr_max == 255, so it is always caught. On a
-DBIG_PIXELS build addr_max == 65535, so the only remaining guard is the strip length —
and the new CLI warning concedes exactly this in passing: "which the module rejects on any
strip shorter than 2561 pixels". A -DBIG_PIXELS module driving more than 2560 pixels — the
builds the widening exists to serve — takes the stale invocation as length == 0 and floods
the whole strip, silently, with none of the DEBUG1 diagnosis the design is built around.

The same root cause reaches a supported invocation: --color r,g,b,5,0 has its start=5
validated and then thrown away, because length == 0 means the whole strip regardless of
start. Nothing warns.

Cheapest mitigation, and consistent with the change's own "loud rather than quiet" reasoning:
DEBUG1 when length == 0 && start != 0. That combination is either the stale form or a
caller who has misunderstood the zero rule; it is never something a sender means.

3. Suggested test: pin start > 0, length == 0

test_color_zero_length_fills_whole_strip uses start=0, so the "start is validated and then
discarded" path is unasserted on both sides. One native case — start=5, length=0 on an
8-pixel strip, expecting setAllRGB and pixels 0-4 lit as well — pins the documented meaning
and would fail loudly if anyone later "fixes" zero-length to mean start..end. The Python side
has the same gap: no test covers ProgramColor(..., start=5, length=0).

4. test-python still names files individually, which re-arms the defect it documents

HMTL/Makefile's new comment diagnoses this correctly — "a new test file therefore has to be
added HERE to run at all" — and then ships the form that requires it. The next test file added
to python/hmtl/tests/ runs nowhere again, and nothing will notice.
pytest hmtl/tests/ --ignore=hmtl/tests/test_CircularBuffer.py keeps the known-failing module
out of the default run (the stated reason for naming files) while collecting anything added
later. Right diagnosis, wrong fix.

5. test_color_message_carries_the_payload_after_the_headers derives its expectation from the code under test

In python/hmtl/tests/test_protocol.py, that case builds payload = ProgramColor(...).pack()
and asserts msg.endswith(payload) — which proves only that prepare_msg calls pack. It is
the one place the file departs from the literal-byte discipline its own docstring insists on
("Deriving it from FORMAT would only prove FORMAT agrees with itself"). Transcribe it instead:
with MAX_DATA == 32, msg[-32:-25] == b"\xff\x00\x00\x02\x00\x03\x00" for start=2, length=3. The msg[-(len(payload)+1)] == 0x31 assertion in the same test is good and should
stay.

6. The reject diagnostic conflates three causes, and the (uint32_t) casts are inert

(num == 0) || (start >= num) || (start > addr_max) all emit the same
COLOR start past addressable range: N numPixels: M. On a 400-pixel default-flag build,
start:300 numPixels:400 reads as self-contradictory unless the reader already knows
PIXEL_ADDR_TYPE is uint8_t — precisely the knowledge this task exists to stop people
needing. Printing addr_max alongside num turns it back into a diagnosis, which is the
stated purpose of the line. (An empty strip landing under "start past addressable range" is
the third, smaller case of the same conflation.)

Minor, same statement: (uint32_t)color->range.start > (uint32_t)addr_max casts two operands
that are both already uint16_t, and under -DBIG_PIXELS the clause is unreachable
(addr_max == 65535, and start is a uint16_t). Dropping the casts loses nothing and avoids
implying a promotion hazard that isn't there.

7. Suggested post-merge check: confirm test_protocol.py is actually collected

make -C HMTL test-python on merged main, checking that test_protocol.py appears in pytest's
collected output rather than only that the target is green. The new test file's runner is
part of this change (a one-line Makefile recipe edit), and a Makefile conflict resolved the
wrong way at merge would drop the file back to running nowhere with no red build to show for
it — which is the exact failure mode this PR set out to close.

Both reviews on this PR made the same point: aphelps/HMTL#9 adds behavioural
tests for program_color() — the narrowing, the zero-length rule, the
stale-invocation rejection — and NOTHING invoked them. HMTL has no
.github/workflows, and test-hmtl here reached only HMTL/tests/layout/. So CI
got the new static_asserts and none of the code that reads those structs.

The sweep covers compile-time LAYOUT. That is a different question from
whether the reader is correct, and this repo is the only place both get asked.

Both pixel-width envs, because an `#ifdef BIG_PIXELS` branch in a test body is
dead source unless something compiles the flag — which is exactly how HMTL#9's
first draft shipped a test whose wide-width half had never been built.

Delegated to HMTL's own `make test-native` so the env list stays in the repo
that owns it. PIO defaults to the venv setup.sh builds and falls back to PATH;
if neither resolves, this is a skipped suite like any other. Verified both
ways rather than assumed: lenient exits 0 with a "-- skipped: --" note,
STRICT=1 exits non-zero with the ERROR line.

HMTL's `test-python` is deliberately NOT wired in. It needs pytest, which is
not in WLED/requirements.txt, so it would fail on a fresh CI venv — a local
venv that happens to have pytest would have hidden that. Adding pytest to the
pinned toolchain is a separate decision about this repo's dependency set;
filed rather than smuggled in here.

Pointer moves to dbd6673, which also carries HMTL#9's review fixes.

Verified on this combination:
  make test STRICT=1  — sweep on host/host-avr-proxy/avr/xtensa x both flags,
                        484/484 perturbations red as required, 61 native tests
                        per pixel-width env, router relay+election+attach
  pio run -e ampworks — SUCCESS after rm -rf .pio/libdeps/ampworks

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_013HqzdRdTRnreSvevaQGQSJ

@aphelps-reviewer-bot aphelps-reviewer-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Re-review of b2d420e..3447e25 plus the submodule delta aphelps/HMTL a1a1e0c..dbd6673,
which I fetched separately — PR #35's own diff is the gitlink and the Makefile, so almost
everything below is top-level for the same reason as last time: an inline comment on a submodule
path 422s the whole review.

Prior issues

  • 1 (dead #ifdef BIG_PIXELS half) — fixed, and verified running rather than asserted.
    [env:native_bigpixels] extends env:native with the flag, and HMTL's test-native runs both.
    I checked the CI log for run 31837134539 rather than taking the PR's word: all six suites compile
    and execute under both widths, and test_color_start_beyond_a_byte_is_not_truncated passes in
    native_bigpixels — so the branch asserting start=300 landing on pixels 300-301 is now
    executed, not merely compiled. The stub honours the flag too (stubs/PixelUtil.h), which is
    what makes the wide run mean anything.
  • 2 (strip-length-dependent guard) — fixed, and the replacement is stronger than what I asked
    for.
    I traced the whole stale family rather than just the example: a 5-byte
    -C r,g,b,start,length always leaves wire bytes 5-6 zero-filled, so the wire length is always
    0. Every stale invocation therefore rejects on the length == 0 && start != 0 pairing regardless
    of strip length or flag, and the single survivor (old start=0, length=0) means the same thing
    in both layouts. addr_max is correctly retained for the separate narrowing question. This is
    the flag-independent rule the finding wanted.
  • 3 (pin start > 0, length == 0) — half fixed. The native case landed
    (test_color_zero_length_with_nonzero_start_is_rejected, now as a rejection, matching the new
    rule). The Python half is still absent — see new finding 4.
  • 4 (test-python naming files) — fixed. pytest hmtl/tests/ --ignore=…test_CircularBuffer.py,
    and the comment now describes what the recipe does instead of what it fails to do.
  • 5 (expectation derived from the encoder) — fixed. Literal
    b"\xff\x00\x00\x02\x00\x03\x00" + 25 nulls, and the good msg[-33] == 0x31 assertion kept.
  • 6 (conflated diagnostic + inert casts) — fixed. Three distinct messages, addr_max printed
    beside the offending value, (uint32_t) casts dropped.
  • 7 was a post-merge check; unchanged.

New findings — all in aphelps/HMTL#9 at dbd6673

1. The new validity rule exists in C only, so the two-implementation cross-check disagrees with itself on the day it was built

python/hmtl/HMTLprotocol.py:702 (the ProgramColor docstring) still states the rule the firmware
just stopped implementing: "length == 0 means the WHOLE strip, whatever start says; the firmware
rejects a start past the end rather than clamping it."
Both halves are now false — the firmware
rejects a nonzero start with zero length, and the "past the end" framing is the one this round
replaced. ProgramColor([r,g,b], start=5, length=0) still packs happily.

This class — a typed encoder that pins the layout — was added by this PR precisely so the two ends
could not drift. It drifted in one round, on a validity rule rather than a layout, which is the
same failure wearing different clothes. State the rule in the docstring and raise when
length == 0 and start != 0.

2. --color, the supported path, tells the operator the opposite of what the module now does

python/bin/HMTLClient:267 prints " (length 0 = whole strip)" for --color 255,0,0,5,0, and the
--color help text at :71 says the same. The firmware now drops that message, and the only
feedback is a DEBUG1 line on the module's serial port — which the person running the CLI is not
watching. Round 1's finding 2 named this exact invocation as the second half of the same root
cause ("--color r,g,b,5,0 has its start validated and then thrown away; nothing warns"); it was
fixed in the module and left alone in the sender, and the outcome moved from "floods the strip"
to "does nothing, silently". A sys.exit(1) beside the existing arity check is the whole fix:

if int(length) == 0 and int(start) != 0:
    print("--color: length 0 means the whole strip, so start must be 0; "
          "the module rejects start=%s with length=0" % start)
    sys.exit(1)

3. The -P color warning still carries the sentence that was the evidence for the bug

python/bin/HMTLClient (generic branch, ~line 310) still ends with: "…becomes start=2560,
length=0, which the module rejects on any strip shorter than 2561 pixels."
That clause is what made
round 1's finding demonstrable, and this round removed the caveat from the firmware. As shipped the
warning understates its own guarantee and reads as "it may be accepted on a longer strip" — the
belief the fix exists to kill.

                      "         start=2560, length=0. A zero length with a "
                      "nonzero start is now\n"
                      "         rejected on EVERY strip, whatever its length. "
                      "Use --color instead.")

(indicative — transcribe against the surrounding string continuation.)

4. Suggested test: pin the zero-length rule on the Python side

python/hmtl/tests/test_protocol.py has no case for it. One test that start=0, length=0 is the
only legal zero-length form and that start=5, length=0 is refused by the encoder (once finding 1
lands) closes the asymmetry: the C side has test_color_zero_length_with_nonzero_start_is_rejected
and nothing on the Python side answers it. Same argument the file's own docstring makes for the
byte layout, applied to the one rule that is not a byte layout.

5. The rule is not in the header a sender-implementer reads

Libraries/HMTLMessaging/HMTLPrograms.h's hmtl_program_color_t comment covers the widening, the
uint16_t decision, and the deliberate absence of hmtl_program_color_fmt() — but not
"length == 0 requires start == 0". That constraint currently lives only in the body of
program_color() in the .cpp. It is the same shape as the missing *_fmt this PR reasons so
carefully about: a rule stated in one implementation and absent from the contract everyone else
reads. One line beside the struct, where the layout asserts already are.

6. Stale rationale in the Python test that carries the cross-check narrative

test_stale_generic_invocation_now_encodes_a_rejectable_start still says "The firmware refuses a
start past the end for exactly this reason"
and points at test_color_stale_five_byte_invocation….
The rejection is now the zero-length pairing — and the test's own assert length == 0 is precisely
what makes the message rejectable, so the correct rationale is already sitting in the assertions.
Trivial, but this docstring is the one place the two implementations are narrated as checking each
other.

Comment thread Makefile Resolved
…coverage

Pointer moves to 3e23ada, which teaches python/'s ProgramColor and HMTLClient
the zero-length rule the C reader learned last round — the two implementations
had disagreed about message VALIDITY for one commit, which is the drift this
whole PR exists to prevent.

Also from the re-review, on this side: the "== HMTL native behaviour tests
(both pixel widths) ==" banner was asserted HERE while the env list lives in
HMTL's own Makefile, so an older HMTL pin would run a single env under a banner
claiming two. Dropped the claim; HMTL's test-native prints what it actually ran.

Verified: make test STRICT=1 green (61 native tests per pixel-width env,
484/484 perturbations red as required, router suites passing).

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_013HqzdRdTRnreSvevaQGQSJ

@aphelps-reviewer-bot aphelps-reviewer-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Re-review of 3447e25..b4da0cf plus the submodule delta aphelps/HMTL dbd6673..3e23ada, which
I fetched separately — PR #35's own diff is the gitlink and one Makefile comment, so everything
below is top-level for the usual reason: an inline comment on a submodule path 422s the review.

Prior issues

  • 1 (validity rule in C only) — fixed, and I checked the two sides state the same rule rather
    than two similar ones.
    program_color() rejects (range.length == 0) && (range.start != 0);
    HMTLprotocol.py:731 raises on length == 0 and start != 0. Identical, and neither is strip-length
    or -DBIG_PIXELS dependent. The one legal zero-length form (0,0) survives on both sides.
  • 2 (--color told the operator the opposite) — fixed, and the construct-before-announce ordering
    is the right shape.
    I checked the failure path is clean rather than assuming it: sys.exit(1) at
    HMTLClient:276 runs before HMTLClient(...) is constructed at :346, so no socket is opened and
    no partial message is sent. Ran it against the worktree copy: exit status 1, one line of output,
    nothing half-done.
  • 3 (-P color warning carried the stale sentence) — fixed. "Every 5-byte form leaves the wire
    length zero … on every strip and both -DBIG_PIXELS settings" now matches the C comment's
    reasoning instead of contradicting it.
  • 4 (Python test for the rule) — fixed, and better than asked. Three cases: the refusal, the legal
    0,0 form, and a nonzero-start-with-real-length control so the rule cannot over-fire.
  • 5 (rule absent from the header) — fixed. HMTLPrograms.h:245-257 states it as contract, with
    the reason the pairing beats the magnitude test.
  • 6 (stale rationale in the Python test) — NOT fixed. See new finding 1.

New findings

1. Prior finding 6 is unaddressed, and that docstring is now the only place in the tree still stating the replaced rule

python/hmtl/tests/test_protocol.py:123-125 still reads "The firmware refuses a start past the end
for exactly this reason"
. git grep "past the end" over python/, Libraries/ and
platformio/HMTL_Test/ at 3e23ada returns that one hit and nothing else — every other site was
corrected this round, so the file that exists to narrate the two implementations checking each other
is the last one narrating the old rule. The cross-reference is also stale in a second way: the native
test is test_color_stale_five_byte_invocation_is_rejected_not_flooded, not
test_color_stale_five_byte_invocation_is_rejected.

    Read at the current layout those same five bytes are start=2560,
    length=0 — and a zero length with a nonzero start is exactly what the
    firmware refuses (see program_color in HMTLPrograms.cpp, and
    test_color_stale_five_byte_invocation_is_rejected_not_flooded in the
    native suite). The `assert length == 0` below is what makes the message
    rejectable, which is why the rule catches every 5-byte invocation rather
    than this one example. This test pins the encoding half of that story so
    the two sides cannot drift apart again.

2. The new except ValueError also swallows the int() conversions, and then misdescribes what happened

HMTLClient:269-276 puts int(r), int(g), int(b), int(start), int(length) inside the try.
Verified: --color 255,0,x prints the bare line invalid literal for int() with base 10: 'x' — no
--color prefix, unlike the arity check six lines above — and the comment sitting on that handler
says "The module would drop this message", which is false; nothing was constructed and no message
exists. Narrow the try to the constructor and give the parse failure its own message:

        try:
            (r, g, b) = [int(v) for v in parts[:3]]
            (start, length) = ([int(v) for v in parts[3:5]]
                               if len(parts) == 5 else (0, 0))
        except ValueError as e:
            print("--color takes integers: %s" % e)
            sys.exit(1)
        try:
            program = HMTLprotocol.ProgramColor([r, g, b], start, length)
        except ValueError as e:
            # The module would drop this message. Say so here rather than
            # letting the operator watch a strip do nothing.
            print("%s" % e)
            sys.exit(1)

(the later print re-converts with int(r)/int(start), which is harmless on ints.)

3. Validating in __init__ creates a seam that catches one rule and drops the rest of the domain on the floor

struct.error is not a ValueError (it derives straight from Exception), so the CLI's new handler
cannot catch it. Verified against the worktree copy:

  • --color 255,0,0,70000,5 → raw traceback, struct.error: ushort format requires 0 <= number <= 65535
  • --color 300,0,0,0,5 → raw traceback, struct.error: ubyte format requires 0 <= number <= 255

This pattern predates the PR for ProgramCircular/ProgramSparkle, but ProgramColor is now the
path two separate warnings tell operators to use, and its docstring advertises that it fails at the
CLI rather than at the module. As shipped it does that for one input and tracebacks for the
neighbouring ones. Either range-check start/length/values in __init__ beside the pairing
check, or widen the CLI to except (ValueError, struct.error).

4. The docstring's promise is now broader than what the encoder can deliver

"an operator finds out at the CLI, not by watching a strip do nothing" is true for the pairing rule
and only the pairing rule. program_color() has two further rejections a sender cannot evaluate —
start >= numPixels() and start > addr_max — and --color 0,0,255,300,10 is precisely the
invocation the widening exists to enable: it packs cleanly, and any default-width
(uint8_t PIXEL_ADDR_TYPE) module drops it with nothing but a DEBUG1 line. The pre-round docstring
at least mentioned the past-the-end rejection; the rewrite dropped it rather than correcting it, and
the correct version is still true. One sentence naming the two rejections the sender cannot see —
and that an over-long length is clamped, not rejected — keeps the claim honest.

5. The super-repo Makefile fixed the banner but not its own rationale

The @echo change is right. Five lines above the paragraph that explains the env list belongs to
HMTL, the comment block still asserts "Both pixel-width envs, because an #ifdef BIG_PIXELS branch
in a test body is dead source unless something compiles the flag"
— the same claim about the same
list this repo does not own, which an older HMTL pin falsifies in exactly the way the banner change
describes. Same edit, one paragraph up.

6. Suggested test: pin the CLI refusal, not just the encoder refusal

Three tests pin ProgramColor; none pins the thing this round actually shipped in the CLI — that
--color 255,0,0,5,0 exits non-zero before HMTLClient(...) is constructed. That ordering is the
whole fix (the commit message says so), and it is exactly what a future refactor moving the print
back above the constructor would silently undo, with the encoder tests staying green. A subprocess
check asserting exit 1 and no connection attempt closes it. Pin the import to the worktree when you
write it — this round's own near-miss was a CLI check that passed against an installed hmtl.

…st we do not own

Pointer moves to d8769c3: ProgramColor now range-checks every field (struct.error
is not a ValueError, so an out-of-range field was escaping HMTLClient's except
clause as a raw traceback), parsing and validation are separated so a typo does
not report as a module rejection, and the docstring no longer claims the CLI
catches mistakes that depend on the target strip.

On this side, the leftover from last round: the comment block still promised
"Both pixel-width envs" five lines above the paragraph explaining that the env
list lives in HMTL's Makefile, not here. Same defect as the banner, one comment
over — a claim made by the repo that cannot keep it. It now says why it declines
to name the envs at all.

Verified: make test STRICT=1 green (61 native tests per pixel-width env at this
pin, 484/484 perturbations red as required, router suites passing).

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_013HqzdRdTRnreSvevaQGQSJ

@aphelps-reviewer-bot aphelps-reviewer-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Re-review of b4da0cf..031e84c plus the submodule delta aphelps/HMTL 3e23ada..d8769c3, which I fetched separately — PR #35's own diff is the gitlink and one Makefile comment. All top-level for the usual reason: an inline comment on a submodule path 422s the review.

Prior issues

  • 1 (stale rationale in test_protocol.py) — fixed, both halves. The docstring now narrates the pairing rule and the "five bytes always leave wire bytes 5-6 zero" generalisation, and the cross-reference names test_color_stale_five_byte_invocation_is_rejected_not_flooded — I checked that symbol exists at test_pixel_programs.cpp:538. git grep "past the end" over python/ now returns only the docstring sentence that is supposed to say it.
  • 2 (except ValueError swallowed the int() conversions) — fixed, and I ran it rather than reading it. --color 255,0,x → --color values must be integers; got: 255,0,x, exit 1, no traceback. The two try blocks have separate messages and the constructor's comment no longer claims a message was built.
  • 3 (struct.error is not a ValueError) — fixed, verified on both inputs from my last round. --color 255,0,0,70000,5 → COLOR start must be 0-65535 …; --color 300,0,0,0,5 → COLOR r must be 0-255 …. Both exit 1 with no traceback. With every field range-checked in __init__, pack() genuinely cannot raise struct.error any more, so the CLI's except ValueError now means what its comment says.
  • 4 (docstring over-claimed) — mostly fixed; see nit 2. The "what this class can and cannot catch" paragraph is right and I confirmed both named rejections against the shipped C: start >= num at HMTLPrograms.cpp:724 and start > addr_max at :733.
  • 5 (super-repo Makefile rationale) — fixed. The comment now explains why it declines to name the env list instead of naming it, matching the banner. I also checked the new sentence's factual claim: PIO ?= ./.venv/bin/pio really does fall back to command -v in the recipe, so "falls back to PATH" is true and not aspirational.
  • 6 (suggested test: pin the CLI refusal) — done, and three of the four are exactly right. test_cli_refuses_the_invalid_pairing_without_claiming_to_send pins the ordering via the absence of the announcement, which is a sound proxy since the print precedes the constructor. The fourth is new finding 1.

make test-python's selection is 26 passing here, matching the PR's claim, and I confirmed the directory-with---ignore form picks the new file up without anyone having to remember it.

New findings

1. test_cli_accepts_a_valid_range runs the CLI all the way into the network client — it passes only because nothing is listening, and hangs forever when something is

The other three CLI tests sys.exit(1) before HMTLClient(...) is constructed, so they never touch a socket. This one takes the accept path, which falls through to HMTLClient(options.address, options.port, …) at HMTLClient:357 with the defaults localhost:6000. Three consequences, all reproduced against the worktree at d8769c3:

  • Nothing listening (today's machine): connect is refused, the process dies with a raw Traceback and exit 1 — and the test still passes, because it asserts only on stdout. Note it is the one test of the four that does not assert returncode, and its return code is 1: the same value the three refusal tests use as their evidence of failure. So this test cannot currently distinguish "the encoder accepted it" from "the encoder rejected it and something else printed the line" — and it tolerates a traceback that its own sibling, test_cli_reports_an_out_of_range_field_rather_than_a_struct_traceback, treats as a defect.
  • Something listening that is not a command server: _run_cli passes no timeout, and multiprocessing.connection.Client(..., authkey=…) blocks on the auth handshake with no socket timeout. I bound a bare socket on 127.0.0.1:6000 and ran it: the subprocess never returns. make -C HMTL test includes test-python, so the default target hangs indefinitely with no output about why.
  • A real HMTL command server listening — i.e. the machine this tooling exists for: the test connects and client.send_and_ack(msg) transmits a live broadcast COLOR message to the fleet (hmtladdress defaults to BROADCAST, output ALL_OUTPUTS), then blocks in send_and_ack's untimed while True: if self.get_ack() loop. A unit test in the default target should not be able to paint hardware.

The fix is small but has two parts, because a timeout alone still sends the message. Point the test at a port nothing serves, and give _run_cli a bound:

def _run_cli(*args, timeout=30):
    # timeout is not belt-and-braces: HMTLClient's connect (multiprocessing
    # Client + authkey) and send_and_ack both block with no socket timeout, so
    # a test that reaches the network can hang `make test-python` forever.
    env = dict(os.environ, PYTHONPATH=_PYTHON_DIR)
    return subprocess.run([sys.executable, _CLI, *args],
                          capture_output=True, text=True, env=env,
                          timeout=timeout)


def _dead_port():
    """A port nothing is serving, so the CLI's connect is refused at once."""
    with socket.socket() as s:
        s.bind(("127.0.0.1", 0))
        return s.getsockname()[1]

and then make the accept test say what it actually proves:

def test_cli_accepts_a_valid_range():
    # The CLI has no dry-run, so a valid message runs on to HMTLClient() and
    # the network. Aim it at a dead port on purpose: against the default
    # localhost:6000 this passes only because nothing happens to be listening,
    # and if a command server IS up it broadcasts a real COLOR to the fleet
    # and then blocks in send_and_ack's untimed loop.
    r = _run_cli("--color", "-C", "255,0,0,5,3",
                 "-a", "127.0.0.1", "-p", str(_dead_port()))

    assert "Sending COLOR message" in r.stdout
    assert "start=5 length=3" in r.stdout
    # It got as far as the socket and no further: the encoder had no complaint.
    assert "Failed to connect" in r.stderr

(import socket at the top.) That last assertion is what turns the exit code from ambiguous into evidence.

2. Nit — the docstring names the two rejections a sender cannot see, but not the silent clamp

My round-3 finding 4 asked for the two rejections and that an over-long length is clamped rather than rejected. The rejections landed; the clamp did not. HMTLPrograms.cpp:741 computes avail = num - start and lowers length to it, so --color 255,0,0,5,1000 on a 10-pixel strip packs cleanly, is accepted, and paints 5 pixels — a sender-invisible outcome in a paragraph whose stated purpose is enumerating sender-invisible outcomes. Half a sentence after the start=300, length=10 example:

    module, with a DEBUG1 line naming the reason. A length that runs off the
    end is not rejected but silently CLAMPED to what remains, so a too-long
    range paints a shorter one rather than failing anywhere a sender can see.

Not worth a commit on its own — but fold it in if finding 1 gets one.

Convergence

Asked directly: the change itself is converged; the test file is not, by one commit.

Everything this PR set out to do — the fixed-width wire range, the narrowing clamp, the flag-independent zero-length rule stated identically in C, Python and the CLI, the literal-byte cross-check, the both-widths native env, the layout asserts — I now believe is correct and complete, and I re-derived rather than re-read the parts round 3 touched. All five of round 3's targets are genuinely closed; none of them regressed anything else. Finding 2 is a nit and I would leave it alone on its own.

Finding 1 is a real defect and not a stylistic one: a test in the default make test path that can hang the suite indefinitely, and that on the maintainer's own machine can transmit to hardware. It is also, precisely, the fourth consecutive round in which the fix for a review finding introduced a smaller problem of its own — and the shape is the same one this PR keeps rediscovering: the new code was checked against the environment that happened to be present (nothing on port 6000) rather than against the environments it will meet. Worth one commit, and I would not expect a fifth round after it.

aphelps/HMTL#9's new CLI tests aimed at HMTLClient's default command server.
Only the accept-path test reached it, and it passed only because nothing was
listening; against a socket that accepts and holds, `make test` hangs forever.
They now target a deliberately dead port with a subprocess timeout.

That matters here specifically: this repo's test-hmtl runs HMTL's suite in CI,
so a test that hangs on a live listener would hang the workflow rather than
fail it.

Verified: make test STRICT=1 green at this pin.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_013HqzdRdTRnreSvevaQGQSJ

@aphelps-reviewer-bot aphelps-reviewer-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Re-review of 031e84c..e3bfa00 — the super-repo diff is the gitlink alone, so this is really aphelps/HMTL d8769c3..640114b, which I fetched separately. Top-level only, as before: an inline comment on a submodule path 422s.

Deliberately narrow. The change itself I declared converged last round and I have not re-opened it. This is only the test-harness fix for my round-4 finding 1, plus the docstring sentence from nit 2.

Prior issues

  • Finding 1 (the accept test reached the real network) — fixed, and I ran the control rather than reading the diff. With an accept-and-hold listener bound on 127.0.0.1:6000, the file at d8769c3 hangs past 25 s; the file at 640114b passes in 0.15 s with that same listener still up. So the fix is verified against the environment it was written for, not the one that happens to be present — which is the thing this PR has had to relearn four times.
  • Nit 2 (docstring omitted the silent clamp) — folded in, and accurate. "An over-long LENGTH is not dropped but silently clamped to the end of the strip" matches HMTLPrograms.cpp: avail = num - start, further clamped to addr_max, with a DEBUG1 line. "Silently" is right for the frame the paragraph sets — the sender cannot see it — and the added "do not read a lit strip as proof" is the sentence that makes the paragraph's purpose hold.

The four things you would want checked

  • Is _closed_port() sound, or racy? Sound. It binds ('127.0.0.1', 0), reads the number, closes — and never calls listen(), so there is no TIME_WAIT and the port goes straight back to the ephemeral pool clean. The reuse window is one interpreter startup, and reuse only matters if something takes the port as a listener in it. Even then the outcome is a 30 s failure, not a silent transmit: the authkey handshake cannot be completed by an unrelated listener. I also checked the address-family detail my own suggestion had fussed over — multiprocessing.connection.Client types a tuple address as AF_INET, so localhost resolves v4 and matches the v4 bind. The -a 127.0.0.1 I proposed was unnecessary; leaving it out is correct, not an oversight.
  • Does timeout=30 do what the docstring claims? Yes, confirmed by running it. Pointing _closed_port() at the held listener: 1 failed, 12 passed in 30.20s, TimeoutExpired naming the exact argv, exit 1, no orphaned child. subprocess.run does process.kill() then wait() on expiry, and the only child is the CLI itself — no grandchildren to survive the kill. A hang now fails; it does not stall.
  • Did the assertion changes weaken the accept test? No — assertions were only added. "Sending COLOR message" is printed strictly after ProgramColor(...) returns and after every sys.exit(1) path, so it already carried the proof; assert "must be" not in r.stdout is belt-and-braces on top. I would still have preferred assert "Failed to connect" in r.stderr (the uncaught Exception from client.py:39 puts that string there) as positive evidence the run reached the socket — but I checked whether its absence leaves a hole, and it does not: every way the dead port could fail to be dead ends in either that same refusal or the 30 s timeout. Taste, not a gap. Not worth a commit.
  • Anything else the delta introduced? No. Two files, import socket the only new import, no leftover scratch files, the three refusal tests unchanged and still exiting before the client is constructed. Applying the dead port in _run_cli rather than in the one test that needs it is the better call: any future test that takes the accept path inherits the protection instead of having to remember it. I checked the rest of python/hmtl/tests/ for other CLI entry points — test_emulator.py drives its own subprocess and never builds an HMTLClient, so nothing else can reach 6000. make test-python's directory-plus---ignore selection still picks the file up: 13 passed in 0.17 s, matching the PR's claim.

Convergence

Ready for a human. No fifth round, and nothing here warrants another commit.

The change was converged last round and remains so; this commit closes the one defect that was left, and it closes it properly — the fix is verified by a control that can actually fail, which is the specific failure mode this workstream has produced repeatedly (the dropped $v, the uncompiled #ifdef, the installed-vs-checkout import, the unoccupied port). Worth noting that the author caught their own first control being meaningless — an accept-and-drop listener lets the client fail fast — and re-ran it with a listener that holds. That is the round's real result: this is the first time the harness was checked for the ability to fail before the finding was recorded rather than after.

aphelps/HMTL#9's representability check (`start > addr_max`) cannot fire against
the shipped ArduinoLibs — PixelUtil holds num_pixels as PIXEL_ADDR_TYPE and
init() refuses more than 255 pixels by default, so `start >= num` subsumes it.
The test that appeared to prove otherwise built a 400-pixel default-flag strip,
possible only because the HMTL_Test stub declared _num as an unconditional
uint16_t while claiming to mirror the real header.

Found by reviewing that PR as a whole rather than as a delta, which is the one
thing five rounds of incremental review could not do.

Verified: make test STRICT=1 green at this pin (63 native tests per pixel-width
env, 484/484 perturbations red as required).

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_013HqzdRdTRnreSvevaQGQSJ

@aphelps-reviewer-bot aphelps-reviewer-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Re-review of e3bfa00..2e867cf — the super-repo diff is the gitlink alone, so this is aphelps/HMTL 640114b..fd8477a, which I fetched and checked out separately. Top-level only, as before: an inline comment on a submodule path 422s.

Scoped to this delta only. The change itself has been converged since round 4 and I have not re-opened it. Everything below I verified by building and running the worktree at fd8477a, not by reading the diff.

Prior issues — closed

  • The representability check is genuinely subsumed, and the new comment says so accurately. Confirmed the ordering in program_color(): zero-length/nonzero-start, then num == 0, then start >= num, then start > addr_max. Given ArduinoLibs' PixelUtil holding num_pixels as PIXEL_ADDR_TYPE with init() refusing >255 unless BIG_PIXELS, numPixels() <= addr_max always holds, so start >= num fires first for every input. "Kept as the one guard on numPixels() and PIXEL_ADDR_TYPE drifting apart" is the right justification, and it is the honest one.
  • The default-flag half of test_color_start_beyond_a_byte_is_not_truncated now asserts what a real build does. 200 pixels, start=300 → COLOR start past end of strip:300, with getPixel(44) still pinning the no-truncation property. The -DBIG_PIXELS half keeps the 400-pixel strip, which that flag genuinely permits.
  • HMTLPrograms.h's width table no longer cites the colour struct as the live -DBIG_PIXELS justification and points at the pixel_range_t asserts instead — consistent with what tests/layout/Makefile says in the same tree.
  • The -P color warning gate is correct, and I ran every form. Gated on len(commandvalues) == 5: warns on -C 255,0,0,0,10; silent on the correct 7-value form, on 3 values, on 4, and on no -C at all (no TypeError — commandvalues is not None short-circuits, and it is load-bearing, since commandvalue absent yields None). The gate is exactly the stale family and nothing else: no correct invocation can have five values, because length_hi is only reachable at seven, so every 5-value form leaves the wire length zero.

New — one real defect this delta introduced

Narrowing the stub's _num silently truncated an existing test's strip, and the truncation is invisible. test_color_stale_five_byte_invocation_is_rejected_not_flooded builds PixelUtil pixels(3000, 0, 0, 0) unconditionally (test_pixel_programs.cpp:585). Under -e native, (uint8_t)3000 == 184, so that test now runs on a 184-pixel strip. Verified, not inferred — I added TEST_ASSERT_EQUAL_UINT16(3000, pixels.numPixels()) to it and got Expected 3000 Was 184.

It stays green only by accident of ordering: the zero-length/nonzero-start rule is checked before start >= num, so start=2560 is still caught by the rule the test names. But two things are now untrue of it:

  • Its own comment — "This ran on a 3000-pixel strip deliberately. On a short strip the rejection could come from start >= numPixels() and prove nothing about the wide width" — describes precisely the situation the test is now in at the default width. The default run no longer isolates the rule; only the native_bigpixels run does.
  • TEST_ASSERT_EQUAL_HEX8(0x00, pixels.getPixel(2560).r) and getPixel(2999) are vacuous there: the stub returns a default CRGB() for any index past _num, so both indices are out of bounds and pass unconditionally.

This is the same shape as the finding the commit was opened to fix — a test asserting against a strip that isn't the one it says — one test over, introduced by the fix. It's test fidelity, not firmware behaviour, and it's a small edit:

#ifdef BIG_PIXELS
    PixelUtil pixels(3000, 0, 0, 0);
#else
    PixelUtil pixels(200, 0, 0, 0);   // a default build cannot exceed 255
#endif
    // The setup itself, so a stub-width change can never silently shrink it again.
    TEST_ASSERT_EQUAL_UINT16(sizeof(PIXEL_ADDR_TYPE) == 1 ? 200 : 3000,
                             pixels.numPixels());

and the comment then needs one sentence saying the isolation is a -DBIG_PIXELS-only property, with the default run asserting only that the message is rejected. The out-of-bounds getPixel assertions should move inside the #ifdef too.

Related, and the reason the above went unnoticed: the stub's new constructor complaint is reachable but not loud. It fires today — TEST_ASSERT_FALSE(debug_log_contains("too many pixels")) inside that same test fails under -e native, so the tripwire is tripping right now on an existing test and the suite reports 126/126. _debug_emit appends to the in-memory log and a log file (stubs/test_support.cpp:102); it does not write to stdout or stderr and nothing asserts on it. So it is not dead code, but the comment's "say so loudly rather than silently truncating" isn't achieved either. <stdio.h> is already included in the stub and the layout sweep compiles it with avr-g++ happily, so:

        if (n > (uint16_t)(PIXEL_ADDR_TYPE)~(PIXEL_ADDR_TYPE)0) {
            _debug_emit("PixelUtil stub: too many pixels for PIXEL_ADDR_TYPE", 1);
            // Also to stderr: _debug_emit only reaches the log buffer, which no
            // passing test reads, so a truncated strip would otherwise be silent.
            fprintf(stderr, "PixelUtil stub: %u pixels truncated to %u "
                            "(PIXEL_ADDR_TYPE is %u B)\n",
                    (unsigned)n, (unsigned)(PIXEL_ADDR_TYPE)n,
                    (unsigned)sizeof(PIXEL_ADDR_TYPE));
        }

That single line is what would have surfaced the finding above at the moment the stub changed.

Coverage

  • Suggested test: the len(commandvalues) == 5 gate has no test on either side. Nothing asserts that the stale 5-value form still warns, and — the half that this commit is actually about — nothing asserts that the correct 7-value form stays quiet. The code comment cites test_typed_and_generic_forms_agree_when_the_generic_one_is_written_out as blessing the 7-byte form, but that test is library-level and never runs the CLI, so a regression to warning-on-everything would be caught by nothing. _run_cli already exists and makes this two asserts each: assert "MISREAD" in _run_cli("-P", "color", "-C", "255,0,0,0,10").stdout and assert "MISREAD" not in _run_cli("-P", "color", "-C", "255,0,0,0,10,0,0").stdout. Round 3 added four CLI tests for exactly this reason; this is the same seam, one commit later.

Things you would want checked, and the answers

  • Do the two new tests exercise the branches they name, and can they fail? Yes to both, mutation-tested. if (num == 0) → if (false): exactly test_color_on_an_empty_output_draws_nothing goes red (1 failed, 19 passed) — with the check gone, start >= num catches it instead and reports the wrong diagnosis, which is what the test distinguishes. start >= num → start > num: exactly test_color_start_past_the_end_of_the_strip_is_rejected goes red, and it is guarding a real hazard rather than a message — with the off-by-one, avail = num - start = 0, the length clamps to 0, and setRangeRGB routes a zero length to setAllRGB, so an out-of-range request floods the whole strip. I confirmed that directly: pixel 7 of the 8-pixel strip comes back 0xFF.
  • Does the _num narrowing break any other test's loops or comparisons? No. Every use promotes cleanly — idx < _num, for (uint16_t i = 0; i < _num; ...), avail = _num - range.start, numPixels() returning uint16_t — and no expression relies on _num being 16-bit. The only setup affected is the 3000-pixel one above; every other construction in test_pixelutil and test_pixel_programs is ≤ 8 pixels or already #ifdef-guarded.
  • What I ran. pio test -e native -e native_bigpixels → 126/126 (63 × 2, matching the PR's claim). pytest hmtl/tests/test_protocol.py → 13 passed in 0.17 s. make -C HMTL test-layout → exit 0, so the stub's new constructor body compiles under avr-g++ and xtensa as well as host.

Convergence

One more commit, then hand it to a human — and it does not need a seventh review round.

The firmware change, the clamp, the zero-length rule and the cross-checks are unchanged and remain correct; nothing here touches shipped behaviour. What this delta introduced is a test that now runs on a strip 16× shorter than it says it does, which is the exact defect class this commit was opened to remove, reintroduced by the removal. The fix is a #ifdef and an assertion on the setup, both verifiable by the suite itself, and the fprintf makes the stub's own tripwire capable of being noticed next time.

Worth recording alongside round 6's lesson: a stub is a shared fixture, and narrowing a shared fixture is a change to every test's setup, not just to the one you were looking at. The complaint added in the same commit would have caught it — it fired — but it emitted into a buffer nobody reads, which is the seventh instance in this workstream of a guard checked against an environment where its output cannot be seen.

aphelps/HMTL#9's stub narrowing silently truncated another test's 3000-pixel
strip to 184 under the default width, leaving its comment false and three of
its assertions unable to fail. Strip sizes are now per-flag and asserted via
numPixels(), so a stub change cannot rewrite a test's premise unnoticed.

Verified: make test STRICT=1 green at this pin.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_013HqzdRdTRnreSvevaQGQSJ

@aphelps-reviewer-bot aphelps-reviewer-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Re-review of 2e867cf..52838b7 — the super-repo diff is the gitlink alone, so this is aphelps/HMTL fd8477a..07717b8, which I fetched into a separate worktree and ran. Top-level only, as before: an inline comment on a submodule path 422s.

Scoped to this delta. Everything below I verified by running the worktree at 07717b8 and mutating it, not by reading the diff.

Prior issues — closed

  • The per-flag strip size and its numPixels() assertion are a real guard, in both envs. NUM is 3000 under BIG_PIXELS and 200 otherwise, and TEST_ASSERT_EQUAL_UINT16(NUM, pixels.numPixels()) sits at the setup. Verified by restoring the impossible unconditional 3000: pio test -e native reports test_color_stale_five_byte_invocation_is_rejected_not_flooded: Expected 3000 Was 184, 1 failed / 19 passed. It is tautological under native_bigpixels today (3000 fits a uint16_t), which is the right shape for a tripwire — it fires exactly when a stub narrowing makes it untrue.
  • The derived probe indices are meaningful, not trivially true — and I isolated them rather than inferring it. With the zero-length rule mutated to if (false) the test fails at the debug_log_contains assertion before ever reaching the probes, so that mutation alone proves nothing about them. Neutralising those earlier asserts as well: native_bigpixels reports Expected 0x00 Was 0xFF at getPixel(NUM / 2) — the flood is caught. Under -e native the probes pass regardless, because at 200 pixels start >= num rejects start=2560 first and no flood is reachable at that width. That is correct behaviour, and the new comment does not over-claim it: it says the -DBIG_PIXELS run is the interesting one. Both indices are now in bounds under both flags, so the vacuous out-of-bounds lookups are gone.
  • stderr rather than _debug_emit in the stub constructor — a better fix than the one I suggested. I proposed keeping both; dropping _debug_emit is the right call, because the debug log is a buffer other tests assert on with debug_log_contains, and a constructor writing into it is a fixture that perturbs unrelated assertions. The comment says exactly that. It compiles everywhere it needs to: make test-layout exits 0, so avr-g++ and xtensa take the fprintf (<stdio.h> was already included, stubs/PixelUtil.h:20).
  • The softened claim matches reality. "Do not rely on this ALONE … pio test does not surface a passing test's stderr … the thing that actually catches a shrunk strip is a TEST_ASSERT on numPixels()" is accurate, and it correctly names which of the two is the guard.
  • My round-6 coverage suggestion (the -P color gate) is taken. Both asserts I asked for exist, and both can fail — mutation-tested. Gate → if (false): exactly test_generic_color_warns_on_the_stale_five_byte_form goes red. Gate with the len(commandvalues) == 5 half deleted: exactly test_generic_color_is_silent_on_the_correct_seven_byte_form goes red.

New — one finding, and it is test strength rather than a defect

test_other_generic_programs_are_never_warned_about cannot fail for the reason its name gives. It runs -P blink -C 1,2,3 — three values, so the len(commandvalues) == 5 half of the gate already keeps it silent no matter what the program half does. The program_number == NAME_MAP["color"] half is therefore untested. Verified by mutation: with that condition deleted from the gate, all 16 tests in test_protocol.py still pass, while -P blink -C 1,2,3,4,5 prints the COLOR migration warning at a blink message. Five values instead of three closes it — same file, python/hmtl/tests/test_protocol.py:

def test_other_generic_programs_are_never_warned_about():
    # FIVE values, not three: with three, the len(commandvalues) == 5 half of
    # the gate keeps this quiet on its own and the program half goes untested.
    r = _run_cli("-P", "blink", "-C", "1,2,3,4,5")

    assert "WARNING" not in r.stdout

I confirmed that form is silent on the real code and warns under the mutation, so it discriminates. Worth noting what is and is not at stake: the untested half only governs a spurious warning on a non-COLOR program — no wire, firmware or validation behaviour rides on it. The two tests that matter for the migration both exercise their side of the gate and both fail under mutation.

The two negative tests would also be a little stronger with a positive anchor (assert "Sending generic program message" in r.stdout), so an early exit from some future refactor could not make "no WARNING" true by never reaching the gate. Today it is reached — the only failure ahead of it is a NAME_MAP KeyError, and both color and blink are in the map.

Nothing else in this delta broke anything

  • pio test -e native -e native_bigpixels → 126/126 (63 × 2), matching the PR's claim.
  • pytest hmtl/tests/ --ignore=test_CircularBuffer.py → 29 passed, matching the claim.
  • make test-layout → exit 0 across host / host-avr-proxy / avr / xtensa × both widths.
  • make test-layout-negative → 484/484 perturbations broke the build as required, 0 did not.
  • The _num narrowing from the previous commit still promotes cleanly everywhere; the only setup it affected was the 3000-pixel one this commit fixes.

(Unrelated to this delta, and not a finding: make test-python resolves PYTEST ?= pytest from PATH, so pointing it at an interpreter without the emulator's dependencies fails 13 test_emulator cases that pass under the checkout's own Python. Pre-existing, no CI exposure — test-python is deliberately not wired into super-repo CI, filed as [[run-hmtl-s-python-protocol-tests-in-super-repo-ci-needs-pytest-in-the-pinned-toolchain]].)

Convergence

Ready to hand to a human as it stands. No further changes required, and no eighth round.

This delta does what it says: the premise that the previous commit silently rewrote is now asserted rather than assumed, the assertions that had become vacuous are back in bounds, the stub's complaint goes somewhere it can be seen, and the honest limitation of that complaint is written down. Shipped behaviour is untouched, as it has been since round 4.

The one finding above is a five-character change to a test whose failure mode is a cosmetic warning. It is not worth a commit on its own; fold it in if this branch is touched again for any other reason, and otherwise it is a note for whoever next edits that file.

One thing worth adding to the record, since the author's decision to stop the loop is the right one and this is the last round: rounds 6 and 7 both turned on a fixture change being a change to every test's setup, and the answer both times was to assert the premise instead of trusting it. That is a durable habit, not a patch — the numPixels() assertion in this commit is the first thing in this workstream that would have caught its own class of defect without a reviewer present.

Final commit on aphelps/HMTL#9. `-C 1,2,3` was kept silent by the len()==5 half
of the warning gate alone, so test_other_generic_programs_are_never_warned_about
could not fail for the reason its name gives. Five values now, mutation-checked
both ways.

Verified: make test STRICT=1 green at this pin.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_013HqzdRdTRnreSvevaQGQSJ

@aphelps-reviewer-bot aphelps-reviewer-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Re-review of 52838b7..df91403 — the super-repo diff is the gitlink alone, so this is aphelps/HMTL 07717b8..3566ca5: one commit, one file, six lines, of which the functional change is a single test argument. Reviewed in a worktree at 3566ca5 by running and mutating it. Top-level only, as before — an inline comment on a submodule path 422s.

The one finding from round 8 is closed, and the fix is real

  • test_other_generic_programs_are_never_warned_about now exercises the program == color half of the gate. Verified in both directions, which is the whole question:

    • Delete program_number == NAME_MAP["color"] from the gate (python/bin/HMTLClient:321), leaving the len(commandvalues) == 5 half: 1 failed, 15 passed, and the one failure is exactly test_other_generic_programs_are_never_warned_about. Nothing else in the file moves.
    • Same mutation, test reverted to the pre-fix -C 1,2,3: 16 passed. So the old form provably could not fail for the reason its name gives, and the new one does.

    The commit message and the new comment claim precisely this ("green at three values and red at five") and both halves check out.

  • -P blink -C 1,2,3,4,5 is a valid invocation that reaches the gate — it is not passing for an unintended reason. This was the way the fix could have gone quietly wrong, so I checked the path rather than the outcome. blink has no branch of its own: -P sets commandtype == "program" and everything resolves through ProgramGeneric.NAME_MAP, whose blink is 0x01 — truthy, so the if not program_number early-out does not fire. ProgramGeneric.FORMAT is "<" + "B"*32 zero-filled, so five byte values are as acceptable as three; nothing counts arguments for a generic program. Confirmed by running all three forms against a dead port and checking the anchor the assertion depends on:

    invocation reaches Sending generic program message WARNING
    -P blink -C 1,2,3,4,5 yes no
    -P blink -C 1,2,3 yes no
    -P color -C 1,2,3,4,5 yes yes

    The silence is genuine — the gate is evaluated and declines — rather than an early exit ahead of it.

Nothing else in the delta

  • Full Python suite at 3566ca5: 29 passed (test_protocol.py + test_emulator.py), matching the previous round's count. The 16 in test_protocol.py are unchanged in number and identity.
  • The commit touches one file, and it is a test. No C, no HMTLPrograms.h, no stubs, no Makefile, no layout header — so the native (63 × 2 widths), layout and negative-control results verified at 07717b8 last round carry over untouched. I did not re-run them, and say so deliberately rather than reporting a result I did not produce.
  • HMTL#9 head is 3566ca5, which is what the gitlink points at; WLED_dev#35 head is df91403 and reports mergeable.
  • Not a finding, for the record: I suggested last round that the two negative tests would be marginally stronger with a positive anchor (assert "Sending generic program message" in r.stdout). It was not taken, and that is a defensible call — I verified above that the anchor holds today for all three forms, so the assertions are reached. It guards a future refactor, not a present gap.

Convergence

Clean. Ready to merge with no further changes.

This round found nothing, which is how the loop is supposed to end. The author's reason for taking a fix the previous reviewer marked "not worth a commit" is the better principle and worth keeping: impact is the wrong axis for a test that cannot fail for the reason its name gives, in a PR whose entire subject is guards that cannot fail. Cost was five characters; the alternative was leaving a small instance of the exact defect the change spent eight rounds eliminating.

Shipped behaviour is untouched, as it has been since round 4.

Last inline comment on aphelps/HMTL#9. ProgramColor's docstring detailed what
receivers do with the range while omitting the one in-tree receiver that never
reads it — this repo's own RS485 bridge, which takes programVals[0..2] and
nothing else.

Docstring only; no behaviour change, so the C and layout suites are unaffected.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_013HqzdRdTRnreSvevaQGQSJ

@aphelps-reviewer-bot aphelps-reviewer-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Re-review of df91403..d61a119 — the super-repo diff is the gitlink alone (HMTL 3566ca5..d7d7e8b, one commit, one file, +6/-0), and every one of those six lines is inside ProgramColor's class docstring. Top-level only, as before: an inline comment on a submodule path 422s.

The claim is true, checked against the pinned revision

  • Verified in the WLED tree this PR pins (WLED b186c5d0, the gitlink at d61a119), not in my working copy. usermods/rs485_bridge/usermod_rs485_bridge.cpp:432-435 is exactly what the commit says it is:

    case PROGRAM_COLOR:
      if (d.programLen < 3) { counters.unsupported++; return; }   // needs a full RGB triple
      seg.setColor(0, RGBW32(d.programVals[0], d.programVals[1], d.programVals[2], 0));
      break;

    Three reads, indices 0/1/2, a programLen < 3 guard, and no fourth byte touched.

  • Nothing elsewhere in the usermod reads the range either — that is the half of the claim a citation of four lines does not establish on its own, so I checked it separately. grep -rn 'programVals\|programLen\|range' over usermods/rs485_bridge/ returns five sites and no more: the decode that sets the pointer (rs485_bridge_protocol.h:434-435, payload + sizeof(output_hdr_t) + 1), PROGRAM_BRIGHTNESS reading [0], the three reads above, and two lines in tests/. Wire bytes 3-6 of a COLOR message are never dereferenced anywhere in the bridge.

  • programVals offset 0 really is the struct's r. The docstring says "the RGB triple at offset 0", and the pointer is the byte after programType, i.e. the base of the values array that hmtl_program_color_t overlays — so offsets 0/1/2 are r/g/b and range sits at 3, unread. The phrasing is precise rather than approximate.

  • "One in-tree receiver" is the right count. The Python emulator still does not implement 0x31 (python/hmtl/emulator/emulator.py _parse_program handles 0x01/0x02/0x05/0x09 only), so besides the C firmware's program_color() the bridge is the only other thing in the super-repo tree that receives a COLOR.

The wording neither overstates nor understates it

  • "lights whatever that usermod lights regardless of start and length" is correctly hedged. The bridge sets main-segment colour 0 and — unlike the default: branch — does not change mode, so what the strip actually shows depends on the running effect. A sentence promising "lights the whole strip" would have been the overstatement available here, and it was not taken.
  • It sits in the right place: immediately after the paragraph about what a sender cannot evaluate (start past the end, over-long length silently clamped), extending the same "do not read a lit strip as proof" point to a receiver that never even parses the field. The closing line — "it may never have read it" — is the diagnostic value, and it is stated as a caveat rather than a rule.
  • The omission I looked for and decided is correct: it does not mention the programLen < 3 guard. That guard cannot fire in practice — both producers pad to ProgramHdr.MAX_DATA — and mentioning it would dilute a claim that is about the range, not about truncation.
  • Not a finding, for the record: the path usermods/rs485_bridge/usermod_rs485_bridge.cpp is WLED-relative, in a docstring living in HMTL. A reader of HMTL alone will not find that path in HMTL. It is unambiguous as written because the sentence names "WLED's RS485 bridge" first, and "in-tree" plainly means the super-repo tree that pins both. Not worth a byte.

Nothing else in the delta

  • Docstring-only, confirmed structurally rather than by eye. The six added lines land between range was accepted verbatim. and Raising for what it CAN see, both already inside the """; TYPE, BASE_FORMAT = 'BBBHH', FORMAT, the padding arithmetic and every validation branch in __init__ are untouched by the diff. No wire bytes move.
  • Python suite at d7d7e8b: 29 passed (python/hmtl/tests/, --ignore=test_CircularBuffer.py, i.e. what make test-python runs). Same count and same identities as the previous round — a docstring change that broke the string literal would have shown up as a collection error, and did not.
  • No C, no HMTLPrograms.h, no stubs, no Makefile, no layout header — so the native (63 × 2 widths), layout and negative-control results verified at earlier heads carry over untouched. I did not re-run them, and say so deliberately rather than reporting a result I did not produce.
  • HMTL#9 head is d7d7e8b, which is what the gitlink points at, and reports mergeable; WLED_dev#35 head is d61a119 and reports mergeable.

Convergence

Clean. Ready to merge with no further changes.

Two clean rounds in a row, and this one closed the last outstanding inline comment on aphelps/HMTL#9 with six lines of prose and no behaviour change. Worth noting what the finding was, since it is the loop's own shape one last time: the docstring enumerated what receivers do with the COLOR range and omitted the receiver that does nothing with it — a complete-looking account validated against the receivers that happened to be in view. Cheap to fix, and it makes the docstring's "do not read a lit strip as proof" advice actually cover the case where a strip lights for a reason unrelated to the range.

Shipped behaviour is untouched, as it has been since round 4.

@aphelps-claude-bot aphelps-claude-bot left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

⏸ Approved and CI-green, but do not merge yet — the submodule PR underneath it now conflicts.

aphelps/HMTL#9 is CONFLICTING against HMTL main. Main moved to f904b6c when the PixelUtil
stack landed (aphelps/ArduinoLibs#13 + aphelps/HMTL#8), and both that stack and #9 edit
platformio/HMTL_Test/stubs/PixelUtil.h.

Why this PR must wait rather than merge first. It pins HMTL at d7d7e8b, which is #9's head and
is not on HMTL main. Merging now would put a submodule pointer on main that no HMTL ref reaches —
a fresh git submodule update --init would fail to fetch it. That is the same repair that had to be
done by hand on #33, so it is a known cost rather than a hypothetical one.

Resolved locally, not pushed. The rebase of pin-color-wire-range-width onto origin/main is
done and green (70 native tests at both pixel widths, 29 Python). Two conflicts, both mechanical:

  1. setRangeRGB — took main's version. Behaviourally identical to #9's, and it additionally emits
    the DEBUG1 start-past-end diagnostic, so a test can observe that branch ran.
  2. Main's new init() vs #9's _num-narrowing comment — kept both.

The rebase then exposed a genuine inconsistency worth flagging, because it is a defect neither PR had
on its own: main's init() assigns into the now-narrowed _num while allocating with the
un-narrowed n, which silently re-admits exactly the impossible strips #9's constructor exists to
reject — a test could reach the strip through init() instead. Fixed so both entry points agree.

Waiting on a human, deliberately. Publishing the fix needs a force-push over an approved PR,
and the resolution carries a behaviour change (init()) that the approval of d7d7e8b did not
cover. Not doing that unattended.

Sequence once approved: force-push #9 → merge #9 → repoint this PR at the squashed SHA → merge.

HMTL#9 landed as a squash (ab149d6), which makes the previously pinned d7d7e8b
unreachable once the topic branch goes. The pin also predated the last three
commits on that PR, including the init() narrowing fix — building against
d7d7e8b would have shipped the truncating stub this PR exists to depend on.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01F4oTr1YW3z7ozksMUT1z5j
@aphelps-claude-bot
aphelps-claude-bot merged commit 56de8da into main Aug 20, 2026
1 check passed
@aphelps-claude-bot
aphelps-claude-bot deleted the bump-hmtl-color-wire-range branch August 20, 2026 06:00
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.

3 participants