@@ -31,11 +31,14 @@ import {
3131} from "@t3tools/contracts" ;
3232import * as DateTime from "effect/DateTime" ;
3333import * as Effect from "effect/Effect" ;
34+ import * as Deferred from "effect/Deferred" ;
35+ import * as Fiber from "effect/Fiber" ;
3436import * as Layer from "effect/Layer" ;
3537import * as Option from "effect/Option" ;
3638import * as Schema from "effect/Schema" ;
3739import * as Tracer from "effect/Tracer" ;
3840import * as SqlClient from "effect/sql/SqlClient" ;
41+ import * as Statement from "effect/sql/Statement" ;
3942import { projectThreadAwarenessV2 } from "@t3tools/shared/agentAwareness" ;
4043
4144import * as SqlitePersistence from "../persistence/Sqlite.ts" ;
@@ -257,6 +260,48 @@ it.effect("routes full projection reads to readers and retains uncommitted write
257260 ) ;
258261 assert . isAbove ( queries . length , 1 ) ;
259262 assert . deepEqual ( [ ...new Set ( queries . map ( ( row ) => row . connection ) ) ] , [ "reader" ] ) ;
263+ const commitRequested = yield * Deferred . make < void > ( ) ;
264+ const writer = yield * Deferred . await ( commitRequested ) . pipe (
265+ Effect . andThen (
266+ sql . withTransaction (
267+ Effect . gen ( function * ( ) {
268+ yield * sql `
269+ UPDATE orchestration_v2_projection_threads
270+ SET payload_json = json_set(payload_json, '$.title', 'Committed title')
271+ WHERE thread_id = ${ threadId }
272+ ` ;
273+ yield * sql `
274+ UPDATE orchestration_v2_projection_turn_items
275+ SET payload_json = json_set(payload_json, '$.title', 'Committed command')
276+ WHERE thread_id = ${ parentId }
277+ ` ;
278+ } ) ,
279+ ) ,
280+ ) ,
281+ Effect . forkChild ,
282+ ) ;
283+ let commitInjected = false ;
284+ const duringCommit = yield * store . getThreadProjection ( threadId ) . pipe (
285+ Effect . provideService ( Statement . CurrentTransformer , ( statement ) => {
286+ const [ query ] = statement . compile ( ) ;
287+ if ( ! commitInjected && query . includes ( "FROM orchestration_v2_projection_turn_items" ) ) {
288+ commitInjected = true ;
289+ return Deferred . succeed ( commitRequested , undefined ) . pipe (
290+ Effect . andThen ( Fiber . join ( writer ) . pipe ( Effect . orDie ) ) ,
291+ Effect . as ( statement ) ,
292+ ) ;
293+ }
294+ return Effect . succeed ( statement ) ;
295+ } ) ,
296+ ) ;
297+ assert . isTrue ( commitInjected ) ;
298+ assert . deepEqual ( duringCommit , projection ) ;
299+ const afterCommit = yield * store . getThreadProjection ( threadId ) ;
300+ assert . equal ( afterCommit . thread . title , "Committed title" ) ;
301+ assert . equal (
302+ afterCommit . visibleTurnItems . find ( ( row ) => row . visibility === "inherited" ) ?. item . title ,
303+ "Committed command" ,
304+ ) ;
260305 yield * sql . withTransaction (
261306 Effect . gen ( function * ( ) {
262307 yield * sql `
0 commit comments