mirror of
https://github.com/Kilo-Org/kilocode.git
synced 2026-09-24 16:02:55 +08:00
fix: resolve OpenCode v1.15.4 merge regressions
This commit is contained in:
@@ -59,8 +59,7 @@ describe("config HttpApi", () => {
|
||||
lsp: false,
|
||||
})
|
||||
yield* Fiber.join(disposed)
|
||||
expect(yield* Effect.promise(() => Bun.file(path.join(tmp.path, "opencode.json")).json())).toMatchObject({
|
||||
// kilocode_change
|
||||
expect(yield* Effect.promise(() => Bun.file(path.join(tmp.path, "opencode.json")).json())).toMatchObject({ // kilocode_change
|
||||
username: "patched-user",
|
||||
formatter: false,
|
||||
lsp: false,
|
||||
|
||||
@@ -5,8 +5,17 @@ import { InstanceRef } from "../../src/effect/instance-ref"
|
||||
import { Server } from "../../src/server/server"
|
||||
import { EventPaths } from "../../src/server/routes/instance/httpapi/groups/event"
|
||||
import { Event as ServerEvent } from "../../src/server/event"
|
||||
// kilocode_change start - verify transformed EventV2 values at the legacy SSE boundary
|
||||
import { Catalog } from "@opencode-ai/core/catalog"
|
||||
import { EventV2 } from "@opencode-ai/core/event"
|
||||
import { ModelV2 } from "@opencode-ai/core/model"
|
||||
import { ProviderV2 } from "@opencode-ai/core/provider"
|
||||
import { SessionEvent } from "@opencode-ai/core/session-event"
|
||||
import { GlobalPaths } from "../../src/server/routes/instance/httpapi/groups/global"
|
||||
import { SessionID } from "../../src/session/schema"
|
||||
// kilocode_change end
|
||||
import * as Log from "@opencode-ai/core/util/log"
|
||||
import { Effect, Schema } from "effect"
|
||||
import { DateTime, Effect, Schema } from "effect"
|
||||
import { resetDatabase } from "../fixture/db"
|
||||
import { disposeAllInstances, reloadTestInstance, tmpdir } from "../fixture/fixture"
|
||||
|
||||
@@ -22,6 +31,17 @@ const EventData = Schema.Struct({
|
||||
properties: Schema.Record(Schema.String, Schema.Any),
|
||||
})
|
||||
|
||||
// kilocode_change start - inspect the real global SSE envelope
|
||||
const GlobalEventData = Schema.Struct({
|
||||
directory: Schema.optional(Schema.String),
|
||||
payload: Schema.Struct({
|
||||
id: Schema.optional(Schema.String),
|
||||
type: Schema.String,
|
||||
properties: Schema.optional(Schema.Record(Schema.String, Schema.Any)),
|
||||
}),
|
||||
})
|
||||
// kilocode_change end
|
||||
|
||||
async function readChunk(reader: ReadableStreamDefaultReader<Uint8Array>, delay = 5_000) {
|
||||
let timeout: ReturnType<typeof setTimeout> | undefined
|
||||
try {
|
||||
@@ -90,6 +110,33 @@ async function readEventWithin(reader: ReadableStreamDefaultReader<Uint8Array>,
|
||||
return Schema.decodeUnknownSync(EventData)(JSON.parse(new TextDecoder().decode(result.value).replace(/^data: /, "")))
|
||||
}
|
||||
|
||||
// kilocode_change start - read transformed values from the global SSE wire payload
|
||||
async function readGlobal(reader: ReadableStreamDefaultReader<Uint8Array>, delay = 5_000) {
|
||||
const result = await readChunk(reader, delay)
|
||||
if (result.done || !result.value) throw new Error("global event stream closed")
|
||||
return Schema.decodeUnknownSync(GlobalEventData)(
|
||||
JSON.parse(new TextDecoder().decode(result.value).replace(/^data: /, "")),
|
||||
)
|
||||
}
|
||||
|
||||
function properties(event: Schema.Schema.Type<typeof GlobalEventData>) {
|
||||
if (!event.payload.properties) throw new Error(`event ${event.payload.type} has no properties`)
|
||||
return event.payload.properties
|
||||
}
|
||||
|
||||
async function readGlobalUntil(
|
||||
reader: ReadableStreamDefaultReader<Uint8Array>,
|
||||
predicate: (event: Schema.Schema.Type<typeof GlobalEventData>) => boolean,
|
||||
delay = 5_000,
|
||||
) {
|
||||
const end = Date.now() + delay
|
||||
while (true) {
|
||||
const event = await readGlobal(reader, end - Date.now())
|
||||
if (predicate(event)) return event
|
||||
}
|
||||
}
|
||||
// kilocode_change end
|
||||
|
||||
afterEach(async () => {
|
||||
await disposeAllInstances()
|
||||
await resetDatabase()
|
||||
@@ -145,4 +192,70 @@ describe("event HttpApi", () => {
|
||||
await reader.cancel()
|
||||
}
|
||||
})
|
||||
|
||||
// kilocode_change start - transformed EventV2 data is numeric on legacy SSE while domain data stays decoded
|
||||
test("encodes catalog and session EventV2 data on the global event stream", async () => {
|
||||
await using tmp = await tmpdir({ git: true, config: { formatter: false, lsp: false } })
|
||||
const response = await app().request(GlobalPaths.event)
|
||||
if (!response.body) throw new Error("missing response body")
|
||||
|
||||
const reader = response.body.getReader()
|
||||
try {
|
||||
expect(await readGlobal(reader)).toMatchObject({ payload: { type: "server.connected", properties: {} } })
|
||||
const ctx = await reloadTestInstance({ directory: tmp.path })
|
||||
const released = DateTime.makeUnsafe(1_750_000_000_123)
|
||||
const model = new ModelV2.Info({
|
||||
...ModelV2.Info.empty(ProviderV2.ID.make("test"), ModelV2.ID.make("model")),
|
||||
time: { released },
|
||||
})
|
||||
const catalogID = EventV2.ID.create()
|
||||
const catalog = readGlobalUntil(reader, (event) => event.payload.id === catalogID)
|
||||
const catalogDomain = await AppRuntime.runPromise(
|
||||
EventV2.Service.use((events) => events.publish(Catalog.Event.ModelUpdated, { model }, { id: catalogID })).pipe(
|
||||
Effect.provideService(InstanceRef, ctx),
|
||||
),
|
||||
)
|
||||
|
||||
expect(DateTime.isDateTime(catalogDomain.data.model.time.released)).toBe(true)
|
||||
expect(properties(await catalog).model.time.released).toBe(1_750_000_000_123)
|
||||
|
||||
const globalID = EventV2.ID.create()
|
||||
const global = readGlobalUntil(reader, (event) => event.payload.id === globalID)
|
||||
await AppRuntime.runPromise(
|
||||
EventV2.Service.use((events) => events.publish(Catalog.Event.ModelUpdated, { model }, { id: globalID })),
|
||||
)
|
||||
expect((await global).directory).toBe("global")
|
||||
|
||||
const timestamp = DateTime.makeUnsafe(1_234)
|
||||
const sessionID = SessionID.make("ses_event_encoding")
|
||||
const session = readGlobalUntil(
|
||||
reader,
|
||||
(event) =>
|
||||
event.payload.type === SessionEvent.Text.Delta.type && properties(event).sessionID === sessionID,
|
||||
)
|
||||
const sessionDomain = await AppRuntime.runPromise(
|
||||
EventV2.Service.use((events) =>
|
||||
events.publish(SessionEvent.Text.Delta, { sessionID, timestamp, delta: "hello" }),
|
||||
).pipe(Effect.provideService(InstanceRef, ctx)),
|
||||
)
|
||||
|
||||
expect(DateTime.isDateTime(sessionDomain.data.timestamp)).toBe(true)
|
||||
expect(properties(await session).timestamp).toBe(1_234)
|
||||
|
||||
const prompted = readGlobalUntil(reader, (event) => event.payload.type === SessionEvent.Prompted.type)
|
||||
await AppRuntime.runPromise(
|
||||
EventV2.Service.use((events) =>
|
||||
events.publish(SessionEvent.Prompted, {
|
||||
sessionID,
|
||||
timestamp,
|
||||
prompt: { text: "hello", files: [], agents: [], references: [] },
|
||||
}),
|
||||
).pipe(Effect.provideService(InstanceRef, ctx)),
|
||||
)
|
||||
expect(properties(await prompted)).toMatchObject({ timestamp: 1_234, prompt: { text: "hello" } })
|
||||
} finally {
|
||||
await reader.cancel()
|
||||
}
|
||||
})
|
||||
// kilocode_change end
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user