test fixes

This commit is contained in:
Dax Raad
2026-05-14 22:31:28 -04:00
parent 10c8493940
commit 16639eee76
3 changed files with 203 additions and 203 deletions

View File

@@ -11,16 +11,7 @@ import "@opencode-ai/core/catalog"
import "@opencode-ai/core/session-event"
import { Context, Effect, Layer, Option } from "effect"
const syncDefinitions = new WeakMap<EventV2.Definition, SyncEvent.Definition>()
export function toSyncDefinition<D extends EventV2.Definition>(
definition: D,
): SyncEvent.Definition<D["type"], D["data"], D["data"]> {
const cached = syncDefinitions.get(definition)
if (cached) return cached as SyncEvent.Definition<D["type"], D["data"], D["data"]>
if (definition.version === undefined)
throw new Error(`Event.toSyncDefinition: version required for ${definition.type}`)
if (!definition.aggregate) throw new Error(`Event.toSyncDefinition: aggregate required for ${definition.type}`)
export function toSyncDefinition<D extends EventV2.Definition>(definition: D) {
const result = {
type: definition.type,
version: definition.version,
@@ -28,8 +19,7 @@ export function toSyncDefinition<D extends EventV2.Definition>(
schema: definition.data,
properties: definition.data,
}
syncDefinitions.set(definition, result)
return result
return result as SyncEvent.Definition<D["type"], D["data"], D["data"]>
}
export class Service extends Context.Service<Service, EventV2.Interface>()("@opencode/EventV2Bridge") {}

View File

@@ -227,6 +227,16 @@ export function reset() {
export function init(input: { projectors: Array<[Definition, ProjectorFunc]>; convertEvent?: ConvertEvent }) {
projectors = new Map(input.projectors)
for (let entry of EventV2.registry.values()) {
if (!entry.version || !entry.aggregate) continue
register({
type: entry.type,
version: entry.version,
aggregate: entry.aggregate,
properties: entry.data,
schema: entry.data,
})
}
// Install all the latest event defs to the bus. We only ever emit
// latest versions from code, and keep around old versions for