@@ -4860,6 +4860,93 @@ it.layer(layerSharedApplicationDataPlaneTest)("visited projection", (it) => {
48604860 ) ;
48614861} ) ;
48624862
4863+ it . layer ( Layer . fresh ( layerSharedApplicationDataPlaneTest ) ) ( "compact PR events" , ( it ) => {
4864+ it . effect ( "persists only the changed PR link and replays it without losing other links" , ( ) =>
4865+ Effect . gen ( function * ( ) {
4866+ const orchestrator = yield * Orchestrator . OrchestratorV2 ;
4867+ const maintenance = yield * ProjectionMaintenance . ProjectionMaintenanceV2 ;
4868+ const sql = yield * SqlClient . SqlClient ;
4869+ const threadId = ThreadId . make ( "compact-pr-sync" ) ;
4870+ yield * orchestrator . dispatch ( {
4871+ type : "thread.create" ,
4872+ createdBy : "user" ,
4873+ creationSource : "web" ,
4874+ commandId : CommandId . make ( "compact-pr-create" ) ,
4875+ threadId,
4876+ projectId : ProjectId . make ( "compact-pr-project" ) ,
4877+ title : "PR sync" ,
4878+ modelSelection,
4879+ runtimeMode : "full-access" ,
4880+ interactionMode : "default" ,
4881+ branch : null ,
4882+ worktreePath : null ,
4883+ } ) ;
4884+ const key = { host : "github.com" , repository : "pingdotgg/t3code" } ;
4885+ for ( const number of [ 1 , 2 , 3 ] ) {
4886+ yield * orchestrator . dispatch ( {
4887+ type : "thread.pull-request.link" ,
4888+ commandId : CommandId . make ( `compact-pr-link-${ number } ` ) ,
4889+ threadId,
4890+ ...key ,
4891+ number,
4892+ url : `https://github.com/pingdotgg/t3code/pull/${ number } ` ,
4893+ source : "manual" ,
4894+ } ) ;
4895+ }
4896+ const before = yield * orchestrator . getThreadShell ( threadId ) ;
4897+ yield * orchestrator . dispatch ( {
4898+ type : "thread.pull-request-link.sync" ,
4899+ commandId : CommandId . make ( "compact-pr-sync" ) ,
4900+ threadId,
4901+ ...key ,
4902+ number : 2 ,
4903+ snapshot : {
4904+ state : "open" ,
4905+ title : "Updated PR" ,
4906+ headBranch : "feature/pr" ,
4907+ baseBranch : "main" ,
4908+ isDraft : false ,
4909+ updatedAt : null ,
4910+ syncedAt : "2026-10-13T12:00:00.000Z" ,
4911+ } ,
4912+ stack : {
4913+ kind : "native" ,
4914+ id : "updated" ,
4915+ number : 2 ,
4916+ url : "https://github.com/pingdotgg/t3code/pull/2" ,
4917+ base : "main" ,
4918+ layers : [ ] ,
4919+ } ,
4920+ } ) ;
4921+ const rows = yield * sql < { event_type : string ; payload_json : string } > `
4922+ SELECT event_type, payload_json FROM orchestration_events
4923+ WHERE command_id = ${ "compact-pr-sync" }
4924+ ` ;
4925+ assert . equal ( rows . length , 1 ) ;
4926+ assert . equal ( rows [ 0 ] ?. event_type , "thread.pull-request-link-updated" ) ;
4927+ const payload = JSON . parse ( rows [ 0 ] ! . payload_json ) ;
4928+ assert . equal ( payload . number , 2 ) ;
4929+ assert . isUndefined ( payload . pullRequests ) ;
4930+ const after = yield * orchestrator . getThreadShell ( threadId ) ;
4931+ assert . equal ( after ?. pullRequests ?. length , 3 ) ;
4932+ assert . deepEqual ( after ?. pullRequests ?. [ 0 ] , before ?. pullRequests ?. [ 0 ] ) ;
4933+ assert . deepEqual ( after ?. pullRequests ?. [ 2 ] , before ?. pullRequests ?. [ 2 ] ) ;
4934+ assert . equal ( after ?. pullRequests ?. [ 1 ] ?. stack ?. id , "updated" ) ;
4935+ assert . isTrue ( ( yield * maintenance . rebuild ) . valid ) ;
4936+ assert . deepEqual (
4937+ ( yield * orchestrator . getThreadShell ( threadId ) ) ?. pullRequests ,
4938+ after ?. pullRequests ,
4939+ ) ;
4940+ yield * maintenance . compactEventStore ;
4941+ assert . isTrue ( ( yield * maintenance . rebuild ) . valid ) ;
4942+ assert . deepEqual (
4943+ ( yield * orchestrator . getThreadShell ( threadId ) ) ?. pullRequests ,
4944+ after ?. pullRequests ,
4945+ ) ;
4946+ } ) ,
4947+ ) ;
4948+ } ) ;
4949+
48634950it . layer ( layerSharedApplicationDataPlaneTest ) ( "shared application data plane" , ( it ) => {
48644951 it . effect ( "orders retained project transactions and V2 thread transactions in one source" , ( ) =>
48654952 Effect . gen ( function * ( ) {
0 commit comments