@@ -18,6 +18,8 @@ import {
1818 type OrchestrationV2Run ,
1919 ProjectId ,
2020 type PullRequestDetail ,
21+ type PullRequestComment ,
22+ PullRequestOperationError ,
2123 ProviderDriverKind ,
2224 ProviderInstanceId ,
2325 ProviderThreadId ,
@@ -2307,11 +2309,17 @@ it.layer(TestLayer)("OrchestrationV2LayerLive lifecycle", (it) => {
23072309 } ) ,
23082310 ) ;
23092311
2310- it . effect ( "wakes a watched thread once for failed checks and a review comment" , ( ) =>
2312+ it . effect . each ( [
2313+ "single page" ,
2314+ "paginated" ,
2315+ "page failure" ,
2316+ "repeated cursor" ,
2317+ "missing comments" ,
2318+ ] ) ( "wakes a watched thread once: %s" , ( mode ) =>
23112319 Effect . gen ( function * ( ) {
23122320 const orchestrator = yield * Orchestrator . OrchestratorV2 ;
2313- const threadId = ThreadId . make ( " runtime-pull-request-watch-wake" ) ;
2314- const projectId = ProjectId . make ( " pr-watch-wake-project" ) ;
2321+ const threadId = ThreadId . make ( ` runtime-pull-request-watch-wake- ${ mode } ` ) ;
2322+ const projectId = ProjectId . make ( ` pr-watch-wake-project- ${ mode } ` ) ;
23152323 yield * seedProject ( {
23162324 projectId,
23172325 title : "Watch wake" ,
@@ -2323,7 +2331,7 @@ it.layer(TestLayer)("OrchestrationV2LayerLive lifecycle", (it) => {
23232331 type : "thread.create" ,
23242332 createdBy : "user" ,
23252333 creationSource : "web" ,
2326- commandId : CommandId . make ( " pr-watch-wake-create" ) ,
2334+ commandId : CommandId . make ( ` pr-watch-wake-create- ${ mode } ` ) ,
23272335 threadId,
23282336 projectId,
23292337 title : "Watch wake" ,
@@ -2337,15 +2345,15 @@ it.layer(TestLayer)("OrchestrationV2LayerLive lifecycle", (it) => {
23372345 const url = "https://github.com/pingdotgg/t3code/pull/7" ;
23382346 yield * orchestrator . dispatch ( {
23392347 type : "thread.pull-request.link" ,
2340- commandId : CommandId . make ( " pr-watch-wake-link" ) ,
2348+ commandId : CommandId . make ( ` pr-watch-wake-link- ${ mode } ` ) ,
23412349 threadId,
23422350 ...key ,
23432351 url,
23442352 source : "agent" ,
23452353 } ) ;
23462354 yield * orchestrator . dispatch ( {
23472355 type : "thread.pull-request.watch" ,
2348- commandId : CommandId . make ( " pr-watch-wake-start" ) ,
2356+ commandId : CommandId . make ( ` pr-watch-wake-start- ${ mode } ` ) ,
23492357 threadId,
23502358 ...key ,
23512359 watching : true ,
@@ -2398,6 +2406,37 @@ it.layer(TestLayer)("OrchestrationV2LayerLive lifecycle", (it) => {
23982406 mergeCapabilities : { merge : true , squash : true , rebase : true } ,
23992407 viewer : "agent-user" ,
24002408 } ;
2409+ const initialWatch = ( yield * orchestrator . getThreadShell ( threadId ) ) ?. pullRequests ?. [ 0 ] ?. watch ;
2410+ assert . isDefined ( initialWatch ) ;
2411+ const remark : PullRequestComment = {
2412+ id : "review-1" ,
2413+ kind : "review-comment" ,
2414+ author : { login : "reviewer" , name : null , avatarUrl : null } ,
2415+ body : "One more thing." ,
2416+ createdAt : "2999-01-01T00:00:03.000Z" ,
2417+ url : null ,
2418+ path : "src/index.ts" ,
2419+ reviewState : null ,
2420+ } ;
2421+ const firstTen = Array . from ( { length : 10 } , ( _ , index ) => ( {
2422+ ...remark ,
2423+ id : `old-${ index } ` ,
2424+ createdAt : "1900-01-01T00:00:00.000Z" ,
2425+ } ) ) ;
2426+ const eleventh = {
2427+ ...remark ,
2428+ id : "reply-11" ,
2429+ body : "Eleventh reply." ,
2430+ createdAt : "2999-01-01T00:00:01.000Z" ,
2431+ } ;
2432+ const twelfth = {
2433+ ...remark ,
2434+ id : "reply-12" ,
2435+ body : "Twelfth reply." ,
2436+ createdAt : "2999-01-01T00:00:02.000Z" ,
2437+ } ;
2438+ const incomplete = mode !== "single page" && mode !== "paginated" ;
2439+ let recovering = false ;
24012440 const reactor = yield * PullRequestWatchReactor . make . pipe (
24022441 Effect . provide (
24032442 Layer . mergeAll (
@@ -2406,27 +2445,70 @@ it.layer(TestLayer)("OrchestrationV2LayerLive lifecycle", (it) => {
24062445 detail : ( ) => Effect . succeed ( detail ) ,
24072446 activity : ( ) =>
24082447 Effect . succeed ( {
2409- comments : [
2410- {
2411- id : "review-1" ,
2412- kind : "review-comment" ,
2413- author : { login : "reviewer" , name : null , avatarUrl : null } ,
2414- body : "One more thing." ,
2415- createdAt : "2999-01-01T00:00:00.000Z" ,
2416- url : null ,
2417- path : "src/index.ts" ,
2418- reviewState : null ,
2419- } ,
2420- ] ,
2421- commentCount : 1 ,
2422- commentsTruncated : false ,
2423- reviewThreads : [ ] ,
2448+ comments :
2449+ mode === "single page"
2450+ ? [ remark ]
2451+ : [ ...firstTen , { ...remark , kind : "issue-comment" } ] ,
2452+ commentCount : mode === "single page" ? 1 : 13 ,
2453+ commentsTruncated : mode !== "single page" ,
2454+ reviewThreads :
2455+ mode === "single page"
2456+ ? [ ]
2457+ : [
2458+ {
2459+ id : "review-thread" ,
2460+ path : "src/index.ts" ,
2461+ line : 1 ,
2462+ side : "right" ,
2463+ isResolved : false ,
2464+ isOutdated : false ,
2465+ comments : firstTen ,
2466+ commentCount : 12 ,
2467+ nextCommentsCursor : "after-10" ,
2468+ } ,
2469+ ] ,
24242470 commits : [ ] ,
24252471 } ) ,
2472+ threadComments : ( input ) => {
2473+ assert . equal ( input . threadId , "review-thread" ) ;
2474+ if ( input . cursor === "after-10" ) {
2475+ return Effect . succeed ( { comments : [ eleventh ] , nextCursor : "after-11" } ) ;
2476+ }
2477+ assert . equal ( input . cursor , "after-11" ) ;
2478+ if ( ! recovering && mode === "page failure" ) {
2479+ return Effect . fail (
2480+ new PullRequestOperationError ( {
2481+ operation : "threadComments" ,
2482+ detail : "Page unavailable" ,
2483+ } ) ,
2484+ ) ;
2485+ }
2486+ if ( ! recovering && mode === "repeated cursor" ) {
2487+ return Effect . succeed ( { comments : [ eleventh ] , nextCursor : "after-11" } ) ;
2488+ }
2489+ if ( ! recovering && mode === "missing comments" ) {
2490+ return Effect . succeed ( { comments : [ ] , nextCursor : null } ) ;
2491+ }
2492+ // Overlapping pages must not report the same reply twice.
2493+ return Effect . succeed ( { comments : [ eleventh , twelfth ] , nextCursor : null } ) ;
2494+ } ,
24262495 } ) ,
24272496 ) ,
24282497 ) ,
24292498 ) ;
2499+ if ( incomplete ) {
2500+ yield * reactor . sweep ;
2501+ const held = ( yield * orchestrator . getThreadShell ( threadId ) ) ?. pullRequests ?. [ 0 ] ?. watch ;
2502+ assert . equal ( held ?. remarksThrough , initialWatch ?. remarksThrough ) ;
2503+ assert . deepEqual ( held ?. remarkIds , initialWatch ?. remarkIds ) ;
2504+ assert . deepEqual ( held ?. failedChecks , [ "lint" ] ) ;
2505+ const { messages } = yield * orchestrator . getThreadRecords ( threadId , [ "messages" ] ) ;
2506+ assert . deepEqual (
2507+ messages . map ( ( message ) => message . notification ?. summary ) ,
2508+ [ "#7: checks failed" ] ,
2509+ ) ;
2510+ recovering = true ;
2511+ }
24302512 yield * reactor . sweep ;
24312513 yield * reactor . sweep ;
24322514
@@ -2435,12 +2517,22 @@ it.layer(TestLayer)("OrchestrationV2LayerLive lifecycle", (it) => {
24352517 messages . flatMap ( ( message ) =>
24362518 message . notification === undefined ? [ ] : [ message . notification . summary ] ,
24372519 ) ,
2438- [ "#7: checks failed, new comments" ] ,
2520+ incomplete
2521+ ? [ "#7: checks failed" , "#7: new comments" ]
2522+ : [ "#7: checks failed, new comments" ] ,
24392523 ) ;
2524+ if ( mode !== "single page" ) {
2525+ const wake = messages . at ( - 1 ) ;
2526+ assert . include ( wake ?. text ?? "" , "3 new comments" ) ;
2527+ assert . include ( wake ?. text ?? "" , "Eleventh reply." ) ;
2528+ assert . include ( wake ?. text ?? "" , "Twelfth reply." ) ;
2529+ }
24402530 const watch = ( yield * orchestrator . getThreadShell ( threadId ) ) ?. pullRequests ?. [ 0 ] ?. watch ;
2531+ assert . equal ( watch ?. remarksThrough , remark . createdAt ) ;
2532+ assert . deepEqual ( watch ?. remarkIds , [ remark . id ] ) ;
24412533 assert . deepEqual (
24422534 { headSha : watch ?. headSha , failedChecks : watch ?. failedChecks , wakes : watch ?. wakes } ,
2443- { headSha : "abc1234def" , failedChecks : [ "lint" ] , wakes : 0 } ,
2535+ { headSha : "abc1234def" , failedChecks : [ "lint" ] , wakes : incomplete ? 1 : 0 } ,
24442536 ) ;
24452537 } ) ,
24462538 ) ;
0 commit comments