Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 10, 2025

  • Understand the current implementation in Verify-Links.ps1
  • Implement the corrected npm URL replacement logic to handle:
    • Versioned URLs: https://www.npmjs.com/package/@azure/ai-agents/v/1.1.0https://registry.npmjs.org/@azure/ai-agents/1.1.0
    • Non-versioned URLs: https://www.npmjs.com/package/@azure/ai-agentshttps://registry.npmjs.org/@azure/ai-agents
  • Create tests to validate the new logic
  • Test the implementation manually
  • Address code review feedback (simplified regex pattern)
  • Fix regex to properly handle query parameters and URL fragments
  • Add comprehensive edge case test coverage
  • Update comment documentation
  • Address test helper function feedback
  • Run code review again
  • Run security scan with CodeQL

Summary

Successfully updated the npm URL replacement logic in eng/common/scripts/Verify-Links.ps1 to correctly handle both versioned and non-versioned npmjs package URLs.

Key Changes

  • Simplified regex pattern from ([^/]+(?:/[^/]+)?) to ([^?#]+) based on review feedback
  • Updated regex to properly exclude query parameters and URL fragments from transformation
  • Added comprehensive test coverage including edge cases (query params, fragments, trailing slashes)
  • Updated documentation to clarify how query parameters and fragments are handled
  • Enhanced test helper function documentation to explain its purpose

All 12 tests pass successfully. The implementation now correctly strips query parameters and fragments from URLs before transformation, ensuring accurate conversion to registry.npmjs.org URLs.

Original prompt

Update the link replacement logic introduced in PR #13281 to correctly handle npmjs package URLs for both versioned and non-versioned forms, with the following specific behavior:

Supported URL inputs:

Required behavior:

Acceptance criteria:

  • The replacement logic correctly identifies npmjs package links with and without a version segment ("/v/") and treats both as valid targets.
  • Versioned URLs are rewritten to preserve the version while removing the "/v" segment as described.
  • Non-versioned URLs remain unchanged and valid.
  • Add/adjust unit tests to cover both URL types and edge cases, including multiple version patterns (e.g., "1.1.0", "1.1.0-beta.1").
  • Run the repo’s link-check workflow or tests locally (if applicable) to confirm there are no regressions.
  • Update documentation/comments in the replacement script to clarify supported npm URL formats and the "/v" removal rule.

Notes:

  • The prior merged PR (Fix link checks to npm for packages #13281) fixed link checks to npm for packages; use it as a reference to find the code path(s) that perform the npm URL handling and enhance them.
  • Coordinate with existing repository conventions (e.g., regex helpers or URL utilities) to avoid duplicate logic.
  • Consider making the version recognition robust (e.g., semver and common prerelease/build metadata), while maintaining simplicity.

This pull request was created as a result of the following prompt from Copilot chat.

Update the link replacement logic introduced in PR #13281 to correctly handle npmjs package URLs for both versioned and non-versioned forms, with the following specific behavior:

Supported URL inputs:

Required behavior:

Acceptance criteria:

  • The replacement logic correctly identifies npmjs package links with and without a version segment ("/v/") and treats both as valid targets.
  • Versioned URLs are rewritten to preserve the version while removing the "/v" segment as described.
  • Non-versioned URLs remain unchanged and valid.
  • Add/adjust unit tests to cover both URL types and edge cases, including multiple version patterns (e.g., "1.1.0", "1.1.0-beta.1").
  • Run the repo’s link-check workflow or tests locally (if applicable) to confirm there are no regressions.
  • Update documentation/comments in the replacement script to clarify supported npm URL formats and the "/v" removal rule.

Notes:

  • The prior merged PR (Fix link checks to npm for packages #13281) fixed link checks to npm for packages; use it as a reference to find the code path(s) that perform the npm URL handling and enhance them.
  • Coordinate with existing repository conventions (e.g., regex helpers or URL utilities) to avoid duplicate logic.
  • Consider making the version recognition robust (e.g., semver and common prerelease/build metadata), while maintaining simplicity.

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits December 10, 2025 21:47
Co-authored-by: weshaggard <9010698+weshaggard@users.noreply.github.com>
Co-authored-by: weshaggard <9010698+weshaggard@users.noreply.github.com>
Copilot AI changed the title [WIP] Update link replacement logic for npm package URLs Fix npm package URL transformation to handle versioned URLs correctly Dec 10, 2025
Copilot AI requested a review from weshaggard December 10, 2025 21:53
# Handle non-versioned URLs: https://www.npmjs.com/package/@azure/ai-agents -> https://registry.npmjs.org/@azure/ai-agents
# The regex captures the package name (which may contain a slash for scoped packages) and optionally the version
$urlString = $linkUri.ToString()
if ($urlString -match '^https?://(?:www\.)?npmjs\.com/package/([^/]+(?:/[^/]+)?)/v/(.+)$') {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if ($urlString -match '^https?://(?:www\.)?npmjs\.com/package/([^/]+(?:/[^/]+)?)/v/(.+)$') {
if ($urlString -match '^https?://(?:www\.)?npmjs\.com/package/(.+)/v/(.+)$') {

@copilot you can simplify this regex with the suggestion.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Simplified the regex pattern as suggested. Commit a36dad8 changes ([^/]+(?:/[^/]+)?) to (.+) in both the main code and test helper function. All tests pass with the simplified pattern.

Co-authored-by: weshaggard <9010698+weshaggard@users.noreply.github.com>
@weshaggard
Copy link
Member

/azp run azure-sdk-tools - sync - eng-common

@weshaggard weshaggard marked this pull request as ready for review December 11, 2025 19:08
@weshaggard weshaggard requested a review from a team as a code owner December 11, 2025 19:08
Copilot AI review requested due to automatic review settings December 11, 2025 19:08
@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes the npm package URL transformation logic in the link verification script to correctly handle versioned npm package URLs. The implementation removes the literal "/v/" path segment from versioned URLs while preserving the version number, and maintains non-versioned URLs unchanged.

Key Changes:

  • Updated regex-based URL transformation in ProcessNpmLink function to handle both versioned and non-versioned npm package URLs
  • Added comprehensive test suite with 8 test cases covering scoped packages, unscoped packages, URLs with/without "www" prefix, and version variations

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
eng/common/scripts/Verify-Links.ps1 Replaced single-line regex transformation with conditional logic to handle versioned URLs (removing "/v/" segment) and non-versioned URLs separately
eng/common-tests/Verify-Links-ProcessNpmLink.Tests.ps1 Added new test file with 8 test cases validating URL transformations for various npm package URL formats

@azure-sdk
Copy link
Collaborator

The following pipelines have been queued for testing:
java - template
java - template - tests
js - template
net - template
net - template - tests
python - template
python - template - tests
You can sign off on the approval gate to test the release stage of each pipeline.
See eng/common workflow

Co-authored-by: weshaggard <9010698+weshaggard@users.noreply.github.com>
Copilot AI changed the title Fix npm package URL transformation to handle versioned URLs correctly Fix npm package URL transformation to handle versioned URLs and edge cases correctly Dec 11, 2025
Co-authored-by: weshaggard <9010698+weshaggard@users.noreply.github.com>
@weshaggard
Copy link
Member

/azp run azure-sdk-tools - sync - eng-common

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@weshaggard
Copy link
Member

/azp run azure-sdk-tools - sync - eng-common

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@azure-sdk
Copy link
Collaborator

The following pipelines have been queued for testing:
java - template
java - template - tests
js - template
net - template
net - template - tests
python - template
python - template - tests
You can sign off on the approval gate to test the release stage of each pipeline.
See eng/common workflow

weshaggard added a commit to Azure/azure-sdk-for-js that referenced this pull request Dec 11, 2025
Sync eng/common directory with azure-sdk-tools for PR
Azure/azure-sdk-tools#13307 See [eng/common
workflow](https://github.com/Azure/azure-sdk-tools/blob/main/eng/common/README.md#workflow)

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: weshaggard <9010698+weshaggard@users.noreply.github.com>
weshaggard added a commit to Azure/azure-sdk-for-rust that referenced this pull request Dec 11, 2025
Sync eng/common directory with azure-sdk-tools for PR
Azure/azure-sdk-tools#13307 See [eng/common
workflow](https://github.com/Azure/azure-sdk-tools/blob/main/eng/common/README.md#workflow)

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: weshaggard <9010698+weshaggard@users.noreply.github.com>
@weshaggard weshaggard merged commit 55604df into main Dec 11, 2025
6 of 8 checks passed
@weshaggard weshaggard deleted the copilot/update-npm-url-replacement-logic branch December 11, 2025 22:54
JiaqiZhang-Dev pushed a commit that referenced this pull request Dec 22, 2025
…cases correctly (#13307)

* Initial plan

* Fix npm URL replacement logic to handle versioned and non-versioned URLs

Co-authored-by: weshaggard <9010698+weshaggard@users.noreply.github.com>

* Refactor tests to reduce duplication with helper function

Co-authored-by: weshaggard <9010698+weshaggard@users.noreply.github.com>

* Simplify regex pattern as suggested by weshaggard

Co-authored-by: weshaggard <9010698+weshaggard@users.noreply.github.com>

* Fix regex to handle query params and fragments, add edge case tests

Co-authored-by: weshaggard <9010698+weshaggard@users.noreply.github.com>

* Improve test helper documentation per feedback

Co-authored-by: weshaggard <9010698+weshaggard@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: weshaggard <9010698+weshaggard@users.noreply.github.com>
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.

3 participants