A Fix That Passed Everything and Changed Nothing
The promotion rule shipped with a guard: if the head already has enough pictures, do nothing. Correct rule, correct constant, and it made no visible difference whatsoever.
The guard measured the head as the first limit rows — the number the client asked for. But the client asks for a page many times larger than a screen, because it wants scroll headroom. Across that many rows, enough carry pictures to clear any reasonable floor. So the guard concluded there was no problem and returned early, while the dozen cards a person sees without scrolling stayed exactly as empty as before.
Two Meanings of "Head" That Look Identical in Code
The bug is one expression. Slicing to the requested limit and slicing to the visible region are both a slice of the front of a list, they both read as "the top of the shelf", and only one of them is the thing the complaint was about. Nothing in the type system distinguishes them, and nothing in a review will either, because the wrong one looks exactly as reasonable as the right one.
The fix is to make the visible region an explicit named constant and to slice against the smaller of the two. The naming is the actual repair: once the code says screen rather than limit, a future reader can tell which of the two meanings is intended, and the next person adding a rule here has the right noun available.
The Simulation Confirmed It, and the Simulation Was Fiction
This is the part with the longest reach. Before shipping, the rule had been checked in a simulation, which reported it working. The simulation had hard-coded a head size and a candidate pool — both plausible, neither matching what the endpoint actually produces. It was measuring a shelf the code never renders.
A simulation cannot catch a bug in your model of the system, because the simulation is your model of the system. It will faithfully confirm whatever you believed when you wrote it, and the more carefully you build it, the more convincing that confirmation is. What found this was calling the real endpoint at the real limit and counting the pictures in the first twelve rows of the actual response.
Assert on What a Person Would See
The durable form of the lesson is about where an assertion points. A test that checks the function returned rows in the right order tests the function. A test that counts pictures in the first screen of a real response tests the claim the feature exists to make. Only the second one fails when the two definitions of head diverge.