Files
AirCoding/packages/opencode/test/server/httpapi-file.test.ts
airlongdian e2fd375a1c feat: 品牌替换 + 启动优化 + AGENTS.md 模板定制
- 品牌替换:OpenCode/opencode → AirCoding/aircoding(16+ 文件)
- Logo ASCII art:修复 left/right 行数不匹配导致的启动崩溃
- 启动诊断:添加 OPENCODE_PRINT_TIMING 计时探针
- dev 模式默认 --pure 跳过外部插件加载
- AGENTS.md 模板:追加 AirCoding 多 Agent 专项段落
- architect prompt + plugin:强化 AGENTS.md 产出验证
2026-06-14 09:31:29 +08:00

74 lines
2.4 KiB
TypeScript

import { afterEach, describe, expect, test } from "bun:test"
import { Context } from "effect"
import path from "path"
import { HttpApiApp } from "../../src/server/routes/instance/httpapi/server"
import { FilePaths } from "../../src/server/routes/instance/httpapi/groups/file"
import { resetDatabase } from "../fixture/db"
import { disposeAllInstances, tmpdir } from "../fixture/fixture"
const context = Context.empty() as Context.Context<unknown>
function request(route: string, directory: string, query?: Record<string, string>) {
const url = new URL(`http://localhost${route}`)
for (const [key, value] of Object.entries(query ?? {})) {
url.searchParams.set(key, value)
}
return HttpApiApp.webHandler().handler(
new Request(url, {
headers: {
"x-opencode-directory": directory,
},
}),
context,
)
}
afterEach(async () => {
await disposeAllInstances()
await resetDatabase()
})
describe("file HttpApi", () => {
test("serves read endpoints", async () => {
await using tmp = await tmpdir({ git: true })
await Bun.write(path.join(tmp.path, "hello.txt"), "hello")
const [list, content, status] = await Promise.all([
request(FilePaths.list, tmp.path, { path: "." }),
request(FilePaths.content, tmp.path, { path: "hello.txt" }),
request(FilePaths.status, tmp.path),
])
expect(list.status).toBe(200)
expect(await list.json()).toContainEqual(
expect.objectContaining({ name: "hello.txt", path: "hello.txt", type: "file" }),
)
expect(content.status).toBe(200)
expect(await content.json()).toMatchObject({ type: "text", content: "hello" })
expect(status.status).toBe(200)
expect(await status.json()).toEqual([])
})
test("serves search endpoints", async () => {
await using tmp = await tmpdir({ git: true })
await Bun.write(path.join(tmp.path, "hello.txt"), "needle")
const [text, files, symbols] = await Promise.all([
request(FilePaths.findText, tmp.path, { pattern: "needle" }),
request(FilePaths.findFile, tmp.path, { query: "hello", type: "file" }),
request(FilePaths.findSymbol, tmp.path, { query: "hello" }),
])
expect(text.status).toBe(200)
expect(await text.json()).toContainEqual(expect.objectContaining({ line_number: 1 }))
expect(files.status).toBe(200)
expect(await files.json()).toContain("hello.txt")
expect(symbols.status).toBe(200)
expect(await symbols.json()).toEqual([])
})
})