Skip to content

Commit 81f45fa

Browse files
committed
Pin the arrival boundary, including the assertion that was pinning the bug
The first version of this file asserted the zero-tolerance form as if it were the rule: /var canUp = y > ledgerTopOffset\(\);/ so 57 assertions were green and one of them was holding the defect in place. That is the other half of 「a guard that cannot fail is not a guard」 — a guard can pass while naming the wrong thing as right, and nothing in a green run distinguishes the two. So this fix is not only to add assertions. It is to take back the one that was asserting the bug. verify-ledger-jump.mjs 57 -> 61 assertions. Four new ones: the zero-tolerance form cannot come back; the boundary is rounded UP, with floor and nearest both rejected — nearest rejected even though it is the rounding this browser actually does; the bottom test is left alone; and the landing keeps the un-rounded offset, so the same fix cannot be reached a second way by rounding where a jump ends instead of how 「arrived」 is read. mutate-ledger-jump.py 53 -> 58 mutations, all caught; file restored byte for byte and green again afterwards. Two of the five are worth naming. Dropping the boundary is the defect itself, and the only one here a reader could walk back into by accident: the shorter form reads as the obvious way to ask 「is there more above」, and nothing in the source says a landing does not land where it was aimed. Changing it to Math.round is kept precisely because it is CORRECT on this browser — it holds only for the one rounding rule in force, and a green run says nothing about that. This is also why what is pinned is 「up」 rather than 「a rounding that works」. The probe had to change too, for the same shape of reason. Its reader carried its own copy of the predicate under test, so the first run after the fix reported the landing as 「still more above」 while the product had already answered no — it was measuring its own copy, which would never have moved no matter what shipped. Verdicts now read the shipped function's own answer, and the old form is kept in the output only as a contrast. node tests/run.mjs 57/57. Fixture check OK.
1 parent ea1f366 commit 81f45fa

2 files changed

Lines changed: 78 additions & 1 deletion

File tree

‎plugins/avatasia/mmc-trajectory/tests/mutate-ledger-jump.py‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,47 @@
190190
[("return ledgerScrollDir === 'up';", "return ledgerScrollDir === 'up' && canUp;")],
191191
"the rule is not collapsed into two terms whose order would decide a case silently"),
192192

193+
# ---- D49: the landing and the test for it ----
194+
195+
# This is the defect itself, taken back out. It is the only mutation here that a reader can
196+
# reach by accident rather than on purpose: the un-rounded form is the shorter expression, it
197+
# reads as the obvious way to ask 「is there more above」, and nothing in the source suggests a
198+
# landing does not land exactly where it was aimed. Measured: at the top of the ledger the arrow
199+
# pointed up and a second press moved the page by zero pixels.
200+
("the top test loses the arrival boundary",
201+
[("var canUp = y > Math.ceil(ledgerTopOffset());", "var canUp = y > ledgerTopOffset();")],
202+
"the top test tolerates the landing itself, so arriving at the top cannot read as 「more above」"),
203+
204+
# Down is the wrong direction: the browser rounds to the nearest pixel, so on any width whose
205+
# offset lands on a fraction above the nearest integer the landing sits ABOVE the rounded-down
206+
# boundary and the control freezes again. This one is worth keeping precisely because it passes
207+
# at one measured width — it is what makes the wrong direction easy to pick.
208+
("the arrival boundary is rounded down",
209+
[("Math.ceil(ledgerTopOffset())", "Math.floor(ledgerTopOffset())")],
210+
"the arrival boundary is rounded up, which holds for floor, nearest and ceiling alike"),
211+
212+
# Nearest is what this browser does today, which is exactly why it is dangerous: it is right
213+
# until the rounding rule is not the one it was written against, and nothing in the run would
214+
# have said so. Up is the only direction that holds for all three, so up is what is pinned.
215+
("the arrival boundary is rounded to nearest, one browser's rule",
216+
[("Math.ceil(ledgerTopOffset())", "Math.round(ledgerTopOffset())")],
217+
"the arrival boundary is rounded up, which holds for floor, nearest and ceiling alike"),
218+
219+
# The bottom's landing is the end at the top of the viewport and its test asks whether the end is
220+
# still below the fold — a whole viewport apart. Giving it the same tolerance tunes a boundary
221+
# that was never wrong, and it would be the kind of change that looks like symmetry.
222+
("the bottom test grows the tolerance the top needed",
223+
[("var canDown = ledgerEndBelow();", "var canDown = ledgerEndBelow() + 1;")],
224+
"the bottom test is left alone: its landing is a whole viewport away from its own boundary"),
225+
226+
# The same fix reached a second way. Rounding the landing too also makes the two agree, so it
227+
# passes the tolerance assertion — and it is a different change, because it moves where a jump
228+
# ends rather than how 「arrived」 is read. The landing is never what was wrong.
229+
("the landing is rounded as well, moving where a jump goes",
230+
[("window.scrollTo(0, up ? ledgerTopOffset() : ledgerBottomOffset())",
231+
"window.scrollTo(0, up ? Math.ceil(ledgerTopOffset()) : ledgerBottomOffset())")],
232+
"the landing keeps the un-rounded offset: the defect was in the test, not in where a jump goes"),
233+
193234
# ---- D47: the scroll listener ----
194235

195236
# Nothing on the page says which way the reader went, so the arrow sits at whatever the last

‎plugins/avatasia/mmc-trajectory/tests/verify-ledger-jump.mjs‎

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,37 @@ assert('an end that is in view or already passed leaves up as the only move',
203203
assert('a top that is in view leaves down as the only move',
204204
!!goesUpSrc && /if \(!canUp\) return false;/.test(goesUpSrc));
205205
assert('the direction decides only the case neither end has already vetoed',
206-
!!goesUpSrc && /var canUp = y > ledgerTopOffset\(\);/.test(goesUpSrc)
206+
!!goesUpSrc && /var canUp = y > Math\.ceil\(ledgerTopOffset\(\)\);/.test(goesUpSrc)
207207
&& goesUpSrc.indexOf('if (!canUp) return false;') < goesUpSrc.indexOf('return ledgerScrollDir'));
208+
209+
/* ---------- the landing and the test for it ---------- */
210+
211+
// These three are about one relationship rather than about the four branches: the top's landing
212+
// point and the test for it read the SAME number, and the browser does not keep it. So they are
213+
// written next to the branches and not with the two targets, even though a landing point is what
214+
// they are about.
215+
//
216+
// The first version of this file asserted the zero-tolerance form as if it were the rule, so the
217+
// defect was pinned rather than missed: 57 green assertions, one of them holding the bug in place.
218+
// That is the other half of 「a guard that cannot fail is not a guard」 — a guard can pass while
219+
// naming the wrong thing as right, and nothing in a green run distinguishes the two.
220+
assert('the top test tolerates the landing itself, so arriving at the top cannot read as 「more above」',
221+
!!goesUpSrc && !/var canUp = y > ledgerTopOffset\(\);/.test(goesUpSrc));
222+
// Rounding DOWN fails whenever the browser rounds up; rounding to NEAREST is right only for the one
223+
// rounding rule that happens to be in force. Measured widths showed the landing on the nearest
224+
// pixel, but the reader cannot know that about the next browser, and a test that holds for all
225+
// three does not need to be re-derived when the answer moves. Up is the direction that holds.
226+
assert('the arrival boundary is rounded up, which holds for floor, nearest and ceiling alike',
227+
!!goesUpSrc && /Math\.ceil\(ledgerTopOffset\(\)\)/.test(goesUpSrc)
228+
&& !/Math\.floor\(ledgerTopOffset\(\)\)/.test(goesUpSrc)
229+
&& !/Math\.round\(ledgerTopOffset\(\)\)/.test(goesUpSrc));
230+
// The bottom gets no tolerance, and this pins that it does not start getting one. Its landing is the
231+
// end at the top of the viewport while its test asks whether the end is still below the fold — a
232+
// whole viewport apart, so no rounding error reaches across. A tolerance there would move a boundary
233+
// that is already correct, and the two ends would then be tuned for different reasons.
234+
assert('the bottom test is left alone: its landing is a whole viewport away from its own boundary',
235+
!!goesUpSrc && /var canDown = ledgerEndBelow\(\);/.test(goesUpSrc)
236+
&& !/ledgerEndBelow\(\)\s*[+\-*/]/.test(goesUpSrc));
208237
// 「Follows the reader, unless an end is on screen」 cannot be written as two terms joined by `&&` or
209238
// `||`: the order of those terms decides the both-ends-off-screen case, and it would decide it
210239
// silently. This pins the shape, not the truth table — a two-term rewrite reads correctly at every
@@ -264,6 +293,13 @@ assert("down means the sentinel at the ledger's own bottom",
264293
assert('the click chooses between the two ends from the same reading the arrow does',
265294
!!buildSrc && /var up = ledgerJumpGoesUp\(\);/.test(buildSrc)
266295
&& /window\.scrollTo\(0, up \? ledgerTopOffset\(\) : ledgerBottomOffset\(\)\)/.test(buildSrc));
296+
// The landing stays on the un-rounded offset. Rounding it too would also make the two agree, and it
297+
// would be a different change: it moves where a jump actually ends. The defect was never in the
298+
// landing — a press that arrives a fraction of a pixel past the top is still arriving — it was in
299+
// reading that arrival as 「not there yet」. Pinned so the same fix cannot be reached a second way.
300+
assert('the landing keeps the un-rounded offset: the defect was in the test, not in where a jump goes',
301+
!!buildSrc && /window\.scrollTo\(0, up \? ledgerTopOffset\(\) : ledgerBottomOffset\(\)\)/.test(buildSrc)
302+
&& !/Math\.(ceil|floor|round)\(ledgerTopOffset\(\)\)/.test(buildSrc));
267303
// A jump IS a movement, and the reader did not scroll themselves — so the press writes the
268304
// direction rather than waiting for a scroll event that `scrollTo()` does not fire synchronously,
269305
// and that fires not at all when the press targets the end the reader is already at. Waiting there

0 commit comments

Comments
 (0)