mirror of
https://github.com/anomalyco/opencode.git
synced 2026-05-18 02:22:32 +00:00
test(session): use Effect polling in processor tests (#27354)
This commit is contained in:
@@ -105,6 +105,17 @@ function defer<T>() {
|
||||
return { promise, resolve }
|
||||
}
|
||||
|
||||
const waitFor = <A>(check: Effect.Effect<A | undefined>, message: string) =>
|
||||
Effect.gen(function* () {
|
||||
const stop = Date.now() + 500
|
||||
while (Date.now() < stop) {
|
||||
const value = yield* check
|
||||
if (value !== undefined) return value
|
||||
yield* Effect.sleep("10 millis")
|
||||
}
|
||||
return yield* Effect.fail(new Error(message))
|
||||
})
|
||||
|
||||
const user = Effect.fn("TestSession.user")(function* (sessionID: SessionID, text: string) {
|
||||
const session = yield* Session.Service
|
||||
const msg = yield* session.updateMessage({
|
||||
@@ -301,15 +312,10 @@ it.live("session.processor effect tests preserve text start time", () =>
|
||||
})
|
||||
.pipe(Effect.forkChild)
|
||||
|
||||
yield* Effect.promise(async () => {
|
||||
const stop = Date.now() + 500
|
||||
while (Date.now() < stop) {
|
||||
const text = MessageV2.parts(msg.id).find((part): part is MessageV2.TextPart => part.type === "text")
|
||||
if (text?.time?.start) return
|
||||
await Bun.sleep(10)
|
||||
}
|
||||
throw new Error("timed out waiting for text part")
|
||||
})
|
||||
yield* waitFor(
|
||||
Effect.sync(() => MessageV2.parts(msg.id).find((part): part is MessageV2.TextPart => part.type === "text")),
|
||||
"timed out waiting for text part",
|
||||
)
|
||||
yield* Effect.sleep("20 millis")
|
||||
gate.resolve()
|
||||
|
||||
@@ -691,14 +697,10 @@ it.live("session.processor effect tests mark pending tools as aborted on cleanup
|
||||
.pipe(Effect.forkChild)
|
||||
|
||||
yield* llm.wait(1)
|
||||
yield* Effect.promise(async () => {
|
||||
const end = Date.now() + 500
|
||||
while (Date.now() < end) {
|
||||
const parts = await MessageV2.parts(msg.id)
|
||||
if (parts.some((part) => part.type === "tool")) return
|
||||
await Bun.sleep(10)
|
||||
}
|
||||
})
|
||||
yield* waitFor(
|
||||
Effect.sync(() => MessageV2.parts(msg.id).find((part): part is MessageV2.ToolPart => part.type === "tool")),
|
||||
"timed out waiting for tool part",
|
||||
)
|
||||
yield* Fiber.interrupt(run)
|
||||
|
||||
const exit = yield* Fiber.await(run)
|
||||
|
||||
Reference in New Issue
Block a user