Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/specify_cli/bundler/services/primitives.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,7 @@ def install(self, component: ComponentRef) -> None:
f"is disabled; re-run without --offline or install it first with "
f"'specify workflow step add {component.id}'."
)
self._assert_pinned_version(component)
from ... import workflow_step_add

with _chdir(self._root):
Expand Down Expand Up @@ -436,6 +437,20 @@ def refresh(self, component: ComponentRef) -> None:
finally:
shutil.rmtree(backup_dir.parent, ignore_errors=True)

def _assert_pinned_version(self, component: ComponentRef) -> None:
if not component.version:
return
try:
from ...workflows.catalog import StepCatalog

info = StepCatalog(self._root).get_step_info(component.id)
except Exception: # noqa: BLE001 - catalog unreachable: cannot enforce
return
if info:
_assert_pinned_version(
"Step", component.id, component.version, info.get("version")
)

def remove(self, component: ComponentRef) -> None:
from ... import workflow_step_remove

Expand Down
20 changes: 20 additions & 0 deletions tests/unit/test_bundler_primitives.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,26 @@ def test_workflow_version_mismatch_refuses(tmp_path: Path, monkeypatch):
manager.install(component)


def test_step_version_mismatch_refuses(tmp_path: Path, monkeypatch):
import specify_cli
from specify_cli.workflows.catalog import StepCatalog

monkeypatch.setattr(
StepCatalog, "get_step_info", lambda self, sid: {"version": "9.9.9"}
)
calls: list[str] = []
monkeypatch.setattr(
specify_cli, "workflow_step_add", lambda sid: calls.append(sid)
)

manager = primitive_manager("steps", tmp_path, allow_network=True)
component = ComponentRef(kind="steps", id="step-a", version="0.3.0")

with pytest.raises(BundlerError, match="pinned to version 0.3.0"):
manager.install(component)
assert calls == []


def test_preset_install_preserves_explicit_zero_priority(tmp_path: Path, monkeypatch):
import specify_cli._assets as assets

Expand Down