test(session): de-flake shell-cancel tests by waiting for busy state (#27622)
This commit is contained in:
@@ -336,6 +336,21 @@ const pollWithTimeout = <A, E, R>(
|
|||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// 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
|
||||||
|
// no-op once we observe it.
|
||||||
|
const waitForBusy = (sessionID: SessionID, duration: Duration.Input = "2 seconds") =>
|
||||||
|
pollWithTimeout(
|
||||||
|
Effect.gen(function* () {
|
||||||
|
const status = yield* SessionStatus.Service
|
||||||
|
const s = yield* status.get(sessionID)
|
||||||
|
return s.type === "busy" ? (true as const) : undefined
|
||||||
|
}),
|
||||||
|
`session ${sessionID} never became busy`,
|
||||||
|
duration,
|
||||||
|
)
|
||||||
|
|
||||||
const hasBash = Effect.sync(() => Bun.which("bash") !== null)
|
const hasBash = Effect.sync(() => Bun.which("bash") !== null)
|
||||||
|
|
||||||
const deferredAsPromise = <A>(deferred: Deferred.Deferred<A>): PromiseLike<A> => ({
|
const deferredAsPromise = <A>(deferred: Deferred.Deferred<A>): PromiseLike<A> => ({
|
||||||
@@ -1493,7 +1508,7 @@ it.instance(
|
|||||||
const sh = yield* prompt
|
const sh = yield* prompt
|
||||||
.shell({ sessionID: chat.id, agent: "build", command: "sleep 0.2" })
|
.shell({ sessionID: chat.id, agent: "build", command: "sleep 0.2" })
|
||||||
.pipe(Effect.forkChild)
|
.pipe(Effect.forkChild)
|
||||||
yield* Effect.sleep(50)
|
yield* waitForBusy(chat.id)
|
||||||
|
|
||||||
const loop = yield* prompt.loop({ sessionID: chat.id }).pipe(Effect.forkChild)
|
const loop = yield* prompt.loop({ sessionID: chat.id }).pipe(Effect.forkChild)
|
||||||
yield* Effect.sleep(50)
|
yield* Effect.sleep(50)
|
||||||
@@ -1530,7 +1545,7 @@ it.instance(
|
|||||||
const sh = yield* prompt
|
const sh = yield* prompt
|
||||||
.shell({ sessionID: chat.id, agent: "build", command: "sleep 0.2" })
|
.shell({ sessionID: chat.id, agent: "build", command: "sleep 0.2" })
|
||||||
.pipe(Effect.forkChild)
|
.pipe(Effect.forkChild)
|
||||||
yield* Effect.sleep(50)
|
yield* waitForBusy(chat.id)
|
||||||
|
|
||||||
const a = yield* prompt.loop({ sessionID: chat.id }).pipe(Effect.forkChild)
|
const a = yield* prompt.loop({ sessionID: chat.id }).pipe(Effect.forkChild)
|
||||||
const b = yield* prompt.loop({ sessionID: chat.id }).pipe(Effect.forkChild)
|
const b = yield* prompt.loop({ sessionID: chat.id }).pipe(Effect.forkChild)
|
||||||
@@ -1597,7 +1612,7 @@ unix(
|
|||||||
const sh = yield* prompt
|
const sh = yield* prompt
|
||||||
.shell({ sessionID: chat.id, agent: "build", command: "sleep 30" })
|
.shell({ sessionID: chat.id, agent: "build", command: "sleep 30" })
|
||||||
.pipe(Effect.forkChild)
|
.pipe(Effect.forkChild)
|
||||||
yield* Effect.sleep(50)
|
yield* waitForBusy(chat.id)
|
||||||
|
|
||||||
yield* prompt.cancel(chat.id)
|
yield* prompt.cancel(chat.id)
|
||||||
|
|
||||||
@@ -1721,7 +1736,7 @@ unix(
|
|||||||
const { prompt, chat } = yield* boot()
|
const { prompt, chat } = yield* boot()
|
||||||
|
|
||||||
const sh = yield* prompt.shell({ sessionID: chat.id, agent: "build", command: "sleep 30" }).pipe(Effect.forkChild)
|
const sh = yield* prompt.shell({ sessionID: chat.id, agent: "build", command: "sleep 30" }).pipe(Effect.forkChild)
|
||||||
yield* Effect.sleep(50)
|
yield* waitForBusy(chat.id)
|
||||||
|
|
||||||
const loop = yield* prompt.loop({ sessionID: chat.id }).pipe(Effect.forkChild)
|
const loop = yield* prompt.loop({ sessionID: chat.id }).pipe(Effect.forkChild)
|
||||||
yield* Effect.sleep(50)
|
yield* Effect.sleep(50)
|
||||||
@@ -1751,7 +1766,7 @@ unix(
|
|||||||
const a = yield* prompt
|
const a = yield* prompt
|
||||||
.shell({ sessionID: chat.id, agent: "build", command: "sleep 30" })
|
.shell({ sessionID: chat.id, agent: "build", command: "sleep 30" })
|
||||||
.pipe(Effect.forkChild)
|
.pipe(Effect.forkChild)
|
||||||
yield* Effect.sleep(50)
|
yield* waitForBusy(chat.id)
|
||||||
|
|
||||||
const exit = yield* prompt.shell({ sessionID: chat.id, agent: "build", command: "echo hi" }).pipe(Effect.exit)
|
const exit = yield* prompt.shell({ sessionID: chat.id, agent: "build", command: "echo hi" }).pipe(Effect.exit)
|
||||||
expect(Exit.isFailure(exit)).toBe(true)
|
expect(Exit.isFailure(exit)).toBe(true)
|
||||||
|
|||||||
Reference in New Issue
Block a user