From d004f5b54ee3c1dcdc7b12be384a5819317f4300 Mon Sep 17 00:00:00 2001 From: scanner Date: Tue, 10 Nov 2026 04:25:33 +0000 Subject: [PATCH 1/4] fix: widen the dogfood installer's per-key gap under console noise type_keys sent each keystroke to the QEMU monitor with a fixed 0.15s gap, so the injected console noise could make the guest miss a scancode. A 16-character password typed twice at that gap registered 15 then 16 characters on first boot, and the two password prompts said they did not match (#600). Widen the per-key gap to 0.35s while console noise is active so the guest has time to accept each scancode. A unit test types a string against a stand-in QEMU monitor and asserts the noisy run takes roughly twice as long as the quiet one; the test fails without the widening. Hive-Run: projectbluefin/server#600 Hive-Spec: projectbluefin-server#600 Assisted-by: lemonade/ornith-1.5-35b-a3b-gguf-q6_k via GitHub Copilot Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: scanner --- scripts/dogfood-installer.sh | 10 ++-- tests/unit/test_dogfood_installer.py | 76 ++++++++++++++++++++++++++++ 2 files changed, 83 insertions(+), 3 deletions(-) diff --git a/scripts/dogfood-installer.sh b/scripts/dogfood-installer.sh index 27ce3afd..cef23097 100644 --- a/scripts/dogfood-installer.sh +++ b/scripts/dogfood-installer.sh @@ -440,16 +440,20 @@ hold_console() { } # type_keys : type on the guest's keyboard through the -# QEMU monitor (sendkey); a newline is Enter. +# QEMU monitor (sendkey); a newline is Enter. Widen the per-key gap while +# console noise is active: the injected errors can make the guest miss a +# scancode, and a 16-character password typed at the default gap lost one +# keystroke under noise, so the two password prompts did not match (#600). type_keys() { - python3 - "${state}/$1.mon" "$2" <<'PY' + python3 - "${state}/$1.mon" "$2" "${console_noise:-0}" <<'PY' import socket, sys, time keys = {" ": "spc", "\n": "ret", "-": "minus", ".": "dot", "/": "slash", "=": "equal", ",": "comma"} +gap = 0.35 if sys.argv[3] == "1" else 0.15 with socket.socket(socket.AF_UNIX) as s: s.connect(sys.argv[1]) for ch in sys.argv[2]: s.sendall(f"sendkey {keys.get(ch, ch)}\n".encode()) - time.sleep(0.15) + time.sleep(gap) time.sleep(0.5) PY } diff --git a/tests/unit/test_dogfood_installer.py b/tests/unit/test_dogfood_installer.py index 891e2fd3..dd0c9818 100644 --- a/tests/unit/test_dogfood_installer.py +++ b/tests/unit/test_dogfood_installer.py @@ -12,9 +12,13 @@ """ +import os import re import shlex +import socket import subprocess +import threading +import time from pathlib import Path import pytest @@ -103,3 +107,75 @@ def test_the_journal_mirror_opens_after_the_flush(script: str) -> None: lines = unit[1].splitlines() assert "ExecStart=journalctl -b -f --no-pager -o short-monotonic" in lines assert "After=systemd-journal-flush.service" in lines + + +class _FakeMonitor: + """A stand-in QEMU monitor: a Unix socket that accepts and drains the + sendkeys type_keys types on, so the script never blocks sending. Under + console noise type_keys widens its per-key gap, so typing the whole + string takes longer (#600).""" + + def __init__(self, path: Path) -> None: + if path.exists(): + path.unlink() + self._srv = socket.socket(socket.AF_UNIX) + self._srv.bind(str(path)) + self._srv.listen(1) + self._thread = threading.Thread(target=self._serve, daemon=True) + + def __enter__(self) -> "_FakeMonitor": + self._thread.start() + return self + + def __exit__(self, *_exc) -> None: + try: + self._srv.close() + except OSError: + pass + + def _serve(self) -> None: + try: + conn, _ = self._srv.accept() + except OSError: + return + while conn.recv(4096): + pass + conn.close() + + +def type_keys_elapsed(tmp_path: Path, text: str, console_noise: str) -> float: + """Seconds type_keys takes to type ; the noise-widened gap is + roughly twice the quiet one over the same string.""" + with _FakeMonitor(tmp_path / "t.mon"): + script = ( + "set -euo pipefail\n" + f'state="{tmp_path}"\n' + + function("type_keys") + + 'console_noise="$TK_NOISE"\n' + + 'type_keys "t" "$TK_TEXT"\n' + ) + env = os.environ.copy() + env["TK_TEXT"] = text + env["TK_NOISE"] = console_noise + env.pop("COVERAGE_PROCESS_CONFIG", None) + start = time.monotonic() + result = subprocess.run( + ["bash", "-c", script, "type_keys"], + env=env, + capture_output=True, + text=True, + timeout=60, + ) + elapsed = time.monotonic() - start + assert result.returncode == 0, result.stderr + return elapsed + + +def test_type_keys_widens_its_gap_under_console_noise(tmp_path: Path) -> None: + text = "1234567890\n" + quiet = type_keys_elapsed(tmp_path, text, "0") + noisy = type_keys_elapsed(tmp_path, text, "1") + # Eleven keys at 0.15s vs 0.35s are about 2.2s apart; this separates the + # two without depending on per-key scheduling jitter. + assert quiet < 3.0, f"quiet gap unexpectedly large: {quiet:.2f}s" + assert noisy > 3.5, f"noise gap unexpectedly small: {noisy:.2f}s" From 76c9496a8b34901fc68d193258e39351fe4e9c1e Mon Sep 17 00:00:00 2001 From: scanner Date: Tue, 10 Nov 2026 04:41:37 +0000 Subject: [PATCH 2/4] test: drop unnecessary quotes from _FakeMonitor annotation (UP037) --- tests/unit/test_dogfood_installer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/test_dogfood_installer.py b/tests/unit/test_dogfood_installer.py index dd0c9818..7088544c 100644 --- a/tests/unit/test_dogfood_installer.py +++ b/tests/unit/test_dogfood_installer.py @@ -123,7 +123,7 @@ def __init__(self, path: Path) -> None: self._srv.listen(1) self._thread = threading.Thread(target=self._serve, daemon=True) - def __enter__(self) -> "_FakeMonitor": + def __enter__(self) -> _FakeMonitor: self._thread.start() return self From a646fdb3e224445803669d3ed1a25cb388636915 Mon Sep 17 00:00:00 2001 From: scanner Date: Tue, 10 Nov 2026 16:25:27 +0000 Subject: [PATCH 3/4] test(dogfood): add future annotations so the unquoted _FakeMonitor ref collects UP037 wants the quote removed, but the self-referential return annotation is a forward reference with no future-import header, so it raised NameError at collection. PEP 563 makes it lazy while staying UP037-clean. --- tests/unit/test_dogfood_installer.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/unit/test_dogfood_installer.py b/tests/unit/test_dogfood_installer.py index 7088544c..1994b33e 100644 --- a/tests/unit/test_dogfood_installer.py +++ b/tests/unit/test_dogfood_installer.py @@ -10,6 +10,7 @@ These tests run the script's own ``boot_wait`` against a stand-in QEMU that never exits, without booting anything. """ +from __future__ import annotations import os From b7769283bd7c07660fba1bac8027d5bd67279d99 Mon Sep 17 00:00:00 2001 From: scanner Date: Thu, 12 Nov 2026 05:52:47 +0000 Subject: [PATCH 4/4] fix(tests): collapse blank line after __future__ import (ruff I001) ruff I001 fails on the double blank line between the __future__ import and the stdlib group. UP037 (quoted _FakeMonitor annotation) is already unquoted. (server#647) --- tests/unit/test_dogfood_installer.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/unit/test_dogfood_installer.py b/tests/unit/test_dogfood_installer.py index 1994b33e..7175cadd 100644 --- a/tests/unit/test_dogfood_installer.py +++ b/tests/unit/test_dogfood_installer.py @@ -12,7 +12,6 @@ """ from __future__ import annotations - import os import re import shlex