Skip to content

Commit b3f41bb

Browse files
authored
Merge pull request #712 from yadavchiragg/fix/duplicate-container-names
Reject nodes that share a container name in mkconcore and validate
2 parents 5bb9b2f + 47b44ac commit b3f41bb

3 files changed

Lines changed: 105 additions & 0 deletions

File tree

‎concore_cli/commands/validate.py‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ def _classify_message(message, bucket_name):
5858
return {"error_type": "missing_node_label"}
5959
if message.startswith("Error parsing node:"):
6060
return {"error_type": "node_parse_error"}
61+
if message.startswith("Duplicate node container name:"):
62+
return {"error_type": "duplicate_container_name"}
6163
if message.startswith("Duplicate node label:"):
6264
return {"error_type": "duplicate_node_label"}
6365
if message == "Edge missing source or target":
@@ -290,6 +292,18 @@ def finalize():
290292
errors.append(f"Duplicate node label: '{label}'")
291293
seen.add(label)
292294

295+
# two nodes with the same container name share one directory
296+
containers = {}
297+
for label in set(node_labels):
298+
if ":" in label:
299+
containers.setdefault(label.split(":")[0], []).append(label)
300+
for container, labels in sorted(containers.items()):
301+
if len(labels) > 1:
302+
errors.append(
303+
f"Duplicate node container name: '{container}' "
304+
f"used by {', '.join(sorted(labels))}"
305+
)
306+
293307
node_ids = {node.get("id") for node in nodes if node.get("id")}
294308
for edge in edges:
295309
source = edge.get("source")

‎mkconcore.py‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,16 @@ def cleanup_script_files():
377377
logging.error(f"Duplicate node labels found: {sorted(duplicates)}")
378378
sys.exit(1)
379379

380+
# Two nodes with the same container name would share one directory
381+
containers = {}
382+
for _label in label_values:
383+
containers.setdefault(_label.split(':')[0], []).append(_label)
384+
shared = {name: labels for name, labels in containers.items() if len(labels) > 1}
385+
if shared:
386+
for name, labels in sorted(shared.items()):
387+
logging.error(f"Container name '{name}' is used by more than one node: {', '.join(labels)}")
388+
sys.exit(1)
389+
380390
for edge in edges_text:
381391
try:
382392
data = edge.find('data', recursive=False)
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import subprocess
2+
import sys
3+
from pathlib import Path
4+
5+
from concore_cli.commands.validate import validate_workflow
6+
7+
MKCONCORE = Path(__file__).resolve().parent.parent / "mkconcore.py"
8+
9+
GRAPH = """<?xml version="1.0"?>
10+
<graphml xmlns="http://graphml.graphdrawing.org/xmlns"
11+
xmlns:y="http://www.yworks.com/xml/graphml">
12+
<graph id="G" edgedefault="directed">
13+
<node id="n0"><data key="d0"><y:NodeLabel>{first}</y:NodeLabel></data></node>
14+
<node id="n1"><data key="d0"><y:NodeLabel>{second}</y:NodeLabel></data></node>
15+
<edge source="n0" target="n1"><data key="d1"><y:EdgeLabel>u</y:EdgeLabel></data></edge>
16+
<edge source="n1" target="n0"><data key="d1"><y:EdgeLabel>y</y:EdgeLabel></data></edge>
17+
</graph>
18+
</graphml>
19+
"""
20+
21+
22+
class _Console:
23+
def __init__(self):
24+
self.lines = []
25+
26+
def print(self, *args, **kwargs):
27+
self.lines.append(" ".join(str(a) for a in args))
28+
29+
30+
def _setup(tmp_path, first, second):
31+
src = tmp_path / "src"
32+
src.mkdir()
33+
for name in ("a.py", "b.py"):
34+
(src / name).write_text("print('x')\n")
35+
wf = tmp_path / "w.graphml"
36+
wf.write_text(GRAPH.format(first=first, second=second))
37+
return wf, src
38+
39+
40+
def _run_mkconcore(tmp_path, wf, src):
41+
return subprocess.run(
42+
[
43+
sys.executable,
44+
str(MKCONCORE),
45+
str(wf),
46+
str(src),
47+
str(tmp_path / "out"),
48+
"posix",
49+
],
50+
cwd=tmp_path,
51+
capture_output=True,
52+
text=True,
53+
)
54+
55+
56+
def test_mkconcore_rejects_two_nodes_with_same_container_name(tmp_path):
57+
wf, src = _setup(tmp_path, "ctrl:a.py", "ctrl:b.py")
58+
result = _run_mkconcore(tmp_path, wf, src)
59+
assert result.returncode != 0
60+
assert "Container name 'ctrl' is used by more than one node" in (
61+
result.stdout + result.stderr
62+
)
63+
64+
65+
def test_mkconcore_accepts_distinct_container_names(tmp_path):
66+
wf, src = _setup(tmp_path, "ctrl:a.py", "plant:b.py")
67+
assert _run_mkconcore(tmp_path, wf, src).returncode == 0
68+
69+
70+
def test_validate_reports_duplicate_container_name(tmp_path):
71+
wf, src = _setup(tmp_path, "ctrl:a.py", "ctrl:b.py")
72+
console = _Console()
73+
assert validate_workflow(str(wf), str(src), console) is False
74+
assert any(
75+
"Duplicate node container name: 'ctrl'" in line for line in console.lines
76+
)
77+
78+
79+
def test_validate_accepts_distinct_container_names(tmp_path):
80+
wf, src = _setup(tmp_path, "ctrl:a.py", "plant:b.py")
81+
assert validate_workflow(str(wf), str(src), _Console()) is True

0 commit comments

Comments
 (0)