@@ -813,6 +813,18 @@ const createdPullRequests = ({ tool, input, output }: ShellEntry) =>
813813 tool === "Bash" && isRecord ( input ) && typeof input . command === "string"
814814 ? changeRequestsCreatedBy ( input . command , output ) . map ( ( { url } ) => url )
815815 : [ ] ;
816+
817+ /** The PR number a shell command opened for `branch`; `--head` naming another branch is not it. */
818+ const branchPullRequestCreatedBy = ( entry : ShellEntry , branch : string | undefined ) => {
819+ const command = isRecord ( entry . input ) ? valueText ( entry . input . command ) : "" ;
820+ const head = / - - h e a d [ = \s ] + [ " ' ] ? ( [ ^ \s " ' ] + ) / . exec ( command ) ?. [ 1 ] ;
821+ if ( head !== undefined && branch !== undefined && head . split ( ":" ) . at ( - 1 ) !== branch ) {
822+ return undefined ;
823+ }
824+ return createdPullRequests ( entry )
825+ . map ( ( url ) => Number ( / \/ p u l l \/ ( \d + ) / . exec ( url ) ?. [ 1 ] ) )
826+ . find ( ( number ) => number > 0 ) ;
827+ } ;
816828/**
817829 * One sample's state. ToolSearch adds loaded schemas to `tools`, like Claude Code. `shell` is the
818830 * history the simulator keeps consistent with; `linked`, `nextTask` and `threads` do the same for
@@ -877,10 +889,14 @@ export const makeSample = (testCase: McpToolUseCase, base: Base): Sample => {
877889 shell,
878890 shellUsage : emptyUsage ( ) ,
879891 linked : new Set ( [ ...urls , ...shell . flatMap ( createdPullRequests ) ] ) ,
880- openedPullRequest : shell
881- . flatMap ( createdPullRequests )
882- . map ( ( url ) => Number ( / \/ p u l l \/ ( \d + ) / . exec ( url ) ?. [ 1 ] ) )
883- . find ( ( number ) => number > 0 ) ,
892+ openedPullRequest :
893+ shell
894+ . map ( ( entry ) => branchPullRequestCreatedBy ( entry , testCase . setup . world ?. branch ) )
895+ . find ( ( number ) => number !== undefined ) ??
896+ priorCalls
897+ . filter ( ( call ) => call . tool === "pull_request_create" )
898+ . map ( ( call ) => Number ( / \/ p u l l \/ ( \d + ) / . exec ( valueText ( call . result ) ) ?. [ 1 ] ) )
899+ . find ( ( number ) => number > 0 ) ,
884900 codeStore : { } ,
885901 nextTask : Math . max ( 0 , ...taskNumbers ) + 1 ,
886902 threads : new Map ( ) ,
@@ -1705,6 +1721,10 @@ const simulate = Effect.fn("evaluateMcpToolUse.simulate")(function* (
17051721 const entry = { ...call , output } ;
17061722 sample . shell . push ( entry ) ;
17071723 for ( const url of createdPullRequests ( entry ) ) sample . linked . add ( url ) ;
1724+ sample . openedPullRequest ??= branchPullRequestCreatedBy (
1725+ entry ,
1726+ sample . testCase . setup . world ?. branch ,
1727+ ) ;
17081728 return output ;
17091729} ) ;
17101730
0 commit comments