rust-lang / rust-lang/mdBook

GUI tests fail locally on Windows due to pathing and execution bugs

Open
#3,067 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug
Dominant language
Rust
Stars
22.2k
Forks
1.9k
PR merge metrics
PR metrics pending

Description

Problem

Running cargo test --test gui fails completely on Windows machines. I dug into tests/gui/runner.rs and found three distinct Windows-specific issues preventing the headless browser tests from running:

1. npm and npx commands not found
Rust's Command::new("npm") fails on Windows because the executables are actually batch files (npm.cmd).

2. Drive letters break the version parser
The parser does l.split(':').nth(1) expecting the version after the first :. However, Windows paths have a drive letter (e.g., V:\), so nth(1) returns the path segment instead of the version. This causes the browser-ui-test version check to panic with "not installed".

3. Backslash separators break DOC_PATH in redirect tests
out_dir.display() on Windows returns backslashes (V:\coding\...). The headless browser receives file://V:\coding\... but reports file:///V:/coding/... — causing redirect.goml to fail on every run due to a string mismatch.

Expected Behavior
Running cargo test --test gui should execute the test suite locally on Windows machines without panicking on OS-specific pathing or command formatting.

Steps
  1. On a Windows machine with Rust and Node/npm installed, clone the repository.
  2. Run npm install in the root directory.
  3. Run cargo test --test gui.
  4. Result: Immediate panic on npm command not found. (If patched manually, it subsequently panics on the version parser, and then fails the redirect test).
Possible Solution(s)

1. Add a helper for Windows .cmd resolution:

fn npm_cmd(name: &str) -> Command {
    if cfg!(windows) {
        let mut cmd = Command::new("cmd");
        cmd.args(["/C", &format!("{}.cmd", name)]);
        cmd
    } else {
        Command::new(name)
    }
}

Use npm_cmd("npm") and npm_cmd("npx") in place of
Command::new("npm") / Command::new("npx").

2. Fix drive letter breaking version parse:

Change nth(1) to last() so it grabs the version string
regardless of drive letters.

l.split(':').last()?.strip_prefix("browser-ui-test@")

3. Fix path separators in DOC_PATH:

Normalize slashes before formatting the file URI.

let out_dir_str = out_dir.display().to_string().replace('\\', "/");
let mut doc_path = format!("file:///{}", out_dir_str);
Notes
  • Environment: Windows 11, PowerShell, Rust stable (msvc), Node 24, npm 10.
  • Willingness to contribute: I have all three fixes working locally. All 19 GUI tests pass flawlessly on my Windows machine after applying these changes. I am happy to submit a PR if this is something the team would like addressed!
Version
0.5.2

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in tests/gui/runner.rs and reproduce the failure with npm install followed by cargo test --test gui on Windows. Check the command execution, version parsing, and redirect path handling described in the issue; done means all 19 GUI tests pass locally without Windows-specific panics or redirect mismatches.

Written by the indexing model from the issue text.

Assessment

Tech stack
node.js, rust
Domain
operating-systems, testing-qa
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
72/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.