@@ -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,18 @@ 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+ "thread list truncated" ,
2319+ ] ) ( "wakes a watched thread once: %s" , ( mode ) =>
23112320 Effect . gen ( function * ( ) {
23122321 const orchestrator = yield * Orchestrator . OrchestratorV2 ;
2313- const threadId = ThreadId . make ( " runtime-pull-request-watch-wake" ) ;
2314- const projectId = ProjectId . make ( " pr-watch-wake-project" ) ;
2322+ const threadId = ThreadId . make ( ` runtime-pull-request-watch-wake- ${ mode } ` ) ;
2323+ const projectId = ProjectId . make ( ` pr-watch-wake-project- ${ mode } ` ) ;
23152324 yield * seedProject ( {
23162325 projectId,
23172326 title : "Watch wake" ,
@@ -2323,7 +2332,7 @@ it.layer(TestLayer)("OrchestrationV2LayerLive lifecycle", (it) => {
23232332 type : "thread.create" ,
23242333 createdBy : "user" ,
23252334 creationSource : "web" ,
2326- commandId : CommandId . make ( " pr-watch-wake-create" ) ,
2335+ commandId : CommandId . make ( ` pr-watch-wake-create- ${ mode } ` ) ,
23272336 threadId,
23282337 projectId,
23292338 title : "Watch wake" ,
@@ -2337,15 +2346,15 @@ it.layer(TestLayer)("OrchestrationV2LayerLive lifecycle", (it) => {
23372346 const url = "https://github.com/pingdotgg/t3code/pull/7" ;
23382347 yield * orchestrator . dispatch ( {
23392348 type : "thread.pull-request.link" ,
2340- commandId : CommandId . make ( " pr-watch-wake-link" ) ,
2349+ commandId : CommandId . make ( ` pr-watch-wake-link- ${ mode } ` ) ,
23412350 threadId,
23422351 ...key ,
23432352 url,
23442353 source : "agent" ,
23452354 } ) ;
23462355 yield * orchestrator . dispatch ( {
23472356 type : "thread.pull-request.watch" ,
2348- commandId : CommandId . make ( " pr-watch-wake-start" ) ,
2357+ commandId : CommandId . make ( ` pr-watch-wake-start- ${ mode } ` ) ,
23492358 threadId,
23502359 ...key ,
23512360 watching : true ,
@@ -2398,6 +2407,38 @@ it.layer(TestLayer)("OrchestrationV2LayerLive lifecycle", (it) => {
23982407 mergeCapabilities : { merge : true , squash : true , rebase : true } ,
23992408 viewer : "agent-user" ,
24002409 } ;
2410+ const initialWatch = ( yield * orchestrator . getThreadShell ( threadId ) ) ?. pullRequests ?. [ 0 ] ?. watch ;
2411+ assert . isDefined ( initialWatch ) ;
2412+ const remark : PullRequestComment = {
2413+ id : "review-1" ,
2414+ kind : "review-comment" ,
2415+ author : { login : "reviewer" , name : null , avatarUrl : null } ,
2416+ body : "One more thing." ,
2417+ createdAt : "2999-01-01T00:00:03.000Z" ,
2418+ url : null ,
2419+ path : "src/index.ts" ,
2420+ reviewState : null ,
2421+ } ;
2422+ const firstTen = Array . from ( { length : 10 } , ( _ , index ) => ( {
2423+ ...remark ,
2424+ id : `old-${ index } ` ,
2425+ createdAt : "1900-01-01T00:00:00.000Z" ,
2426+ } ) ) ;
2427+ const eleventh = {
2428+ ...remark ,
2429+ id : "reply-11" ,
2430+ body : "Eleventh reply." ,
2431+ createdAt : "2999-01-01T00:00:01.000Z" ,
2432+ } ;
2433+ const twelfth = {
2434+ ...remark ,
2435+ id : "reply-12" ,
2436+ body : "Twelfth reply." ,
2437+ createdAt : "2999-01-01T00:00:02.000Z" ,
2438+ } ;
2439+ const incomplete = mode !== "single page" && mode !== "paginated" ;
2440+ let recovering = false ;
2441+ let pagesRead = 0 ;
24012442 const reactor = yield * PullRequestWatchReactor . make . pipe (
24022443 Effect . provide (
24032444 Layer . mergeAll (
@@ -2406,41 +2447,101 @@ it.layer(TestLayer)("OrchestrationV2LayerLive lifecycle", (it) => {
24062447 detail : ( ) => Effect . succeed ( detail ) ,
24072448 activity : ( ) =>
24082449 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 : [ ] ,
2450+ comments :
2451+ mode === "single page"
2452+ ? [ remark ]
2453+ : [ ...firstTen , { ...remark , kind : "issue-comment" } ] ,
2454+ commentCount : mode === "single page" ? 1 : 13 ,
2455+ commentsTruncated : mode !== "single page" ,
2456+ reviewThreadsTruncated : mode === "thread list truncated" && ! recovering ,
2457+ reviewThreads :
2458+ mode === "single page"
2459+ ? [ ]
2460+ : [
2461+ {
2462+ id : "review-thread" ,
2463+ path : "src/index.ts" ,
2464+ line : 1 ,
2465+ side : "right" ,
2466+ isResolved : false ,
2467+ isOutdated : false ,
2468+ comments : firstTen ,
2469+ commentCount : 12 ,
2470+ nextCommentsCursor : "after-10" ,
2471+ } ,
2472+ ] ,
24242473 commits : [ ] ,
24252474 } ) ,
2475+ threadComments : ( input ) => {
2476+ pagesRead += 1 ;
2477+ assert . equal ( input . threadId , "review-thread" ) ;
2478+ if ( input . cursor === "after-10" ) {
2479+ return Effect . succeed ( { comments : [ eleventh ] , nextCursor : "after-11" } ) ;
2480+ }
2481+ assert . equal ( input . cursor , "after-11" ) ;
2482+ if ( ! recovering && mode === "page failure" ) {
2483+ return Effect . fail (
2484+ new PullRequestOperationError ( {
2485+ operation : "threadComments" ,
2486+ detail : "Page unavailable" ,
2487+ } ) ,
2488+ ) ;
2489+ }
2490+ if ( ! recovering && mode === "repeated cursor" ) {
2491+ return Effect . succeed ( { comments : [ eleventh ] , nextCursor : "after-11" } ) ;
2492+ }
2493+ if ( ! recovering && mode === "missing comments" ) {
2494+ return Effect . succeed ( { comments : [ ] , nextCursor : null } ) ;
2495+ }
2496+ // Overlapping pages must not report the same reply twice.
2497+ return Effect . succeed ( { comments : [ eleventh , twelfth ] , nextCursor : null } ) ;
2498+ } ,
24262499 } ) ,
24272500 ) ,
24282501 ) ,
24292502 ) ;
2503+ if ( incomplete ) {
2504+ yield * reactor . sweep ;
2505+ const held = ( yield * orchestrator . getThreadShell ( threadId ) ) ?. pullRequests ?. [ 0 ] ?. watch ;
2506+ assert . equal ( held ?. remarksThrough , initialWatch ?. remarksThrough ) ;
2507+ assert . deepEqual ( held ?. remarkIds , initialWatch ?. remarkIds ) ;
2508+ assert . deepEqual ( held ?. failedChecks , [ "lint" ] ) ;
2509+ const { messages } = yield * orchestrator . getThreadRecords ( threadId , [ "messages" ] ) ;
2510+ assert . deepEqual (
2511+ messages . map ( ( message ) => message . notification ?. summary ) ,
2512+ [ "#7: checks failed" ] ,
2513+ ) ;
2514+ // Keep the two notifications ordered independently of their random message IDs.
2515+ yield * TestClock . adjust ( "1 millis" ) ;
2516+ recovering = true ;
2517+ }
24302518 yield * reactor . sweep ;
2519+ // A thread whose count has not moved is not paged again.
2520+ const pagesBefore = pagesRead ;
24312521 yield * reactor . sweep ;
2522+ assert . equal ( pagesRead , pagesBefore ) ;
24322523
24332524 const { messages } = yield * orchestrator . getThreadRecords ( threadId , [ "messages" ] ) ;
24342525 assert . deepEqual (
24352526 messages . flatMap ( ( message ) =>
24362527 message . notification === undefined ? [ ] : [ message . notification . summary ] ,
24372528 ) ,
2438- [ "#7: checks failed, new comments" ] ,
2529+ incomplete
2530+ ? [ "#7: checks failed" , "#7: new comments" ]
2531+ : [ "#7: checks failed, new comments" ] ,
24392532 ) ;
2533+ if ( mode !== "single page" ) {
2534+ const wake = messages . at ( - 1 ) ;
2535+ assert . include ( wake ?. text ?? "" , "3 new comments" ) ;
2536+ assert . include ( wake ?. text ?? "" , "Eleventh reply." ) ;
2537+ assert . include ( wake ?. text ?? "" , "Twelfth reply." ) ;
2538+ }
24402539 const watch = ( yield * orchestrator . getThreadShell ( threadId ) ) ?. pullRequests ?. [ 0 ] ?. watch ;
2540+ assert . equal ( watch ?. remarksThrough , remark . createdAt ) ;
2541+ assert . deepEqual ( watch ?. remarkIds , [ remark . id ] ) ;
24412542 assert . deepEqual (
24422543 { headSha : watch ?. headSha , failedChecks : watch ?. failedChecks , wakes : watch ?. wakes } ,
2443- { headSha : "abc1234def" , failedChecks : [ "lint" ] , wakes : 0 } ,
2544+ { headSha : "abc1234def" , failedChecks : [ "lint" ] , wakes : incomplete ? 1 : 0 } ,
24442545 ) ;
24452546 } ) ,
24462547 ) ;
0 commit comments