|
1 | 1 | import { assert, it } from "@effect/vitest"; |
2 | 2 | import { Session } from "@opencode/client/effect"; |
| 3 | +import * as Cause from "effect/Cause"; |
| 4 | +import * as Deferred from "effect/Deferred"; |
3 | 5 | import * as Effect from "effect/Effect"; |
| 6 | +import * as Fiber from "effect/Fiber"; |
4 | 7 | import * as Layer from "effect/Layer"; |
5 | 8 | import * as Redacted from "effect/Redacted"; |
6 | 9 | import * as Schema from "effect/Schema"; |
| 10 | +import * as TestClock from "effect/testing/TestClock"; |
7 | 11 | import * as HttpClient from "effect/http/HttpClient"; |
8 | 12 | import * as HttpClientResponse from "effect/http/HttpClientResponse"; |
9 | 13 | import { describe } from "vite-plus/test"; |
@@ -48,6 +52,36 @@ describe("OpenCode2Client authorization", () => { |
48 | 52 | ); |
49 | 53 | }); |
50 | 54 |
|
| 55 | +describe("OpenCode2Client event subscription", () => { |
| 56 | + it.effect("times out and cancels a subscription with no response headers", () => |
| 57 | + Effect.gen(function* () { |
| 58 | + const cancelled = yield* Deferred.make<void>(); |
| 59 | + const transport = Layer.succeed( |
| 60 | + HttpClient.HttpClient, |
| 61 | + HttpClient.make((request) => { |
| 62 | + assert.strictEqual(request.url, "http://127.0.0.1:4096/api/event"); |
| 63 | + return Effect.never.pipe(Effect.ensuring(Deferred.succeed(cancelled, undefined))); |
| 64 | + }), |
| 65 | + ); |
| 66 | + const opencode = yield* OpenCode2Client.OpenCode2Client.pipe( |
| 67 | + Effect.provide(OpenCode2Client.layer.pipe(Layer.provide(transport))), |
| 68 | + ); |
| 69 | + const { events } = yield* opencode.connect({ |
| 70 | + baseUrl: "http://127.0.0.1:4096", |
| 71 | + password: "test-password", |
| 72 | + }); |
| 73 | + const opening = yield* events.pipe(Effect.flip, Effect.forkScoped); |
| 74 | + |
| 75 | + yield* TestClock.adjust("10 seconds"); |
| 76 | + assert.isTrue(yield* Deferred.isDone(cancelled)); |
| 77 | + const error = yield* Fiber.join(opening); |
| 78 | + assert.strictEqual(error._tag, "HttpClientError"); |
| 79 | + assert.strictEqual(error.reason._tag, "TransportError"); |
| 80 | + assert.isTrue(Cause.isTimeoutError(error.cause)); |
| 81 | + }).pipe(Effect.scoped), |
| 82 | + ); |
| 83 | +}); |
| 84 | + |
51 | 85 | const previous = { |
52 | 86 | id: "msg_repro088", |
53 | 87 | type: "synthetic", |
|
0 commit comments