Skip to content

Commit adebb87

Browse files
authored
test(opencode): use EventV2 location contract (#33383)
1 parent 4d5efba commit adebb87

1 file changed

Lines changed: 16 additions & 8 deletions

File tree

packages/opencode/test/server/httpapi-v2-location.test.ts

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import { afterEach, describe, expect, test } from "bun:test"
2+
import { EventV2 } from "@opencode-ai/core/event"
3+
import { Location } from "@opencode-ai/core/location"
24
import { Context, Schema } from "effect"
35
import { HttpApiApp } from "../../src/server/routes/instance/httpapi/server"
46
import { resetDatabase } from "../fixture/db"
@@ -19,14 +21,9 @@ function request(route: string, directory: string, init: RequestInit = {}) {
1921
}
2022

2123
const Event = Schema.Struct({
22-
id: Schema.String,
24+
id: EventV2.ID,
2325
type: Schema.String,
24-
location: Schema.optional(
25-
Schema.Struct({
26-
directory: Schema.String,
27-
project: Schema.Struct({ id: Schema.String, directory: Schema.String }),
28-
}),
29-
),
26+
location: Schema.optional(Location.Ref),
3027
data: Schema.Unknown,
3128
})
3229

@@ -50,6 +47,17 @@ afterEach(async () => {
5047
})
5148

5249
describe("v2 location HttpApi", () => {
50+
test("decodes EventV2 location refs without resolved project metadata", () => {
51+
expect(
52+
Schema.decodeUnknownSync(Event)({
53+
id: "evt_test",
54+
type: "file.watcher.updated",
55+
location: { directory: "/tmp/project" },
56+
data: {},
57+
}),
58+
).toMatchObject({ location: { directory: "/tmp/project" } })
59+
})
60+
5361
test("returns command and skill snapshots with resolved locations", async () => {
5462
await using tmp = await tmpdir({ git: true })
5563

@@ -79,7 +87,7 @@ describe("v2 location HttpApi", () => {
7987
expect(created.status).toBe(200)
8088
expect(await readEventType(reader, "session.created")).toMatchObject({
8189
type: "session.created",
82-
location: { directory: publisher.path, project: { directory: publisher.path } },
90+
location: { directory: publisher.path },
8391
data: { sessionID: expect.any(String) },
8492
})
8593
await reader.cancel()

0 commit comments

Comments
 (0)