def test_stateful_file_operations(windows_bash_session, temp_work_dir):
    """Test file operations to verify runspace state persistence.

    This test verifies that:
    1. The working directory state persists between commands
    2. File operations work correctly relative to the current directory
    3. The runspace maintains state for path-dependent operations
    """
    abs_temp_work_dir = os.path.abspath(temp_work_dir)

    # 1. Create a subdirectory
    sub_dir_name = 'file_test_dir'
    sub_dir_path = Path(abs_temp_work_dir) / sub_dir_name

    # Use PowerShell to create directory
    create_dir_action = CmdRunAction(
        command=f'New-Item -Path "{sub_dir_name}" -ItemType Directory'
    )
    result = windows_bash_session.execute(create_dir_action)
    assert result.exit_code == 0

    # Verify directory exists on disk
    assert sub_dir_path.exists() and sub_dir_path.is_dir()

    # 2. Change to the new directory
    cd_action = CmdRunAction(command=f"Set-Location '{sub_dir_name}'")
    result = windows_bash_session.execute(cd_action)
    assert result.exit_code == 0
    # Check only the last directory component
    assert windows_bash_session._cwd.lower().endswith(f'\\{sub_dir_name.lower()}')

    # 3. Create a file in the current directory (which should be the subdirectory)
    test_content = 'This is a test file created by PowerShell'
    create_file_action = CmdRunAction(
        command=f'Set-Content -Path "test_file.txt" -Value "{test_content}"'
    )
    result = windows_bash_session.execute(create_file_action)
    assert result.exit_code == 0

    # 4. Verify file exists at the expected path (in the subdirectory)
    expected_file_path = sub_dir_path / 'test_file.txt'
    assert expected_file_path.exists() and expected_file_path.is_file()

    # 5. Read file contents using PowerShell and verify
    read_file_action = CmdRunAction(command='Get-Content -Path "test_file.txt"')
    result = windows_bash_session.execute(read_file_action)
    assert result.exit_code == 0
    assert test_content in result.content

    # 6. Go back to parent and try to access file using relative path
    cd_parent_action = CmdRunAction(command='Set-Location ..')
    result = windows_bash_session.execute(cd_parent_action)
    assert result.exit_code == 0
    # Check only the base name of the temp directory
    temp_dir_basename = os.path.basename(abs_temp_work_dir)
    assert windows_bash_session._cwd.lower().endswith(temp_dir_basename.lower())

    # 7. Read the file using relative path
    read_from_parent_action = CmdRunAction(
        command=f'Get-Content -Path "{sub_dir_name}/test_file.txt"'
    )
    result = windows_bash_session.execute(read_from_parent_action)
    assert result.exit_code == 0
    assert test_content in result.content

    # 8. Clean up
    remove_file_action = CmdRunAction(
        command=f'Remove-Item -Path "{sub_dir_name}/test_file.txt" -Force'
    )
    result = windows_bash_session.execute(remove_file_action)
    assert result.exit_code == 0
Test file operations to verify runspace state persistence.

    This test verifies that:
    1. The working directory state persists between commands
    2. File operations work correctly relative to the current directory
    3. The runspace maintains state for path-dependent operations
    
tests/unit/test_windows_bash.py