The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 04:45 UTC
| 1 | import * as BunHttpClient from "@effect/platform-bun/BunHttpClient" |
| 2 | import { assert, describe, it } from "@effect/vitest" |
| 3 | import * as Effect from "effect/Effect" |
| 4 | import * as HttpClient from "effect/http/HttpClient" |
| 5 | import * as Layer from "effect/Layer" |
| 6 | import * as Fs from "node:fs" |
| 7 | import * as Os from "node:os" |
| 8 | import * as Path from "node:path" |
| 9 | |
| 10 | describe("BunHttpClient", () => { |
| 11 | it.effect("layerOptions applies native options over the RequestInit in effect", () => |
| 12 | Effect.gen(function*() { |
| 13 | const unix = yield* Effect.acquireRelease( |
| 14 | Effect.sync(() => { |
| 15 | const directory = Fs.mkdtempSync(Path.join(Os.tmpdir(), "bun-http-client-")) |
| 16 | const unix = Path.join(directory, "server.sock") |
| 17 | const server = Bun.serve({ unix, fetch: (request) => new Response(request.headers.get("x-default")) }) |
| 18 | return { directory, server, unix } |
| 19 | }), |
| 20 | ({ directory, server }) => |
| 21 | Effect.promise(() => server.stop(true)).pipe( |
| 22 | Effect.andThen(Effect.sync(() => Fs.rmSync(directory, { recursive: true, force: true }))) |
| 23 | ) |
| 24 | ).pipe(Effect.map(({ unix }) => unix)) |
| 25 | const get = HttpClient.get("http://localhost/").pipe(Effect.flatMap((response) => response.text)) |
| 26 | const responses = yield* Effect.all([ |
| 27 | get, |
| 28 | get.pipe(Effect.provideService(BunHttpClient.RequestInit, { headers: { "x-default": "request" } })) |
| 29 | ]).pipe( |
| 30 | Effect.provide( |
| 31 | BunHttpClient.layerOptions({ unix }).pipe( |
| 32 | Layer.provide(Layer.succeed(BunHttpClient.RequestInit, { headers: { "x-default": "layer" } })) |
| 33 | ) |
| 34 | ) |
| 35 | ) |
| 36 | assert.deepStrictEqual(responses, ["layer", "request"]) |
| 37 | })) |
| 38 | }) |