From e416e59ea69f7600acbdb593ba68ac0fb1ee2633 Mon Sep 17 00:00:00 2001 From: Luke Parker <10430890+Hona@users.noreply.github.com> Date: Tue, 17 Mar 2026 12:55:58 +1000 Subject: test(app): deflake slash terminal toggle flow (#17881) --- packages/app/src/testing/prompt.ts | 56 ++++++++++++++++++++++++++++++++++++ packages/app/src/testing/terminal.ts | 15 ++++++++++ 2 files changed, 71 insertions(+) create mode 100644 packages/app/src/testing/prompt.ts (limited to 'packages/app/src/testing') diff --git a/packages/app/src/testing/prompt.ts b/packages/app/src/testing/prompt.ts new file mode 100644 index 000000000..e11462f30 --- /dev/null +++ b/packages/app/src/testing/prompt.ts @@ -0,0 +1,56 @@ +import type { E2EWindow } from "./terminal" + +export type PromptProbeState = { + popover: "at" | "slash" | null + slash: { + active: string | null + ids: string[] + } + selected: string | null + selects: number +} + +export const promptEnabled = () => { + if (typeof window === "undefined") return false + return (window as E2EWindow).__opencode_e2e?.prompt?.enabled === true +} + +const root = () => { + if (!promptEnabled()) return + return (window as E2EWindow).__opencode_e2e?.prompt +} + +export const promptProbe = { + set(input: Omit) { + const state = root() + if (!state) return + state.current = { + popover: input.popover, + slash: { + active: input.slash.active, + ids: [...input.slash.ids], + }, + selected: state.current?.selected ?? null, + selects: state.current?.selects ?? 0, + } + }, + select(id: string) { + const state = root() + if (!state) return + const prev = state.current + state.current = { + popover: prev?.popover ?? null, + slash: { + active: prev?.slash.active ?? null, + ids: [...(prev?.slash.ids ?? [])], + }, + selected: id, + selects: (prev?.selects ?? 0) + 1, + } + }, + clear() { + const state = root() + if (!state) return + state.current = undefined + }, +} diff --git a/packages/app/src/testing/terminal.ts b/packages/app/src/testing/terminal.ts index af1c33309..2bca39b31 100644 --- a/packages/app/src/testing/terminal.ts +++ b/packages/app/src/testing/terminal.ts @@ -7,6 +7,7 @@ export type TerminalProbeState = { connects: number rendered: string settled: number + focusing: number } type TerminalProbeControl = { @@ -19,6 +20,10 @@ export type E2EWindow = Window & { enabled?: boolean current?: ModelProbeState } + prompt?: { + enabled?: boolean + current?: import("./prompt").PromptProbeState + } terminal?: { enabled?: boolean terminals?: Record @@ -32,6 +37,7 @@ const seed = (): TerminalProbeState => ({ connects: 0, rendered: "", settled: 0, + focusing: 0, }) const root = () => { @@ -88,6 +94,15 @@ export const terminalProbe = (id: string) => { const prev = state[id] ?? seed() state[id] = { ...prev, settled: prev.settled + 1 } }, + focus(count: number) { + set({ focusing: Math.max(0, count) }) + }, + step() { + const state = terms() + if (!state) return + const prev = state[id] ?? seed() + state[id] = { ...prev, focusing: Math.max(0, prev.focusing - 1) } + }, control(next: Partial) { const state = controls() if (!state) return -- cgit v1.2.3