Skip to content

Commit 3eec154

Browse files
marcelsafinCopilot
andauthored
fix(workflows): reject malformed step config on add (#4087)
Assisted-by: GitHub Copilot (model: gpt-5.6-sol, autonomous) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 3f14ff4 commit 3eec154

2 files changed

Lines changed: 21 additions & 2 deletions

File tree

‎src/specify_cli/workflows/catalog.py‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1396,12 +1396,14 @@ def add_catalog(self, url: str, name: str | None = None) -> None:
13961396
data: dict[str, Any] = {"catalogs": []}
13971397
if config_path.exists():
13981398
try:
1399-
raw = yaml.safe_load(config_path.read_text(encoding="utf-8")) or {}
1399+
raw = yaml.safe_load(config_path.read_text(encoding="utf-8"))
14001400
except (yaml.YAMLError, OSError, UnicodeDecodeError) as exc:
14011401
raise StepValidationError(
14021402
f"Catalog config file is unreadable or malformed: {exc}"
14031403
) from exc
1404-
if not isinstance(raw, dict):
1404+
if raw is None:
1405+
raw = {}
1406+
elif not isinstance(raw, dict):
14051407
raise StepValidationError(
14061408
"Catalog config file is corrupted (expected a mapping)."
14071409
)

‎tests/test_workflows.py‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9102,6 +9102,23 @@ def test_add_catalog_empty_yaml_file(self, project_dir):
91029102
assert len(data["catalogs"]) == 1
91039103
assert data["catalogs"][0]["url"] == "https://example.com/steps.json"
91049104

9105+
@pytest.mark.parametrize("bad", [[], False, 0, ""])
9106+
def test_add_catalog_rejects_falsy_non_mapping_config(
9107+
self, project_dir, bad
9108+
):
9109+
from specify_cli.workflows.catalog import StepCatalog, StepValidationError
9110+
9111+
config_path = project_dir / ".specify" / "step-catalogs.yml"
9112+
original = yaml.safe_dump(bad)
9113+
config_path.write_text(original, encoding="utf-8")
9114+
9115+
with pytest.raises(StepValidationError, match="expected a mapping"):
9116+
StepCatalog(project_dir).add_catalog(
9117+
"https://example.com/steps.json", "my-steps"
9118+
)
9119+
9120+
assert config_path.read_text(encoding="utf-8") == original
9121+
91059122
def test_add_catalog_duplicate_rejected(self, project_dir):
91069123
from specify_cli.workflows.catalog import StepCatalog, StepValidationError
91079124

0 commit comments

Comments
 (0)