Skip to content

[Test] Avoid unnecessary package manager install lock#2

Open
EscapeB wants to merge 1 commit into
mainfrom
codex/package-manager-install-lock
Open

[Test] Avoid unnecessary package manager install lock#2
EscapeB wants to merge 1 commit into
mainfrom
codex/package-manager-install-lock

Conversation

@EscapeB

@EscapeB EscapeB commented Jul 21, 2026

Copy link
Copy Markdown
Owner

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 --verbose

Summary by CodeRabbit

  • Bug Fixes
    • Improved package manager setup to avoid unnecessary global locking and reinstallations when the requested package manager is already available.
    • Ensured installation locks are reliably released, including when installation encounters an error.
    • Preserved required setup steps while safely handling existing installation lock files.

Co-authored-by: Ian Clanton-Thuon <iclanton@users.noreply.github.com>
@coderabbitai

coderabbitai Bot commented Jul 21, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: cec606a8-f989-44a4-be87-30b3de0b8599

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • ✅ Review completed - (🔄 Check again to review again)
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

@EscapeB EscapeB changed the title [Test] [Test] Avoid unnecessary package manager install lock Jul 21, 2026
@EscapeB EscapeB closed this Jul 21, 2026
@EscapeB EscapeB reopened this Jul 21, 2026
@EscapeB EscapeB closed this Jul 21, 2026
@EscapeB EscapeB reopened this Jul 21, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
libraries/rush-lib/src/logic/test/InstallHelpers.test.ts (1)

129-250: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Missing 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

📥 Commits

Reviewing files that changed from the base of the PR and between 8d872db and f5d1d4b.

📒 Files selected for processing (4)
  • common/changes/@microsoft/rush/package-manager-install-lock_2026-06-23-13-27.json
  • libraries/rush-lib/src/api/LastInstallFlag.ts
  • libraries/rush-lib/src/logic/installManager/InstallHelpers.ts
  • libraries/rush-lib/src/logic/test/InstallHelpers.test.ts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant