@@ -61,6 +61,11 @@ type MatrixQaScenarioResult = {
6161 title : string ;
6262} ;
6363
64+ type MatrixQaScheduledScenario = {
65+ originalIndex : number ;
66+ scenario : ( typeof MATRIX_QA_SCENARIOS ) [ number ] ;
67+ } ;
68+
6469type MatrixQaScenarioConfigEntry = MatrixQaSummary [ "config" ] [ "scenarios" ] [ number ] ;
6570
6671type MatrixQaSummary = {
@@ -178,6 +183,25 @@ function buildMatrixQaScenarioResult(params: {
178183 } ;
179184}
180185
186+ function scheduleMatrixQaScenariosByConfig (
187+ scenarios : readonly ( typeof MATRIX_QA_SCENARIOS ) [ number ] [ ] ,
188+ ) : MatrixQaScheduledScenario [ ] {
189+ const grouped = new Map < string , MatrixQaScheduledScenario [ ] > ( ) ;
190+
191+ scenarios . forEach ( ( scenario , originalIndex ) => {
192+ const configKey = buildMatrixQaGatewayConfigKey ( scenario . configOverrides ) ;
193+ const existing = grouped . get ( configKey ) ;
194+ const scheduled = { originalIndex, scenario } ;
195+ if ( existing ) {
196+ existing . push ( scheduled ) ;
197+ return ;
198+ }
199+ grouped . set ( configKey , [ scheduled ] ) ;
200+ } ) ;
201+
202+ return [ ...grouped . values ( ) ] . flat ( ) ;
203+ }
204+
181205export type MatrixQaRunResult = {
182206 observedEventsPath : string ;
183207 outputDir : string ;
@@ -368,7 +392,9 @@ export async function runMatrixQaLive(params: {
368392 ] . join ( "\n" ) ,
369393 } ,
370394 ] ;
371- const scenarioResults : MatrixQaScenarioResult [ ] = [ ] ;
395+ const scenarioResults : Array < MatrixQaScenarioResult | undefined > = Array . from ( {
396+ length : scenarios . length ,
397+ } ) ;
372398 const cleanupErrors : string [ ] = [ ] ;
373399 let canaryArtifact : MatrixQaCanaryArtifact | undefined ;
374400 let gatewayHarness : MatrixQaLiveLaneGatewayHarness | null = null ;
@@ -388,6 +414,8 @@ export async function runMatrixQaLive(params: {
388414 const defaultConfigSnapshot = buildMatrixQaConfigSnapshot ( gatewayConfigParams ) ;
389415 const scenarioConfigSnapshots : MatrixQaScenarioConfigEntry [ ] = [ ] ;
390416
417+ const scheduledScenarios = scheduleMatrixQaScenariosByConfig ( scenarios ) ;
418+
391419 try {
392420 const ensureGatewayHarness = async ( overrides ?: MatrixQaConfigOverrides ) => {
393421 const nextKey = buildMatrixQaGatewayConfigKey ( overrides ) ;
@@ -460,13 +488,13 @@ export async function runMatrixQaLive(params: {
460488 }
461489
462490 if ( ! canaryFailed ) {
463- for ( const scenario of scenarios ) {
491+ for ( const { scenario, originalIndex } of scheduledScenarios ) {
464492 const { entry : scenarioConfigEntry , summary : scenarioConfigSummary } =
465493 buildMatrixQaScenarioConfigEntry ( {
466494 gatewayConfigParams,
467495 scenario,
468496 } ) ;
469- scenarioConfigSnapshots . push ( scenarioConfigEntry ) ;
497+ scenarioConfigSnapshots [ originalIndex ] = scenarioConfigEntry ;
470498 try {
471499 const scenarioGateway = await ensureGatewayHarness ( scenario . configOverrides ) ;
472500 const result = await runMatrixQaScenario ( scenario , {
@@ -497,24 +525,20 @@ export async function runMatrixQaLive(params: {
497525 timeoutMs : scenario . timeoutMs ,
498526 topology : provisioning . topology ,
499527 } ) ;
500- scenarioResults . push (
501- buildMatrixQaScenarioResult ( {
502- artifacts : result . artifacts ,
503- configSummary : scenarioConfigSummary ,
504- details : result . details ,
505- scenario,
506- status : "pass" ,
507- } ) ,
508- ) ;
528+ scenarioResults [ originalIndex ] = buildMatrixQaScenarioResult ( {
529+ artifacts : result . artifacts ,
530+ configSummary : scenarioConfigSummary ,
531+ details : result . details ,
532+ scenario,
533+ status : "pass" ,
534+ } ) ;
509535 } catch ( error ) {
510- scenarioResults . push (
511- buildMatrixQaScenarioResult ( {
512- configSummary : scenarioConfigSummary ,
513- details : formatErrorMessage ( error ) ,
514- scenario,
515- status : "fail" ,
516- } ) ,
517- ) ;
536+ scenarioResults [ originalIndex ] = buildMatrixQaScenarioResult ( {
537+ configSummary : scenarioConfigSummary ,
538+ details : formatErrorMessage ( error ) ,
539+ scenario,
540+ status : "fail" ,
541+ } ) ;
518542 }
519543 }
520544 }
@@ -532,6 +556,9 @@ export async function runMatrixQaLive(params: {
532556 appendLiveLaneIssue ( cleanupErrors , "Matrix harness cleanup" , error ) ;
533557 }
534558 }
559+ const completedScenarioResults = scenarioResults . filter (
560+ ( scenario ) : scenario is MatrixQaScenarioResult => scenario !== undefined ,
561+ ) ;
535562 if ( cleanupErrors . length > 0 ) {
536563 checks . push ( {
537564 name : "Matrix cleanup" ,
@@ -555,7 +582,7 @@ export async function runMatrixQaLive(params: {
555582 startedAt : startedAtDate ,
556583 finishedAt : finishedAtDate ,
557584 checks,
558- scenarios : scenarioResults . map ( ( scenario ) => ( {
585+ scenarios : completedScenarioResults . map ( ( scenario ) => ( {
559586 details : scenario . details ,
560587 name : scenario . title ,
561588 status : scenario . status ,
@@ -592,7 +619,7 @@ export async function runMatrixQaLive(params: {
592619 serverName : harness . serverName ,
593620 } ,
594621 observedEventCount : observedEvents . length ,
595- scenarios : scenarioResults ,
622+ scenarios : completedScenarioResults ,
596623 startedAt,
597624 sutAccountId,
598625 userIds : {
@@ -623,7 +650,7 @@ export async function runMatrixQaLive(params: {
623650 const failedChecks = checks . filter (
624651 ( check ) => check . status === "fail" && check . name !== "Matrix cleanup" ,
625652 ) ;
626- const failedScenarios = scenarioResults . filter ( ( scenario ) => scenario . status === "fail" ) ;
653+ const failedScenarios = completedScenarioResults . filter ( ( scenario ) => scenario . status === "fail" ) ;
627654 if ( failedChecks . length > 0 || failedScenarios . length > 0 ) {
628655 throw new Error (
629656 buildLiveLaneArtifactsError ( {
@@ -651,16 +678,18 @@ export async function runMatrixQaLive(params: {
651678 observedEventsPath,
652679 outputDir,
653680 reportPath,
654- scenarios : scenarioResults ,
681+ scenarios : completedScenarioResults ,
655682 summaryPath,
656683 } ;
657684}
658685
659686export const __testing = {
660687 buildMatrixQaSummary,
688+ scheduleMatrixQaScenariosByConfig,
661689 MATRIX_QA_SCENARIOS ,
662690 buildMatrixQaConfig,
663691 buildMatrixQaConfigSnapshot,
692+ findMatrixQaScenarios,
664693 isMatrixAccountReady,
665694 resolveMatrixQaModels,
666695 summarizeMatrixQaConfigSnapshot,
0 commit comments