From e4343174a9128bef5e0feca18ad68e8792bff548 Mon Sep 17 00:00:00 2001 From: Sebastiaan Huber Date: Tue, 13 Feb 2024 23:19:48 +0100 Subject: [PATCH] `ShellJob`: Fix symlinking of remote folder data --- src/aiida_shell/calculations/shell.py | 3 ++- tests/calculations/test_shell.py | 28 +++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/aiida_shell/calculations/shell.py b/src/aiida_shell/calculations/shell.py index 6301e03..1740d63 100644 --- a/src/aiida_shell/calculations/shell.py +++ b/src/aiida_shell/calculations/shell.py @@ -7,7 +7,7 @@ import shlex import typing as t -from aiida.common.datastructures import CalcInfo, CodeInfo +from aiida.common.datastructures import CalcInfo, CodeInfo, FileCopyOrder from aiida.common.folders import Folder from aiida.engine import CalcJob, CalcJobProcessSpec from aiida.orm import Data, Dict, FolderData, List, RemoteData, SinglefileData, to_aiida_type @@ -308,6 +308,7 @@ def prepare_for_submission(self, folder: Folder) -> CalcInfo: calc_info.remote_symlink_list = remote_symlink_list calc_info.retrieve_temporary_list = retrieve_list calc_info.provenance_exclude_list = [p.name for p in dirpath.iterdir()] + calc_info.file_copy_order = FileCopyOrder.REMOTE_LOCAL_SANDBOX return calc_info diff --git a/tests/calculations/test_shell.py b/tests/calculations/test_shell.py index c439e24..89d14f6 100644 --- a/tests/calculations/test_shell.py +++ b/tests/calculations/test_shell.py @@ -4,6 +4,7 @@ import pytest from aiida.common.datastructures import CodeInfo +from aiida.engine import run_get_node from aiida.orm import Data, Float, FolderData, Int, List, RemoteData, SinglefileData, Str from aiida_shell.calculations.shell import ShellJob from aiida_shell.data import EntryPointData, PickledData @@ -430,3 +431,30 @@ def test_input_output_filename_overlap(generate_calc_job, generate_code, tmp_pat 'nodes': {'folder': folder_data}, }, ) + + +def test_remote_folder_copying_order(generate_code, aiida_localhost, tmp_path): + """Test that files in ``RemoteData`` input nodes do not overwrite files written by the ``ShellJob`` itself.""" + filename_submit_script = ShellJob.spec().inputs['metadata']['options']['submit_script_filename'].default + + # Create a ``RemoteData`` node containing a file with the default submit script name. The content is ``SENTINEL`` + # so that it can be easily detected in the final assert of this test. + dirpath = tmp_path / 'remote' + dirpath.mkdir() + (dirpath / filename_submit_script).write_text('SENTINEL') + + inputs = { + 'code': generate_code(), + 'arguments': [], + 'nodes': { + 'remote': RemoteData(remote_path=str(dirpath.absolute()), computer=aiida_localhost), + }, + } + _, node = run_get_node(ShellJob, inputs) + + # Now retrieve the content of the submit script that was written to the working directory. It should not be equal + # to the content of the submit script in the ``remote`` input node which would mean it overwrote the submit script + # of the shell job itself. + filepath_submit_script = dirpath / 'output' + node.outputs.remote_folder.getfile(filename_submit_script, str(filepath_submit_script)) + assert filepath_submit_script.read_text() != 'SENTINEL'