This reverts: -28b03595bresearch: delete Hono backend (do not merge) (#25667) -b24a4e897chore(server): clean up post-Hono-deletion scar tissue (#26542) v1.14.42 broke startup for users with plugins that depend on the Hono wire format (most visibly opencode-gemini-auth, see #26546). Restoring Hono as the default backend on stable channels while we investigate the actual plugin compatibility story. OPENCODE_EXPERIMENTAL_HTTPAPI flag and dual-backend selection come back. Stable installs default to Hono; dev/beta default to HTTP API. Conflict resolution: took the pre-deletion side for control-plane schemas and the seven test files where post-deletion follow-up PRs had also touched the conflicting lines. The HTTP API code added since the deletion (compression, cors-vary, fence, lifecycle log, account error mapping, etc.) is preserved as-is — those still apply on the HTTP API path for users on dev/beta channels.
55 lines
1.8 KiB
TypeScript
55 lines
1.8 KiB
TypeScript
import { afterEach, describe, expect, test } from "bun:test"
|
|
import path from "path"
|
|
import { Flag } from "@opencode-ai/core/flag/flag"
|
|
import { Server } from "../../src/server/server"
|
|
import * as Log from "@opencode-ai/core/util/log"
|
|
import { resetDatabase } from "../fixture/db"
|
|
import { disposeAllInstances, tmpdir } from "../fixture/fixture"
|
|
import { waitGlobalBusEventPromise } from "./global-bus"
|
|
|
|
void Log.init({ print: false })
|
|
|
|
const original = Flag.OPENCODE_EXPERIMENTAL_HTTPAPI
|
|
|
|
function app() {
|
|
Flag.OPENCODE_EXPERIMENTAL_HTTPAPI = true
|
|
return Server.Default().app
|
|
}
|
|
|
|
async function waitDisposed(directory: string) {
|
|
await waitGlobalBusEventPromise({
|
|
message: "timed out waiting for instance disposal",
|
|
predicate: (event) => event.payload.type === "server.instance.disposed" && event.directory === directory,
|
|
})
|
|
}
|
|
|
|
afterEach(async () => {
|
|
Flag.OPENCODE_EXPERIMENTAL_HTTPAPI = original
|
|
await disposeAllInstances()
|
|
await resetDatabase()
|
|
})
|
|
|
|
describe("config HttpApi", () => {
|
|
test("serves config update through Hono bridge", async () => {
|
|
await using tmp = await tmpdir({ config: { formatter: false, lsp: false } })
|
|
const disposed = waitDisposed(tmp.path)
|
|
|
|
const response = await app().request("/config", {
|
|
method: "PATCH",
|
|
headers: {
|
|
"content-type": "application/json",
|
|
"x-opencode-directory": tmp.path,
|
|
},
|
|
body: JSON.stringify({ username: "patched-user", formatter: false, lsp: false }),
|
|
})
|
|
|
|
expect(response.status).toBe(200)
|
|
expect(await response.json()).toMatchObject({ username: "patched-user", formatter: false, lsp: false })
|
|
await disposed
|
|
expect(await Bun.file(path.join(tmp.path, "config.json")).json()).toMatchObject({
|
|
username: "patched-user",
|
|
formatter: false,
|
|
lsp: false,
|
|
})
|
|
})
|
|
})
|