Skip to content

Avoid redundant Az module root on GitHub-hosted runners - #648

Draft
Nathan McNulty (nathanmcnulty) wants to merge 1 commit into
Azure:masterfrom
nathanmcnulty:fix/psmodulepath-hosted-runner-review
Draft

Nathan McNulty (nathanmcnulty) wants to merge 1 commit into
Azure:masterfrom
nathanmcnulty:fix/psmodulepath-hosted-runner-review

Conversation

@nathanmcnulty

Copy link
Copy Markdown

With enable-AzPSSession enabled, Azure/login prepends the broad default module root even when GitHub-hosted images already expose the installed Az directories directly. Skip that prepend on GitHub-hosted runners when the root or an existing direct child containing Az.Accounts is already on PSModulePath. Preserve the existing prepend and root precedence for self-hosted, unknown, and unspecified runner environments. PowerShell module discovery and manifest-version selection remain unchanged.

Adds tests for private-runner precedence and direct-child boundaries. Validation of this exact source-only candidate:

  • All 61 Jest tests pass on native Windows with Node 24.21.0 and PowerShell 7.4.20 and 7.6.6, and on native Linux with Node 24.19.0 and PowerShell 7.6.6.
  • Main and cleanup builds succeed and reproduce identical hashes on both platforms. Generated lib/ output is omitted under the repository's source-only policy.
  • PowerShell 7.7.0-preview.5 passes all 61 tests on Windows as an edge-case check; this does not introduce a preview support requirement.
  • Baseline/candidate discovery and import checks pass with real Az.Accounts 5.5.3, including inherited paths from Windows PowerShell 5.1. No fresh live Azure authentication was performed.
  • tsc --noEmit --skipLibCheck passes. Plain tsc --noEmit reports identical existing TypeScript 4.9 / @types/node 24 declaration errors on baseline and candidate; this PR does not change dependencies.

The September reproduction measured first pwsh startup at 4.48 s mean with image defaults versus 25.40 s with /usr/share prepended, across ten fresh Ubuntu jobs per arm. These historical measurements motivate the guard; they are not fresh timing results for this revised commit.

Fixes #646.

Copilot AI balanced review requested due to automatic review settings October 11, 2026 05:49

Copilot AI 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.

🟡 Changes recommended

Raw path comparisons miss equivalent trailing-separator and Windows case variants, retaining the targeted slowdown.

1 open finding
What changed in this PR

Optimizes PowerShell module discovery on GitHub-hosted runners by avoiding redundant broad module roots.

Changes:

  • Detects reachable Az.Accounts module paths before prepending.
  • Preserves existing behavior for non-hosted runners.
  • Adds hosted, self-hosted, and path-boundary tests.
File Description
src/​PowerShell/​AzPSUtils.ts Adds the hosted-runner path guard.
__tests__/​PowerShell/​AzPSUtils.test.ts Tests path handling and runner environments.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +45 to +50
const entries = (process.env.PSModulePath || '').split(path.delimiter);
if (isGitHubHosted && entries.some(entry => entry === psModulePath ||
(path.dirname(entry) === psModulePath && fs.existsSync(path.join(entry, AzPSConstants.AzAccounts))))) {
core.debug(`Skip setting the default PowerShell module path, ${psModulePath} is already reachable.`);
return;
}

This branch has not been deployed

No deployments
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.

enable-AzPSSession slows hosted Linux runners by prepending /usr/share

2 participants