From cd390636226c964df81979eb6089f186fc7f7e16 Mon Sep 17 00:00:00 2001 From: "opencode-agent[bot]" <219766164+opencode-agent[bot]@users.noreply.github.com> Date: Mon, 21 Sep 2026 14:45:33 -0500 Subject: [PATCH] test(core): stabilize browser idle attachment (#50418) Co-authored-by: rekram1-node --- packages/core/test/browser-idle.test.ts | 36 +++++++++++-------------- 1 file changed, 16 insertions(+), 20 deletions(-) diff --git a/packages/core/test/browser-idle.test.ts b/packages/core/test/browser-idle.test.ts index 26ad0ae8830..a7db22b729d 100644 --- a/packages/core/test/browser-idle.test.ts +++ b/packages/core/test/browser-idle.test.ts @@ -1,5 +1,5 @@ import { expect } from "bun:test" -import { Context, Deferred, Effect, Fiber, RcMap, Stream } from "effect" +import { Context, Effect, Fiber, RcMap, Schedule } from "effect" import { Browser } from "@opencode/plugin-browser/rpc" import { AppNodeBuilder } from "@opencode/core/effect/app-node-builder" import { LayerNode } from "@opencode/util/effect/layer-node" @@ -51,19 +51,17 @@ it.live( const session = yield* sessions.create({ location: ref }) const rpc = Context.get(context, Rpc.Service).client(Browser.Definition) const attachment = { sessionID: session.id, connectionID: crypto.randomUUID() } - const attached = yield* Deferred.make() - yield* rpc.events.subscribe("control").pipe( - Stream.runForEach((event) => - event.data.type === "attached" ? Deferred.succeed(attached, undefined) : Effect.void, - ), - Effect.forkScoped({ startImmediately: true }), - ) + const state = { ...attachment, state: { tabs: [], focusedTabID: null } } const pending = yield* rpc .attach({ ...attachment, version: 4 }) .pipe(Effect.provide(locations.get(ref)), Effect.flip, Effect.forkScoped) - yield* Deferred.await(attached) - const state = { ...attachment, state: { tabs: [], focusedTabID: null } } - yield* rpc.state(state) + yield* rpc.state(state).pipe( + Effect.retry({ + while: (error) => "type" in error && error.type === "unavailable", + schedule: Schedule.spaced("10 millis"), + }), + Effect.timeout("5 seconds"), + ) // Real idle cleanup must end the long-lived request, not leave a second registry behind it. expect(yield* Fiber.join(pending).pipe(Effect.timeout("10 seconds"))).toMatchObject({ type: "rpc.unavailable" }) @@ -73,16 +71,14 @@ it.live( const replacement = yield* locations.contextEffect(ref) yield* Plugin.awaitActivation.pipe(Effect.provideContext(replacement)) const fresh = Context.get(replacement, Rpc.Service).client(Browser.Definition) - const restored = yield* Deferred.make() - yield* fresh.events.subscribe("control").pipe( - Stream.runForEach((event) => - event.data.type === "attached" ? Deferred.succeed(restored, undefined) : Effect.void, - ), - Effect.forkScoped({ startImmediately: true }), - ) const resumed = yield* fresh.attach({ ...attachment, version: 4 }).pipe(Effect.forkScoped) - yield* Deferred.await(restored) - yield* fresh.state(state) + yield* fresh.state(state).pipe( + Effect.retry({ + while: (error) => "type" in error && error.type === "unavailable", + schedule: Schedule.spaced("10 millis"), + }), + Effect.timeout("5 seconds"), + ) expect(resumed.pollUnsafe()).toBeUndefined() yield* Fiber.interrupt(resumed) }),