From 47b44ac29274b0e72f3753a2631d8aca5272a273 Mon Sep 17 00:00:00 2001 From: yadavchiragg Date: Thu, 19 Nov 2026 09:18:38 +0530 Subject: [PATCH] Reject nodes that share a container name in mkconcore and validate --- concore_cli/commands/validate.py | 14 +++++ mkconcore.py | 10 +++ tests/test_duplicate_container_names.py | 81 +++++++++++++++++++++++++ 3 files changed, 105 insertions(+) create mode 100644 tests/test_duplicate_container_names.py diff --git a/concore_cli/commands/validate.py b/concore_cli/commands/validate.py index c8972d7..14f7fc6 100644 --- a/concore_cli/commands/validate.py +++ b/concore_cli/commands/validate.py @@ -58,6 +58,8 @@ def _classify_message(message, bucket_name): return {"error_type": "missing_node_label"} if message.startswith("Error parsing node:"): return {"error_type": "node_parse_error"} + if message.startswith("Duplicate node container name:"): + return {"error_type": "duplicate_container_name"} if message.startswith("Duplicate node label:"): return {"error_type": "duplicate_node_label"} if message == "Edge missing source or target": @@ -279,6 +281,18 @@ def finalize(): errors.append(f"Duplicate node label: '{label}'") seen.add(label) + # two nodes with the same container name share one directory + containers = {} + for label in set(node_labels): + if ":" in label: + containers.setdefault(label.split(":")[0], []).append(label) + for container, labels in sorted(containers.items()): + if len(labels) > 1: + errors.append( + f"Duplicate node container name: '{container}' " + f"used by {', '.join(sorted(labels))}" + ) + node_ids = {node.get("id") for node in nodes if node.get("id")} for edge in edges: source = edge.get("source") diff --git a/mkconcore.py b/mkconcore.py index a1f44ef..503090b 100644 --- a/mkconcore.py +++ b/mkconcore.py @@ -368,6 +368,16 @@ def cleanup_script_files(): logging.error(f"Duplicate node labels found: {sorted(duplicates)}") sys.exit(1) +# Two nodes with the same container name would share one directory +containers = {} +for _label in label_values: + containers.setdefault(_label.split(':')[0], []).append(_label) +shared = {name: labels for name, labels in containers.items() if len(labels) > 1} +if shared: + for name, labels in sorted(shared.items()): + logging.error(f"Container name '{name}' is used by more than one node: {', '.join(labels)}") + sys.exit(1) + for edge in edges_text: try: data = edge.find('data', recursive=False) diff --git a/tests/test_duplicate_container_names.py b/tests/test_duplicate_container_names.py new file mode 100644 index 0000000..aeef270 --- /dev/null +++ b/tests/test_duplicate_container_names.py @@ -0,0 +1,81 @@ +import subprocess +import sys +from pathlib import Path + +from concore_cli.commands.validate import validate_workflow + +MKCONCORE = Path(__file__).resolve().parent.parent / "mkconcore.py" + +GRAPH = """ + + + {first} + {second} + u + y + + +""" + + +class _Console: + def __init__(self): + self.lines = [] + + def print(self, *args, **kwargs): + self.lines.append(" ".join(str(a) for a in args)) + + +def _setup(tmp_path, first, second): + src = tmp_path / "src" + src.mkdir() + for name in ("a.py", "b.py"): + (src / name).write_text("print('x')\n") + wf = tmp_path / "w.graphml" + wf.write_text(GRAPH.format(first=first, second=second)) + return wf, src + + +def _run_mkconcore(tmp_path, wf, src): + 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_rejects_two_nodes_with_same_container_name(tmp_path): + wf, src = _setup(tmp_path, "ctrl:a.py", "ctrl:b.py") + result = _run_mkconcore(tmp_path, wf, src) + assert result.returncode != 0 + assert "Container name 'ctrl' is used by more than one node" in ( + result.stdout + result.stderr + ) + + +def test_mkconcore_accepts_distinct_container_names(tmp_path): + wf, src = _setup(tmp_path, "ctrl:a.py", "plant:b.py") + assert _run_mkconcore(tmp_path, wf, src).returncode == 0 + + +def test_validate_reports_duplicate_container_name(tmp_path): + wf, src = _setup(tmp_path, "ctrl:a.py", "ctrl:b.py") + console = _Console() + assert validate_workflow(str(wf), str(src), console) is False + assert any( + "Duplicate node container name: 'ctrl'" in line for line in console.lines + ) + + +def test_validate_accepts_distinct_container_names(tmp_path): + wf, src = _setup(tmp_path, "ctrl:a.py", "plant:b.py") + assert validate_workflow(str(wf), str(src), _Console()) is True