Skip to content

Commit 381ae9f

Browse files
marcelsafinCopilot
andauthored
fix(workflows): reject malformed step config on remove (#4095)
Assisted-by: GitHub Copilot (model: gpt-5.6-sol, autonomous) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 0e6124a commit 381ae9f

2 files changed

Lines changed: 16 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
@@ -1465,12 +1465,14 @@ def remove_catalog(self, index: int) -> str:
14651465
raise StepValidationError("No step catalog config file found.")
14661466

14671467
try:
1468-
data = yaml.safe_load(config_path.read_text(encoding="utf-8")) or {}
1468+
data = yaml.safe_load(config_path.read_text(encoding="utf-8"))
14691469
except (yaml.YAMLError, OSError, UnicodeDecodeError) as exc:
14701470
raise StepValidationError(
14711471
f"Catalog config file is unreadable or malformed: {exc}"
14721472
) from exc
1473-
if not isinstance(data, dict):
1473+
if data is None:
1474+
data = {}
1475+
elif not isinstance(data, dict):
14741476
raise StepValidationError(
14751477
"Catalog config file is corrupted (expected a mapping)."
14761478
)

tests/test_workflows.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9134,6 +9134,18 @@ def test_remove_catalog_invalid_index(self, project_dir):
91349134
with pytest.raises(StepValidationError, match="out of range"):
91359135
catalog.remove_catalog(5)
91369136

9137+
@pytest.mark.parametrize("bad", [[], False, 0, ""])
9138+
def test_remove_catalog_rejects_falsy_non_mapping_config(
9139+
self, project_dir, bad
9140+
):
9141+
from specify_cli.workflows.catalog import StepCatalog, StepValidationError
9142+
9143+
config_path = project_dir / ".specify" / "step-catalogs.yml"
9144+
config_path.write_text(yaml.safe_dump(bad), encoding="utf-8")
9145+
9146+
with pytest.raises(StepValidationError, match="expected a mapping"):
9147+
StepCatalog(project_dir).remove_catalog(0)
9148+
91379149
def test_remove_catalog_no_config(self, project_dir):
91389150
from specify_cli.workflows.catalog import StepCatalog, StepValidationError
91399151

0 commit comments

Comments
 (0)