@@ -2,6 +2,8 @@ import { assert, it } from "@effect/vitest";
22import {
33 ComposerContextId ,
44 EventId ,
5+ ProjectId ,
6+ ProviderInstanceId ,
57 type OrchestrationMessageContext ,
68 ThreadId ,
79} from "@t3tools/contracts" ;
@@ -150,6 +152,69 @@ it.effect("propagates interruption from transcript reads and retry-marker writes
150152 } ) . pipe ( Effect . provide ( layerTest ) ) ,
151153) ;
152154
155+ it . effect ( "caches the absent legacy transcript for a native V2 thread" , ( ) =>
156+ Effect . gen ( function * ( ) {
157+ const importer = yield * LegacyV1ThreadImporter . LegacyV1ThreadImporter ;
158+ const eventSink = yield * EventSink . EventSinkV2 ;
159+ const projections = yield * ProjectionStore . ProjectionStoreV2 ;
160+ const threadId = ThreadId . make ( "thread:v2-born" ) ;
161+ const providerInstanceId = ProviderInstanceId . make ( "codex" ) ;
162+ const now = DateTime . makeUnsafe ( "2026-01-01T00:00:00.000Z" ) ;
163+ yield * eventSink . write ( {
164+ events : [
165+ {
166+ id : EventId . make ( "event:v2-born" ) ,
167+ type : "thread.created" ,
168+ threadId,
169+ occurredAt : now ,
170+ payload : {
171+ id : threadId ,
172+ projectId : ProjectId . make ( "project:v2-born" ) ,
173+ title : "Native V2 thread" ,
174+ providerInstanceId,
175+ modelSelection : { instanceId : providerInstanceId , model : "gpt-6" } ,
176+ createdBy : "user" ,
177+ creationSource : "web" ,
178+ runtimeMode : "full-access" ,
179+ interactionMode : "default" ,
180+ branch : null ,
181+ worktreePath : null ,
182+ activeProviderThreadId : null ,
183+ lineage : { parentThreadId : null , relationshipToParent : null , rootThreadId : threadId } ,
184+ forkedFrom : null ,
185+ createdAt : now ,
186+ updatedAt : now ,
187+ archivedAt : null ,
188+ settledOverride : null ,
189+ settledAt : null ,
190+ lastVisitedAt : null ,
191+ deletedAt : null ,
192+ } ,
193+ } ,
194+ ] ,
195+ } ) ;
196+ const before = yield * projections . getThreadProjection ( threadId ) ;
197+ let legacyLookups = 0 ;
198+ for ( let read = 0 ; read < 3 ; read ++ ) {
199+ const summary = yield * importer . ensureTranscript ( threadId ) . pipe (
200+ Effect . provideService ( Statement . CurrentTransformer , ( statement ) => {
201+ const [ query , parameters ] = statement . compile ( ) ;
202+ if (
203+ query . includes ( "FROM orchestration_v2_legacy_imports" ) &&
204+ parameters [ 0 ] === threadId
205+ ) {
206+ legacyLookups ++ ;
207+ }
208+ return Effect . succeed ( statement ) ;
209+ } ) ,
210+ ) ;
211+ assert . deepStrictEqual ( summary , { importedThreadCount : 0 , importedMessageCount : 0 } ) ;
212+ }
213+ assert . equal ( legacyLookups , 1 ) ;
214+ assert . deepStrictEqual ( yield * projections . getThreadProjection ( threadId ) , before ) ;
215+ } ) . pipe ( Effect . provide ( layerTest ) ) ,
216+ ) ;
217+
153218it . layer ( layerTest ) ( "LegacyV1ThreadImporter" , ( it ) => {
154219 it . effect ( "imports lightweight shells, hydrates transcripts, and remains idempotent" , ( ) =>
155220 Effect . gen ( function * ( ) {
0 commit comments