Skip to content

Commit 947e5f3

Browse files
committed
freebuff: Attempt e2e test fix with waitForReady
1 parent c339634 commit 947e5f3

File tree

4 files changed

+36
-3
lines changed

4 files changed

+36
-3
lines changed

freebuff/e2e/tests/code-edit.e2e.test.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,14 @@ describe('Freebuff: Code Edit', () => {
5252
initialFiles: { 'index.js': initialContent },
5353
})
5454

55+
// Wait for the CLI to be fully ready before sending input
56+
await session.waitForReady()
57+
5558
// Verify the file was created
5659
expect(session.readFile('index.js')).toBe(initialContent)
5760

5861
// Send a prompt asking freebuff to add a console.log
59-
await session.send("Add a console.log('hello world') to index.js")
62+
await session.send('Add console.log("hello world") to index.js')
6063

6164
// Wait for the file to be modified with the console.log
6265
const finalContent = await session.waitForFileContent(

freebuff/e2e/tests/knowledge-file.e2e.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ describe('Freebuff: Knowledge Files', () => {
4949
},
5050
})
5151

52+
// Wait for the CLI to be fully ready before sending input
53+
await session.waitForReady()
54+
5255
await session.send('What is the project keyword? Reply with only the keyword.')
5356

5457
const output = await session.waitForText(keyword, 120_000)

freebuff/e2e/tests/terminal-command.e2e.test.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,13 @@ describe('Freebuff: Terminal Command', () => {
4141
const binary = requireFreebuffBinary()
4242
session = await FreebuffSession.start(binary, { waitSeconds: 5 })
4343

44+
// Wait for the CLI to be fully ready before sending input
45+
await session.waitForReady()
46+
4447
// Ask freebuff to run a shell command whose output can only come from
4548
// actual terminal execution (not file-writing tools)
4649
await session.send(
47-
'Use the terminal to run: date +%s > timestamp.txt && echo done',
50+
'Execute a shell command in the terminal to write the current Unix timestamp in seconds to timestamp.txt',
4851
)
4952

5053
// Wait for the file to be created by the terminal command

freebuff/e2e/utils/freebuff-session.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,33 @@ export class FreebuffSession {
103103
} catch {
104104
// ignore
105105
}
106+
const terminalOutput = await this.capture()
106107
throw new Error(
107108
`Timed out after ${timeoutMs}ms waiting for "${pattern}" in ${relativePath}.\n` +
108-
`Last content:\n${finalContent}`,
109+
`Last content:\n${finalContent}\n` +
110+
`Terminal output:\n${terminalOutput}`,
111+
)
112+
}
113+
114+
/**
115+
* Wait for the CLI to be fully initialized and ready for input.
116+
* Polls terminal output until enough non-empty lines are visible,
117+
* indicating the TUI has rendered its initial layout.
118+
*/
119+
async waitForReady(timeoutMs = 15_000, minLines = 5): Promise<void> {
120+
const start = Date.now()
121+
while (Date.now() - start < timeoutMs) {
122+
const output = await this.capture()
123+
const nonEmptyLines = output
124+
.split('\n')
125+
.filter((line) => line.trim().length > 0)
126+
if (nonEmptyLines.length >= minLines) return
127+
await new Promise((resolve) => setTimeout(resolve, 250))
128+
}
129+
const finalOutput = await this.capture()
130+
throw new Error(
131+
`Timed out after ${timeoutMs}ms waiting for CLI to be ready.\n` +
132+
`Last output:\n${finalOutput}`,
109133
)
110134
}
111135

0 commit comments

Comments
 (0)