mirror of
https://github.com/anomalyco/opencode.git
synced 2026-09-10 13:04:37 +00:00
fix(browser): let a newer attachment replace a stale one
This commit is contained in:
parent
510d3f4b67
commit
67029d207b
2 changed files with 10 additions and 5 deletions
|
|
@ -44,8 +44,10 @@ export default Plugin.define({
|
|||
const browser = yield* Effect.acquireRelease(
|
||||
Effect.gen(function* () {
|
||||
const closed = yield* Deferred.make<void>()
|
||||
if (!active || browsers.has(input.sessionID))
|
||||
return yield* Effect.fail(call.error("unavailable", "Browser is unavailable.", {}))
|
||||
if (!active) return yield* Effect.fail(call.error("unavailable", "Browser is unavailable.", {}))
|
||||
// The newest desktop attachment wins so a re-register that races the
|
||||
// previous connection's teardown does not leave the session detached.
|
||||
yield* close(input.sessionID)
|
||||
const browser: Attachment = {
|
||||
connectionID: input.connectionID,
|
||||
state: null,
|
||||
|
|
|
|||
|
|
@ -113,10 +113,13 @@ test(
|
|||
expect(yield* host.execute({ type: "open" }).pipe(Effect.flip)).toMatchObject({
|
||||
message: "No desktop browser is connected.",
|
||||
})
|
||||
const stale = yield* host.attach("stale")
|
||||
// A newer attachment for the same session replaces the previous one.
|
||||
const attached = yield* host.attach("first")
|
||||
expect(
|
||||
yield* host.rpc.attach({ ...attached.input, connectionID: "duplicate" }, options).pipe(Effect.flip),
|
||||
).toMatchObject({ type: "unavailable" })
|
||||
yield* Fiber.join(stale.lifetime).pipe(Effect.timeout("5 seconds"))
|
||||
expect(yield* host.rpc.state({ ...stale.input, state }, options).pipe(Effect.flip)).toMatchObject({
|
||||
type: "unavailable",
|
||||
})
|
||||
const other = Location.Ref.make({ directory: AbsolutePath.make(path.join(host.location.directory, "other")) })
|
||||
yield* Effect.promise(() => mkdir(other.directory))
|
||||
yield* host.opencode.plugin.list({ location: other })
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue