test(tui): update prompt fixture preload

This commit is contained in:
Simon Klee
2026-07-30 19:43:02 +02:00
parent a5cc34b2ec
commit bfddb33cbb
+13 -3
View File
@@ -77,14 +77,16 @@ async function mountPrompt(read: () => Promise<ClipboardReadResult>, imagePrevie
const events = createEventStream()
const calls = createFetch(undefined, events)
const requests: string[] = []
let preloaded!: () => void
const preload = new Promise<void>((resolve) => (preloaded = resolve))
const server = Bun.serve({
port: 0,
fetch: async (request) => {
requests.push(new URL(request.url).pathname)
const response = await calls.fetch(request)
const url = new URL(request.url)
if (url.pathname === "/api/session" && url.searchParams.has("project")) preloaded()
if (url.pathname === "/api/session/active") preloaded()
return response
},
})
@@ -103,14 +105,22 @@ async function mountPrompt(read: () => Promise<ClipboardReadResult>, imagePrevie
log: () => {},
}).pipe(Effect.provide(AppNodeBuilder.build(Global.node)), Effect.provide(FileSystem.layerNoop({}))),
)
await mounted
await Promise.race([
mounted,
task.then(() => {
throw new Error("Prompt application exited before mounting")
}),
Bun.sleep(2_000).then(() => {
throw new Error(`Prompt application did not mount; requests: ${requests.join(", ")}`)
}),
])
await setup.waitFor(() => activePromptRef?.focused === true)
await preload
await Bun.sleep(0)
} catch (error) {
setup.renderer.destroy()
await task?.catch(() => undefined)
await server.stop()
await task?.catch(() => undefined)
activeSetup = undefined
activeHost = undefined
activePromptRef = undefined