resolve merge conflicts

This commit is contained in:
Johnny Amancio
2026-07-30 02:16:42 +02:00
1212 changed files with 105281 additions and 49413 deletions
@@ -1,4 +1,6 @@
import { afterEach, describe, expect, test } from "bun:test"
import { EventV2 } from "@opencode-ai/core/event"
import { Location } from "@opencode-ai/core/location"
import { Context, Schema } from "effect"
import { HttpApiApp } from "../../src/server/routes/instance/httpapi/server"
import { resetDatabase } from "../fixture/db"
@@ -19,22 +21,50 @@ function request(route: string, directory: string, init: RequestInit = {}) {
}
const Event = Schema.Struct({
id: Schema.String,
id: EventV2.ID,
type: Schema.String,
location: Schema.Struct({
directory: Schema.String,
project: Schema.Struct({ id: Schema.String, directory: Schema.String }),
}),
location: Schema.optional(Location.Ref),
data: Schema.Unknown,
})
async function readEvent(reader: ReadableStreamDefaultReader<Uint8Array>) {
const value = await reader.read()
if (value.done) throw new Error("event stream closed")
return Schema.decodeUnknownSync(Event)(JSON.parse(new TextDecoder().decode(value.value).replace(/^data: /, "")))
async function* eventStream(body: ReadableStream<Uint8Array>) {
const reader = body.getReader()
const decoder = new TextDecoder()
let buffer = ""
try {
while (true) {
const boundary = buffer.match(/(?:\r\n|\r|\n){2}/)
if (!boundary || boundary.index === undefined) {
const value = await reader.read()
if (value.done) return
buffer += decoder.decode(value.value, { stream: true })
continue
}
const record = buffer.slice(0, boundary.index)
buffer = buffer.slice(boundary.index + boundary[0].length)
const data = record
.split(/\r\n|\r|\n/)
.filter((line) => line.startsWith("data:"))
.map((line) => line.slice(5).replace(/^ /, ""))
if (data.length) yield Schema.decodeUnknownSync(Event)(JSON.parse(data.join("\n")))
}
} finally {
try {
await reader.cancel()
} finally {
reader.releaseLock()
}
}
}
async function readEventType(reader: ReadableStreamDefaultReader<Uint8Array>, type: string) {
async function readEvent(reader: AsyncIterator<typeof Event.Type>) {
const value = await reader.next()
if (value.done) throw new Error("event stream closed")
return value.value
}
async function readEventType(reader: AsyncIterator<typeof Event.Type>, type: string) {
for (let index = 0; index < 20; index++) {
const event = await readEvent(reader)
if (event.type === type) return event
@@ -60,35 +90,49 @@ describe("v2 location HttpApi", () => {
})
// kilocode_change end
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()
}
test("decodes EventV2 location refs without resolved project metadata", () => {
expect(
Schema.decodeUnknownSync(Event)({
id: "evt_test",
type: "file.watcher.updated",
location: { directory: "/tmp/project" },
data: {},
}),
).toMatchObject({ location: { directory: "/tmp/project" } })
})
test("streams native EventV2 payloads with resolved locations", async () => {
await using tmp = await tmpdir({ git: true })
const response = await request("/api/event", tmp.path)
const reader = response.body!.getReader()
expect((await readEvent(reader)).type).toBe("server.connected")
test("returns command and skill snapshots with resolved locations", async () => {
await using tmp = await tmpdir({ git: true })
const created = await request("/session", tmp.path, { method: "POST" })
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()
}
})
test("streams native EventV2 payloads across locations", async () => {
await using subscriber = await tmpdir({ git: true })
await using publisher = await tmpdir({ git: true })
const response = await request("/api/event", subscriber.path)
const reader = eventStream(response.body!)
const connected = await readEvent(reader)
expect(connected.type).toBe("server.connected")
expect(connected.location).toBeUndefined()
const created = await request("/session", publisher.path, { method: "POST" })
expect(created.status).toBe(200)
expect(await readEventType(reader, "session.created")).toMatchObject({
type: "session.created",
location: { directory: tmp.path, project: { directory: tmp.path } },
location: { directory: publisher.path },
data: { sessionID: expect.any(String) },
})
await reader.cancel()
await reader.return(undefined)
})
})