Skip to content

graff — a fast agentic coding harness in Zig: multi-provider, MCP, workflows, DGM evolution loop, TS/Python SDKs

Python

Wait for the terminal hover baseline to settle

justrachdfd87116581b
diff --git a/scripts/eval/hover_baseline_cases.py b/scripts/eval/hover_baseline_cases.py
new file mode 100644
index 00000000..f9e326cf
--- /dev/null
+++ b/scripts/eval/hover_baseline_cases.py
@@ -0,0 +1,70 @@
+"""Deterministic frame-clock coverage for the terminal hover baseline."""
+import importlib.util
+from pathlib import Path
+import unittest
+
+probe_path = Path(__file__).resolve().parents[1] / "test-tui-hover.py"
+spec = importlib.util.spec_from_file_location("tui_hover_probe", probe_path)
+probe = importlib.util.module_from_spec(spec)
+spec.loader.exec_module(probe)
+from ptyharness import Cell
+
+
+class Frames:
+ cols, rows = 40, 6
+ canvas, flash = (20, 20, 20), (36, 36, 36)
+
+ def __init__(self, style):
+ self.now = 0.0
+ self.style = style
+
+ def pump(self, seconds):
+ self.now += seconds
+
+ def screen_lines(self):
+ return ["", "› Read 1 file" if self.style(self.now) != "missing" else "", "", "", "", ""]
+
+ def cell(self, x, y):
+ text = self.screen_lines()[y].ljust(self.cols)
+ style = self.style(self.now)
+ colored = y == 1 and (style == "uniform" or (style == "flash" and 1 <= x < self.cols - 1))
+ return Cell(text[x], bg=self.flash if colored else self.canvas)
+
+
+class HoverBaselineTests(unittest.TestCase):
+ def wait(self, frames, timeout=2.0):
+ return probe.wait_for_resting_row(frames, timeout, lambda: frames.now)
+
+ def test_completion_flash_must_end_before_baseline(self):
+ frames = Frames(lambda t: "flash" if t < 1.0 else "canvas")
+ self.assertEqual(self.wait(frames), 1)
+ self.assertGreaterEqual(frames.now, 1.1)
+ self.assertLess(frames.now, 1.3)
+
+ def test_one_transitional_canvas_frame_does_not_satisfy_stability(self):
+ frames = Frames(lambda t: "canvas" if t < 0.05 or t >= 1.0 else "flash")
+ self.assertEqual(self.wait(frames), 1)
+ self.assertGreaterEqual(frames.now, 1.1)
+
+ def test_uniform_non_canvas_tint_is_not_a_valid_baseline(self):
+ frames = Frames(lambda _: "uniform")
+ with self.assertRaisesRegex(TimeoutError, "canvas"):
+ self.wait(frames)
+ self.assertAlmostEqual(frames.now, 2.0)
+
+ def test_permanent_mixed_background_still_fails(self):
+ frames = Frames(lambda _: "flash")
+ with self.assertRaisesRegex(TimeoutError, "did not settle"):
+ self.wait(frames)
+ self.assertAlmostEqual(frames.now, 2.0)
+
+ def test_missing_header_fails_at_the_deadline(self):
+ frames = Frames(lambda _: "missing")
+ with self.assertRaisesRegex(TimeoutError, "no folded tool summary"):
+ self.wait(frames)
+ self.assertAlmostEqual(frames.now, 2.0)
+
+ def test_already_settled_row_needs_only_a_stable_frame_interval(self):
+ frames = Frames(lambda _: "canvas")
+ self.assertEqual(self.wait(frames), 1)
+ self.assertAlmostEqual(frames.now, 0.1)
diff --git a/scripts/eval/test_tier1_tuiguard.py b/scripts/eval/test_tier1_tuiguard.py
index c3f84853..c3294c85 100644
--- a/scripts/eval/test_tier1_tuiguard.py
+++ b/scripts/eval/test_tier1_tuiguard.py
@@ -15,6 +15,7 @@ import unittest
from concurrent.futures import ThreadPoolExecutor
from threading import Barrier
from unittest import mock
+from hover_baseline_cases import HoverBaselineTests
RUNNER_PATH = Path(__file__).with_name("tier1_tuiguard.py")
diff --git a/scripts/test-tui-hover.py b/scripts/test-tui-hover.py
index b11cab95..a5ad7e39 100644
--- a/scripts/test-tui-hover.py
+++ b/scripts/test-tui-hover.py
@@ -180,11 +180,42 @@ def workspace(tmp, port):
return env
+def wait_for_resting_row(h, timeout=3.0, clock=None):
+ """Observe the end of the completion flash, not a guessed wall delay.
+
+ The untouched row below supplies the canvas color independently of the
+ header. A uniform flash must not become the baseline either. Require a
+ short stable interval and retain a bounded failure for permanent styling.
+ """
+ clock = clock or time.monotonic
+ deadline = clock() + timeout
+ previous, stable_since = None, None
+ detail = "no folded tool summary on screen"
+ while clock() < deadline:
+ y = summary_row(h)
+ if y is not None and y + 1 < h.rows:
+ colors, canvas = row_bgs(h, y), row_bgs(h, y + 1)
+ detail = f"resting row backgrounds {colors}, canvas {canvas}"
+ frame = (y, tuple(c.tuple() for c in row_cells(h, y)))
+ if len(canvas) == 1 and colors == canvas and EXPAND_MARK in h.screen_lines()[y]:
+ if frame != previous:
+ previous, stable_since = frame, clock()
+ elif clock() - stable_since >= 0.1:
+ return y
+ else:
+ previous, stable_since = None, None
+ else:
+ previous, stable_since = None, None
+ h.pump(min(0.05, max(0, deadline - clock())))
+ raise TimeoutError(f"hover baseline did not settle within {timeout:g}s: {detail}")
+
+
def check_affordance(h):
"""(2)-(6): the tint, the mark swap, the neighbour, and the two gestures."""
- y = summary_row(h)
- if y is None:
- return f"no folded tool summary on screen\n{h.screen_contents()}"
+ try:
+ y = wait_for_resting_row(h)
+ except TimeoutError as error:
+ return f"{error}\n{h.screen_contents()}"
line = h.screen_lines()[y]
if EXPAND_MARK not in line:
return f"the folded header carries no disclosure chevron: {line!r}"