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 产出验证
This commit is contained in:
63
packages/opencode/test/server/httpapi-cors-vary.test.ts
Normal file
63
packages/opencode/test/server/httpapi-cors-vary.test.ts
Normal file
@@ -0,0 +1,63 @@
|
||||
import { afterEach, describe, expect, test } from "bun:test"
|
||||
import { Server } from "../../src/server/server"
|
||||
import { resetDatabase } from "../fixture/db"
|
||||
import { disposeAllInstances } from "../fixture/fixture"
|
||||
|
||||
afterEach(async () => {
|
||||
await disposeAllInstances()
|
||||
await resetDatabase()
|
||||
})
|
||||
|
||||
function app() {
|
||||
return Server.Default().app
|
||||
}
|
||||
|
||||
const PREFLIGHT_HEADERS = {
|
||||
origin: "http://localhost:3000",
|
||||
"access-control-request-method": "POST",
|
||||
"access-control-request-headers": "content-type, x-opencode-directory",
|
||||
}
|
||||
|
||||
// effect-smol's HttpMiddleware.cors overwrites `Vary: Origin` with
|
||||
// `Vary: Access-Control-Request-Headers` on OPTIONS preflight responses
|
||||
// (the two share the same record key during the spread). With dynamic
|
||||
// origin echoing, missing Vary: Origin lets shared caches serve a preflight
|
||||
// cached for one origin against a different origin. corsVaryFixLayer
|
||||
// restores the merged form.
|
||||
describe("CORS preflight Vary header", () => {
|
||||
test("HTTP API backend preflight Vary contains Origin", async () => {
|
||||
const response = await app().request("/global/config", {
|
||||
method: "OPTIONS",
|
||||
headers: PREFLIGHT_HEADERS,
|
||||
})
|
||||
|
||||
expect([200, 204]).toContain(response.status)
|
||||
expect(response.headers.get("access-control-allow-origin")).toBe("http://localhost:3000")
|
||||
expect((response.headers.get("vary") ?? "").toLowerCase()).toContain("origin")
|
||||
})
|
||||
|
||||
test("HTTP API backend preflight Vary still preserves Access-Control-Request-Headers", async () => {
|
||||
const response = await app().request("/global/config", {
|
||||
method: "OPTIONS",
|
||||
headers: PREFLIGHT_HEADERS,
|
||||
})
|
||||
|
||||
const vary = (response.headers.get("vary") ?? "").toLowerCase()
|
||||
expect(vary).toContain("origin")
|
||||
expect(vary).toContain("access-control-request-headers")
|
||||
})
|
||||
|
||||
test("HTTP API backend does not duplicate Origin in Vary", async () => {
|
||||
const response = await app().request("/global/config", {
|
||||
method: "OPTIONS",
|
||||
headers: PREFLIGHT_HEADERS,
|
||||
})
|
||||
|
||||
const vary = response.headers.get("vary") ?? ""
|
||||
const originCount = vary
|
||||
.split(",")
|
||||
.map((s: string) => s.trim().toLowerCase())
|
||||
.filter((s: string) => s === "origin").length
|
||||
expect(originCount).toBe(1)
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user