Skip to content

Commit 7c2c673

Browse files
jawwad-aliclaude
andcommitted
test(workflows): cover add_catalog() OverflowError fallback for existing priority: .inf
The workflow/step catalog priority guards added OverflowError to _coerce_priority (the 'catalog add' fallback), but the tests only exercised get_active_catalogs(). Add tests that prewrite an existing 'priority: .inf' entry and call add_catalog() for both WorkflowCatalog and StepCatalog, asserting the command succeeds and the new entry gets a valid priority (inf coerced to 0, +1). Fails before: int(inf) OverflowError crashed add_catalog. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 2422ac7 commit 7c2c673

1 file changed

Lines changed: 49 additions & 0 deletions

File tree

tests/test_workflows.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5898,6 +5898,31 @@ def test_add_catalog(self, project_dir):
58985898
assert len(data["catalogs"]) == 1
58995899
assert data["catalogs"][0]["url"] == "https://example.com/new-catalog.json"
59005900

5901+
def test_add_catalog_with_existing_inf_priority(self, project_dir):
5902+
"""add_catalog() derives the new priority from existing ones via
5903+
_coerce_priority; an existing `priority: .inf` must not crash it
5904+
(int(float('inf')) is an OverflowError) — it is treated as 0 and the add
5905+
succeeds."""
5906+
from specify_cli.workflows.catalog import WorkflowCatalog
5907+
5908+
config_path = project_dir / ".specify" / "workflow-catalogs.yml"
5909+
config_path.parent.mkdir(parents=True, exist_ok=True)
5910+
config_path.write_text(yaml.dump({
5911+
"catalogs": [{
5912+
"name": "existing",
5913+
"url": "https://a.example.com/c.json",
5914+
"priority": float("inf"),
5915+
"install_allowed": True,
5916+
}]
5917+
}))
5918+
5919+
catalog = WorkflowCatalog(project_dir)
5920+
catalog.add_catalog("https://b.example.com/c.json", "new")
5921+
5922+
data = yaml.safe_load(config_path.read_text())
5923+
new = next(c for c in data["catalogs"] if c["url"] == "https://b.example.com/c.json")
5924+
assert new["priority"] == 1 # max(inf coerced to 0) + 1
5925+
59015926
def test_add_catalog_duplicate_rejected(self, project_dir):
59025927
from specify_cli.workflows.catalog import WorkflowCatalog, WorkflowValidationError
59035928

@@ -6432,6 +6457,30 @@ def test_add_catalog(self, project_dir):
64326457
assert len(data["catalogs"]) == 1
64336458
assert data["catalogs"][0]["url"] == "https://example.com/new-steps.json"
64346459

6460+
def test_add_catalog_with_existing_inf_priority(self, project_dir):
6461+
"""Step-catalog add_catalog() must not crash when an existing entry has a
6462+
`priority: .inf` (int(float('inf')) is an OverflowError) — _coerce_priority
6463+
treats it as 0 and the add succeeds."""
6464+
from specify_cli.workflows.catalog import StepCatalog
6465+
6466+
config_path = project_dir / ".specify" / "step-catalogs.yml"
6467+
config_path.parent.mkdir(parents=True, exist_ok=True)
6468+
config_path.write_text(yaml.dump({
6469+
"catalogs": [{
6470+
"name": "existing",
6471+
"url": "https://a.example.com/s.json",
6472+
"priority": float("inf"),
6473+
"install_allowed": True,
6474+
}]
6475+
}))
6476+
6477+
catalog = StepCatalog(project_dir)
6478+
catalog.add_catalog("https://b.example.com/s.json", "new")
6479+
6480+
data = yaml.safe_load(config_path.read_text())
6481+
new = next(c for c in data["catalogs"] if c["url"] == "https://b.example.com/s.json")
6482+
assert new["priority"] == 1 # max(inf coerced to 0) + 1
6483+
64356484
def test_add_catalog_empty_yaml_file(self, project_dir):
64366485
"""An empty YAML config file should be treated as empty, not corrupted."""
64376486
from specify_cli.workflows.catalog import StepCatalog

0 commit comments

Comments
 (0)