Skip to content
Merged
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
11 changes: 11 additions & 0 deletions src/specify_cli/bundles/manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,17 @@ def structural_errors(self) -> list[str]:
errors.append(
f"{ref.kind[:-1]} '{ref.id}' has invalid version '{ref.version}'."
)
# Preset and extension installs refuse a priority below 1, which
# would otherwise surface only mid-install, after earlier components.
if (
ref.kind in ("extensions", "presets")
and ref.priority is not None
and ref.priority < 1
):
errors.append(
f"{ref.kind[:-1]} '{ref.id}' priority must be 1 or higher, "
f"got {ref.priority}."
)

for ref in self.presets:
if ref.priority is None:
Expand Down
20 changes: 20 additions & 0 deletions tests/contract/test_manifest_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,26 @@ def test_non_integer_priority_raises_actionable_error():
BundleManifest.from_dict(data)


@pytest.mark.parametrize(
("kind", "priority"), [("presets", 0), ("presets", -3), ("extensions", 0)]
)
def test_non_positive_priority_is_rejected(kind, priority):
"""Preset and extension installs reject a priority below 1, so validation must too."""
data = valid_manifest_dict()
data["provides"][kind][0]["priority"] = priority
errors = BundleManifest.from_dict(data).structural_errors()
assert any(
"priority must be 1 or higher" in e and f"got {priority}" in e for e in errors
), errors


@pytest.mark.parametrize("kind", ["presets", "extensions"])
def test_priority_of_one_is_accepted(kind):
data = valid_manifest_dict()
data["provides"][kind][0]["priority"] = 1
assert BundleManifest.from_dict(data).structural_errors() == []


def test_non_step_components_must_be_pinned():
data = valid_manifest_dict()
data["provides"]["extensions"] = [{"id": "ext-unpinned"}]
Expand Down
31 changes: 31 additions & 0 deletions tests/specify_cli/bundles/test_command_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,37 @@ def test_local_bundle_rejects_mismatched_bundled_workflow_pin_offline(project: P
assert not (project / ".specify" / "workflows" / "bugfix").exists()


def test_local_bundle_with_non_positive_priority_is_rejected_before_any_install(
project: Path,
):
"""A priority the preset installer refuses must fail before earlier components install."""
bundle_dir = project / "zero-priority"
bundle_dir.mkdir()
(bundle_dir / "bundle.yml").write_text(
yaml.safe_dump(
valid_manifest_dict(
provides={
"extensions": [
{"id": "bug", "version": bundled_extension_version("bug")}
],
"presets": [
{"id": "lean", "version": "1.0.0", "priority": 0, "strategy": "replace"}
],
}
)
),
encoding="utf-8",
)

result = runner.invoke(app, ["bundle", "install", str(bundle_dir), "--offline"])

assert result.exit_code == 1
assert "preset 'lean' priority must be 1 or higher, got 0" in " ".join(
result.output.split()
)
assert not (project / ".specify" / "extensions").exists()


def test_local_bundle_refuses_unbundled_workflow_offline(project: Path):
bundle_dir = project / "unbundled-workflow"
(bundle_dir / "bundle.yml").parent.mkdir()
Expand Down
27 changes: 27 additions & 0 deletions tests/specify_cli/bundles/test_command_validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,33 @@ def test_validate_bundled_patch_compatibility(
assert ("newer packaged patch" in " ".join(result.output.split())) is warning


def test_validate_rejects_non_positive_preset_priority(project: Path, monkeypatch):
"""A manifest every install would reject must not be reported as valid."""
import specify_cli._assets as assets

payload = project / "packaged-preset"
payload.mkdir()
(payload / "preset.yml").write_text(
yaml.safe_dump({"preset": {"id": "p", "version": "1.0.0"}}), encoding="utf-8",
)
monkeypatch.setattr(assets, "_locate_bundled_preset", lambda cid: payload)
data = valid_manifest_dict(
provides={
"presets": [
{"id": "p", "version": "1.0.0", "priority": 0, "strategy": "replace"}
]
},
)
(project / "bundle.yml").write_text(yaml.safe_dump(data), encoding="utf-8")

result = runner.invoke(app, ["bundle", "validate", "--offline"])

assert result.exit_code == 1, result.output
assert "preset 'p' priority must be 1 or higher, got 0" in " ".join(
result.output.split()
)


@pytest.mark.parametrize("offline", [False, True])
def test_validate_bundled_workflow_patch_warns_without_catalog_lookup(
project: Path, monkeypatch, offline: bool,
Expand Down
Loading