diff --git a/mkconcore.py b/mkconcore.py index a1f44ef..7d34fc6 100644 --- a/mkconcore.py +++ b/mkconcore.py @@ -331,6 +331,10 @@ def cleanup_script_files(): edges_text = soup.find_all('edge') nodes_text = soup.find_all('node') +if not nodes_text: + logging.error(f"No nodes found in {GRAPHML_FILE}. Is it a valid GraphML workflow?") + sys.exit(1) + # Store the edges and nodes in a dictionary edge_label_regex = re.compile(r"0x([a-fA-F0-9]+)_(\S+)") edges_dict = dict() @@ -438,6 +442,7 @@ def cleanup_script_files(): node_edge_params = {} edge_label_regex = re.compile(r"0x([^_]+)_(\S+)") +missing_sources = [] logging.info("Aggregating ZMQ edge parameters for nodes...") if copy_script_py_path: for edge_element in soup.find_all('edge'): @@ -533,6 +538,7 @@ def cleanup_script_files(): template_script_full_path = os.path.join(sourcedir, original_script) if not os.path.exists(template_script_full_path): logging.error(f"Cannot specialize: Original script '{template_script_full_path}' not found in '{sourcedir}'.") + missing_sources.append(original_script) continue new_script_relpath = copy_with_port_portname.run_specialization_script( @@ -602,6 +608,8 @@ def cleanup_script_files(): shutil.copy2(script_source_path, script_target_path) else: logging.error(f"Script '{sourcecode}' not found in sourcedir '{sourcedir}'") + if "." in sourcecode: # pulled containers have no source file + missing_sources.append(sourcecode) # The rest of the file handling (Dockerfiles, .dir) uses 'dockername', # which is now derived from the specialized script name, maintaining consistency. @@ -615,6 +623,10 @@ def cleanup_script_files(): shutil.copytree(os.path.join(sourcedir, dir_for_node), os.path.join(outdir, "src", dir_for_node), dirs_exist_ok=True) +if missing_sources: + logging.error(f"Node source file(s) not found in {sourcedir}: {', '.join(sorted(set(missing_sources)))}") + sys.exit(1) + #determine languages used in the graphml required_langs = set() for node in nodes_dict: diff --git a/tests/test_mkconcore_missing_sources.py b/tests/test_mkconcore_missing_sources.py new file mode 100644 index 0000000..f72d56f --- /dev/null +++ b/tests/test_mkconcore_missing_sources.py @@ -0,0 +1,48 @@ +import subprocess +import sys +from pathlib import Path + +MKCONCORE = Path(__file__).resolve().parent.parent / "mkconcore.py" + +GRAPH = """ + + + a:a.py + b:b.py + 0x1_x + + +""" + + +def _run(tmp_path, scripts): + src = tmp_path / "src" + src.mkdir() + for name in scripts: + (src / name).write_text("print('x')\n") + wf = tmp_path / "w.graphml" + wf.write_text(GRAPH) + return subprocess.run( + [ + sys.executable, + str(MKCONCORE), + str(wf), + str(src), + str(tmp_path / "out"), + "posix", + ], + cwd=tmp_path, + capture_output=True, + text=True, + ) + + +def test_mkconcore_fails_when_source_file_missing(tmp_path): + result = _run(tmp_path, ["a.py"]) + assert result.returncode != 0 + assert "b.py" in result.stdout + result.stderr + + +def test_mkconcore_succeeds_when_all_sources_exist(tmp_path): + assert _run(tmp_path, ["a.py", "b.py"]).returncode == 0 diff --git a/tests/test_mkconcore_no_nodes.py b/tests/test_mkconcore_no_nodes.py new file mode 100644 index 0000000..f4ae46c --- /dev/null +++ b/tests/test_mkconcore_no_nodes.py @@ -0,0 +1,32 @@ +import subprocess +import sys +from pathlib import Path + +import pytest + +MKCONCORE = Path(__file__).resolve().parent.parent / "mkconcore.py" + +EMPTY_GRAPH = ( + '\n' + '' + '\n' +) + + +@pytest.mark.parametrize("content", [EMPTY_GRAPH, "this is not xml"]) +def test_mkconcore_fails_when_graph_has_no_nodes(tmp_path, content): + wf = tmp_path / "w.graphml" + wf.write_text(content) + src = tmp_path / "src" + src.mkdir() + out = tmp_path / "out" + + result = subprocess.run( + [sys.executable, str(MKCONCORE), str(wf), str(src), str(out), "posix"], + cwd=tmp_path, + capture_output=True, + text=True, + ) + + assert result.returncode != 0 + assert "No nodes found" in result.stdout + result.stderr