11import {
22 EnvironmentId ,
33 NodeId ,
4+ type OrchestratorMcpThreadReadResult ,
45 type OrchestrationV2ThreadProjection ,
56 type OrchestrationV2ThreadShell ,
67 ProjectId ,
@@ -9,6 +10,7 @@ import {
910 RunId ,
1011 ScheduledTaskId ,
1112 ThreadId ,
13+ TurnItemId ,
1214} from "@t3tools/contracts" ;
1315import * as DateTime from "effect/DateTime" ;
1416import * as Effect from "effect/Effect" ;
@@ -183,6 +185,95 @@ it("readThread prefers activity-run status over a newer cancelled queued run", a
183185 } ) . pipe ( Effect . provide ( layer ) , Effect . runPromise ) ;
184186} ) ;
185187
188+ it ( "readThread pages cut-off text without splitting an emoji across pages" , async ( ) => {
189+ const text = "a😀bc" ;
190+ const itemId = TurnItemId . make ( "turn-item-mcp-reasoning" ) ;
191+ const projection = {
192+ thread : baseThread ( {
193+ threadId : parentThreadId ,
194+ title : "Parent" ,
195+ instanceId : parentInstanceId ,
196+ model : "gpt-5.4" ,
197+ } ) ,
198+ runs : [ makeRun ( { id : activeRunId , ordinal : 1 , status : "running" } ) ] ,
199+ visibleTurnItems : [ ] ,
200+ runtimeRequests : [ ] ,
201+ messages : [ ] ,
202+ contextTransfers : [ ] ,
203+ subagents : [ ] ,
204+ updatedAt : now ,
205+ } as unknown as OrchestrationV2ThreadProjection ;
206+ const row = {
207+ position : 0 ,
208+ visibility : "visible" ,
209+ sourceThreadId : parentThreadId ,
210+ sourceItemId : itemId ,
211+ item : {
212+ type : "reasoning" ,
213+ runId : activeRunId ,
214+ status : "completed" ,
215+ title : null ,
216+ text,
217+ updatedAt : now ,
218+ } ,
219+ } ;
220+
221+ const layer = layerOrchestratorService . pipe (
222+ Layer . provide (
223+ Layer . mergeAll (
224+ Layer . mock ( ThreadManagementService . ThreadManagementService ) ( {
225+ getTimelinePage : ( ) =>
226+ Effect . succeed ( {
227+ items : [ row ] as unknown as OrchestrationV2ThreadProjection [ "visibleTurnItems" ] ,
228+ totalItems : 1 ,
229+ hasMore : false ,
230+ } ) ,
231+ getThreadRecords : ( ) => Effect . succeed ( projection ) ,
232+ getProjectThreadRecords : ( ) => Effect . succeed ( projection ) ,
233+ getThreadShell : ( ) =>
234+ Effect . succeed ( projection . thread as unknown as OrchestrationV2ThreadShell ) ,
235+ } satisfies Partial < ThreadManagementService . ThreadManagementService [ "Service" ] > ) ,
236+ ServerSettings . layerTest ( ) ,
237+ Layer . mock ( ProviderRegistry . ProviderRegistry ) ( {
238+ getProviders : Effect . succeed ( [ ] ) ,
239+ } satisfies Partial < ProviderRegistry . ProviderRegistry [ "Service" ] > ) ,
240+ Layer . mock ( ProjectService . ProjectService ) ( { } ) ,
241+ Layer . mock ( SecretRequests . SecretRequests ) ( { } ) ,
242+ Layer . mock ( RemoteDelegation . RemoteDelegation ) ( { } ) ,
243+ Layer . mock ( ScheduledTaskService . ScheduledTaskService ) ( {
244+ list : ( ) => Effect . succeed ( { tasks : [ ] } ) ,
245+ } satisfies Partial < ScheduledTaskService . ScheduledTaskService [ "Service" ] > ) ,
246+ Layer . mock ( ProviderAdapterRegistry . ProviderAdapterRegistryV2 ) ( {
247+ list : ( ) => Effect . succeed ( [ ] ) ,
248+ } satisfies Partial < ProviderAdapterRegistry . ProviderAdapterRegistryV2 [ "Service" ] > ) ,
249+ NodeCrypto . layer ,
250+ ) ,
251+ ) ,
252+ ) ;
253+
254+ await Effect . gen ( function * ( ) {
255+ const service = yield * OrchestratorMcpService . OrchestratorMcpService ;
256+ const pages = Effect . fn ( function * ( maxCharsPerItem : number ) {
257+ const read : Array < string | null > = [ ] ;
258+ let textOffset : number | null = 0 ;
259+ while ( textOffset !== null ) {
260+ const result : OrchestratorMcpThreadReadResult = yield * service . readThread ( makeScope ( ) , {
261+ threadId : parentThreadId ,
262+ view : "activity" ,
263+ itemId,
264+ textOffset,
265+ maxCharsPerItem,
266+ } ) ;
267+ read . push ( result . items [ 0 ] ! . text ) ;
268+ textOffset = result . items [ 0 ] ! . nextTextOffset ?? null ;
269+ }
270+ return read ;
271+ } ) ;
272+ expect ( yield * pages ( 2 ) ) . toEqual ( [ "a" , "😀" , "bc" ] ) ;
273+ expect ( yield * pages ( 1 ) ) . toEqual ( [ "a" , "😀" , "b" , "c" ] ) ;
274+ } ) . pipe ( Effect . provide ( layer ) , Effect . runPromise ) ;
275+ } ) ;
276+
186277it ( "taskStatus returns task.providerInstanceId rather than the driver kind" , async ( ) => {
187278 const parentProjection = {
188279 thread : baseThread ( {
0 commit comments