Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 10, 2025

Problem

PR #52973 introduced a change that uses Push-Location to change the working directory to eng/common/tsp-client before invoking tsp-client. This causes issues because tsp-client makes assumptions based on the current working directory where it's executed.

Solution

This PR keeps Push-Location/Pop-Location for npm ci (which requires running from the tsp-client directory) but executes tsp-client using npm exec --prefix instead of running it from within the changed directory. This ensures:

  1. npm dependencies are installed correctly from the tsp-client directory
  2. tsp-client runs from the current working directory where it makes its assumptions
  3. The pinned tsp-client version from eng/common/tsp-client is used

Changes

Before:

Push-Location $tspClientDir
try {
    npm ci
    $tspclientCommand = "npm exec --no -- tsp-client init ..."
    Invoke-Expression $tspclientCommand
}
finally {
    Pop-Location
}

After:

Push-Location $tspClientDir
try {
    npm ci
}
finally {
    Pop-Location
}

$tspclientCommand = "npm exec --prefix $tspClientDir --no -- tsp-client init --update-if-exists ..."
Invoke-Expression $tspclientCommand

This ensures that tsp-client runs from the correct working directory where it can properly resolve paths and make its assumptions, while still using the pinned version from eng/common/tsp-client.

Fixes #53155

Original prompt

This section details on the original issue you should resolve

<issue_title>Don't change working directory in Invoke-GenerateAndBuildV2.ps1</issue_title>
<issue_description>#52973 changed the working directory before invoking tsp-client. This is a problem as tsp-client makes assumptions based on working directory. We need to just pass the path to the tsp-client to invoke.</issue_description>

Comments on the Issue (you are @copilot in this section)

Fixes #53155


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Replace Push-Location/Pop-Location with npm --prefix option to avoid changing the working directory before invoking tsp-client. This fixes the issue where tsp-client makes assumptions based on the working directory.

Co-authored-by: JoshLove-msft <[email protected]>
@JoshLove-msft JoshLove-msft marked this pull request as ready for review October 10, 2025 20:00
Copilot AI review requested due to automatic review settings October 10, 2025 20:00
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 a working directory issue in the PowerShell script Invoke-GenerateAndBuildV2.ps1 where the script was changing the working directory before invoking tsp-client, which caused problems because tsp-client makes assumptions based on the current working directory.

Key changes:

  • Removed the Push-Location/Pop-Location pattern that was changing the working directory
  • Used npm's --prefix option to specify the target directory without changing the current working directory
  • Maintained the same functionality while avoiding the working directory change issue

Copilot AI changed the title [WIP] Fix working directory change in Invoke-GenerateAndBuildV2.ps1 Fix: Don't change working directory when invoking tsp-client Oct 10, 2025
Copilot AI requested a review from JoshLove-msft October 10, 2025 20:01
Copilot finished work on behalf of JoshLove-msft October 10, 2025 20:01
Keep Push-Location for npm ci as required, but execute tsp-client using the full path to the binary. This ensures npm ci runs from the correct directory while tsp-client executes from the current working directory.

Co-authored-by: JoshLove-msft <[email protected]>
Keep Push-Location/Pop-Location for npm ci, then use npm exec --prefix to invoke tsp-client from the current working directory while using the pinned version from tsp-client directory.

Co-authored-by: JoshLove-msft <[email protected]>
Copilot finished work on behalf of JoshLove-msft October 10, 2025 20:21
@JoshLove-msft JoshLove-msft enabled auto-merge (squash) October 10, 2025 20:25
@JoshLove-msft
Copy link
Member

/check-enforcer evaluate

@JoshLove-msft JoshLove-msft merged commit 2863858 into main Oct 10, 2025
23 checks passed
@JoshLove-msft JoshLove-msft deleted the copilot/fix-invoke-generateandbuildv2 branch October 10, 2025 20:55
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.

Don't change working directory in Invoke-GenerateAndBuildV2.ps1

4 participants