fix(sdk): stabilize generated event ordering

This commit is contained in:
marius-kilocode
2026-06-08 12:31:59 +02:00
parent 5b32c368c9
commit 97dd460482
5 changed files with 3623 additions and 3614 deletions
+4 -1
View File
@@ -17,8 +17,11 @@ export function define<Type extends string, Properties extends Schema.Top>(
}
export function effectPayloads() {
// kilocode_change start - keep generated schemas stable across module evaluation orders
return registry
.entries()
.toArray()
.sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0))
.map(([type, def]) =>
Schema.Struct({
id: Schema.String,
@@ -26,7 +29,7 @@ export function effectPayloads() {
properties: def.properties,
}).annotate({ identifier: `Event.${type}` }),
)
.toArray()
// kilocode_change end
}
export * as BusEvent from "./bus-event"
@@ -0,0 +1,14 @@
import { expect, test } from "bun:test"
import { Schema, SchemaAST } from "effect"
import { BusEvent } from "../../../src/bus/bus-event"
test("event payload schemas use stable event type order", () => {
BusEvent.define("test.order.z", Schema.Struct({}))
BusEvent.define("test.order.a", Schema.Struct({}))
const ids = BusEvent.effectPayloads()
.map((schema) => SchemaAST.resolveIdentifier(schema.ast))
.filter((id) => id?.startsWith("Event.test.order."))
expect(ids).toEqual(["Event.test.order.a", "Event.test.order.z"])
})
-8
View File
@@ -9,14 +9,6 @@ import path from "path"
import { createClient } from "@hey-api/openapi-ts"
// kilocode_change start - prevent runtime-dependent generated SDK ordering
const pkg = await Bun.file(path.resolve(dir, "../../../package.json")).json()
const manager = pkg.packageManager ?? ""
const version = manager.startsWith("bun@") ? manager.slice(4) : ""
if (!version) throw new Error("Root packageManager must specify bun@<version>")
if (Bun.version !== version) throw new Error(`SDK generation requires Bun ${version}, but is running Bun ${Bun.version}`)
// kilocode_change end
const opencode = path.resolve(dir, "../../opencode")
await $`bun dev generate > ${dir}/openapi.json`.cwd(opencode)
File diff suppressed because it is too large Load Diff
+2624 -2624
View File
File diff suppressed because it is too large Load Diff