From 22f53c28f1c91ed1f1a0a12aa34aeb47282d116c Mon Sep 17 00:00:00 2001 From: agent Date: Tue, 10 Nov 2026 06:54:04 -0400 Subject: [PATCH] tests: pin the tail-head zero-run clamp, the case engine#1773's arms leave out (engine#1740) The zero run is counted from EOF, so a head whose own last tiles are zero adds to it like padding does: plan_tail_head computes last = base - n*tile and only 'if (p.last < base) p.last = base;' keeps the answer at the envelope's end. No arm covered that. Added four, measured on the hidden-896 geometry: head's last 2 tiles zero (first=last=1856), zero run spanning head tail + 5 tiles padding (1856), 512 B padding (1856), padding longer than the head (1856). Red proof: removing the last clamp fails exactly the two arms that depend on it and no others. --- tests/npu_pack_import_test.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/tests/npu_pack_import_test.cpp b/tests/npu_pack_import_test.cpp index b40a08fa1..b4c65c710 100644 --- a/tests/npu_pack_import_test.cpp +++ b/tests/npu_pack_import_test.cpp @@ -3775,6 +3775,31 @@ void test_tail_head_placement() { check(p.why.empty() && p.exact, "tail placement: a tail that ends with the head is exact"); check(p.first == env && p.last == env, "tail placement: and the only candidate is the envelope's end"); } + // (b2) engine#1773's review: the zero run is counted FROM EOF, so a head whose own last tiles are zero contributes + // to it exactly like padding does, and `last` then computes as base - n*tile with only the `last < base` clamp + // keeping it at the envelope's end. Measured by lifting `plan_tail_head` verbatim and running the hidden-896 + // geometry through it: all four cases below give first == last == 1,856. They are the cases where a clamp + // mistake would hide, so they are pinned here rather than left to the pad-whole-tiles arm. + { + const pi::TailHeadPlacement p = pi::plan_tail_head(exact_bytes, 0, env, rows, tile, 2 * tile); + check(p.why.empty() && p.last == env && p.first == env, + "tail placement: a head whose own last two tiles are zero still lands on the envelope's end"); + } + { + const pi::TailHeadPlacement p = pi::plan_tail_head(exact_bytes + 5 * tile, 0, env, rows, tile, 7 * tile); + check(p.why.empty() && p.last == env && p.first == env, + "tail placement: a zero run spanning the head's own tail tiles AND its padding is not counted twice"); + } + { + const pi::TailHeadPlacement p = pi::plan_tail_head(exact_bytes + 512, 0, env, rows, tile, 512); + check(p.why.empty() && p.last == env && p.first == env, + "tail placement: padding smaller than one tile still lands on the envelope's end"); + } + { + const pi::TailHeadPlacement p = pi::plan_tail_head(exact_bytes + rows * tile, 0, env, rows, tile, rows * tile); + check(p.why.empty() && p.last == env && p.first == env, + "tail placement: a zero run longer than the head is clamped to its start"); + } // (b) n whole zero tiles after the head: the candidate walks back by exactly n tiles, never past the envelope for (int64_t n : {1, 3, 9}) { const int64_t bytes = exact_bytes + n * tile;