-
Notifications
You must be signed in to change notification settings - Fork 61
fix(ssh): add optional remote_root auto-creation #590
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
njzjz-bot
wants to merge
1
commit into
deepmodeling:master
Choose a base branch
from
njzjz-bot:fix/issue-436-create-remote-root
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| import os | ||
| import sys | ||
| import unittest | ||
| from unittest.mock import MagicMock | ||
|
|
||
| sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))) | ||
| __package__ = "tests" | ||
|
|
||
| from .context import SSHContext, setUpModule # noqa: F401 | ||
|
|
||
|
|
||
| class TestSSHCreateRemoteRoot(unittest.TestCase): | ||
| def test_recursive_mkdir_disabled_by_default(self): | ||
| calls = [] | ||
| context = SSHContext.__new__(SSHContext) | ||
| context.ssh_session = MagicMock() | ||
| context.ssh_session.sftp = MagicMock() | ||
| context.ssh_session.sftp.mkdir.side_effect = lambda path: calls.append(path) | ||
|
|
||
| context._mkdir("/data/home/user/work", recursive=False) | ||
|
|
||
| self.assertEqual(calls, ["/data/home/user/work"]) | ||
|
|
||
| def test_recursive_mkdir_creates_missing_parents(self): | ||
| calls = [] | ||
| context = SSHContext.__new__(SSHContext) | ||
| context.ssh_session = MagicMock() | ||
| context.ssh_session.sftp = MagicMock() | ||
|
|
||
| def mkdir(path): | ||
| calls.append(path) | ||
| if path in {"/data", "/data/home/user/work"}: | ||
| raise OSError("already exists") | ||
|
|
||
| context.ssh_session.sftp.mkdir.side_effect = mkdir | ||
|
|
||
| context._mkdir("/data/home/user/work", recursive=True) | ||
|
|
||
| self.assertEqual( | ||
| calls, | ||
| [ | ||
| "/data", | ||
| "/data/home", | ||
| "/data/home/user", | ||
| "/data/home/user/work", | ||
| ], | ||
| ) | ||
|
|
||
| def test_machine_roundtrip_keeps_create_remote_root(self): | ||
| machine_dict = { | ||
| "batch_type": "Shell", | ||
| "context_type": "SSHContext", | ||
| "local_root": "./", | ||
| "remote_root": "/some/path", | ||
| "clean_asynchronously": False, | ||
| "create_remote_root": True, | ||
| "remote_profile": { | ||
| "hostname": "example.com", | ||
| "username": "alice", | ||
| }, | ||
| } | ||
|
|
||
| from .context import Machine | ||
|
|
||
| original_init = SSHContext.__init__ | ||
|
|
||
| def fake_init( | ||
| self, | ||
| local_root, | ||
| remote_root, | ||
| remote_profile, | ||
| clean_asynchronously=False, | ||
| create_remote_root=False, | ||
| *args, | ||
| **kwargs, | ||
| ): | ||
| self.init_local_root = local_root | ||
| self.init_remote_root = remote_root | ||
| self.remote_profile = remote_profile | ||
| self.clean_asynchronously = clean_asynchronously | ||
| self.create_remote_root = create_remote_root | ||
|
|
||
| SSHContext.__init__ = fake_init | ||
| try: | ||
| machine = Machine.load_from_dict(machine_dict) | ||
| serialized = machine.serialize() | ||
| finally: | ||
| SSHContext.__init__ = original_init | ||
|
|
||
| self.assertTrue(serialized["create_remote_root"]) | ||
| self.assertFalse(serialized["clean_asynchronously"]) | ||
| self.assertEqual(serialized["remote_root"], "/some/path") | ||
| self.assertEqual(serialized["remote_profile"]["hostname"], "example.com") |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: deepmodeling/dpdispatcher
Length of output: 297
🏁 Script executed:
Repository: deepmodeling/dpdispatcher
Length of output: 838
🏁 Script executed:
Repository: deepmodeling/dpdispatcher
Length of output: 1824
Serialization issue: LocalContext machines will not include
clean_asynchronouslyin serialized output, but the test expects it.The
serialize()method conditionally includesclean_asynchronouslyonly viahasattr(self.context, "clean_asynchronously"). However,LocalContextdoes not define this attribute, so forLocalContextmachines the field will not be included in the serialized dict. Yettest_machine_argcheckexpects"clean_asynchronously": Falsein the output for aLocalContextmachine (line 29). This will cause the test to fail.Either:
LocalContextneeds to defineclean_asynchronouslyas an attribute, orAdditionally, the
serialize()method lacks type hints. Per the coding guidelines, add proper type annotations:def serialize(self, if_empty_remote_profile: bool = False) -> dict:🤖 Prompt for AI Agents