From 0fa10683065d4d7f1c4bd7ba59937f92446cb0be Mon Sep 17 00:00:00 2001 From: yadavchiragg Date: Sun, 15 Nov 2026 20:42:04 +0530 Subject: [PATCH] feat(validate): add --type to catch workflows that cannot build for that execution type mkconcore.py exits with 'cannot pull container' when a node has no file extension and the type is posix or windows, but concore validate passed such workflows. validate --type posix|windows now reports pulled containers as errors up front. Without --type nothing changes. Checked against mkconcore on every bundled workflow: same 6 workflow/type pairs, no differences. Tests and docs included. --- concore_cli/README.md | 1 + concore_cli/cli.py | 11 +++++++- concore_cli/commands/validate.py | 13 ++++++++- tests/test_validate_exec_type.py | 48 ++++++++++++++++++++++++++++++++ 4 files changed, 71 insertions(+), 2 deletions(-) create mode 100644 tests/test_validate_exec_type.py diff --git a/concore_cli/README.md b/concore_cli/README.md index 78f98b1a..96825f2b 100644 --- a/concore_cli/README.md +++ b/concore_cli/README.md @@ -83,6 +83,7 @@ Validates a GraphML workflow file before running. **Options:** - `-s, --source ` - Source directory to verify file references exist +- `-t, --type ` - Also check the workflow can be built for this execution type (`windows`, `posix` or `docker`). Pulled containers (a node label with no file extension, such as `CZ:cpymat`) are only valid with `docker` Checks: - Valid XML structure diff --git a/concore_cli/cli.py b/concore_cli/cli.py index dc8fca34..a916c0b0 100644 --- a/concore_cli/cli.py +++ b/concore_cli/cli.py @@ -111,7 +111,15 @@ def build(workflow_file, source, output, type, auto_build, compose, zmq): type=click.Choice(["text", "json"]), help="Validation output format", ) -def validate(workflow_file, source, output_format): +@click.option( + "--type", + "-t", + "exec_type", + default=None, + type=click.Choice(["windows", "posix", "docker"]), + help="Also check the workflow can be built for this execution type", +) +def validate(workflow_file, source, output_format, exec_type): """Validate a workflow file""" try: ok = validate_workflow( @@ -119,6 +127,7 @@ def validate(workflow_file, source, output_format): source, console, output_format=output_format, + exec_type=exec_type, ) if not ok: sys.exit(1) diff --git a/concore_cli/commands/validate.py b/concore_cli/commands/validate.py index c8972d77..02687572 100644 --- a/concore_cli/commands/validate.py +++ b/concore_cli/commands/validate.py @@ -132,7 +132,9 @@ def _build_payload(workflow_path, source_root, errors, warnings, info, source_no } -def validate_workflow(workflow_file, source_dir, console, output_format="text"): +def validate_workflow( + workflow_file, source_dir, console, output_format="text", exec_type=None +): workflow_path = Path(workflow_file) source_root = resolve_source_dir(workflow_path, source_dir) @@ -256,6 +258,15 @@ def finalize(): 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"] diff --git a/tests/test_validate_exec_type.py b/tests/test_validate_exec_type.py new file mode 100644 index 00000000..d6c7be59 --- /dev/null +++ b/tests/test_validate_exec_type.py @@ -0,0 +1,48 @@ +import pytest +from click.testing import CliRunner + +from concore_cli.cli import cli + +GRAPH = """ + + + CZ:{first} + PZ:pm.py + + +""" + + +def _validate(tmp_path, first, *extra): + src = tmp_path / "src" + src.mkdir(exist_ok=True) + (src / "pm.py").write_text("x\n") + if "." in first: + (src / first).write_text("x\n") + wf = tmp_path / "wf.graphml" + wf.write_text(GRAPH.format(first=first), encoding="utf-8") + return CliRunner().invoke(cli, ["validate", str(wf), "--source", str(src), *extra]) + + +@pytest.mark.parametrize("exec_type", ["posix", "windows"]) +def test_pulled_container_is_an_error_for_posix_and_windows(tmp_path, exec_type): + result = _validate(tmp_path, "cpymat", "--type", exec_type) + assert result.exit_code == 1 + assert "pulled container" in result.output + assert f"not {exec_type}" in result.output + + +def test_pulled_container_is_fine_for_docker(tmp_path): + result = _validate(tmp_path, "cpymat", "--type", "docker") + assert "pulled container" not in result.output + + +def test_without_type_nothing_changes(tmp_path): + result = _validate(tmp_path, "cpymat") + assert "pulled container" not in result.output + + +def test_regular_source_files_pass_with_a_type(tmp_path): + result = _validate(tmp_path, "controller.py", "--type", "posix") + assert result.exit_code == 0, result.output + assert "pulled container" not in result.output