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
33 changes: 17 additions & 16 deletions concore_cli/commands/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ def _classify_message(message, bucket_name):
return {"error_type": "invalid_node_label_format"}
if message.startswith("Node '") and message.endswith("has invalid format"):
return {"error_type": "invalid_node_label_format"}
if message.startswith("Node '") and message.endswith("has no filename"):
return {"error_type": "missing_node_filename"}
if message.startswith("Node '") and message.endswith("has unusual file extension"):
return {"error_type": "unusual_file_extension"}
if message.startswith("Missing source file:"):
Expand Down Expand Up @@ -253,20 +251,23 @@ def finalize():
warnings.append(f"Node '{label}' has invalid format")
else:
nodeId_part, filename = parts
source_nodes[filename] = node_id
if not filename:
errors.append(f"Node '{label}' has no filename")
elif not any(
filename.endswith(ext)
for ext in [".py", ".cpp", ".m", ".v", ".java"]
):
warnings.append(
f"Node '{label}' has unusual file extension"
)
elif source_root.exists():
file_path = source_root / filename
if not file_path.exists():
errors.append(f"Missing source file: {filename}")
# A node with no filename ('IN:' / 'OUT:') is a
# port-only input/output source: nothing to check.
if filename:
source_nodes[filename] = node_id
if not any(
filename.endswith(ext)
for ext in [".py", ".cpp", ".m", ".v", ".java"]
):
warnings.append(
f"Node '{label}' has unusual file extension"
)
elif source_root.exists():
file_path = source_root / filename
if not file_path.exists():
errors.append(
f"Missing source file: {filename}"
)
else:
warnings.append(f"Node {node_id} has no label")
except Exception as e:
Expand Down
4 changes: 3 additions & 1 deletion mkconcore.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,9 @@ def cleanup_script_files():
if ':' in node_label:
container_part, source_part = node_label.split(':', 1)
safe_name(container_part, f"Node container name '{container_part}'")
source_part = safe_relpath(source_part, f"Node source file '{source_part}'")
# A node may have no source file (port endpoints such as 'IN:' / 'OUT:').
if source_part:
source_part = safe_relpath(source_part, f"Node source file '{source_part}'")
node_label = f"{container_part}:{source_part}"
else:
safe_name(node_label, f"Node label '{node_label}'")
Expand Down
16 changes: 11 additions & 5 deletions tests/test_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,22 +96,28 @@ def test_validate_broken_edges(self):
self.assertIn("Validation failed", result.output)
self.assertIn("Edge references non-existent target node", result.output)

def test_validate_node_missing_filename(self):
def test_validate_port_only_node_is_valid(self):
content = """
<graphml xmlns:y="http://www.yworks.com/xml/graphml">
<graph id="G" edgedefault="directed">
<node id="n0">
<data key="d0"><y:NodeLabel>n0:</y:NodeLabel></data>
<data key="d0"><y:NodeLabel>IN:</y:NodeLabel></data>
</node>
<node id="n1">
<data key="d0"><y:NodeLabel>OUT:</y:NodeLabel></data>
</node>
<edge id="e0" source="n0" target="n1">
<data key="d1"><y:EdgeLabel>0x1000_a</y:EdgeLabel></data>
</edge>
</graph>
</graphml>
"""
filepath = self.create_graph_file("bad_node.graphml", content)
filepath = self.create_graph_file("port_only.graphml", content)

result = self.runner.invoke(cli, ["validate", filepath])

self.assertIn("Validation failed", result.output)
self.assertIn("has no filename", result.output)
self.assertNotIn("has no filename", result.output)
self.assertNotIn("Validation failed", result.output)

def test_validate_unsafe_node_label(self):
content = """
Expand Down
59 changes: 59 additions & 0 deletions tests/test_port_only_nodes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
"""Nodes with no source file ("IN:", "OUT:") must not stop a study from building.

Port-only nodes are used by the distributed / ZMQ and measurement workflows
in this repository. mkconcore.py used to reject them while validating node
labels ("Node source file '' cannot be empty"), although the rest of the
generator handles a node without a source file.
"""

import re
import subprocess
import sys
from pathlib import Path

import pytest

REPO_ROOT = Path(__file__).resolve().parent.parent
LABEL_RE = re.compile(r"<y:NodeLabel[^>]*>([^<]*)</y:NodeLabel>")


def _has_port_only_node(graphml):
text = graphml.read_text(errors="ignore")
for label in LABEL_RE.findall(text):
label = re.sub(r"\s+", " ", label)
if ":" in label and not label.split(":", 1)[1].strip():
return True
return False


PORT_ONLY_WORKFLOWS = sorted(
p for p in REPO_ROOT.rglob("*.graphml") if _has_port_only_node(p)
)


def test_port_only_workflows_were_found():
assert PORT_ONLY_WORKFLOWS, "no workflow with a port-only node found"


@pytest.mark.parametrize("build_type", ["posix", "windows", "docker"])
@pytest.mark.parametrize(
"workflow",
PORT_ONLY_WORKFLOWS,
ids=[str(p.relative_to(REPO_ROOT)) for p in PORT_ONLY_WORKFLOWS],
)
def test_workflow_with_port_only_node_builds(tmp_path, workflow, build_type):
result = subprocess.run(
[
sys.executable,
str(REPO_ROOT / "mkconcore.py"),
str(workflow),
str(workflow.parent),
str(tmp_path / "study"),
build_type,
],
capture_output=True,
text=True,
cwd=str(REPO_ROOT),
timeout=120,
)
assert result.returncode == 0, result.stdout + result.stderr