@@ -5460,6 +5460,136 @@ describe(`jest@${JEST_VERSION} commonJS`, () => {
54605460 eventsPromise ,
54615461 ] )
54625462 } )
5463+
5464+ it ( 'quarantine prevents session failure when ATR is also enabled' , async ( ) => {
5465+ receiver . setSettings ( {
5466+ test_management : { enabled : true } ,
5467+ flaky_test_retries_enabled : true ,
5468+ } )
5469+
5470+ const eventsPromise = receiver
5471+ . gatherPayloadsMaxTimeout ( ( { url } ) => url . endsWith ( '/api/v2/citestcycle' ) , ( payloads ) => {
5472+ const events = payloads . flatMap ( ( { payload } ) => payload . events )
5473+ const tests = events . filter ( event => event . type === 'test' ) . map ( event => event . content )
5474+ const testSession = events . find ( event => event . type === 'test_session_end' ) . content
5475+
5476+ // Session should pass because the only failing test is quarantined
5477+ assert . strictEqual ( testSession . meta [ TEST_STATUS ] , 'pass' )
5478+ assert . strictEqual ( testSession . meta [ TEST_MANAGEMENT_ENABLED ] , 'true' )
5479+
5480+ // All executions of the quarantined test should be tagged as quarantined
5481+ const quarantinedTests = tests . filter (
5482+ test => test . meta [ TEST_NAME ] === 'quarantine tests can quarantine a test'
5483+ )
5484+ assert . ok ( quarantinedTests . length > 1 , 'quarantined test should have been retried by ATR' )
5485+ for ( const test of quarantinedTests ) {
5486+ assert . strictEqual ( test . meta [ TEST_MANAGEMENT_IS_QUARANTINED ] , 'true' )
5487+ }
5488+
5489+ // The last execution should have final_status = skip
5490+ const lastExecution = quarantinedTests [ quarantinedTests . length - 1 ]
5491+ assert . strictEqual ( lastExecution . meta [ TEST_FINAL_STATUS ] , 'skip' )
5492+ } )
5493+
5494+ childProcess = exec (
5495+ runTestsCommand ,
5496+ {
5497+ cwd,
5498+ env : {
5499+ ...getCiVisAgentlessConfig ( receiver . port ) ,
5500+ TESTS_TO_RUN : 'test-management/test-quarantine-1' ,
5501+ } ,
5502+ }
5503+ )
5504+
5505+ const [ [ exitCode ] ] = await Promise . all ( [ once ( childProcess , 'exit' ) , eventsPromise ] )
5506+
5507+ // Exit code should be 0 because the failing test is quarantined
5508+ assert . strictEqual ( exitCode , 0 )
5509+ } )
5510+
5511+ it ( 'session passes when EFD flaky retries and quarantine failures are combined' , async ( ) => {
5512+ const NUM_RETRIES_EFD = 3
5513+
5514+ // The new flaky test is NOT in known tests so EFD will retry it
5515+ receiver . setKnownTests ( { jest : { } } )
5516+
5517+ receiver . setSettings ( {
5518+ test_management : { enabled : true } ,
5519+ early_flake_detection : {
5520+ enabled : true ,
5521+ slow_test_retries : { '5s' : NUM_RETRIES_EFD } ,
5522+ faulty_session_threshold : 100 ,
5523+ } ,
5524+ known_tests_enabled : true ,
5525+ } )
5526+
5527+ // Only quarantine the always-failing test
5528+ receiver . setTestManagementTests ( {
5529+ jest : {
5530+ suites : {
5531+ 'ci-visibility/test-management/test-efd-and-quarantine.js' : {
5532+ tests : {
5533+ 'efd and quarantine is a quarantined failing test' : {
5534+ properties : {
5535+ quarantined : true ,
5536+ } ,
5537+ } ,
5538+ } ,
5539+ } ,
5540+ } ,
5541+ } ,
5542+ } )
5543+
5544+ const eventsPromise = receiver
5545+ . gatherPayloadsMaxTimeout ( ( { url } ) => url . endsWith ( '/api/v2/citestcycle' ) , ( payloads ) => {
5546+ const events = payloads . flatMap ( ( { payload } ) => payload . events )
5547+ const tests = events . filter ( event => event . type === 'test' ) . map ( event => event . content )
5548+ const testSession = events . find ( event => event . type === 'test_session_end' ) . content
5549+
5550+ // Session should pass:
5551+ // - The new flaky test has at least one passing EFD retry (so EFD can ignore its failures)
5552+ // - The quarantined test is quarantined (so quarantine can ignore its failure)
5553+ assert . strictEqual ( testSession . meta [ TEST_STATUS ] , 'pass' )
5554+
5555+ // Verify the quarantined test is tagged
5556+ const quarantinedTests = tests . filter (
5557+ test => test . meta [ TEST_NAME ] === 'efd and quarantine is a quarantined failing test'
5558+ )
5559+ assert . ok ( quarantinedTests . length >= 1 )
5560+ for ( const test of quarantinedTests ) {
5561+ assert . strictEqual ( test . meta [ TEST_MANAGEMENT_IS_QUARANTINED ] , 'true' )
5562+ }
5563+
5564+ // Verify the new flaky test has EFD retries (at least original + retries)
5565+ const flakyTests = tests . filter (
5566+ test => test . meta [ TEST_NAME ] === 'efd and quarantine is a new flaky test'
5567+ )
5568+ assert . ok ( flakyTests . length > 1 , 'flaky test should have been retried by EFD' )
5569+
5570+ // At least one EFD retry should have passed
5571+ const passingFlakyTests = flakyTests . filter ( t => t . meta [ TEST_STATUS ] === 'pass' )
5572+ assert . ok ( passingFlakyTests . length > 0 , 'at least one EFD retry should pass' )
5573+ } )
5574+
5575+ childProcess = exec (
5576+ runTestsCommand ,
5577+ {
5578+ cwd,
5579+ env : {
5580+ ...getCiVisAgentlessConfig ( receiver . port ) ,
5581+ TESTS_TO_RUN : 'test-management/test-efd-and-quarantine' ,
5582+ } ,
5583+ }
5584+ )
5585+
5586+ const [ [ exitCode ] ] = await Promise . all ( [ once ( childProcess , 'exit' ) , eventsPromise ] )
5587+
5588+ // Exit code should be 0 because:
5589+ // - The flaky test has at least one passing retry (EFD considers it OK)
5590+ // - The always-failing test is quarantined
5591+ assert . strictEqual ( exitCode , 0 )
5592+ } )
54635593 } )
54645594
54655595 it ( 'does not crash if the request to get test management tests fails' , async ( ) => {
0 commit comments