@@ -35,7 +35,12 @@ import { FetchHttpClient, HttpClient, HttpClientRequest } from "effect/http";
3535import { taskPrompt } from "../../apps/server/src/mcp/delegatedTaskModes.ts" ;
3636import * as McpInvocationContext from "../../apps/server/src/mcp/McpInvocationContext.ts" ;
3737import { advertisedJsonSchema } from "../../apps/server/src/mcp/advertisedJsonSchema.ts" ;
38- import { EnvironmentId , ORCHESTRATOR_MCP_RUNNING_TASK_NEXT , ThreadId } from "@t3tools/contracts" ;
38+ import {
39+ EnvironmentId ,
40+ ORCHESTRATOR_MCP_RUNNING_TASK_NEXT ,
41+ PullRequestState ,
42+ ThreadId ,
43+ } from "@t3tools/contracts" ;
3944import { projectComposerContextForProvider } from "@t3tools/shared/composerContextReferences" ;
4045import { formatThreadLink } from "@t3tools/shared/threadLinks" ;
4146import { buildCodexAdditionalContext } from "../../apps/server/src/provider/CodexDeveloperInstructions.ts" ;
@@ -166,6 +171,8 @@ const McpToolUseExpect = Schema.Struct({
166171 textMustNot : Schema . optional ( Schema . Array ( Schema . String ) ) ,
167172 /** Each entry matches a PR URL linked at the end, as `args` values match. */
168173 linked : Schema . optional ( Schema . Array ( Schema . String ) ) ,
174+ /** The PR numbers linked at the end, exactly. */
175+ linkedNumbers : Schema . optional ( Schema . Array ( Schema . Number ) ) ,
169176 /** Device manager checks: child briefs, simulator UI over the shell, failures, recordings. */
170177 device : Schema . optional ( DeviceExpect ) ,
171178} ) ;
@@ -210,6 +217,12 @@ const McpToolUseWorld = Schema.StructWithRest(
210217 deviceInvalidCapture : Schema . optional ( Schema . Boolean ) ,
211218 /** Devices another thread's agent-device session holds, by device id: that thread's id. */
212219 deviceOwners : Schema . optional ( Schema . Record ( Schema . String , Schema . String ) ) ,
220+ /** PRs already linked to the thread, with the state T3 last saw. */
221+ linkedPullRequests : Schema . optional (
222+ Schema . Array (
223+ Schema . Struct ( { number : Schema . Number , state : PullRequestState , title : Schema . String } ) ,
224+ ) ,
225+ ) ,
213226 } ) ,
214227 Rest ,
215228) ;
@@ -731,11 +744,16 @@ export const makeSample = (testCase: McpToolUseCase, base: Base): Sample => {
731744 const prior = testCase . setup . priorTurns ?? [ ] ;
732745 const priorCalls = prior . flatMap ( ( turn ) => turn . toolCalls ?? [ ] ) ;
733746 const repo = testCase . setup . world ?. repo ?? "acme/app" ;
734- const urls = priorCalls . flatMap ( ( call ) =>
735- [ "link_pull_request" , "watch_pull_request" ] . includes ( call . tool ) && isRecord ( call . input )
736- ? [ pullRequest ( repo , call . input ) . url ]
737- : [ ] ,
738- ) ;
747+ const urls = [
748+ ...( testCase . setup . world ?. linkedPullRequests ?? [ ] ) . map (
749+ ( { number } ) => pullRequest ( repo , { number } ) . url ,
750+ ) ,
751+ ...priorCalls . flatMap ( ( call ) =>
752+ [ "link_pull_request" , "watch_pull_request" ] . includes ( call . tool ) && isRecord ( call . input )
753+ ? [ pullRequest ( repo , call . input ) . url ]
754+ : [ ] ,
755+ ) ,
756+ ] ;
739757 const taskNumbers = [ ...valueText ( prior ) . matchAll ( / t a s k - ( \d + ) / g) ] . map ( ( match ) =>
740758 Number ( match [ 1 ] ) ,
741759 ) ;
@@ -952,6 +970,15 @@ const pullRequest = (repo: string, input: Readonly<Record<string, unknown>>) =>
952970 } ;
953971} ;
954972
973+ /** A linked PR as `list_thread_pull_requests` shows it. Links made in the sample are open. */
974+ const linkedEntry = ( sample : Sample , url : string ) => {
975+ const pr = pullRequest ( sample . repo , { url } ) ;
976+ const seeded = sample . testCase . setup . world ?. linkedPullRequests ?. find (
977+ ( { number } ) => number === pr . number && pr . repository === sample . repo ,
978+ ) ;
979+ return { ...pr , state : seeded ?. state ?? "open" , title : seeded ?. title ?? null } ;
980+ } ;
981+
955982/** A believable T3 result for a tool the case does not mock. */
956983const t3Default = ( sample : Sample , name : string , input : Readonly < Record < string , unknown > > ) => {
957984 const pr = ( ) => pullRequest ( sample . repo , input ) ;
@@ -1006,6 +1033,24 @@ const t3Default = (sample: Sample, name: string, input: Readonly<Record<string,
10061033 }
10071034 case "unlink_pull_request" :
10081035 return { ...pr ( ) , wasLinked : sample . linked . delete ( pr ( ) . url ) } ;
1036+ case "unlink_pull_requests" : {
1037+ const states = Array . isArray ( input . states ) ? input . states : [ ] ;
1038+ const unlinked = [ ...sample . linked ]
1039+ . map ( ( url ) => linkedEntry ( sample , url ) )
1040+ . filter ( ( entry ) => states . includes ( entry . state ) ) ;
1041+ for ( const { url } of unlinked ) sample . linked . delete ( url ) ;
1042+ const groups = Map . groupBy ( unlinked , ( entry ) => `${ entry . repository } /${ entry . state } ` ) ;
1043+ return {
1044+ unlinked : [ ...groups . values ( ) ] . map ( ( entries ) => ( {
1045+ host : "github.com" ,
1046+ repository : entries [ 0 ] ! . repository ,
1047+ state : entries [ 0 ] ! . state ,
1048+ numbers : entries . map ( ( entry ) => entry . number ) ,
1049+ } ) ) ,
1050+ unlinkedCount : unlinked . length ,
1051+ remaining : sample . linked . size ,
1052+ } ;
1053+ }
10091054 case "watch_pull_request" :
10101055 sample . linked . add ( pr ( ) . url ) ;
10111056 return { ...pr ( ) , watching : true , wasWatching : false } ;
@@ -1014,10 +1059,9 @@ const t3Default = (sample: Sample, name: string, input: Readonly<Record<string,
10141059 case "list_thread_pull_requests" :
10151060 return {
10161061 pullRequests : [ ...sample . linked ] . map ( ( url ) => ( {
1017- ...pullRequest ( sample . repo , { url } ) ,
1062+ ...linkedEntry ( sample , url ) ,
10181063 source : "agent" ,
10191064 watching : false ,
1020- state : "open" ,
10211065 } ) ) ,
10221066 chains : [ ] ,
10231067 } ;
@@ -1403,6 +1447,11 @@ export const gradeSample = (expect: McpToolUseCase["expect"], run: SampleRun) =>
14031447 for ( const p of expect . textMustNot ?? [ ] ) add ( `textMustNot /${ p } /` , ! test ( p , run . text ) ) ;
14041448 const isLinked = ( url : string ) => ( run . linked ?? [ ] ) . some ( ( at ) => matches ( url , at ) ) ;
14051449 for ( const url of expect . linked ?? [ ] ) add ( `linked ${ url } ` , isLinked ( url ) ) ;
1450+ if ( expect . linkedNumbers !== undefined ) {
1451+ const numbers = ( run . linked ?? [ ] ) . map ( ( url ) => Number ( / ( \d + ) \/ ? $ / . exec ( url ) ?. [ 1 ] ) ) ;
1452+ const exact = valueText ( numbers . toSorted ( ( a , b ) => a - b ) ) ;
1453+ add ( "linkedNumbers" , exact === valueText ( expect . linkedNumbers . toSorted ( ( a , b ) => a - b ) ) ) ;
1454+ }
14061455 checks . push ( ...gradeDevice ( expect . device , run ) ) ;
14071456 return checks ;
14081457} ;
0 commit comments