@@ -45,6 +45,7 @@ import * as ProviderAdapterRegistry from "../../orchestration-v2/ProviderAdapter
4545import * as ThreadLaunchService from "../../orchestration-v2/ThreadLaunchService.ts" ;
4646import * as GitVcsDriver from "../../vcs/GitVcsDriver.ts" ;
4747import * as ThreadManagement from "../../orchestration-v2/ThreadManagementService.ts" ;
48+ import type * as ProjectionStore from "../../orchestration-v2/ProjectionStore.ts" ;
4849import * as ThreadSearch from "../../orchestration-v2/ThreadSearch.ts" ;
4950import * as PreviewBrowser from "../../preview/PreviewBrowser.ts" ;
5051import * as ProjectService from "../../project/ProjectService.ts" ;
@@ -467,6 +468,101 @@ it.effect("records only failed calls of tools that hand off no work", () => {
467468 ) ;
468469} ) ;
469470
471+ // A thread read whose runs or messages are bounded by nothing but the thread.
472+ const historyReads = ( reads : Array < string > ) => {
473+ const record = (
474+ fields : ReadonlyArray < string > ,
475+ filter : ProjectionStore . ProjectionRecordFilter | undefined ,
476+ ) => {
477+ if (
478+ fields . includes ( "runs" ) &&
479+ filter ?. runIds === undefined &&
480+ filter ?. runStatuses === undefined
481+ )
482+ reads . push ( "every run" ) ;
483+ if (
484+ fields . includes ( "messages" ) &&
485+ filter ?. messageIds === undefined &&
486+ filter ?. messageRunIds === undefined
487+ )
488+ reads . push ( "every message" ) ;
489+ } ;
490+ const projection = McpToolAccessTestkit . idleThreadProjection (
491+ McpToolAccessTestkit . liveThreadShell ( threadId ) ,
492+ ) ;
493+ return Layer . mock ( ThreadManagement . ThreadManagementService ) ( {
494+ getThreadShell : ( id ) => Effect . succeed ( McpToolAccessTestkit . liveThreadShell ( id ) ) ,
495+ getProjectThreadRecords : ( _target , fields , filter ) =>
496+ Effect . sync ( ( ) => record ( fields , filter ) ) . pipe ( Effect . as ( projection as never ) ) ,
497+ getThreadRecords : ( _id , fields , filter ) =>
498+ Effect . sync ( ( ) => record ( fields , filter ) ) . pipe ( Effect . as ( projection as never ) ) ,
499+ getMessagesById : ( ) => Effect . succeed ( new Map ( ) ) ,
500+ dispatch : ( ) => Effect . succeed ( { sequence : 1 } as never ) ,
501+ } ) ;
502+ } ;
503+
504+ it . effect ( "t3_queue list and read load only the queued runs and their messages" , ( ) => {
505+ const reads : Array < string > = [ ] ;
506+ return Effect . gen ( function * ( ) {
507+ const server = yield * McpServer . McpServer ;
508+ const call = ( args : Record < string , unknown > ) =>
509+ server
510+ . callTool ( { name : "t3_queue" , arguments : args } )
511+ . pipe (
512+ Effect . provideService ( McpInvocationContext . McpInvocationContext , scope ) ,
513+ Effect . provideService ( McpSchema . McpServerClient , client ) ,
514+ ) ;
515+ yield * call ( { action : "list" } ) ;
516+ yield * call ( { action : "read" , queuedRunId : "run:queued" } ) ;
517+ expect ( reads ) . toEqual ( [ ] ) ;
518+ } ) . pipe (
519+ Effect . provide (
520+ layerThreadToolkit . pipe (
521+ Layer . provideMerge ( McpHttpServer . layerInProcessMcpServer ) ,
522+ Layer . provide ( NodeCrypto . layer ) ,
523+ Layer . provide ( historyReads ( reads ) ) ,
524+ ) ,
525+ ) ,
526+ ) ;
527+ } ) ;
528+
529+ it . effect ( "handoff analytics read only the caller's active run and its message" , ( ) => {
530+ const reads : Array < string > = [ ] ;
531+ const recorded = Deferred . makeUnsafe < void > ( ) ;
532+ return Effect . gen ( function * ( ) {
533+ const server = yield * McpServer . McpServer ;
534+ yield * server
535+ . callTool ( {
536+ name : "t3_queue" ,
537+ arguments : { action : "edit" , queuedRunId : "run:queued" , text : "Edited" } ,
538+ } )
539+ . pipe (
540+ Effect . provideService ( McpInvocationContext . McpInvocationContext , scope ) ,
541+ Effect . provideService ( McpSchema . McpServerClient , client ) ,
542+ ) ;
543+ yield * Deferred . await ( recorded ) ;
544+ expect ( reads ) . toEqual ( [ ] ) ;
545+ } ) . pipe (
546+ Effect . provide (
547+ layerThreadToolkit . pipe (
548+ Layer . provideMerge ( McpHttpServer . layerInProcessMcpServer ) ,
549+ Layer . provide ( NodeCrypto . layer ) ,
550+ Layer . provide ( historyReads ( reads ) ) ,
551+ Layer . provide (
552+ Layer . succeed (
553+ AnalyticsService . AnalyticsService ,
554+ AnalyticsService . AnalyticsService . of ( {
555+ record : ( ) => Deferred . succeed ( recorded , undefined ) . pipe ( Effect . asVoid ) ,
556+ flush : Effect . void ,
557+ recordOwners : ( ) => Effect . void ,
558+ } ) ,
559+ ) ,
560+ ) ,
561+ ) ,
562+ ) ,
563+ ) ;
564+ } ) ;
565+
470566it . effect ( "rejects an unknown organize target instead of archiving the calling thread" , ( ) => {
471567 const dispatched : Array < unknown > = [ ] ;
472568 return Effect . gen ( function * ( ) {
0 commit comments