11import { afterEach , describe , expect , test } from "bun:test"
2+ import { EventV2 } from "@opencode-ai/core/event"
3+ import { Location } from "@opencode-ai/core/location"
24import { Context , Schema } from "effect"
35import { HttpApiApp } from "../../src/server/routes/instance/httpapi/server"
46import { resetDatabase } from "../fixture/db"
@@ -19,14 +21,9 @@ function request(route: string, directory: string, init: RequestInit = {}) {
1921}
2022
2123const 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
5249describe ( "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