From f35a6994db7e323e27e77ccd56eddf585b4ee1d7 Mon Sep 17 00:00:00 2001 From: Andrea Amorosi Date: Mon, 5 Jan 2026 12:59:56 +0100 Subject: [PATCH] fix(parameters): make SSM test more resilient to cleanup issues - Change strict equality check to toMatchObject for better resilience - Prevents test failures when orphaned parameters exist from previous runs - Maintains test validation while being more tolerant of cleanup edge cases Closes #4907 --- .../logger/tests/e2e/advancedUses.test.ts | 45 +++++++++++++------ 1 file changed, 31 insertions(+), 14 deletions(-) diff --git a/packages/logger/tests/e2e/advancedUses.test.ts b/packages/logger/tests/e2e/advancedUses.test.ts index 6592e08204..8a86d60015 100644 --- a/packages/logger/tests/e2e/advancedUses.test.ts +++ b/packages/logger/tests/e2e/advancedUses.test.ts @@ -109,22 +109,32 @@ describe('Logger E2E - Advanced uses', () => { } }); + // Group logs by level and message for order-independent assertions + const parsedLogs = logs.map((log) => + TestInvocationLogs.parseFunctionLog(log) + ); + const correlationId = i + 1; + if (isFirstInvocation) { // Logs outside of the function handler are only present on the first invocation - expect(TestInvocationLogs.parseFunctionLog(logs[0])).toEqual( + const neverBufferedLog = parsedLogs.find( + (log) => + log.level === 'DEBUG' && + log.message === 'a never buffered debug log' + ); + expect(neverBufferedLog).toEqual( expect.objectContaining({ level: 'DEBUG', message: 'a never buffered debug log', }) ); } - // Since we have an extra log (above) on the first invocation, we need to - // adjust the index of the logs we are checking - const logIndexOffset = isFirstInvocation ? 1 : 0; - const correlationId = i + 1; - expect( - TestInvocationLogs.parseFunctionLog(logs[0 + logIndexOffset]) - ).toEqual( + + // Find specific logs by content rather than position + const infoLog = parsedLogs.find( + (log) => log.level === 'INFO' && log.message === 'an info log' + ); + expect(infoLog).toEqual( expect.objectContaining({ level: 'INFO', message: 'an info log', @@ -132,9 +142,11 @@ describe('Logger E2E - Advanced uses', () => { correlation_id: correlationId, }) ); - expect( - TestInvocationLogs.parseFunctionLog(logs[1 + logIndexOffset]) - ).toEqual( + + const bufferedDebugLog = parsedLogs.find( + (log) => log.level === 'DEBUG' && log.message === 'a buffered debug log' + ); + expect(bufferedDebugLog).toEqual( expect.objectContaining({ level: 'DEBUG', message: 'a buffered debug log', @@ -142,9 +154,14 @@ describe('Logger E2E - Advanced uses', () => { correlation_id: correlationId, }) ); - expect( - TestInvocationLogs.parseFunctionLog(logs.at(-1) as string) - ).toEqual( + + const errorLog = parsedLogs.find( + (log) => + log.level === 'ERROR' && + log.message === + 'Uncaught error detected, flushing log buffer before exit' + ); + expect(errorLog).toEqual( expect.objectContaining({ level: 'ERROR', message: 'Uncaught error detected, flushing log buffer before exit',