robotcodedev / robotcode

RobotFramework support for Visual Studio Code
https://robotcode.io
Apache License 2.0
168 stars 13 forks source link

[BUG] Windows Mapped Drives Are Not Understood Properly #219

Closed GLMeece closed 2 months ago

GLMeece commented 4 months ago

Summary

RobotCode ignores a mapped drive's pathing and instead uses a full UNC pathing, resulting in a test suite file not being located properly.

Detail

If you have your repo on a mapped network drive (in my case, via VMware's Shared Folders), although your tests are "discovered", when you click on the Go to Test (Alt+Enter) icon, instead of using the Windows mapping (e.g., e:\Repos\windows-qa-automation) it attempts to use the full UNC pathing (e.g. /Shared folders/Repos/windows-qa-automation/tests/MYSUITENAMEHERE.robot).

Because Windows can't find it, it asks the user if they want to create it.

Additionally, in opening up the suite, the test cases are formatted/discovered properly, but you cannot execute the test cases by clicking on a 'run' arrow.

Prerequisites

* FWIW, In the author's case, it is a Windows 11 Virtual Machine running under VMware Workstation Pro 17.5

Steps to Reproduce

Scenario 1 - code.exe CLI

Note: The author will provide other scenarios as time permits; simply trying to describe the initial scenario here.

  1. Launch a PowerShell console, and map the shared repo directory as a Windows drive (see example above)
  2. Run the Code CLI in tunnel mode: .\code.exe tunnel (if you've not authorized this tunnel before, you'll need to do so via GitHub)
  3. Connect to this tunnel via VS Code desktop or via https://vscode.dev/
  4. Make sure you have the following extensions activated:
    • Python
    • Pylance
    • RobotCode
  5. Click on the 'flask' icon to discover tests (they are discovered as shown below)
  6. Find a test you're interested in; click the Go to Test (Alt+Enter) icon

Issue: VS Code/RobotCode attempts to open the file as a UNC path vs. a file on a mapped drive. The result is that the test cannot be executed.

Screenshots

Tests discovered - repo name is 'doubled'

robot_code_test_discovery_doubling_repo_name

Robocorp LSP Example:

robocorp_lsp_tests

Video Screen Captures

Note: GIF "videos" are more easily seen if opened in new tab.

Robocorp's LSP Under Scenario 1

robocorp_behavior

Robotcode Under Scenario 1

robotcode_behavior

Expected Behavior

Using Robocorp's LSP, the tests are discovered, you are able to go to the file/test case in question, execute and debug the test.

I would expect the same behavior with RobotCode.

VS Code Output Logs

RobotCode

executeRobotCode: C:\Users\TestUser\.virtualenvs\windows-qa-automation-JN6Q2o76\Scripts\python.exe -u -X utf8 c:\Users\TestUser\.vscode-server\extensions\d-biehl.robotcode-0.75.0\bundled\tool\robotcode --format json --no-color --no-pager discover info
Error: Can't get items for keywords treeview: Error: Request canceled.
executeRobotCode: exit code 0
executeRobotCode: exit code 0
executeRobotCode: C:\Users\TestUser\.virtualenvs\windows-qa-automation-JN6Q2o76\Scripts\python.exe -u -X utf8 c:\Users\TestUser\.vscode-server\extensions\d-biehl.robotcode-0.75.0\bundled\tool\robotcode --format json --no-color --no-pager --default-path . profiles list
executeRobotCode: exit code 0
executeRobotCode: exit code 0
executeRobotCode: exit code 0
Error: Can't get items for keywords treeview: Error: Request canceled.

RobotCode Language Server

none

Environment

d-biehl commented 4 months ago

I use the Python method pathlib.Path.resolve in some places to get a normalized file name. Depending on how the command line parameters are, I sometimes have absolute paths or relative paths, which can also contain things like .., under Windows even the upper/lower case is irrelevant. But since VSCode internally only works with URI's and these can only be absolute paths and are also case sensitive when comparing, I need a way to make sure that a filename I supply to VSCode is absolute and normalized. Unfortunately, the python method pathlib.Path.resolve has the habit of resolving symbolic links. And you can't turn it off.

In os.path there is also no real way to do this without the symbolic link resolution.

Maybe someone knows an algorithm, function or something else in Python that can do this?

Otherwise I'll have to write one myself.

But problem recognized, I know what to do, but maybe it takes a litte time...

d-biehl commented 4 months ago

Tests discovered - repo name is 'doubled'

image

In contrast to RFLS, RobotCode uses RobotFramework algorithms to recognize which suites/test cases/tasks are in the project. Therefore, the test case structure in RobotCode looks and behaves exactly the same as in RobotFramework execution/reports or logs. You can even use --include --exclude or PreRunModifier if you define them in the (attention spoiler) robot.toml.

And with RobotCode you can open several RobotFramework projects/folders in the same workspace, all of which have completely different Python interpreters, RobotFramework versions etc.. Therefore the top node is the folder/project name, the second node is not duplicated, but the suite name of RobotFramework. You can also customize the name of the suite via command line, (spoiler) robot.toml file, or also with name in *** Settings ***, but also define paths where RobotCode should search for test cases, this corresponds to the call robot folder1 folder2.