Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

studiobench: bound the scroll gesture at both ends, at the extent's own allowance (#9610)

Daniel Han68a40ef18ef9
diff --git a/tests/studio/studiobench/analysis/behaviour.py b/tests/studio/studiobench/analysis/behaviour.py
index 0410dca8a6c..26861280ef4 100644
--- a/tests/studio/studiobench/analysis/behaviour.py
+++ b/tests/studio/studiobench/analysis/behaviour.py
@@ -356,19 +356,174 @@ def thread_survives_reopen(base_row: dict, treat_row: dict) -> list[dict]:
return out
+def _extent_of(row: dict) -> tuple[Optional[float], bool]:
+ """(the arm's scroll extent as `scroll_extent` measures it, was it reconstructed).
+
+ `expect.bottom` is `scrollHeight - clientHeight`, read by `SCROLL_JS` before the gesture moves
+ anything; `scroll_extent` compares `census.viewport_scroll_height`, which is `scrollHeight`.
+ Same physical quantity offset by a constant, and the constant is not harmless: `_drift` is
+ proportional, so subtracting a shared `clientHeight` AMPLIFIES the drift by `H / (H - C)` --
+ 1.087 on the 10,000 px extent and 800 px viewport measured here, so a tolerance applied to
+ `bottom` is 8.7% tighter than the same number applied to the extent, and the two checks print
+ two different percentages for one scrollbar.
+
+ So the extent is reconstructed from `viewport_client_height`, which `scene/dom.js` has recorded
+ in the census all along. `clientHeight` does not change while the viewport scrolls, so reading
+ it from the census and `bottom` from the gesture is not mixing two instants of a moving
+ quantity.
+
+ Falls back to `bottom` when the census does not carry it -- a payload recorded before that
+ field, or a census that failed -- and says which of the two it returned.
+ """
+ bottom = _expect(row, "bottom")
+ if not isinstance(bottom, (int, float)):
+ return None, False
+ client = (row.get("census") or {}).get("viewport_client_height")
+ if not isinstance(client, (int, float)):
+ return float(bottom), False
+ return float(bottom) + float(client), True
+
+
+def _client_height(row: dict) -> Optional[float]:
+ client = (row.get("census") or {}).get("viewport_client_height")
+ return float(client) if isinstance(client, (int, float)) else None
+
+
+def _bottom_of(row: dict) -> Optional[float]:
+ bottom = _expect(row, "bottom")
+ return float(bottom) if isinstance(bottom, (int, float)) else None
+
+
+def _comparable_extents(base_row: dict, treat_row: dict) -> tuple[Any, Any, str]:
+ """The two numbers `scroll_bottom_agrees` compares, and what they are.
+
+ ONE DECISION FOR BOTH ARMS. Reconstructing per arm and comparing whatever each produced puts a
+ `scrollHeight` beside a `bottom`: two arms with an identical 1,200 px `bottom` over an 800 px
+ viewport, one of whose censuses failed, came out 2,000 against 1,200 and BROKEN at 40% drift,
+ with a detail line that said `no client height on both arms` over the mixed pair.
+
+ AND ONLY WHEN THE HEIGHTS AGREE. `clientHeight` is a shared offset only if it is shared. Two
+ arms reporting the same 10,000 px `scrollHeight` at client heights of 800 and 2,000 have
+ bottoms of 9,200 and 8,000 -- 1,200 px less room for the gesture on one of them -- and
+ reconstructing both to 10,000 reports MATCH at 0.0% drift over that. `scroll_extent` already
+ compares the scroll heights; what this check is for is the range the gesture actually had.
+
+ So both arms are reconstructed together or neither is, and a fallback compares the raw bottoms
+ at the same allowance, which is the quantity a differing viewport moves.
+ """
+ b_ext, b_full = _extent_of(base_row)
+ t_ext, t_full = _extent_of(treat_row)
+ b_bottom, t_bottom = _bottom_of(base_row), _bottom_of(treat_row)
+ if not (b_full and t_full):
+ return b_bottom, t_bottom, "bottom (no client height on both arms)"
+ b_client, t_client = _client_height(base_row), _client_height(treat_row)
+ if b_client != t_client:
+ return (
+ b_bottom,
+ t_bottom,
+ f"bottom (client heights differ: {b_client} vs {t_client})",
+ )
+ return b_ext, t_ext, "scroll extent"
+
+
def scroll_travelled(base_row: dict, treat_row: dict) -> list[dict]:
- """scroll_after: the gesture still covers the ground it commanded, on both arms."""
+ """scroll_after: the gesture covers the ground it commanded and no more, on both arms."""
out = []
+ # THE PAIR'S REFERENCE EXTENT, NOT THE ARM'S OWN, and for the same reason `_drift` divides by
+ # the larger of the two: an estimate correction is the arm closing the gap to the REAL extent,
+ # so the gap is what bounds it, and the arm that is wrong is the one whose own extent is the
+ # worse yardstick. Taken per arm the two checks read one tolerance off two denominators, and
+ # disagreed inside it: extents of 10,000 and 9,050 pass `scroll_extent` at 9.5% drift while
+ # the 950 px correction that closes that very gap came out BROKEN against a ceiling granting
+ # 10% of 9,050. A false red is not free here -- it removes the cell from `readings_by_arm`,
+ # takes its healthy partner with it through the arm intersection, and
+ # `unmeasured_planned_cells` can then VOID the plan -- so the two now enforce the same
+ # allowance on the same quantity.
+ #
+ # It only ever loosens: `max` is never below the arm's own extent. An arm carrying NO extent
+ # still gets no ceiling rather than borrowing its partner's, because that would newly bound an
+ # arm this check has always left unbounded above, which is the one direction that could invent
+ # a red rather than retire one.
+ reference = max(
+ (
+ abs(extent)
+ for extent, _ in (_extent_of(base_row), _extent_of(treat_row))
+ if isinstance(extent, (int, float))
+ ),
+ default = None,
+ )
for label, row in (("base", base_row), ("treatment", treat_row)):
fraction = _expect(row, "travel_fraction")
- out.append(
- _check(
- f"scroll_travelled:{label}",
- None if fraction is None else fraction >= 0.9,
- f"the gesture travelled {fraction} of what it commanded",
+ commanded = _expect(row, "commanded_px")
+ travelled = _expect(row, "travelled_px")
+ # THE ALLOWANCE IS A FRACTION OF THE EXTENT, so it is taken on the extent. `bottom` is
+ # `scrollHeight - clientHeight`, and reading `EXTENT_TOLERANCE` off it is the same defect
+ # `_extent_of` exists to fix one check below: on a 10,000 px extent behind an 800 px
+ # viewport it grants 920 px where the tolerance says 1,000, so a 941 px correction -- 9.4%
+ # of the extent, inside the declared 10% -- came out BROKEN.
+ extent, _reconstructed = _extent_of(row)
+ # BOUNDED ABOVE AS WELL AS BELOW, and the ceiling is DERIVED rather than chosen.
+ #
+ # The lower bound is what this invariant was written for: Studio's intent-aware autoscroll
+ # snapping a programmatic move back to the bottom leaves the gesture having covered
+ # nothing. But the predicate was `fraction >= 0.9` and nothing above it, so an arm whose
+ # viewport moved TWICE as far as commanded passed exactly as 1.0 did and the pair returned
+ # MATCH. `travelled` sums `|scrollTop_after - target_before|`, so every pixel above
+ # `commanded` is the viewport being moved by something other than the gesture -- the same
+ # anchor instability this action exists to detect, in the other direction.
+ #
+ # WHY THIS CEILING AND NOT A NUMBER PICKED TO LOOK SYMMETRIC WITH 0.9. Overshoot has one
+ # legitimate source: a windowed list correcting estimated row heights, which moves the
+ # offset by the error in the estimate. Those errors total the error in the arm's extent,
+ # and this file already declares how far the extent may be wrong (`EXTENT_TOLERANCE`). So
+ # the gesture may exceed its command by that fraction of the arm's own extent, both terms
+ # read off the row. No second constant, and it scales with the rung.
+ #
+ # It degrades to no ceiling rather than to a guess: an arm carrying no extent gets the
+ # lower bound alone, said in the detail, because a ceiling of zero fails every correct arm.
+ ceiling: Optional[float] = None
+ if (
+ isinstance(commanded, (int, float))
+ and commanded > 0
+ and isinstance(extent, (int, float))
+ ):
+ ceiling = (commanded + EXTENT_TOLERANCE * reference) / commanded
+ if fraction is None:
+ ok: Optional[bool] = None
+ detail = "the row records no travel fraction"
+ elif ceiling is None:
+ ok = fraction >= 0.9
+ detail = (
+ f"the gesture travelled {fraction} of what it commanded; NO CEILING was applied "
+ f"because the row carries no scrollable extent to derive one from"
+ )
+ else:
+ ok = 0.9 <= fraction <= ceiling
+ detail = (
+ f"the gesture travelled {fraction} of what it commanded "
+ f"({travelled} of {commanded} px, allowed 0.9 to {ceiling:.3f}: "
+ f"{EXTENT_TOLERANCE:.0%} of the pair's {reference} px reference extent)"
)
+ out.append(_check(f"scroll_travelled:{label}", ok, detail))
+ # THE EXTENT, NOT `bottom`, AND AT THE EXTENT'S OWN ALLOWANCE. This compared `bottom` through
+ # `_same_number` and so through `EXACT_TOLERANCE`, 2%, while `scroll_extent` grants the same
+ # physical quantity 10% a few checks earlier and says why a correct virtualizer needs it. An
+ # arm inside the declared allowance was reported behaviourally BROKEN, and a false red is not
+ # free: it removes the cell from `readings_by_arm`, takes its healthy partner with it through
+ # the arm intersection, and `unmeasured_planned_cells` can then VOID the plan.
+ #
+ # `_same_number` is deliberately NOT widened. Its other three keys -- `selected_chars`,
+ # `visible_chars`, `clipboard_chars` -- are not extents and are correctly strict at 2%.
+ b_ext, t_ext, what = _comparable_extents(base_row, treat_row)
+ drift = _drift(b_ext, t_ext)
+ out.append(
+ _check(
+ "scroll_bottom_agrees",
+ None if drift is None else drift <= EXTENT_TOLERANCE,
+ f"{what} {b_ext} vs {t_ext}"
+ + ("" if drift is None else f" ({drift:.1%} drift, {EXTENT_TOLERANCE:.0%} allowed)"),
)
- out.append(_same_number(base_row, treat_row, "bottom", "scroll_bottom_agrees"))
+ )
return out
diff --git a/tests/studio/studiobench/analysis/selftest/test_studiobench_scroll_bounds.py b/tests/studio/studiobench/analysis/selftest/test_studiobench_scroll_bounds.py
new file mode 100644
index 00000000000..0516853c9f4
--- /dev/null
+++ b/tests/studio/studiobench/analysis/selftest/test_studiobench_scroll_bounds.py
@@ -0,0 +1,310 @@
+# SPDX-License-Identifier: AGPL-3.0-only
+# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
+
+"""THE SCROLL GESTURE, bounded at both ends and against the extent's own allowance.
+
+`scroll_travelled` is the only behavioural invariant with two independent quantities in it -- how
+far the gesture went, and whether the two arms agree about how far it COULD have gone -- and it had
+no direct test of its own. Both of its defects were the same mistake in opposite directions: one
+quantity judged against a tolerance meant for a different quantity, and one judged against no upper
+bound at all.
+
+Kept out of the windowed-parity module deliberately. That module is the ui-parity command's own
+suite and these are `analysis/behaviour.py`'s, so they live beside the code they pin.
+"""
+
+from __future__ import annotations
+
+import sys
+from pathlib import Path
+
+_STUDIO_TESTS = Path(__file__).resolve().parents[3]
+if str(_STUDIO_TESTS) not in sys.path:
+ sys.path.insert(0, str(_STUDIO_TESTS))
+
+from studiobench.analysis import behaviour as B # noqa: E402
+from studiobench.analysis import parity as P # noqa: E402
+
+
+def _capture(
+ mounted: int,
+ total: int,
+ digest: str = "d",
+) -> dict:
+ """A parity capture in the shape scene/parity.js writes one; `mounted < total` is a window."""
+ return {
+ "parity_attempted": True,
+ "root_kind": "thread",
+ "digest": digest,
+ "chars": 100,
+ "messages": [
+ {"i": i, "role": "assistant", "digest": f"{digest}{i}", "chars": 10}
+ for i in range(mounted)
+ ],
+ "overlays": [],
+ "styles": {"elements": mounted, "digest": "s", "capped": False},
+ "mounted_messages": mounted,
+ "thread_total": total,
+ }
+
+
+def _row(action: str, capture: dict, **expect) -> dict:
+ return {
+ "row_type": "action",
+ "action": action,
+ "ran": True,
+ "expect_ok": True,
+ "expect": dict(expect),
+ "timings": {},
+ "parity": capture,
+ "census": {"viewport_scroll_height": 10_000},
+ }
+
+
+# ── the scroll gesture is bounded at both ends, at the extent's own allowance ─────
+
+
+def _scroll_row(
+ mounted,
+ *,
+ fraction = 1.0,
+ bottom = 9_200,
+ commanded = 5_880,
+ client = None,
+):
+ row = _row(
+ "scroll_after",
+ _capture(mounted, 18),
+ travel_fraction = fraction,
+ travelled_px = round(fraction * commanded),
+ commanded_px = commanded,
+ bottom = bottom,
+ )
+ if client is not None:
+ row["census"]["viewport_client_height"] = client
+ return row
+
+
+def test_an_extent_inside_the_declared_allowance_is_not_reported_broken():
+ """THE FALSE RED. `scroll_extent` grants the extent 10% because a windowed list computes its
+ total height from estimated row heights, and says so in its own comment. `scroll_travelled`
+ then compared the SAME physical quantity through `_same_number`, which routes through the 2%
+ `EXACT_TOLERANCE`, so an arm inside the declared allowance was reported behaviourally BROKEN.
+
+ A false red is not free here: a broken behavioural invariant removes the cell from
+ `readings_by_arm` and takes its healthy partner with it through the arm intersection, and
+ `unmeasured_planned_cells` now VOIDS the plan over the hole that leaves."""
+ base = _scroll_row(18, bottom = 9_200, client = 800)
+ treat = _scroll_row(6, bottom = 8_600, client = 800)
+ treat["census"]["viewport_scroll_height"] = 9_400 # 6% out: inside EXTENT_TOLERANCE
+ got = B.compare_behaviour(base, treat)
+ assert got["verdict"] == P.MATCH, got
+ checks = {c["invariant"]: c for c in got["checks"]}
+ assert checks["scroll_bottom_agrees"]["ok"] is True, checks["scroll_bottom_agrees"]
+ assert checks["scroll_extent"]["ok"] is True, checks["scroll_extent"]
+
+
+def test_an_extent_outside_the_declared_allowance_is_still_reported_broken():
+ """THE CONTROL. Widening this check must not stop it catching an extent that is a FRACTION of
+ the real one, which is the failure `EXTENT_TOLERANCE` was chosen against: a virtualizer that
+ drops rows instead of sizing spacers has a scrollbar that lies."""
+ base = _scroll_row(18, bottom = 9_200, client = 800)
+ treat = _scroll_row(6, bottom = 4_200, client = 800)
+ treat["census"]["viewport_scroll_height"] = 5_000
+ got = B.compare_behaviour(base, treat)
+ assert got["verdict"] == B.BROKEN, got
+ assert "scroll_bottom_agrees" in got["reason"], got
+
+
+def test_the_extent_is_reconstructed_so_both_checks_answer_about_one_scrollbar():
+ """`bottom` is `scrollHeight - clientHeight` and `_drift` is PROPORTIONAL, so subtracting a
+ shared viewport height amplifies the drift by `H / (H - C)`. Left as a comparison of `bottom`,
+ the same tolerance means something tighter than it says and the two checks print two different
+ percentages for one scrollbar. The census has carried `viewport_client_height` beside the
+ scroll height all along."""
+ base = _scroll_row(18, bottom = 9_200, client = 800)
+ treat = _scroll_row(6, bottom = 8_600, client = 800)
+ treat["census"]["viewport_scroll_height"] = 9_400
+ checks = {c["invariant"]: c for c in B.compare_behaviour(base, treat)["checks"]}
+ # 10000 vs 9400 either way round, so the two details agree to the printed digit.
+ assert "6.0% drift" in checks["scroll_bottom_agrees"]["detail"], checks
+ assert "6.0% drift" in checks["scroll_extent"]["detail"], checks
+ assert "scroll extent" in checks["scroll_bottom_agrees"]["detail"], checks
+
+
+def test_a_payload_with_no_client_height_falls_back_and_says_so():
+ """A row from a checkout that predates the field, or one whose census failed. It compares
+ `bottom` as before rather than refusing, and the detail names which of the two it compared so
+ the tighter effective allowance is not silent."""
+ base = _scroll_row(18, bottom = 9_200)
+ treat = _scroll_row(6, bottom = 9_100)
+ checks = {c["invariant"]: c for c in B.compare_behaviour(base, treat)["checks"]}
+ assert "no client height on both arms" in checks["scroll_bottom_agrees"]["detail"], checks
+ assert checks["scroll_bottom_agrees"]["ok"] is True, checks
+
+
+def test_one_arm_missing_its_client_height_does_not_compare_an_extent_with_a_bottom():
+ """A CENSUS THAT FAILED ON ONE ARM, or two payloads of different vintages. Reconstructing per
+ arm and comparing whatever each produced put a `scrollHeight` beside a `bottom`: identical
+ viewports at `bottom` 1,200 over a client height of 800 came out 2,000 against 1,200 and
+ BROKEN at 40% drift, under a detail line that said `no client height on both arms`. The
+ decision belongs to the pair, so both arms are reconstructed or neither is."""
+ base = _scroll_row(18, bottom = 1_200, client = 800)
+ treat = _scroll_row(18, bottom = 1_200)
+ for row in (base, treat):
+ row["census"]["viewport_scroll_height"] = 2_000
+ got = B.compare_behaviour(base, treat)
+ checks = {c["invariant"]: c for c in got["checks"]}
+ assert checks["scroll_bottom_agrees"]["ok"] is True, checks
+ assert "1200.0 vs 1200.0" in checks["scroll_bottom_agrees"]["detail"], checks
+ assert got["verdict"] == P.MATCH, got
+
+
+def test_client_heights_that_disagree_are_not_treated_as_a_shared_offset():
+ """`clientHeight` is a shared offset only when it is shared. Two arms reporting the same
+ 10,000px `scrollHeight` at client heights of 800 and 2,000 have 9,200px and 8,000px of room
+ for the gesture, and adding each arm's own viewport back reported MATCH at 0.0% drift over
+ that 1,200px difference. `scroll_extent` already compares the scroll heights; this check is
+ about the range the gesture actually had, so it falls back to the raw bottoms and says why."""
+ base = _scroll_row(18, bottom = 9_200, client = 800)
+ treat = _scroll_row(18, bottom = 8_000, client = 2_000)
+ got = B.compare_behaviour(base, treat)
+ checks = {c["invariant"]: c for c in got["checks"]}
+ assert checks["scroll_bottom_agrees"]["ok"] is False, checks
+ assert "client heights differ: 800.0 vs 2000.0" in checks["scroll_bottom_agrees"]["detail"]
+ assert checks["scroll_extent"]["ok"] is True, checks
+ assert got["verdict"] == B.BROKEN, got
+
+
+def test_client_heights_that_agree_are_still_treated_as_a_shared_offset():
+ """The positive control for the two above: the ordinary case, where both arms publish the same
+ viewport height, must still be compared as extents rather than pushed onto the fallback."""
+ base = _scroll_row(18, bottom = 9_200, client = 800)
+ treat = _scroll_row(6, bottom = 8_600, client = 800)
+ treat["census"]["viewport_scroll_height"] = 9_400
+ checks = {c["invariant"]: c for c in B.compare_behaviour(base, treat)["checks"]}
+ assert "scroll extent 10000.0 vs 9400.0" in checks["scroll_bottom_agrees"]["detail"], checks
+ assert checks["scroll_bottom_agrees"]["ok"] is True, checks
+
+
+def test_a_gesture_that_overshot_its_command_is_reported():
+ """THE UNBOUNDED SIDE. The predicate was `fraction >= 0.9` and nothing above it, so a treatment
+ arm whose viewport moved TWICE as far as the gesture asked passed exactly as 1.0 did and the
+ pair returned MATCH. `travelled` is a sum of `|scrollTop_after - target_before|`, so every
+ pixel above `commanded` is the viewport being moved by something other than the gesture --
+ which is the anchor instability this action exists to detect, in the other direction."""
+ base = _scroll_row(18, fraction = 1.0, bottom = 9_200, client = 800)
+ treat = _scroll_row(6, fraction = 2.0, bottom = 9_200, client = 800)
+ got = B.compare_behaviour(base, treat)
+ assert got["verdict"] == B.BROKEN, got
+ assert "scroll_travelled:treatment" in got["reason"], got
+
+
+def test_an_ordinary_estimate_correction_still_passes_the_ceiling():
+ """THE CONTROL, and the reason the ceiling is DERIVED rather than picked to look symmetric with
+ 0.9. A windowed list correcting estimated row heights moves the offset by the error in the
+ estimate, and this file already declares how far the extent may be wrong. So the allowance is
+ `EXTENT_TOLERANCE` of the PAIR'S reference extent -- 1,000px of a 10,000px extent against a
+ 5,880px gesture, a ceiling of 1.170 -- and a correction inside it is ordinary rather than a
+ finding."""
+ base = _scroll_row(18, fraction = 1.0, bottom = 9_200, client = 800)
+ treat = _scroll_row(6, fraction = 1.1, bottom = 9_200, client = 800)
+ got = B.compare_behaviour(base, treat)
+ assert got["verdict"] == P.MATCH, got
+ checks = {c["invariant"]: c for c in got["checks"]}
+ assert "allowed 0.9 to 1.170" in checks["scroll_travelled:treatment"]["detail"], checks
+
+
+def test_the_ceiling_grants_the_tolerance_against_the_extent_not_against_bottom():
+ """THE SAME MISTAKE THE CHECK BELOW WAS FIXED FOR, in the ceiling. `bottom` is
+ `scrollHeight - clientHeight`, so `EXTENT_TOLERANCE` taken on it grants 920px of a 10,000px
+ extent behind an 800px viewport where the tolerance says 1,000. A 941px correction is 9.4% of
+ the extent -- inside the declared 10% -- and came out BROKEN.
+
+ Pinned at both edges so the ceiling is a bound and not merely a larger number: 1.160 is inside
+ the allowance and 1.171 is outside it."""
+ base = _scroll_row(18, fraction = 1.0, bottom = 9_200, client = 800)
+ inside = _scroll_row(6, fraction = 1.16, bottom = 9_200, client = 800)
+ got = B.compare_behaviour(base, inside)
+ assert got["verdict"] == P.MATCH, got
+ checks = {c["invariant"]: c for c in got["checks"]}
+ assert (
+ "of the pair's 10000.0 px reference extent"
+ in checks["scroll_travelled:treatment"]["detail"]
+ )
+
+ outside = _scroll_row(6, fraction = 1.171, bottom = 9_200, client = 800)
+ beyond = B.compare_behaviour(base, outside)
+ assert beyond["verdict"] == B.BROKEN, beyond
+ assert "scroll_travelled:treatment" in beyond["reason"], beyond
+
+
+def test_the_ceiling_and_the_extent_check_enforce_one_tolerance_on_one_quantity():
+ """TWO DENOMINATORS FOR ONE TOLERANCE, and the pair disagreed inside it.
+
+ `scroll_extent` scores drift through `_drift`, which divides by the LARGER of the two extents.
+ The ceiling divided by the arm's OWN. So extents of 10,000 and 9,050 pass `scroll_extent` at
+ 9.5% drift, while the 950px correction that closes that very gap was BROKEN against a ceiling
+ granting 10% of 9,050 -- 1.162 travelled against 1.154 allowed. The arm that most needs the
+ allowance is exactly the arm whose own extent is the worse yardstick for it.
+
+ A false red is not free: it removes the cell from `readings_by_arm`, takes its healthy partner
+ with it through the arm intersection, and `unmeasured_planned_cells` can then VOID the plan.
+
+ Pinned at both edges, so this is a bound and not merely a bigger number: the reference ceiling
+ is 1.170, and a gesture past it is still reported."""
+ base = _scroll_row(18, fraction = 1.0, bottom = 9_200, client = 800)
+ treat = _scroll_row(6, fraction = (5_880 + 950) / 5_880, bottom = 8_250, client = 800)
+ treat["census"]["viewport_scroll_height"] = 9_050
+
+ got = B.compare_behaviour(base, treat)
+ checks = {c["invariant"]: c for c in got["checks"]}
+ # The pair really is inside the extent allowance; that is what makes the red false.
+ assert checks["scroll_extent"]["ok"] is True, checks
+ assert "9.5% drift, 10% allowed" in checks["scroll_extent"]["detail"], checks
+ assert checks["scroll_travelled:treatment"]["ok"] is True, checks
+ assert "allowed 0.9 to 1.170" in checks["scroll_travelled:treatment"]["detail"], checks
+ assert (
+ "of the pair's 10000.0 px reference extent"
+ in (checks["scroll_travelled:treatment"]["detail"])
+ ), checks
+
+ # Still a ceiling: past the pair's reference allowance it is reported.
+ beyond = _scroll_row(6, fraction = (5_880 + 1_060) / 5_880, bottom = 8_250, client = 800)
+ beyond["census"]["viewport_scroll_height"] = 9_050
+ worse = B.compare_behaviour(base, beyond)
+ assert worse["verdict"] == B.BROKEN, worse
+ assert "scroll_travelled:treatment" in worse["reason"], worse
+
+
+def test_an_arm_with_no_extent_does_not_borrow_its_partners_ceiling():
+ """The degradation stays a degradation. Bounding an arm this check has always left unbounded
+ above is the one direction that could INVENT a red rather than retire one, so an arm carrying
+ no extent of its own still gets the lower bound alone and says so."""
+ base = _scroll_row(18, fraction = 1.0, bottom = 9_200, client = 800)
+ treat = _scroll_row(6, fraction = 2.0, bottom = None, client = 800)
+ treat["census"]["viewport_scroll_height"] = None
+
+ checks = {c["invariant"]: c for c in B.compare_behaviour(base, treat)["checks"]}
+ assert checks["scroll_travelled:treatment"]["ok"] is True, checks
+ assert "NO CEILING" in checks["scroll_travelled:treatment"]["detail"], checks
+
+
+def test_the_lower_bound_still_catches_a_gesture_that_was_snapped_back():
+ """The bound this invariant was written for: Studio's intent-aware autoscroll snapping a
+ programmatic move straight back to the bottom left the gesture having covered nothing."""
+ base = _scroll_row(18, fraction = 1.0, bottom = 9_200, client = 800)
+ treat = _scroll_row(6, fraction = 0.1, bottom = 9_200, client = 800)
+ assert B.compare_behaviour(base, treat)["verdict"] == B.BROKEN
+
+
+def test_a_row_with_no_extent_gets_the_lower_bound_and_no_ceiling():
+ """Degrades to no ceiling rather than to a guess. A ceiling of zero would fail every correct
+ arm; the row says which of the two it applied."""
+ base = _scroll_row(18, fraction = 1.0, bottom = 9_200, client = 800)
+ treat = _scroll_row(6, fraction = 2.0, bottom = 9_200, client = 800)
+ del treat["expect"]["bottom"]
+ del base["expect"]["bottom"]
+ checks = {c["invariant"]: c for c in B.compare_behaviour(base, treat)["checks"]}
+ assert checks["scroll_travelled:treatment"]["ok"] is True, checks
+ assert "NO CEILING" in checks["scroll_travelled:treatment"]["detail"], checks