From 13a21fdf37fab8631d459852e36c241b41c5c4e5 Mon Sep 17 00:00:00 2001 From: sarankumar1325 <120080287+sarankumar1325@users.noreply.github.com> Date: Fri, 30 Oct 2026 14:32:23 +0000 Subject: [PATCH] fix: await hasConfigurationChanged before deciding to update the configuration hasConfigurationChanged() is async, but run() called it without await. The pending Promise is always truthy, so UpdateFunctionConfiguration ran on every deploy, and with dry-run enabled the action returned at "Configuration updates are not simulated" without ever doing the DryRun code update. Await the result and rebuild dist/. Add tests that go through run() with the real comparison: unchanged config skips the update, a changed input still updates, and dry run reaches the DryRun code update. Fixes #76 --- __tests__/run_config_change_detection.test.js | 90 +++++++++++++++++++ dist/index.js | 2 +- index.js | 2 +- 3 files changed, 92 insertions(+), 2 deletions(-) create mode 100644 __tests__/run_config_change_detection.test.js diff --git a/__tests__/run_config_change_detection.test.js b/__tests__/run_config_change_detection.test.js new file mode 100644 index 0000000..8e3791b --- /dev/null +++ b/__tests__/run_config_change_detection.test.js @@ -0,0 +1,90 @@ +const core = require('@actions/core'); +const { + LambdaClient, + UpdateFunctionConfigurationCommand, + UpdateFunctionCodeCommand +} = require('@aws-sdk/client-lambda'); +const mainModule = require('../index'); +const validations = require('../validations'); + +jest.mock('@actions/core'); +jest.mock('@aws-sdk/client-lambda'); +jest.mock('@aws-sdk/client-s3'); +jest.mock('@aws-sdk/client-sts'); + +// These tests go through run() with the real hasConfigurationChanged(), so +// they catch the result of the comparison being ignored (for example when +// the async function is called without await and the pending Promise is +// treated as "changed"). +describe('run() configuration change detection', () => { + const currentConfig = { + FunctionName: 'test-function', + PackageType: 'Image', + MemorySize: 512, + Timeout: 60, + Environment: { Variables: { ENV: 'production' } }, + State: 'Active', + LastUpdateStatus: 'Successful' + }; + + let mockSend; + + const setInputs = (overrides = {}) => { + validations.validateAllInputs = jest.fn().mockReturnValue({ + valid: true, + functionName: 'test-function', + packageType: 'Image', + imageUri: '123456789012.dkr.ecr.us-east-1.amazonaws.com/repo:latest', + parsedMemorySize: 512, + timeout: 60, + parsedEnvironment: { ENV: 'production' }, + dryRun: false, + ...overrides + }); + }; + + beforeEach(() => { + jest.clearAllMocks(); + process.env.AWS_REGION = 'us-east-1'; + mockSend = jest.fn().mockImplementation(async () => ({ + ...currentConfig, + FunctionArn: 'arn:aws:lambda:us-east-1:123456789012:function:test-function', + Version: '$LATEST' + })); + LambdaClient.mockImplementation(() => ({ send: mockSend })); + }); + + test('does not update the configuration when nothing changed', async () => { + setInputs(); + + await mainModule.run(); + + expect(core.setFailed).not.toHaveBeenCalled(); + expect(core.info).toHaveBeenCalledWith('No configuration changes detected'); + expect(UpdateFunctionConfigurationCommand).not.toHaveBeenCalled(); + expect(UpdateFunctionCodeCommand).toHaveBeenCalledTimes(1); + }); + + test('updates the configuration when an input differs', async () => { + setInputs({ parsedMemorySize: 1024 }); + + await mainModule.run(); + + expect(core.setFailed).not.toHaveBeenCalled(); + expect(UpdateFunctionConfigurationCommand).toHaveBeenCalledTimes(1); + expect(UpdateFunctionConfigurationCommand.mock.calls[0][0]).toHaveProperty('MemorySize', 1024); + expect(UpdateFunctionCodeCommand).toHaveBeenCalledTimes(1); + }); + + test('dry run still validates the code update when nothing changed', async () => { + setInputs({ dryRun: true }); + + await mainModule.run(); + + expect(core.setFailed).not.toHaveBeenCalled(); + expect(core.info).not.toHaveBeenCalledWith('[DRY RUN] Configuration updates are not simulated in dry run mode'); + expect(UpdateFunctionConfigurationCommand).not.toHaveBeenCalled(); + expect(UpdateFunctionCodeCommand).toHaveBeenCalledTimes(1); + expect(UpdateFunctionCodeCommand.mock.calls[0][0]).toHaveProperty('DryRun', true); + }); +}); diff --git a/dist/index.js b/dist/index.js index 61dc86e..a0c4ddb 100644 --- a/dist/index.js +++ b/dist/index.js @@ -104,7 +104,7 @@ async function run() { return; } - const configChanged = hasConfigurationChanged(currentConfig, { + const configChanged = await hasConfigurationChanged(currentConfig, { ...(role && { Role: role }), // Only include handler, runtime, and layers for Zip package type ...(packageType === 'Zip' && handler && { Handler: handler }), diff --git a/index.js b/index.js index 686c883..e3e2078 100644 --- a/index.js +++ b/index.js @@ -98,7 +98,7 @@ async function run() { return; } - const configChanged = hasConfigurationChanged(currentConfig, { + const configChanged = await hasConfigurationChanged(currentConfig, { ...(role && { Role: role }), // Only include handler, runtime, and layers for Zip package type ...(packageType === 'Zip' && handler && { Handler: handler }),