test(opencode): use EventV2 location contract (#33383)
This commit is contained in:
parent
4d5efba5c9
commit
adebb87191
1 changed files with 16 additions and 8 deletions
|
|
@ -1,4 +1,6 @@
|
||||||
import { afterEach, describe, expect, test } from "bun:test"
|
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 { Context, Schema } from "effect"
|
||||||
import { HttpApiApp } from "../../src/server/routes/instance/httpapi/server"
|
import { HttpApiApp } from "../../src/server/routes/instance/httpapi/server"
|
||||||
import { resetDatabase } from "../fixture/db"
|
import { resetDatabase } from "../fixture/db"
|
||||||
|
|
@ -19,14 +21,9 @@ function request(route: string, directory: string, init: RequestInit = {}) {
|
||||||
}
|
}
|
||||||
|
|
||||||
const Event = Schema.Struct({
|
const Event = Schema.Struct({
|
||||||
id: Schema.String,
|
id: EventV2.ID,
|
||||||
type: Schema.String,
|
type: Schema.String,
|
||||||
location: Schema.optional(
|
location: Schema.optional(Location.Ref),
|
||||||
Schema.Struct({
|
|
||||||
directory: Schema.String,
|
|
||||||
project: Schema.Struct({ id: Schema.String, directory: Schema.String }),
|
|
||||||
}),
|
|
||||||
),
|
|
||||||
data: Schema.Unknown,
|
data: Schema.Unknown,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
@ -50,6 +47,17 @@ afterEach(async () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
describe("v2 location HttpApi", () => {
|
describe("v2 location HttpApi", () => {
|
||||||
|
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("returns command and skill snapshots with resolved locations", async () => {
|
test("returns command and skill snapshots with resolved locations", async () => {
|
||||||
await using tmp = await tmpdir({ git: true })
|
await using tmp = await tmpdir({ git: true })
|
||||||
|
|
||||||
|
|
@ -79,7 +87,7 @@ describe("v2 location HttpApi", () => {
|
||||||
expect(created.status).toBe(200)
|
expect(created.status).toBe(200)
|
||||||
expect(await readEventType(reader, "session.created")).toMatchObject({
|
expect(await readEventType(reader, "session.created")).toMatchObject({
|
||||||
type: "session.created",
|
type: "session.created",
|
||||||
location: { directory: publisher.path, project: { directory: publisher.path } },
|
location: { directory: publisher.path },
|
||||||
data: { sessionID: expect.any(String) },
|
data: { sessionID: expect.any(String) },
|
||||||
})
|
})
|
||||||
await reader.cancel()
|
await reader.cancel()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue