From 0f7ff4f8b8b3edf8f2b1408cea0db8215f755a0e Mon Sep 17 00:00:00 2001 From: eowca <4008965+eowca@users.noreply.github.com> Date: Thu, 26 Nov 2026 03:25:57 +0100 Subject: [PATCH] Reject whitespace-only local check commands Architecture-Review: unchanged; the existing workflow loader rejects invalid commands before stage execution. Co-Authored-By: Codex --- src/loopzero/config.py | 9 ++++++++- tests/test_config.py | 5 +++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/loopzero/config.py b/src/loopzero/config.py index 508ac7a9..cc1ca931 100644 --- a/src/loopzero/config.py +++ b/src/loopzero/config.py @@ -193,7 +193,7 @@ def _build(data: dict[str, Any]) -> Config: ) review[family] = ReviewConfig(table.get("model"), table.get("effort"), allowed) - commands = _strings("checks.commands", checks.get("commands", [])) + commands = _commands(checks.get("commands", [])) kwargs: dict[str, Any] = {} if "runner" in checks: runner = _strings("checks.runner", checks["runner"]) @@ -272,6 +272,13 @@ def _reject_unknown(where: str, table: dict[str, Any], allowed: Any) -> None: raise ConfigError(f"unknown key(s) in {where}: {', '.join(unknown)}") +def _commands(value: list[Any]) -> tuple[str, ...]: + commands = _strings("checks.commands", value) + if any(not command.strip() for command in commands): + raise ConfigError("checks.commands entries must each be a nonblank command") + return commands + + def _strings(label: str, value: list[Any]) -> tuple[str, ...]: if not isinstance(value, list) or not all(isinstance(item, str) and item for item in value): raise ConfigError(f"{label} must be a list of non-empty strings") diff --git a/tests/test_config.py b/tests/test_config.py index 509855bf..a877a3db 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -60,6 +60,9 @@ def test_load_full_config(tmp_path): limits=ResourceLimits(memory_mb=1024, file_mb=512), ) + padded = FULL.replace('"uv run pytest -q"', '" uv run pytest -q "') + assert config.load(write(tmp_path, padded)).checks[0] == " uv run pytest -q " + def test_load_applies_defaults(tmp_path): loaded = config.load(write(tmp_path, '[repo]\nname = "o/n"\n')) @@ -112,6 +115,8 @@ def test_invalid_toml(tmp_path): ('[repo]\nname = 3\n', "repo.name must be a str"), ('[repo]\nname = "o/n"\n[checks]\ncommands = "pytest"\n', "checks.commands must be a list"), ('[repo]\nname = "o/n"\n[checks]\ncommands = ["ok", 1]\n', "non-empty strings"), + ('[repo]\nname = "o/n"\n[checks]\ncommands = ["true", " "]\n', + r"workflow\.toml: checks\.commands.*nonblank command"), ('[repo]\nname = "o/n"\n[checks]\nnetwork = "yes"\n', "checks.network must be a bool"), ('[repo]\nname = "o/n"\n[delivery]\nmerge = "ff"\n', "delivery.merge must be one of"), ('[repo]\nname = "o/n"\n[delivery]\nreviewers = ["gpt"]\n', "delivery.reviewers entries"),