My layout check kept returning an empty list. I was reading it as a verdict.
I generate carousel covers from HTML, render them in headless Chromium, and publish one four times a day. Before a cover ships, three checks run against the PNG: no two blocks overlap, nothing is cut at the edge, the logo keeps its margin. In October a cover passed all three and still read wrong. The title promised an answer, and the big number sat between the title and the sentence explaining what it referred to. Anyone swiping to the second slide met "193x" before knowing the subject.
So I added a fourth check for reading order. It measures ink per pixel, groups rows into blocks, labels each block as title, definition or number, and compares their vertical positions. The check is ordinary. What took four versions to get right is that a check can return green while measuring nothing at all.
Version one trusted the document
The first version knew the order from the HTML: title first, definition second, number third. It read the y coordinate of each block position and compared them.
That held until the title wrapped to two lines. The second line arrived as its own block, the check called it the definition, and the first line of the real definition became the number. The three positions were still in increasing order, so the check passed. It passed while labeling the wrong rows.
The fix was to stop using the document as data. A block is what it measures: a filled band of rows with a height and a width. Nothing in the check reads the HTML any more, only the PNG.
Height alone put the number in the title slot
Font size survives the render as band height, so the tallest band is a good first guess for the number. On a cover with a single digit, the number band measured 114px tall and 90px wide, while the two title lines measured 91px and 72px tall with widths of 686px and 507px. Height separates those three.
Then came a cover whose number was "85". Two digits at 150px measure 584px wide, wider than any single-digit number the check had seen. A cutoff on width at 0.35 of the 904px content column, 316px, was enough for one digit and wrong for two. The number got labeled as text, became the title because it was the tallest text block, and the check reported:
FALHA: 0 numero(s), 1 titulo(s) That message is not a verdict about the cover. The check could not see a number, so it had nothing to compare. I had been treating both outcomes as failures of the same kind for weeks.
The current classifier uses both dimensions, plus a floor relative to the tallest band:
alturas = sorted(b["h"] for b in bs) ref = alturas[int(len(alturas) * PERCENTIL_REF_ALTURA)] estreitas = [b for b in bs if b["h"] > ref * 1.5] h_max = max(b["h"] for b in bs) estreitas = [b for b in estreitas if b["h"] >= NUMERO_MIN_REL * h_max] for b in bs: b["classe"] = "NUMERO" if b in estreitas and \ b["w"] < CONTEUDO * FATOR_LARGURA_NUMERO else "TEXTO" The floor arrived on 21 November, from a cover where the number was "99%" at 429px wide and 145px tall. A filled badge above it was 431px wide and 46px tall. Width could not tell them apart, and the badge passed the 1.5x test because its 46px is more than 1.5 times a 20px text line. Height could: nothing below half the tallest band is a number.
The reference for "tall" moves with the art
The first version compared each band to the median height of all bands. On a seven-band cover the median was 29px, and the 114px number passed easily. On the small art used as a control, with three blocks (title 90, number 114, definition 33), the median was 90. The number needed more than 135 to qualify and had 114. It became text, the title became the tallest block, the function that reads the order found no number and returned an empty list.
The median was measuring the middle of the list, and the middle of the list changes when the list gets shorter. The first quartile held in both cases: 21px on the seven-band cover, 33px on the three-block art, with the number above 1.5x in both. The reference had to be the text line, not a statistic that floats.
A control has to reproduce the defect
A test that only passes is worth nothing. The cover that started this had the number between the title and the definition, so the control rebuilds exactly that: it crops the real blocks out of the real cover, paints over everything below the title, and pastes the number and the definition in the wrong order. The rule that reads the result is the same function as the main test.
y = onde_apaga + VAO_CONTROLE for g in (numero[0], defi): # the wrong order f = fatia(g) nova.paste(f, (MARGEM_X, y)) y += f.height + VAO_CONTROLE Two versions of this control failed before it worked. In the first, the gap between the pasted blocks was 24px and the grouping gap is 30px, so all rows merged into one block, the classifier labeled that block as a number, and the order came out empty. The control "rejected" the art because it could not measure it, which is the same bug it was supposed to catch.
In the second, measured on 17 October, the control art was reduced to three slices. With the top bands removed, the first quartile rose to 72px, the 105px number needed 108px, and the order came out empty again through a new path. The fix was to keep the top of the real cover and recompose only what sits below the title, so the reference stays where it was.
An empty list is now an explicit failure with its own message. It says the measurement did not happen, and it does not count as the defect being caught.
What it prints now
Here is the check on the cover from 22 November, a deep purple background that the per-piece wrapper declares as (88, 3, 124). The wrapper overrides the palette, the measurement window and the file name. It imports the shared module and never copies the rule, because two copies of a rule are two rules, and only one of them survives the next edit.
y 269.. 441 hmax= 54 wmax= 690 -> TITULO y 473.. 581 hmax= 28 wmax= 881 -> DEFINICAO y 624.. 947 hmax=168 wmax= 903 -> NUMERO ordem lida: TITULO -> DEFINICAO -> NUMERO ok: titulo, definicao, numero == controle negativo: a ordem errada tem que reprovar ordem da arte com defeito: TITULO -> NUMERO -> DEFINICAO ok: reprovou Seven blocks were measured on that cover. Four belong to frame elements (the top line, a rule, a badge, the source note), they land in the definition class, and they do not disturb the order because only the first block of each class is compared. The check exits non-zero when the order is wrong, when a block is missing, or when either the main art or the control art produces an empty list.
The lesson I keep relearning: a verifier is code, and code that cannot measure returns a value that looks like an answer. "No number found" and "the number is in the wrong place" are different facts, and only one of them is about the image. Building the control so that it produces the real defect, from real pixels and through the same function, is what separates the two.
Se esse tipo de teste já te deu um verde que não significava nada, conta nos comentários o que estava sendo medido de verdade. Cada verificação que passa por motivo errado é uma armadilha que eu prefiro aprender pelo relato de outra pessoa.

