11import { describe , expect } from "bun:test"
22import { DateTime , Effect , Schema } from "effect"
3- import { asc , eq } from "drizzle-orm"
3+ import { asc , eq , sql } from "drizzle-orm"
44import { Database } from "@opencode-ai/core/database/database"
55import { LayerNode } from "@opencode-ai/core/effect/layer-node"
66import { AppNodeBuilder } from "@opencode-ai/core/effect/app-node-builder"
@@ -22,6 +22,7 @@ import { SessionInput } from "@opencode-ai/core/session/input"
2222import { SessionInputTable , SessionMessageTable , SessionTable } from "@opencode-ai/core/session/sql"
2323import { testEffect } from "./lib/effect"
2424import { Snapshot } from "@opencode-ai/core/snapshot"
25+ import { Location } from "@opencode-ai/core/location"
2526
2627const it = testEffect ( AppNodeBuilder . build ( LayerNode . group ( [ Database . node , EventV2 . node , SessionProjector . node ] ) ) )
2728const sessionsLayer = AppNodeBuilder . build ( SessionV2 . node , [ [ SessionExecution . node , SessionExecution . noopLayer ] ] )
@@ -44,6 +45,39 @@ const assistantRow = (
4445}
4546
4647describe ( "SessionProjector" , ( ) => {
48+ it . effect ( "projects moved sessions without the transitional context epoch table" , ( ) =>
49+ Effect . gen ( function * ( ) {
50+ const { db } = yield * Database . Service
51+ const events = yield * EventV2 . Service
52+ yield * db
53+ . insert ( ProjectTable )
54+ . values ( { id : Project . ID . global , worktree : AbsolutePath . make ( "/project" ) , sandboxes : [ ] } )
55+ . run ( )
56+ yield * db
57+ . insert ( SessionTable )
58+ . values ( {
59+ id : sessionID ,
60+ project_id : Project . ID . global ,
61+ slug : "test" ,
62+ directory : "/project" ,
63+ title : "test" ,
64+ version : "test" ,
65+ } )
66+ . run ( )
67+ yield * db . run ( sql `DROP TABLE session_context_epoch` )
68+
69+ yield * events . publish ( SessionEvent . Moved , {
70+ sessionID,
71+ timestamp : DateTime . makeUnsafe ( 1 ) ,
72+ location : Location . Ref . make ( { directory : AbsolutePath . make ( "/project/subdir" ) } ) ,
73+ } )
74+
75+ expect ( yield * db . select ( { directory : SessionTable . directory } ) . from ( SessionTable ) . get ( ) ) . toEqual ( {
76+ directory : "/project/subdir" ,
77+ } )
78+ } ) ,
79+ )
80+
4781 it . effect ( "projects staged, cleared, and committed reverts" , ( ) =>
4882 Effect . gen ( function * ( ) {
4983 const db = ( yield * Database . Service ) . db
0 commit comments