Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions concore_cli/commands/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down Expand Up @@ -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")
Expand Down
10 changes: 10 additions & 0 deletions mkconcore.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
81 changes: 81 additions & 0 deletions tests/test_duplicate_container_names.py
Original file line number Diff line number Diff line change
@@ -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 = """<?xml version="1.0"?>
<graphml xmlns="http://graphml.graphdrawing.org/xmlns"
xmlns:y="http://www.yworks.com/xml/graphml">
<graph id="G" edgedefault="directed">
<node id="n0"><data key="d0"><y:NodeLabel>{first}</y:NodeLabel></data></node>
<node id="n1"><data key="d0"><y:NodeLabel>{second}</y:NodeLabel></data></node>
<edge source="n0" target="n1"><data key="d1"><y:EdgeLabel>u</y:EdgeLabel></data></edge>
<edge source="n1" target="n0"><data key="d1"><y:EdgeLabel>y</y:EdgeLabel></data></edge>
</graph>
</graphml>
"""


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