@@ -107,6 +107,7 @@ export default async function CloudTestsPage({ params }: { params: Promise<{ org
107107 requiredVariables : string [ ] ;
108108 accountId ?: string ;
109109 regions ?: string [ ] ;
110+ supportsMultipleConnections ?: boolean ;
110111 } ;
111112
112113 const newProviders : Provider [ ] = newConnections . map ( ( conn ) => {
@@ -117,6 +118,7 @@ export default async function CloudTestsPage({ params }: { params: Promise<{ org
117118 const regions = Array . isArray ( metadata . regions )
118119 ? metadata . regions . filter ( ( region ) : region is string => typeof region === 'string' )
119120 : undefined ;
121+ const manifest = getManifest ( conn . provider . slug ) ;
120122
121123 return {
122124 id : conn . id ,
@@ -133,6 +135,7 @@ export default async function CloudTestsPage({ params }: { params: Promise<{ org
133135 requiredVariables : getRequiredVariables ( conn . provider . slug ) ,
134136 accountId,
135137 regions,
138+ supportsMultipleConnections : manifest ?. supportsMultipleConnections ?? false ,
136139 } ;
137140 } ) ;
138141
@@ -144,6 +147,7 @@ export default async function CloudTestsPage({ params }: { params: Promise<{ org
144147 const regions = Array . isArray ( settings . regions )
145148 ? settings . regions . filter ( ( region ) : region is string => typeof region === 'string' )
146149 : undefined ;
150+ const manifest = getManifest ( integration . integrationId ) ;
147151
148152 return {
149153 id : integration . id ,
@@ -160,6 +164,7 @@ export default async function CloudTestsPage({ params }: { params: Promise<{ org
160164 requiredVariables : getRequiredVariables ( integration . integrationId ) ,
161165 accountId,
162166 regions,
167+ supportsMultipleConnections : manifest ?. supportsMultipleConnections ?? false ,
163168 } ;
164169 } ) ;
165170
@@ -231,9 +236,17 @@ export default async function CloudTestsPage({ params }: { params: Promise<{ org
231236
232237 // ====================================================================
233238 // Fetch findings from OLD platform (IntegrationResult)
239+ // Only show results from the most recent scan for each integration
234240 // ====================================================================
235241 const legacyIntegrationIds = activeLegacyIntegrations . map ( ( i ) => i . id ) ;
236242
243+ // Create a map of integration ID to lastRunAt for filtering
244+ const integrationLastRunMap = new Map (
245+ activeLegacyIntegrations
246+ . filter ( ( i ) => i . lastRunAt )
247+ . map ( ( i ) => [ i . id , i . lastRunAt ! ] ) ,
248+ ) ;
249+
237250 const legacyResults =
238251 legacyIntegrationIds . length > 0
239252 ? await db . integrationResult . findMany ( {
@@ -254,17 +267,33 @@ export default async function CloudTestsPage({ params }: { params: Promise<{ org
254267 select : {
255268 integrationId : true ,
256269 id : true ,
270+ lastRunAt : true ,
257271 } ,
258272 } ,
259273 } ,
260274 orderBy : {
261275 completedAt : 'desc' ,
262276 } ,
263- take : 500 ,
264277 } )
265278 : [ ] ;
266279
267- const legacyFindings = legacyResults . map ( ( result ) => ( {
280+ // Filter to only include results from the most recent scan
281+ // Results are considered from the "latest scan" if they were completed
282+ // within 5 minutes of the integration's lastRunAt
283+ const SCAN_WINDOW_MS = 5 * 60 * 1000 ; // 5 minutes
284+
285+ const filteredLegacyResults = legacyResults . filter ( ( result ) => {
286+ const lastRunAt = integrationLastRunMap . get ( result . integration . id ) ;
287+ if ( ! lastRunAt || ! result . completedAt ) return false ;
288+
289+ const lastRunTime = lastRunAt . getTime ( ) ;
290+ const completedTime = result . completedAt . getTime ( ) ;
291+
292+ // Include if completed within the scan window of the last run
293+ return Math . abs ( completedTime - lastRunTime ) <= SCAN_WINDOW_MS ;
294+ } ) ;
295+
296+ const legacyFindings = filteredLegacyResults . map ( ( result ) => ( {
268297 id : result . id ,
269298 title : result . title ,
270299 description : result . description ,
0 commit comments