Skip to content

Commit 002443a

Browse files
CrazyBaranclaude
andcommitted
fix(extensions): block bundled updates whenever the local copy lags the catalog
Copilot review round 2 on #4351: the offer gate only blocked a bundled copy that was no newer than the installation. With installed v1, locally bundled v2, and catalog v3, the command offered and installed v2 and reported success - leaving the project lagging the catalog with no mention of it, contrary to the documented "the update is reported as requiring a spec-kit upgrade first" behavior (and re-nagging about the upgrade on every subsequent run). Compare the bundled version against the catalog version instead: any older local copy is blocked with the upgrade-spec-kit guidance. This subsumes the previous gate (inside the catalog > installed branch, bundled <= installed implies bundled < catalog). A local copy at or above the catalog version (dev/source checkouts) is still offered and installed. Tests added for the intermediate-version block and the newer-than-catalog install. Refs #4345 Assisted-by: Claude Code (model: claude-fable-5, autonomous) Co-Authored-By: Claude Fable 5 <[email protected]>
1 parent 18a12b9 commit 002443a

2 files changed

Lines changed: 90 additions & 1 deletion

File tree

‎src/specify_cli/extensions/_commands.py‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1773,7 +1773,12 @@ def extension_update(
17731773
# to come from the copy shipped with the running spec-kit
17741774
# release, which may lag the catalog on main (#4345).
17751775
bundled_dir, bundled_version = _bundled_update_source(ext_id)
1776-
if bundled_dir is None or bundled_version <= installed_version:
1776+
# Block whenever the local copy lags the catalog, not
1777+
# just when it lags the installation: installing an
1778+
# intermediate version would leave the project behind
1779+
# the catalog while reporting success, contrary to the
1780+
# documented "upgrade spec-kit first" behavior.
1781+
if bundled_dir is None or bundled_version < catalog_version:
17771782
local_desc = (
17781783
f"only ships v{bundled_version}"
17791784
if bundled_dir is not None

‎tests/test_extensions.py‎

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9274,6 +9274,90 @@ def test_update_bundled_blocked_when_local_copy_lags_catalog(self, tmp_path):
92749274
assert "All extensions are up to date!" not in flat
92759275
assert ExtensionManager(project_dir).registry.get("test-ext")["version"] == "1.0.0"
92769276

9277+
def test_update_bundled_blocked_when_local_copy_is_intermediate_version(self, tmp_path):
9278+
"""A bundled copy newer than the installation but older than the
9279+
catalog must be blocked, not installed: an intermediate version would
9280+
leave the project lagging the catalog while reporting success."""
9281+
from typer.testing import CliRunner
9282+
from unittest.mock import patch
9283+
from specify_cli import app
9284+
9285+
runner = CliRunner()
9286+
project_dir = tmp_path / "project"
9287+
project_dir.mkdir()
9288+
(project_dir / ".specify").mkdir()
9289+
(project_dir / ".claude" / "skills").mkdir(parents=True)
9290+
9291+
manager = ExtensionManager(project_dir)
9292+
v1_dir = self._create_extension_source(tmp_path, "1.0.0")
9293+
manager.install_from_directory(v1_dir, "0.1.0")
9294+
v2_dir = self._create_extension_source(tmp_path, "2.0.0")
9295+
9296+
with patch.object(Path, "cwd", return_value=project_dir), \
9297+
patch.object(ExtensionCatalog, "get_extension_info", return_value={
9298+
"id": "test-ext",
9299+
"name": "Test Extension",
9300+
"version": "3.0.0",
9301+
"bundled": True,
9302+
"_install_allowed": True,
9303+
}), \
9304+
patch(
9305+
"specify_cli._locate_bundled_extension", return_value=v2_dir
9306+
), \
9307+
patch.object(
9308+
ExtensionCatalog,
9309+
"download_extension",
9310+
side_effect=AssertionError("blocked bundled update must not download"),
9311+
):
9312+
result = runner.invoke(
9313+
app, ["extension", "update", "test-ext"], catch_exceptions=True
9314+
)
9315+
9316+
flat = " ".join(result.output.split())
9317+
assert result.exit_code == 0, result.output
9318+
assert "only ships v2.0.0" in flat
9319+
assert "upgrade spec-kit" in flat
9320+
assert "Update these extensions?" not in flat
9321+
assert ExtensionManager(project_dir).registry.get("test-ext")["version"] == "1.0.0"
9322+
9323+
def test_update_installs_bundled_copy_newer_than_catalog(self, tmp_path):
9324+
"""A dev/source checkout can ship a copy newer than the fetched
9325+
catalog advertises; the local copy is offered and installed."""
9326+
from typer.testing import CliRunner
9327+
from unittest.mock import patch
9328+
from specify_cli import app
9329+
9330+
runner = CliRunner()
9331+
project_dir = tmp_path / "project"
9332+
project_dir.mkdir()
9333+
(project_dir / ".specify").mkdir()
9334+
(project_dir / ".claude" / "skills").mkdir(parents=True)
9335+
9336+
manager = ExtensionManager(project_dir)
9337+
v1_dir = self._create_extension_source(tmp_path, "1.0.0")
9338+
manager.install_from_directory(v1_dir, "0.1.0")
9339+
v3_dir = self._create_extension_source(tmp_path, "3.0.0")
9340+
9341+
with patch.object(Path, "cwd", return_value=project_dir), \
9342+
patch.object(ExtensionCatalog, "get_extension_info", return_value={
9343+
"id": "test-ext",
9344+
"name": "Test Extension",
9345+
"version": "2.0.0",
9346+
"bundled": True,
9347+
"_install_allowed": True,
9348+
}), \
9349+
patch(
9350+
"specify_cli._locate_bundled_extension", return_value=v3_dir
9351+
):
9352+
result = runner.invoke(
9353+
app, ["extension", "update", "test-ext"], input="y\n", catch_exceptions=True
9354+
)
9355+
9356+
flat = " ".join(result.output.split())
9357+
assert result.exit_code == 0, result.output
9358+
assert "Updated to v3.0.0" in flat
9359+
assert ExtensionManager(project_dir).registry.get("test-ext")["version"] == "3.0.0"
9360+
92779361
def test_update_bundled_blocked_when_no_local_copy_exists(self, tmp_path):
92789362
"""A bundled catalog entry with no locally shipped copy points at a
92799363
spec-kit upgrade instead of failing the update at download time."""

0 commit comments

Comments
 (0)