Files
anomalyco_opencode/packages/opencode/test/server/httpapi-v2-location.test.ts
T
2026-06-03 17:47:38 -04:00

42 lines
1.3 KiB
TypeScript

import { afterEach, describe, expect, test } from "bun:test"
import { Context } from "effect"
import { HttpApiApp } from "../../src/server/routes/instance/httpapi/server"
import * as Log from "@opencode-ai/core/util/log"
import { resetDatabase } from "../fixture/db"
import { disposeAllInstances, tmpdir } from "../fixture/fixture"
void Log.init({ print: false })
const context = Context.empty() as Context.Context<unknown>
function request(route: string, directory: string) {
return HttpApiApp.webHandler().handler(
new Request(`http://localhost${route}`, {
headers: {
"x-opencode-directory": directory,
},
}),
context,
)
}
afterEach(async () => {
await disposeAllInstances()
await resetDatabase()
})
describe("v2 location HttpApi", () => {
test("returns command and skill snapshots with resolved locations", async () => {
await using tmp = await tmpdir({ git: true })
for (const route of ["/api/command", "/api/skill"]) {
const response = await request(route, tmp.path)
expect(response.status).toBe(200)
const body = (await response.json()) as { location: { directory: string; project: { id: string } }; data: unknown }
expect(body.data).toBeArray()
expect(body.location.directory).toBe(tmp.path)
expect(body.location.project.id).toBeTruthy()
}
})
})