diff --git a/test/pty/notes.test.ts b/test/pty/notes.test.ts index c0df1e3d..8193b9ca 100644 --- a/test/pty/notes.test.ts +++ b/test/pty/notes.test.ts @@ -306,7 +306,9 @@ describe("PTY notes", () => { ); expect(whileFocused).toContain("Draft note"); - await session.type("\x1b"); + // Keyboard cancellation is covered above; click the explicit control here so this test can + // focus on whether app-level shortcuts are blocked only while the composer is active. + await session.click(/Cancel \(Esc\)/); await harness.waitForSnapshot(session, (text) => !text.includes("Draft note"), 5_000); await session.press("]"); const afterCancel = await harness.waitForSnapshot( diff --git a/test/pty/pager.test.ts b/test/pty/pager.test.ts index ef9d75d4..d8de4e8e 100644 --- a/test/pty/pager.test.ts +++ b/test/pty/pager.test.ts @@ -1,15 +1,41 @@ import { afterEach, describe, expect, setDefaultTimeout, test } from "bun:test"; +import type { Session } from "tuistory"; import { createPtyHarness } from "./harness"; const harness = createPtyHarness(); -/** Give PTY-backed startup and redraws enough headroom for slower CI machines. */ -setDefaultTimeout(20_000); +/** Give PTY-backed startup, redraws, and wheel retries enough headroom for slower CI machines. */ +setDefaultTimeout(45_000); afterEach(() => { harness.cleanup(); }); +/** Retry PTY wheel ticks one at a time so slow CI does not drop a whole scroll burst. */ +async function scrollWheelUntil( + session: Session, + direction: "down" | "up", + predicate: (text: string) => boolean, +) { + let lastErrorMessage = `Timed out waiting for pager wheel scroll ${direction}.`; + + for (let attempt = 0; attempt < 12; attempt += 1) { + if (direction === "down") { + await session.scrollDown(1); + } else { + await session.scrollUp(1); + } + + try { + return await harness.waitForSnapshot(session, predicate, 700); + } catch (error) { + lastErrorMessage = error instanceof Error ? error.message : String(error); + } + } + + throw new Error(lastErrorMessage); +} + describe("PTY pager", () => { test("pager mode hides chrome and pages forward on space", async () => { const fixture = harness.createPagerPatchFixture(); @@ -155,22 +181,20 @@ describe("PTY pager", () => { expect(initial).not.toContain("before_12"); await session.waitIdle({ timeout: 200 }); - await session.scrollDown(10); - const scrolled = await harness.waitForSnapshot( + const scrolled = await scrollWheelUntil( session, + "down", (text) => !text.includes("before_01") && text.includes("before_12"), - 5_000, ); expect(scrolled).not.toContain("View Navigate Theme Agent Help"); expect(scrolled).not.toContain("before_01"); expect(scrolled).toContain("before_12"); - await session.scrollUp(10); - const restored = await harness.waitForSnapshot( + const restored = await scrollWheelUntil( session, + "up", (text) => text.includes("before_01") && !text.includes("before_12"), - 5_000, ); expect(restored).toContain("before_01"); @@ -196,11 +220,10 @@ describe("PTY pager", () => { expect(initial).not.toContain("before_12"); await session.waitIdle({ timeout: 200 }); - await session.scrollDown(10); - const scrolled = await harness.waitForSnapshot( + const scrolled = await scrollWheelUntil( session, + "down", (text) => !text.includes("before_01") && text.includes("before_12"), - 5_000, ); expect(scrolled).toContain("before_12"); @@ -226,22 +249,20 @@ describe("PTY pager", () => { expect(initial).not.toContain("before_12"); await session.waitIdle({ timeout: 200 }); - await session.scrollDown(10); - const scrolled = await harness.waitForSnapshot( + const scrolled = await scrollWheelUntil( session, + "down", (text) => !text.includes("before_01") && text.includes("before_12"), - 5_000, ); expect(scrolled).not.toContain("View Navigate Theme Agent Help"); expect(scrolled).not.toContain("before_01"); expect(scrolled).toContain("before_12"); - await session.scrollUp(10); - const restored = await harness.waitForSnapshot( + const restored = await scrollWheelUntil( session, + "up", (text) => text.includes("before_01") && !text.includes("before_12"), - 5_000, ); expect(restored).toContain("before_01"); @@ -297,22 +318,20 @@ describe("PTY pager", () => { expect(initial).not.toContain("before_12"); await session.waitIdle({ timeout: 200 }); - await session.scrollDown(10); - const scrolled = await harness.waitForSnapshot( + const scrolled = await scrollWheelUntil( session, + "down", (text) => !text.includes("before_01") && text.includes("before_12"), - 5_000, ); expect(scrolled).not.toContain("View Navigate Theme Agent Help"); expect(scrolled).not.toContain("before_01"); expect(scrolled).toContain("before_12"); - await session.scrollUp(10); - const restored = await harness.waitForSnapshot( + const restored = await scrollWheelUntil( session, + "up", (text) => text.includes("before_01") && !text.includes("before_12"), - 5_000, ); expect(restored).toContain("before_01");