mirror of
https://github.com/anomalyco/opencode.git
synced 2026-07-24 12:15:51 -04:00
40 lines
1.4 KiB
TypeScript
40 lines
1.4 KiB
TypeScript
import { expect, test } from "bun:test"
|
|
import { CodeMode } from "@opencode-ai/codemode"
|
|
import { Effect, Layer } from "effect"
|
|
import { HttpClient, HttpClientResponse } from "effect/unstable/http"
|
|
import { CodeModeHost } from "../src/code-mode"
|
|
|
|
test("exposes the authenticated OpenCode API through CodeMode", async () => {
|
|
const requests: Array<{ readonly url: string; readonly authorization?: string }> = []
|
|
const client = Layer.succeed(
|
|
HttpClient.HttpClient,
|
|
HttpClient.make((request) => {
|
|
requests.push({ url: request.url, authorization: request.headers.authorization })
|
|
return Effect.succeed(
|
|
HttpClientResponse.fromWeb(
|
|
request,
|
|
Response.json(
|
|
{ healthy: true, version: "test", pid: 1 },
|
|
{ headers: { "content-type": "application/json" } },
|
|
),
|
|
),
|
|
)
|
|
}),
|
|
)
|
|
const result = await CodeMode.make({ tools: CodeModeHost.makeTools(client, "secret") })
|
|
.execute("return await tools.opencode.v2.health.get({})")
|
|
.pipe(Effect.runPromise)
|
|
|
|
expect(result).toEqual({
|
|
ok: true,
|
|
value: { healthy: true, version: "test", pid: 1 },
|
|
toolCalls: [{ name: "opencode.v2.health.get" }],
|
|
})
|
|
expect(requests).toEqual([
|
|
{
|
|
url: "http://opencode.local/api/health",
|
|
authorization: `Basic ${Buffer.from("opencode:secret").toString("base64")}`,
|
|
},
|
|
])
|
|
})
|