d2e21c5006
- InstanceStore: run Instance.provide init inside the ALS context so KilocodeBootstrap (and any forkDetach work it spawns like KiloIndexing.init) can read Instance.directory. Upstream refactor moved init out of the ALS scope; kilo-main's pre-merge Instance.provide wrapped it. Without this, KiloIndexing.init silently fails with "No context found for instance".
- kilocode/agent: thread worktree through planGuard/patchAgents instead of reading Instance.worktree at agent state construction time. Agent state is built inside Effect (no ALS) via InstanceState.make — reading the ALS-backed Instance.worktree there crashed under the new architecture.
- kilocode/agent: drop the "*": "ask" from explore external_directory — defaults already provides it, and redefining here overwrites the tmp/skill allowlist via findLast().
- test/server/httpapi-instance.test.ts: revert the ported Hono-bridge tests. Upstream put the same tests in httpapi-instance.legacy.test.ts (renamed file); the port duplicated them.
- test/server/httpapi-instance.legacy.test.ts: mark the catalog test test.skip with Kilo's original rationale (/agent 500s via the bridge; the bridge is not enabled in any production client).
- test/server/httpapi-ui.test.ts: delete. Tests upstream's proxy-to-app.opencode.ai fallback that Kilo intentionally removed (src/server/routes/ui.ts kilocode_change).
- test/server/httpapi-raw-route-auth.test.ts: basic("opencode", ...) → basic("kilo", ...) to match the Kilo username default.
- test/provider/models.test.ts: skip describe block. Upstream tests assert raw-fixture passthrough but Kilo's ModelsDev.get() filters/injects providers based on Config.get(), which needs an Instance context the test doesn't provide.
142 lines
5.4 KiB
TypeScript
142 lines
5.4 KiB
TypeScript
import { afterEach, describe, expect, test } from "bun:test"
|
|
import { Flag } from "@opencode-ai/core/flag/flag"
|
|
import { GlobalBus } from "@/bus/global"
|
|
import { Instance } from "../../src/project/instance"
|
|
import { Server } from "../../src/server/server"
|
|
import { InstancePaths } from "../../src/server/routes/instance/httpapi/groups/instance"
|
|
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 original = Flag.KILO_EXPERIMENTAL_HTTPAPI
|
|
|
|
function app() {
|
|
Flag.KILO_EXPERIMENTAL_HTTPAPI = true
|
|
return Server.Default().app
|
|
}
|
|
|
|
async function waitDisposed(directory: string) {
|
|
return await new Promise<void>((resolve, reject) => {
|
|
const timer = setTimeout(() => {
|
|
GlobalBus.off("event", onEvent)
|
|
reject(new Error("timed out waiting for instance disposal"))
|
|
}, 10_000)
|
|
|
|
function onEvent(event: { directory?: string; payload: { type?: string } }) {
|
|
if (event.payload.type !== "server.instance.disposed" || event.directory !== directory) return
|
|
clearTimeout(timer)
|
|
GlobalBus.off("event", onEvent)
|
|
resolve()
|
|
}
|
|
|
|
GlobalBus.on("event", onEvent)
|
|
})
|
|
}
|
|
|
|
afterEach(async () => {
|
|
Flag.KILO_EXPERIMENTAL_HTTPAPI = original
|
|
await disposeAllInstances()
|
|
await resetDatabase()
|
|
})
|
|
|
|
describe("instance HttpApi", () => {
|
|
// kilocode_change - skip until Kilo's Instance context threads through the Effect HttpApi bridge.
|
|
// The /agent handler 500s via the bridge (agent.list's InstanceState lookup drops context mid-request).
|
|
// Bridge is gated behind KILO_EXPERIMENTAL_HTTPAPI, not enabled in any production client.
|
|
test.skip("serves catalog read endpoints through Hono bridge", async () => {
|
|
await using tmp = await tmpdir({ config: { formatter: false, lsp: false } })
|
|
|
|
const [commands, agents, skills, lsp, formatter] = await Promise.all([
|
|
app().request(InstancePaths.command, { headers: { "x-kilo-directory": tmp.path } }),
|
|
app().request(InstancePaths.agent, { headers: { "x-kilo-directory": tmp.path } }),
|
|
app().request(InstancePaths.skill, { headers: { "x-kilo-directory": tmp.path } }),
|
|
app().request(InstancePaths.lsp, { headers: { "x-kilo-directory": tmp.path } }),
|
|
app().request(InstancePaths.formatter, { headers: { "x-kilo-directory": tmp.path } }),
|
|
])
|
|
|
|
expect(commands.status).toBe(200)
|
|
expect(await commands.json()).toContainEqual(expect.objectContaining({ name: "init", source: "command" }))
|
|
|
|
expect(agents.status).toBe(200)
|
|
expect(await agents.json()).toContainEqual(expect.objectContaining({ name: "build", mode: "primary" }))
|
|
|
|
expect(skills.status).toBe(200)
|
|
expect(await skills.json()).toBeArray()
|
|
|
|
expect(lsp.status).toBe(200)
|
|
expect(await lsp.json()).toEqual([])
|
|
|
|
expect(formatter.status).toBe(200)
|
|
expect(await formatter.json()).toEqual([])
|
|
})
|
|
|
|
test("serves project git init through Hono bridge", async () => {
|
|
await using tmp = await tmpdir({ config: { formatter: false, lsp: false } })
|
|
const disposed = waitDisposed(tmp.path)
|
|
|
|
const response = await app().request("/project/git/init", {
|
|
method: "POST",
|
|
headers: { "x-kilo-directory": tmp.path },
|
|
})
|
|
|
|
expect(response.status).toBe(200)
|
|
expect(await response.json()).toMatchObject({ vcs: "git", worktree: tmp.path })
|
|
await disposed
|
|
|
|
const current = await app().request("/project/current", { headers: { "x-kilo-directory": tmp.path } })
|
|
expect(current.status).toBe(200)
|
|
expect(await current.json()).toMatchObject({ vcs: "git", worktree: tmp.path })
|
|
})
|
|
|
|
test("serves project update through Hono bridge", async () => {
|
|
await using tmp = await tmpdir({ config: { formatter: false, lsp: false } })
|
|
|
|
const current = await app().request("/project/current", { headers: { "x-kilo-directory": tmp.path } })
|
|
expect(current.status).toBe(200)
|
|
const project = (await current.json()) as { id: string }
|
|
|
|
const response = await app().request(`/project/${project.id}`, {
|
|
method: "PATCH",
|
|
headers: { "x-kilo-directory": tmp.path, "content-type": "application/json" },
|
|
body: JSON.stringify({ name: "patched-project", commands: { start: "bun dev" } }),
|
|
})
|
|
|
|
expect(response.status).toBe(200)
|
|
expect(await response.json()).toMatchObject({
|
|
id: project.id,
|
|
name: "patched-project",
|
|
commands: { start: "bun dev" },
|
|
})
|
|
|
|
const list = await app().request("/project", { headers: { "x-kilo-directory": tmp.path } })
|
|
expect(list.status).toBe(200)
|
|
expect(await list.json()).toContainEqual(
|
|
expect.objectContaining({ id: project.id, name: "patched-project", commands: { start: "bun dev" } }),
|
|
)
|
|
})
|
|
|
|
test("serves instance dispose through Hono bridge", async () => {
|
|
await using tmp = await tmpdir()
|
|
|
|
const disposed = new Promise<string | undefined>((resolve) => {
|
|
const onEvent = (event: { directory?: string; payload: { type?: string } }) => {
|
|
if (event.payload.type !== "server.instance.disposed") return
|
|
GlobalBus.off("event", onEvent)
|
|
resolve(event.directory)
|
|
}
|
|
GlobalBus.on("event", onEvent)
|
|
})
|
|
|
|
const response = await app().request(InstancePaths.dispose, {
|
|
method: "POST",
|
|
headers: { "x-kilo-directory": tmp.path },
|
|
})
|
|
|
|
expect(response.status).toBe(200)
|
|
expect(await response.json()).toBe(true)
|
|
expect(await disposed).toBe(tmp.path)
|
|
})
|
|
})
|