test(lib): promote pollWithTimeout/awaitWithTimeout helpers (#27626)

This commit is contained in:
Kit Langton
2026-05-14 19:45:32 -04:00
committed by GitHub
parent dab567aa2d
commit 4e143e3a3e
4 changed files with 84 additions and 49 deletions

View File

@@ -49,7 +49,7 @@ import { Ripgrep } from "../../src/file/ripgrep"
import { Format } from "../../src/format"
import { Reference } from "../../src/reference/reference"
import { TestInstance } from "../fixture/fixture"
import { testEffect } from "../lib/effect"
import { awaitWithTimeout, pollWithTimeout, testEffect } from "../lib/effect"
import { reply, TestLLMServer } from "../lib/llm-server"
import { SyncEvent } from "@/sync"
import { RuntimeFlags } from "@/effect/runtime-flags"
@@ -306,36 +306,6 @@ const useServerConfig = Effect.fn("test.useServerConfig")(function* (config: (ur
return { dir, llm }
})
const awaitWithTimeout = <A, E, R>(
self: Effect.Effect<A, E, R>,
message: string,
duration: Duration.Input = "2 seconds",
) =>
self.pipe(
Effect.timeoutOrElse({
duration,
orElse: () => Effect.fail(new Error(message)),
}),
)
const pollWithTimeout = <A, E, R>(
self: Effect.Effect<A | undefined, E, R>,
message: string,
duration: Duration.Input = "5 seconds",
) =>
Effect.gen(function* () {
while (true) {
const result = yield* self
if (result !== undefined) return result
yield* Effect.sleep("20 millis")
}
}).pipe(
Effect.timeoutOrElse({
duration,
orElse: () => Effect.fail(new Error(message)),
}),
)
// Wait for a session's runner to enter a busy state. SessionStatus is flipped to
// "busy" inside Runner.startShell's modifyEffect at the same moment the runner
// is registered, so this is a deterministic readiness signal — cancel can't