diff --git a/packages/opencode/test/session/processor-effect.test.ts b/packages/opencode/test/session/processor-effect.test.ts index 537665b9a5..61c566eaec 100644 --- a/packages/opencode/test/session/processor-effect.test.ts +++ b/packages/opencode/test/session/processor-effect.test.ts @@ -105,6 +105,17 @@ function defer() { return { promise, resolve } } +const waitFor = (check: Effect.Effect, 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)