[Test] Avoid unnecessary package manager install lock#2
Conversation
Co-authored-by: Ian Clanton-Thuon <iclanton@users.noreply.github.com>
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
libraries/rush-lib/src/logic/test/InstallHelpers.test.ts (1)
129-250: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winMissing test for the "invalid marker + no lock file" branch.
The two new tests cover marker-valid/no-lock (skip lock) and lock-file-present (acquire lock, dirty). Neither covers marker-invalid + no lock file present, which should still take the lock-acquisition path in
InstallHelpers.ts(Line 436). Worth adding to lock down this branch of the new conditional.🧪 Suggested additional test
it('acquires the global lock when the package manager marker is invalid', async () => { const rushGlobalFolder: RushGlobalFolder = getRushGlobalFolder(); // Do not call writeInstalledPackageManagerAsync, so no valid marker exists. const lockAcquireSpy: jest.SpyInstance = jest.spyOn(LockFile, 'acquireAsync').mockResolvedValue({ dirtyWhenAcquired: false, release: jest.fn() } as unknown as LockFile); const installSpy: jest.SpyInstance = jest .spyOn(Utilities, 'installPackageInDirectoryAsync') .mockResolvedValue(); const rushConfiguration: RushConfiguration = getRushConfiguration(); await InstallHelpers.ensureLocalPackageManagerAsync(rushConfiguration, rushGlobalFolder, 1, true); expect(lockAcquireSpy).toHaveBeenCalledTimes(1); expect(installSpy).toHaveBeenCalledTimes(1); });🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@libraries/rush-lib/src/logic/test/InstallHelpers.test.ts` around lines 129 - 250, Add a test in the ensureLocalPackageManagerAsync suite covering an invalid or missing package-manager marker with no lock file. Do not call writeInstalledPackageManagerAsync; mock LockFile.acquireAsync and Utilities.installPackageInDirectoryAsync, invoke the helper, and assert both are called once, confirming the lock-acquisition and installation path is used.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@libraries/rush-lib/src/logic/test/InstallHelpers.test.ts`:
- Around line 129-250: Add a test in the ensureLocalPackageManagerAsync suite
covering an invalid or missing package-manager marker with no lock file. Do not
call writeInstalledPackageManagerAsync; mock LockFile.acquireAsync and
Utilities.installPackageInDirectoryAsync, invoke the helper, and assert both are
called once, confirming the lock-acquisition and installation path is used.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 204d9b8e-c603-4abd-93e5-930392e92b6e
📒 Files selected for processing (4)
common/changes/@microsoft/rush/package-manager-install-lock_2026-06-23-13-27.jsonlibraries/rush-lib/src/api/LastInstallFlag.tslibraries/rush-lib/src/logic/installManager/InstallHelpers.tslibraries/rush-lib/src/logic/test/InstallHelpers.test.ts
Summary
This PR extracts the package-manager install lock optimization from microsoft#5830 into a standalone change.
Rush now skips acquiring the global package manager install lock when the requested package manager is already installed and no matching install lock file exists. If a lock file exists, Rush still acquires the lock to preserve stale/dirty recovery behavior.
Testing
node common/scripts/install-run-rush.js test --to @microsoft/rush-lib --verboseSummary by CodeRabbit