From f9826ebc412300cc0d49afdd470a4c4705df728a Mon Sep 17 00:00:00 2001 From: "sec-check[bot]" Date: Fri, 18 Sep 2026 14:50:16 -0400 Subject: [PATCH] fix(iso): make the fastfetch OCR gate match what tesseract actually reads Post-Testing E2E failed the utah and utah-nvidia flavors on screenshots that plainly showed fastfetch. The gate required tesseract to read two exact words: 'UTAH.E2E.FASTFETCH', which OCR truncated to 'TAH-E2E-FASTFETCH' by dropping the first glyph of the line, and 'Kernel', which never appears at all because the fastfetch config draws its field labels as Nerd Font glyphs. The second condition could not match on any run, so the gate was permanently red rather than flaky. Move the decision into iso/scripts/fastfetch-ocr-match.sh so it can be tested against real transcripts without booting a VM. It still requires two independent tokens - a sentinel alone could come from scrollback - but matches the sentinel as E2EFASTFETCH and accepts the kernel version line as proof of fastfetch's body when the label is unreadable. Print the OCR transcript to the job log when the gate gives up, so the next failure can be told apart from a blank screen without downloading an artifact. Closes #135 Signed-off-by: sec-check[bot] --- iso/scripts/fastfetch-ocr-match.sh | 26 ++++++++++++++ iso/scripts/luks-e2e.sh | 11 ++++-- tests/test_iso_ci.py | 55 ++++++++++++++++++++++++++++++ 3 files changed, 89 insertions(+), 3 deletions(-) create mode 100755 iso/scripts/fastfetch-ocr-match.sh diff --git a/iso/scripts/fastfetch-ocr-match.sh b/iso/scripts/fastfetch-ocr-match.sh new file mode 100755 index 00000000..ad72f1ed --- /dev/null +++ b/iso/scripts/fastfetch-ocr-match.sh @@ -0,0 +1,26 @@ +#!/usr/bin/env bash +# Decide whether a tesseract transcript of the final desktop screenshot proves +# that fastfetch ran inside the installed session. +# +# Kept separate from luks-e2e.sh so the decision can be exercised against real +# transcripts (tests/test_iso_ci.py) without booting a VM. +# +# Two independent tokens must be present, because either alone lies: +# +# 1. The sentinel the test's .bashrc echoes after fastfetch. Matched as +# E2EFASTFETCH rather than the full UTAH-E2E-FASTFETCH: OCR routinely +# drops the first glyph of a line, and run 35374557822 read the sentinel as +# "TAH-E2E-FASTFETCH" on a screenshot that plainly showed fastfetch. +# 2. A token only fastfetch's own body produces, so a sentinel left in +# scrollback cannot pass the gate by itself. Either the "Kernel" field +# label or the kernel version line it labels: Bluefin's fastfetch config +# draws its labels as Nerd Font glyphs, which OCR does not read as text at +# all, so requiring the label alone can never match. +set -euo pipefail + +OCR_TEXT="${1:?path to the tesseract transcript is required}" + +[[ -s "${OCR_TEXT}" ]] || exit 1 + +grep -qiE 'E2E[^A-Za-z0-9]?FASTFETCH' "${OCR_TEXT}" || exit 1 +grep -qiE 'kernel|Linux[[:space:]]+[0-9]+\.[0-9]+' "${OCR_TEXT}" || exit 1 diff --git a/iso/scripts/luks-e2e.sh b/iso/scripts/luks-e2e.sh index 455a5863..78858d08 100755 --- a/iso/scripts/luks-e2e.sh +++ b/iso/scripts/luks-e2e.sh @@ -626,15 +626,20 @@ if [[ "${UTAH_E2E_REQUIRE_FASTFETCH:-0}" == 1 ]]; then shot installed-fastfetch "${MONITOR_INSTALLED}" if [[ -s "${SHOTS}/installed-fastfetch.png" ]]; then tesseract "${SHOTS}/installed-fastfetch.png" "${WORK}/fastfetch-ocr" 2>/dev/null - if grep -qi 'UTAH.E2E.FASTFETCH' "${WORK}/fastfetch-ocr.txt" \ - && grep -qi 'Kernel' "${WORK}/fastfetch-ocr.txt"; then + if bash "${ROOT}/iso/scripts/fastfetch-ocr-match.sh" "${WORK}/fastfetch-ocr.txt"; then fastfetch_seen=1 break fi fi sleep 5 done - (( fastfetch_seen )) || fail "fastfetch output was not visible in the desktop screenshot" + if (( ! fastfetch_seen )); then + # Without this the only way to tell a blank screen from an OCR misread + # is to download the diagnostics artifact. + echo " last OCR transcript of installed-fastfetch.png:" >&2 + sed -n '1,40p' "${WORK}/fastfetch-ocr.txt" 2>/dev/null | sed 's/^/ /' >&2 + fail "fastfetch output was not visible in the desktop screenshot" + fi else sleep 20 shot installed-fastfetch "${MONITOR_INSTALLED}" diff --git a/tests/test_iso_ci.py b/tests/test_iso_ci.py index b2fcd038..e7fed857 100644 --- a/tests/test_iso_ci.py +++ b/tests/test_iso_ci.py @@ -139,3 +139,58 @@ def test_harness_restricts_both_guests_and_requires_real_screenshots(self): self.assertIn("systemd.wants=sshd.service", script) self.assertIn("fastfetch output was not visible", script) self.assertIn("missing required screenshot", script) + + +class FastfetchOcrGateTests(unittest.TestCase): + """The gate runs against tesseract output, which drops and mangles glyphs.""" + + GATE = ROOT / "iso/scripts/fastfetch-ocr-match.sh" + + # Verbatim from _temp/utah-luks-e2e/fastfetch-ocr.txt in the + # iso-diagnostics-utah artifact of run 35374557822, whose screenshot showed + # fastfetch but which the previous gate rejected. + REAL_TRANSCRIPT = """TAH-E2E-FASTFETCH +[utahtest@utah-luks-test ~]$ + +utah: testing-20260918-2216657 & +Utah (Version: testing-20260918-2216657) +Linux 7.1.8-100.fc43.x86_64 + +2 mins + +KVM/QEMU Standard PC (Q35 + ICH9, 2009) (pc-q35-10.2) +GNOME 51.beta +Mutter (Wayland) +""" + + def matches(self, transcript): + with tempfile.TemporaryDirectory() as tmp: + path = Path(tmp) / "fastfetch-ocr.txt" + path.write_text(transcript) + return subprocess.run(["bash", str(self.GATE), str(path)]).returncode == 0 + + def test_accepts_the_transcript_that_previously_failed_a_good_screenshot(self): + self.assertTrue(self.matches(self.REAL_TRANSCRIPT)) + + def test_accepts_a_clean_transcript_with_readable_field_labels(self): + self.assertTrue(self.matches("UTAH-E2E-FASTFETCH\nKernel: 7.1.8-100.fc43.x86_64\n")) + + def test_rejects_a_desktop_with_no_terminal_on_it(self): + self.assertFalse(self.matches("Activities\nSep 18 19:04\nutahtest\n")) + + def test_rejects_the_sentinel_without_any_fastfetch_body(self): + self.assertFalse(self.matches("UTAH-E2E-FASTFETCH\n[utahtest@utah-luks-test ~]$\n")) + + def test_rejects_fastfetch_body_without_the_sentinel(self): + self.assertFalse(self.matches("Kernel: 7.1.8-100.fc43.x86_64\nGNOME 51.beta\n")) + + def test_rejects_an_empty_or_missing_transcript(self): + self.assertFalse(self.matches("")) + self.assertFalse( + subprocess.run(["bash", str(self.GATE), "/nonexistent/ocr.txt"]).returncode == 0) + + def test_harness_delegates_the_decision_and_prints_the_transcript_on_failure(self): + script = (ROOT / "iso/scripts/luks-e2e.sh").read_text() + self.assertIn("fastfetch-ocr-match.sh", script) + self.assertNotIn("grep -qi 'UTAH.E2E.FASTFETCH'", script) + self.assertIn("last OCR transcript", script)