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: give the action bar selftest's two clocks one origin (#9578)

Daniel Han33407803e9d2
diff --git a/tests/studio/studiobench/scene/selftest/test_studiobench_action_bar_wait.py b/tests/studio/studiobench/scene/selftest/test_studiobench_action_bar_wait.py
index 5e5177c1268..db3554527b9 100644
--- a/tests/studio/studiobench/scene/selftest/test_studiobench_action_bar_wait.py
+++ b/tests/studio/studiobench/scene/selftest/test_studiobench_action_bar_wait.py
@@ -53,6 +53,14 @@ DOM_JS = Path(__file__).resolve().parents[1] / "dom.js"
#: comfortably outside anything a single sample could catch.
LATE_MOUNT_MS = 400
+#: The mount deadline is armed by the action's own first look (see `HARNESS_JS`), so it can only
+#: start level with or after `waitForActionButton`'s clock and `waitedMs` cannot undershoot
+#: `LATE_MOUNT_MS` by any elapsed time at all. What is left is dom.js rounding `waitedMs` to a
+#: tenth. This is an allowance for clock granularity, not a tolerance for load: the wait ends at
+#: the first sample taken at or after the bar mounts, and a slow machine can only push that sample
+#: LATER. Nothing here scales with `LATE_MOUNT_MS`.
+MOUNT_CLOCK_SLACK_MS = 1
+
HARNESS_JS = r"""
const fs = require("fs");
const domSrc = fs.readFileSync(process.argv[2], "utf8");
@@ -86,8 +94,26 @@ const node = (sel, attrs, kids) => {
return self;
};
-const started = Date.now();
-const mounted = () => Date.now() - started >= mountAfterMs;
+// ── one clock, one origin ──────────────────────────────────────────────────────────────────────
+//
+// The bar mounts `mountAfterMs` after THE ACTION FIRST LOOKS FOR IT, and the deadline is armed by
+// that first look rather than by this script loading. The two instants are not the same: between
+// them sit two readFileSync calls, the dom.js eval, two Function compiles and V8's lazy compile of
+// the action body on its first call, all of it charged to whatever else the machine is doing.
+// Armed at load, the deadline would already be part-spent by the time `waitForActionButton` set
+// its own `started`, and the `waitedMs` measured from THAT origin would come back short by the
+// setup cost -- a number about the runner's load rather than about the wait.
+//
+// Arming here instead puts both clocks on one origin, and puts them there in the only order that
+// is safe. `waitForActionButton` stamps `started`, hovers, and only then reads a control; that
+// read is the first call below, so the mount deadline can start level with the action's clock or
+// a hair after it, never before. `waitedMs` therefore cannot come in under `mountAfterMs`, and a
+// loaded machine can only push the sample that ends the wait LATER.
+let started = null;
+const mounted = () => {
+ if (started === null) started = performance.now();
+ return performance.now() - started >= mountAfterMs;
+};
const state = { menuOpen: false, hovers: 0 };
@@ -206,7 +232,11 @@ def test_a_control_that_arrives_late_is_waited_for_rather_than_reported_missing(
"""
out = run_menu(LATE_MOUNT_MS)
assert out["ran"] is True, out
- assert out["waitedMs"] >= LATE_MOUNT_MS * 0.8, out
+ # Still a liveness assertion, not a timing one: the bar was NOT there when the wait began, and
+ # the action stayed until it arrived. The bound is tight because the harness arms the mount
+ # deadline off the same clock and the same instant the action starts looking, so anything short
+ # of `LATE_MOUNT_MS` means the wait ended early -- a control that was there all along.
+ assert out["waitedMs"] >= LATE_MOUNT_MS - MOUNT_CLOCK_SLACK_MS, out
assert out["waitedMs"] < ACTION_BAR_WAIT_MS, out
# The menu really opened and closed on the control that was waited for, so the wait produced a
# measurement rather than merely a truthy `ran`.