def test_grep_to_cmdrun_paths_with_spaces(runtime_cls, run_as_openhands, temp_dir):
    """Test paths with spaces and special characters."""
    runtime, config = _load_runtime(temp_dir, runtime_cls, run_as_openhands)
    try:
        # Create test files with content in paths with spaces
        setup_cmd = """
        mkdir -p "src/my project" "test files/unit tests" "src/special$chars" "path with spaces and $pecial ch@rs" && \
        echo "function searchablePattern() { return true; }" > "src/my project/test.js" && \
        echo "function testFunction() { return 42; }" > "test files/unit tests/test.js" && \
        echo "function specialFunction() { return null; }" > "src/special$chars/test.js" && \
        echo "function weirdFunction() { return []; }" > "path with spaces and $pecial ch@rs/test.js"
        """
        obs = _run_cmd_action(runtime, setup_cmd)
        assert obs.exit_code == 0, 'Failed to set up test files'

        special_paths = [
            'src/my project',
            'test files/unit tests',
        ]

        for path in special_paths:
            # Generate grep command and execute it
            cmd = grep_to_cmdrun('function', path)
            assert 'rg -li' in cmd

            obs = _run_cmd_action(runtime, cmd)
            assert obs.exit_code == 0, f'Grep command failed for path: {path}'
            assert 'function' in obs.content, (
                f'Expected pattern not found in output for path: {path}'
            )

            # Verify the actual file was found
            if path == 'src/my project':
                assert 'src/my project/test.js' in obs.content
            elif path == 'test files/unit tests':
                assert 'test files/unit tests/test.js' in obs.content
    finally:
        _close_test_runtime(runtime)
Test paths with spaces and special characters.
tests/runtime/test_glob_and_grep.py