@@ -2113,8 +2113,22 @@ describe("AgentServer HTTP Mode", () => {
21132113 expect ( s . detectedPrUrl ) . toBeNull ( ) ;
21142114 } ) ;
21152115
2116- it ( "fails closed when the run's GitHub identity cannot be resolved" , async ( ) => {
2117- const s = setup ( justNow ( ) ) ;
2116+ it ( "attributes a recent PR when the identity is a GitHub App installation (gh api user unavailable)" , async ( ) => {
2117+ // Cloud runs authenticate with a GitHub App installation token, for which
2118+ // `gh api user` returns 403 → ghLogin is null. The PR is authored by the
2119+ // app bot (e.g. "app/posthog"); recency alone must carry attribution.
2120+ const s = setup ( justNow ( ) , "app/posthog" ) ;
2121+ s . fetchGhLogin = vi . fn ( async ( ) => null ) ;
2122+ s . maybeAttachCreatedPr ( payload , terminalUpdate ( PR_URL ) ) ;
2123+ await flush ( ) ;
2124+ expect ( s . posthogAPI . updateTaskRun ) . toHaveBeenCalledWith ( "t" , "r" , {
2125+ output : { pr_url : PR_URL , pr_urls : [ PR_URL ] } ,
2126+ } ) ;
2127+ expect ( s . detectedPrUrl ) . toBe ( PR_URL ) ;
2128+ } ) ;
2129+
2130+ it ( "still rejects an old PR when the identity cannot be resolved (recency guards)" , async ( ) => {
2131+ const s = setup ( longAgo , "app/posthog" ) ;
21182132 s . fetchGhLogin = vi . fn ( async ( ) => null ) ;
21192133 s . maybeAttachCreatedPr ( payload , terminalUpdate ( PR_URL ) ) ;
21202134 await flush ( ) ;
0 commit comments