From 328c6de80d51704c09bdd962df2ddf5b9d7c82ea Mon Sep 17 00:00:00 2001 From: Luke Parker <10430890+Hona@users.noreply.github.com> Date: Thu, 12 Mar 2026 17:35:26 +1000 Subject: Fix terminal e2e flakiness with a real terminal driver (#17144) --- packages/app/src/components/terminal.tsx | 19 +++++++--- packages/app/src/testing/terminal.ts | 64 ++++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+), 5 deletions(-) create mode 100644 packages/app/src/testing/terminal.ts (limited to 'packages/app/src') diff --git a/packages/app/src/components/terminal.tsx b/packages/app/src/components/terminal.tsx index fda66917f..840903293 100644 --- a/packages/app/src/components/terminal.tsx +++ b/packages/app/src/components/terminal.tsx @@ -10,6 +10,7 @@ import { useSDK } from "@/context/sdk" import { useServer } from "@/context/server" import { monoFontFamily, useSettings } from "@/context/settings" import type { LocalPTY } from "@/context/terminal" +import { terminalAttr, terminalProbe } from "@/testing/terminal" import { disposeIfDisposable, getHoveredLinkText, setOptionIfSupported } from "@/utils/runtime-adapters" import { terminalWriter } from "@/utils/terminal-writer" @@ -160,6 +161,7 @@ export const Terminal = (props: TerminalProps) => { let container!: HTMLDivElement const [local, others] = splitProps(props, ["pty", "class", "classList", "autoFocus", "onConnect", "onConnectError"]) const id = local.pty.id + const probe = terminalProbe(id) const restore = typeof local.pty.buffer === "string" ? local.pty.buffer : "" const restoreSize = restore && @@ -326,6 +328,9 @@ export const Terminal = (props: TerminalProps) => { } onMount(() => { + probe.init() + cleanups.push(() => probe.drop()) + const run = async () => { const loaded = await loadGhostty() if (disposed) return @@ -353,7 +358,13 @@ export const Terminal = (props: TerminalProps) => { } ghostty = g term = t - output = terminalWriter((data, done) => t.write(data, done)) + output = terminalWriter((data, done) => + t.write(data, () => { + probe.render(data) + probe.settle() + done?.() + }), + ) t.attachCustomKeyEventHandler((event) => { const key = event.key.toLowerCase() @@ -441,10 +452,6 @@ export const Terminal = (props: TerminalProps) => { startResize() } - // t.onScroll((ydisp) => { - // console.log("Scroll position:", ydisp) - // }) - const once = { value: false } let closing = false @@ -460,6 +467,7 @@ export const Terminal = (props: TerminalProps) => { ws = socket const handleOpen = () => { + probe.connect() local.onConnect?.() scheduleSize(t.cols, t.rows) } @@ -560,6 +568,7 @@ export const Terminal = (props: TerminalProps) => {