Skip to content

Conversation

@SMoraisAnsys
Copy link
Contributor

@SMoraisAnsys SMoraisAnsys commented Nov 6, 2025

Description

When running on windows, the process username() can contain the DOMAIN which makes the comparison fail.

Issue linked

None

Checklist

When running on windows, the process `username()` can contain the DOMAIN which makes the comparison fail.
Copilot AI review requested due to automatic review settings November 6, 2025 14:31
@SMoraisAnsys SMoraisAnsys requested a review from a team as a code owner November 6, 2025 14:31
@SMoraisAnsys SMoraisAnsys self-assigned this Nov 6, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes a Windows-specific bug in the process access check where username comparison fails when the process username includes a domain prefix (e.g., "DOMAIN\username"). The fix extracts the username portion after the backslash on Windows systems.

Key changes:

  • Added platform-specific handling for Windows usernames in _can_access_process()
  • Extracts username from "DOMAIN\username" format by splitting on backslash

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 197 to 198
if os.name == 'nt' and '\\' in process_user:
return current_user == process_user.split('\\')[-1]
Copy link

Copilot AI Nov 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current_user from getpass.getuser() on Windows may also include the domain prefix (e.g., 'DOMAIN\username'). Both usernames should be normalized to extract only the username portion for consistent comparison. Consider splitting current_user as well: current_user.split('\\\\')[-1] == process_user.split('\\\\')[-1]

Suggested change
if os.name == 'nt' and '\\' in process_user:
return current_user == process_user.split('\\')[-1]
if os.name == 'nt':
# Normalize both current_user and process_user to remove domain prefix if present
return current_user.split('\\')[-1] == process_user.split('\\')[-1]

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't able to produce a case where getpass.getuser() contains the DOMAIN so I'm not sure if it makes sense to use it. @germa89 Do you know if copilot can easily hallucinate / overthink when proposing changes ?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mmhh it does sometimes. I wouldn't bother, if you think the suggestion is not relevant, just discard it.

# Check if we can access basic process info and if it belongs to current user
current_user = getpass.getuser()
process_user = proc.username()
if os.name == 'nt' and '\\' in process_user:
Copy link

Copilot AI Nov 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Consider using platform.system() == 'Windows' instead of os.name == 'nt' for better readability and clarity, or check both usernames for domain prefixes regardless of platform to make the logic more robust.

Suggested change
if os.name == 'nt' and '\\' in process_user:
if '\\' in process_user:

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if that behavior can happen on Linux, at least I wasn't able to reproduce it

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know either, so let's keep it simple :)

@github-actions github-actions bot added the bug Issue, problem or error in PyMAPDL label Nov 6, 2025
current_user = getpass.getuser()
process_user = proc.username()
if platform.system() == "Windows" and "\\" in process_user:
return current_user == process_user.split("\\")[-1]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we should check the domain then too... but I am not sure if that is even the logical thing to do.

Copy link
Collaborator

@germa89 germa89 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I forgot to mention, you should add a test for this please :)

@codecov
Copy link

codecov bot commented Nov 6, 2025

Codecov Report

❌ Patch coverage is 66.66667% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 91.26%. Comparing base (e6ca79f) to head (60ad376).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4293      +/-   ##
==========================================
- Coverage   91.29%   91.26%   -0.04%     
==========================================
  Files         193      193              
  Lines       15742    15745       +3     
==========================================
- Hits        14372    14370       -2     
- Misses       1370     1375       +5     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@SMoraisAnsys
Copy link
Contributor Author

@germa89 The current implementation of the tests do not allow me to test without having mapdl installed (or that's my understand from the need to provide a path for ansysxxx). Would you like me to update the current test so that it patches a few pymapdl commands and runs without requiring any local install ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Issue, problem or error in PyMAPDL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants