Skip to content
Merged
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
58 changes: 33 additions & 25 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 @@ -257,29 +255,39 @@ 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 (
exec_type in ("posix", "windows")
and "." not in filename
):
errors.append(
f"Node '{label}' is a pulled container (no file "
f"extension); pulled containers need --type docker, "
f"not {exec_type}"
)
elif not any(
filename.endswith(ext)
for ext in [".py", ".cpp", ".m", ".v", ".java", ".jl"]
):
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 (
exec_type in ("posix", "windows")
and "." not in filename
):
errors.append(
f"Node '{label}' is a pulled container (no file "
f"extension); pulled containers need --type docker, "
f"not {exec_type}"
)
elif not any(
filename.endswith(ext)
for ext in [
".py",
".cpp",
".m",
".v",
".java",
".jl",
]
):
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 @@ -359,7 +359,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
12 changes: 9 additions & 3 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -1145,16 +1145,22 @@ def test_validate_and_inspect_julia_node(self):
(src_dir / "ctrl.jl").write_text("# julia controller")

# validate passes with no unusual file extension warning
val_res = self.runner.invoke(cli, ["validate", "workflow.graphml", "--format", "json"])
val_res = self.runner.invoke(
cli, ["validate", "workflow.graphml", "--format", "json"]
)
self.assertEqual(val_res.exit_code, 0)
val_payload = json.loads(val_res.output)
self.assertTrue(val_payload["valid"])
self.assertEqual(val_payload["summary"]["error_count"], 0)
warning_messages = [w["message"] for w in val_payload["warnings"]]
self.assertFalse(any("unusual file extension" in m for m in warning_messages))
self.assertFalse(
any("unusual file extension" in m for m in warning_messages)
)

# inspect reports Julia language
insp_res = self.runner.invoke(cli, ["inspect", "workflow.graphml", "--json"])
insp_res = self.runner.invoke(
cli, ["inspect", "workflow.graphml", "--json"]
)
self.assertEqual(insp_res.exit_code, 0)
insp_payload = json.loads(insp_res.output)
self.assertEqual(insp_payload["nodes"]["by_language"].get("julia"), 1)
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
70 changes: 70 additions & 0 deletions tests/test_port_only_nodes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
"""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):
# mkconcore refuses nodes whose source file is missing, and not every
# bundled workflow ships its node scripts, so give each node an empty file.
src = tmp_path / "src"
src.mkdir()
for label in LABEL_RE.findall(workflow.read_text(errors="ignore")):
label = re.sub(r"\s+", " ", label)
if ":" in label:
name = label.split(":", 1)[1].strip()
if name:
(src / name).parent.mkdir(parents=True, exist_ok=True)
(src / name).write_text("")
result = subprocess.run(
[
sys.executable,
str(REPO_ROOT / "mkconcore.py"),
str(workflow),
str(src),
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
Loading