diff --git a/extensions/cli/src/ui/__tests__/TUIChat.editMessage.test.tsx b/extensions/cli/src/ui/__tests__/TUIChat.editMessage.test.tsx index 9e6a92874..73af37d50 100644 --- a/extensions/cli/src/ui/__tests__/TUIChat.editMessage.test.tsx +++ b/extensions/cli/src/ui/__tests__/TUIChat.editMessage.test.tsx @@ -1,4 +1,18 @@ -import { testBothModes, renderInMode } from "./TUIChat.dualModeHelper.js"; +import { renderInMode, testBothModes } from "./TUIChat.dualModeHelper.js"; + +async function waitForCondition( + conditionFn: () => boolean, + timeoutMs = 2000, + intervalMs = 50, +): Promise { + const startTime = Date.now(); + while (Date.now() - startTime < timeoutMs) { + if (conditionFn()) { + return; + } + await new Promise((resolve) => setTimeout(resolve, intervalMs)); + } +} /** * Integration tests for the message edit feature in TUIChat @@ -10,7 +24,6 @@ import { testBothModes, renderInMode } from "./TUIChat.dualModeHelper.js"; * 4. History is rewound and new message is submitted * 5. Chat updates correctly */ - describe("TUIChat - Message Edit Feature", () => { testBothModes("double Esc should open edit selector", async (mode) => { const { lastFrame, stdin } = renderInMode(mode); @@ -119,7 +132,11 @@ describe("TUIChat - Message Edit Feature", () => { // Perform various operations stdin.write("\u001b"); stdin.write("\u001b"); // Open edit with separate Esc presses - await new Promise((resolve) => setTimeout(resolve, 100)); + + // Wait for selector to open (poll instead of fixed timeout) + await waitForCondition( + () => lastFrame()?.includes("No user messages to edit") ?? false, + ); // Verify selector opened let frame = lastFrame(); @@ -130,7 +147,11 @@ describe("TUIChat - Message Edit Feature", () => { await new Promise((resolve) => setTimeout(resolve, 50)); stdin.write("\u001b"); // Close - await new Promise((resolve) => setTimeout(resolve, 100)); + + // Wait for selector to close (poll instead of fixed timeout) + await waitForCondition( + () => !(lastFrame()?.includes("No user messages to edit") ?? true), + ); frame = lastFrame();