Skip to content

Ruby LSP Test Runner - Windows Path Normalization Bug #3881

@chris-olsen-s2s

Description

@chris-olsen-s2s

On Windows, the Test Explorer runs tests successfully but never receives results - the spinner keeps spinning indefinitely and test status never updates. This is caused by a path normalization mismatch when looking up the reporter port from the temp database.

Environment

  • OS: Windows 10/11
  • Ruby: 3.4.0 (via RubyInstaller)
  • ruby-lsp: 0.26.4
  • ruby-lsp-rspec: 0.1.28
  • VS Code: Latest
  • Ruby LSP Extension: Latest

Root Cause

The LSP reporter stores paths in test_reporter_port_db.json with Windows-style backslashes and lowercase drive letters:

{
  "d:\\source\\repos\\myproject": 12345
}

However, Ruby's Dir.pwd returns forward slashes with uppercase drive letters:

Dir.pwd
# => "D:/source/repos/myproject"

When lsp_reporter.rb looks up the port using Dir.pwd directly, the hash lookup fails due to this mismatch. The code then silently falls back to a no-op StringIO, so tests execute but results are never sent back to VS Code.

Steps to Reproduce

  1. Open a Ruby/Rails project on Windows in VS Code
  2. Ensure ruby-lsp and ruby-lsp-rspec are in your Gemfile
  3. Open a spec file
  4. Click "Run" on a test via CodeLens or Test Explorer
  5. Observe: Tests run in terminal, but Test Explorer spinner never stops and results aren't shown

Expected Behavior

Test results should be reported back to VS Code Test Explorer, showing pass/fail status for each test.

Actual Behavior

  • Tests execute successfully (visible in terminal output)
  • Test Explorer spinner keeps spinning indefinitely
  • No pass/fail indicators appear
  • No error messages are shown (silent failure)

Suggested Fix

Normalize paths before the hash lookup in the LSP reporter. Something like:

# Before lookup, normalize Dir.pwd to match database format
def normalized_working_directory
  if Gem.win_platform?
    Dir.pwd.gsub('/', '\\').sub(/^([A-Z]):/) { $1.downcase + ':' }
  else
    Dir.pwd
  end
end

Or alternatively, normalize both the stored paths and lookup paths to a canonical format (e.g., forward slashes, lowercase on Windows).

Workaround

Add this to the top of spec/spec_helper.rb (before any other requires):

# Workaround for ruby-lsp Windows path mismatch
# See: https://github.com/Shopify/ruby-lsp/issues/XXXX
if ENV['RUBY_LSP_TEST_RUNNER'] && !ENV['RUBY_LSP_REPORTER_PORT']
  require 'tmpdir'
  require 'json'
  port_db_path = File.join(Dir.tmpdir, 'ruby-lsp', 'test_reporter_port_db.json')
  if File.exist?(port_db_path)
    db = JSON.load_file(port_db_path)
    # Normalize current directory to match database format (backslashes, lowercase drive)
    normalized_pwd = Dir.pwd.gsub('/', '\\').sub(/^([A-Z]):/) { Regexp.last_match(1).downcase + ':' }
    ENV['RUBY_LSP_REPORTER_PORT'] = db[normalized_pwd].to_s if db[normalized_pwd]
  end
end

This manually sets the RUBY_LSP_REPORTER_PORT environment variable with the correct port by doing the path normalization that the LSP reporter should be doing.

Additional Context

This issue makes the VS Code Test Explorer integration completely non-functional on Windows. The silent fallback to StringIO makes debugging very difficult - there are no error messages indicating why results aren't being reported.

The fix should be straightforward since it's purely a path string normalization issue. Happy to submit a PR if pointed to the right location in the codebase.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions