Skip to content

Reporter crashes on WSL when tests call Windows .exe binaries #351

@mrdavidlaing

Description

@mrdavidlaing

Description

The ShellSpec reporter crashes when tests call Windows .exe binaries from WSL, despite all tests passing successfully. The reporter's protocol parser gets corrupted during the WSL → Windows process boundary crossing, causing an arithmetic syntax error.

Error Message

Finished in 0.45 seconds
1 example, 0 failures, aborted by an unexpected error

Aborted with status code [executor: 0] [reporter: 1] [error handler: 0]
Fatal error occurred, terminated with exit status 1.

Environment

Affected:

  • Platform: WSL2 (Windows Subsystem for Linux)
  • ShellSpec version: 0.28.1
  • Shell: GNU bash, version 5.3.3(1)-release (x86_64-pc-linux-gnu)
  • Kernel: Linux 5.15.167.4-microsoft-standard-WSL2

NOT Affected:

  • Native Linux (ubuntu-latest, archlinux) - tests pass cleanly
  • macOS - tests pass cleanly
  • Native Windows PowerShell - no reporter crashes

Root Cause

When tests call Windows .exe binaries from WSL:

  1. ShellSpec reporter running in WSL
  2. Test calls .exe binary (WSL → Windows process boundary)
  3. Output/error streams cross back (Windows → WSL)
  4. Reporter's protocol parser gets corrupted

The control characters or stream buffering across the WSL → Windows boundary corrupts ShellSpec's internal protocol stream, causing the reporter to fail.

Minimal Reproduction

#!/bin/bash

Describe "WSL boundary test"
  It "calls Windows .exe binary"
    pwsh.exe -NoProfile -Command ":" > /dev/null 2>&1 || true
    When run echo "test"
    The output should equal "test"
  End
End

Result on WSL:

1 example, 0 failures, aborted by an unexpected error
Exit code: 1

Result on native Linux:

1 example, 0 failures
Exit code: 0

Affected Binaries

The bug is triggered by ANY Windows .exe binary called from WSL:

  • pwsh.exe (Windows PowerShell)
  • cmd.exe (Windows Command Prompt)
  • where.exe (Windows utility)
  • hostname.exe (Windows utility)
  • Any other Windows executable

It is NOT specific to:

  • Binary content inspection (od, tail -c)
  • File operations
  • Temp file creation
  • Specific test patterns

Expected Behavior

The reporter should handle output from cross-platform process calls gracefully and exit with code 0 when all tests pass.

Actual Behavior

The reporter's protocol parser receives corrupted stream data, causing it to crash with exit code 1 despite all tests passing (0 failures).

Scope

  • WSL-specific: Only affects users running ShellSpec on WSL
  • Trigger: Only when tests call Windows .exe binaries
  • Impact: Tests pass correctly, but reporter crashes (CI/CD fails on exit code)

Workaround

Install native Linux versions of tools instead of calling Windows binaries via WSL:

# Example: Install native Linux PowerShell
sudo apt-get install -y powershell

# Verify
command -v pwsh
# Should output: /usr/bin/pwsh (not /mnt/c/...)

When native Linux binaries are used, the WSL → Windows boundary is avoided and the reporter works correctly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions