-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Description
Please see the first comment on this issue for the proposed solution.
Description of Issue:
In investigating the symlink issue affecting Python testing in VS Code, I uncovered several contributing factors. The problem begins during the test discovery phase: the Python extension initiates a subprocess which uses the symlink as its current working directory (since the symlink or at least a path relative to the symlink workspace is set as the cwd). Then when node calls the python subprocess which run pytest discovery, Node resolves the symlink cwd to target path. This means the subprocess which pytest run on is on the target path of the symlinked workspace. Consequently, when the PyTest extension is activated, it encounters already-resolved symlinks. This leads to the collection of test data with paths relative to the symlink's target value, not its relative location. These paths are then utilized to populate the Test Explorer in VS Code. As a result, when a user attempts to open a file from the Test Explorer, VS Code erroneously navigates to the target path which is incorrect for the workspace since it is workspace opened at the location of a symlink. Also each test then has its path set as the target path to its file, instead of the symlink, meaning the test is no longer associated with the given workspace it is in.
Given these findings, a design decision is needed to address and rectify the symlink issue in the context of testing within VS Code. This decision will determine the most effective solution or workaround to ensure accurate and efficient test handling.
I will explore how other symlink items are handled in vscode but some ideas include:
- passing the symlink into the subprocess and having the plugin handle returning data relative to the symlink
- editing resulting data on the extension side to substitute symlinks in for the target link if present.
Test Case Design:
Below are the steps to make this problem occur for testing and as an example:
- in terminal cd to parent folder
parent - create folder inside parent
target_folderwith tests such astest_example.py(a file with a test inside) - from terminal create a symlink
ln -s target_folder symlink_to_target_folder - open vscode with the folder
symlink_to_target_foldercan be done withcode symlink_to_target_folderin terminal - run test discovery, test UI will be populated
- 🐛 the root folder will be
target_folderinstead ofsymlink_to_target_folderin the test explorer view - 🐛 click on "go to file" on a test, the incorrect file will be opened
- 🐛 try to run tests, nothing will happen
Notable Code:
-
const proc = spawn(file, args, spawnOptions);whenspawnOptionsin rawProcessApis.ts has a valuecwd. On thisspawncall, the symlink is resolved. -
here run requests are evaluated and tests included in the request and checked against known workspace folder to gather correct workspaces. This does not work correctly for symlinks. Code in controller.ts
if (request.include) {
uniq(request.include.map((r) => this.workspaceService.getWorkspaceFolder(r.uri))).forEach((w) => {
if (w) {
workspaces.push(w);
}
});
fs.lstatSync(workspaceFolderPath).isSymbolicLink();a way to check if a given workspace folder is a symlink, possible addition to the code.