Merge pull request #8909 from uinstinct/retry-cli-tests

fix(cli): wait for tui to update in test
This commit is contained in:
Dallin Romney 2025-12-02 11:10:14 -08:00 • committed by GitHub
commit c1c885e8ca
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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<void> {
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();