From a5193dafeadd3659d2df07e3718d68755d9ac76b Mon Sep 17 00:00:00 2001
From: Miles Budnek <miles.budnek@fortra.com>
Date: Fri, 15 Mar 2024 15:35:40 -0400
Subject: [PATCH] fix(workers/repository): Pass correct lock files when
 updating a dependency in multiple input files (#27898)

---
 .../update/branch/get-updated.spec.ts         | 75 +++++++++++++++++++
 .../repository/update/branch/get-updated.ts   | 12 ++-
 2 files changed, 85 insertions(+), 2 deletions(-)

diff --git a/lib/workers/repository/update/branch/get-updated.spec.ts b/lib/workers/repository/update/branch/get-updated.spec.ts
index 123485920d..04a20633fd 100644
--- a/lib/workers/repository/update/branch/get-updated.spec.ts
+++ b/lib/workers/repository/update/branch/get-updated.spec.ts
@@ -205,6 +205,81 @@ describe('workers/repository/update/branch/get-updated', () => {
       });
     });
 
+    it('for updatedArtifacts passes proper lockFiles', async () => {
+      config.upgrades.push({
+        packageFile: 'composer.json',
+        manager: 'composer',
+        branchName: '',
+      });
+      config.lockFiles = ['different.lock'];
+      config.packageFiles = {
+        composer: [
+          {
+            packageFile: 'composer.json',
+            lockFiles: ['composer.lock'],
+            deps: [],
+          },
+        ] satisfies PackageFile[],
+      };
+      autoReplace.doAutoReplace.mockResolvedValueOnce('some new content');
+      composer.updateArtifacts.mockResolvedValueOnce([
+        {
+          file: {
+            type: 'addition',
+            path: 'composer.lock',
+            contents: 'some contents',
+          },
+        },
+      ]);
+      await getUpdatedPackageFiles(config);
+      expect(composer.updateArtifacts).toHaveBeenCalledWith(
+        expect.objectContaining({
+          config: expect.objectContaining({
+            lockFiles: ['composer.lock'],
+          }),
+        }),
+      );
+    });
+
+    it('for nonUpdatedArtifacts passes proper lockFiles', async () => {
+      config.upgrades.push({
+        packageFile: 'composer.json',
+        manager: 'composer',
+        branchName: '',
+        isLockfileUpdate: true,
+      });
+      composer.updateLockedDependency.mockReturnValueOnce({
+        status: 'unsupported',
+      });
+      config.lockFiles = ['different.lock'];
+      config.packageFiles = {
+        composer: [
+          {
+            packageFile: 'composer.json',
+            lockFiles: ['composer.lock'],
+            deps: [],
+          },
+        ] satisfies PackageFile[],
+      };
+      composer.updateArtifacts.mockResolvedValueOnce([
+        {
+          file: {
+            type: 'addition',
+            path: 'composer.lock',
+            contents: 'some contents',
+          },
+        },
+      ]);
+      await getUpdatedPackageFiles(config);
+      expect(composer.updateArtifacts).toHaveBeenCalledWith(
+        expect.objectContaining({
+          config: expect.objectContaining({
+            lockFiles: ['composer.lock'],
+          }),
+        }),
+      );
+    });
+
     it('for lockFileMaintenance passes proper lockFiles', async () => {
       config.upgrades.push({
         manager: 'composer',
diff --git a/lib/workers/repository/update/branch/get-updated.ts b/lib/workers/repository/update/branch/get-updated.ts
index b036b178d9..c79924d2ed 100644
--- a/lib/workers/repository/update/branch/get-updated.ts
+++ b/lib/workers/repository/update/branch/get-updated.ts
@@ -302,7 +302,11 @@ export async function getUpdatedPackageFiles(
           updatedDeps,
           // TODO #22198
           newPackageFileContent: packageFile.contents!.toString(),
-          config,
+          config: patchConfigForArtifactsUpdate(
+            config,
+            manager,
+            packageFile.path,
+          ),
         });
         processUpdateArtifactResults(results, updatedArtifacts, artifactErrors);
       }
@@ -329,7 +333,11 @@ export async function getUpdatedPackageFiles(
           updatedDeps,
           // TODO #22198
           newPackageFileContent: packageFile.contents!.toString(),
-          config,
+          config: patchConfigForArtifactsUpdate(
+            config,
+            manager,
+            packageFile.path,
+          ),
         });
         processUpdateArtifactResults(results, updatedArtifacts, artifactErrors);
         if (is.nonEmptyArray(results)) {
-- 
GitLab