💫 Toolkit to help you get started with SDD or any other process!
fix(bundler): bundle update uninstalls components dropped by new version (#3353)
Ali jawwadd5ba062eab9f
diff --git a/src/specify_cli/bundler/services/installer.py b/src/specify_cli/bundler/services/installer.pyindex 10f49ef94..3e61ded04 100644--- a/src/specify_cli/bundler/services/installer.py+++ b/src/specify_cli/bundler/services/installer.py@@ -130,6 +130,28 @@ def install_bundle(done.append(component)result.installed.append(component)contributed.append(component)++ # On update (refresh), uninstall components this bundle used to own+ # that the new version no longer ships. Otherwise they are dropped+ # from the record below (contributed only holds plan.components) yet+ # left on disk — permanently orphaned, since no bundle record can+ # ever remove them. A stale component still owned by another bundle+ # is kept installed and simply de-attributed here (it stays in that+ # bundle's record). Mirrors remove_bundle's refcount logic.+ if refresh and existing is not None:+ planned = {(c.kind, c.id) for c in plan.components}+ still_needed = components_still_needed(+ records, exclude_bundle_id=plan.bundle_id+ )+ for component in existing.contributed_components:+ key = (component.kind, component.id)+ if key in planned:+ continue+ if key in still_needed:+ continue+ if installer.is_installed(project_root, component):+ installer.remove(project_root, component)+ result.uninstalled.append(component)except BundlerError:_rollback(project_root, installer, done)raisediff --git a/tests/integration/test_bundler_install_flow.py b/tests/integration/test_bundler_install_flow.pyindex 85dcc6c51..bf066b660 100644--- a/tests/integration/test_bundler_install_flow.py+++ b/tests/integration/test_bundler_install_flow.py@@ -220,3 +220,68 @@ def test_pre_existing_component_is_not_attributed_or_removed(tmp_path: Path):remove_bundle(tmp_path, "demo-bundle", installer)assert ("extensions", "ext-a") in installer.installed+++def _bundle(manifest_id, ext_ids, *, version="1.0.0"):+ data = valid_manifest_dict()+ data["bundle"]["id"] = manifest_id+ data["bundle"]["version"] = version+ data["provides"] = {+ "extensions": [{"id": e, "version": version} for e in ext_ids]+ }+ return BundleManifest.from_dict(data)+++def test_update_uninstalls_components_dropped_by_new_version(tmp_path: Path):+ """`bundle update` must uninstall components the new version no longer+ ships, instead of orphaning them (installed on disk, tracked by nothing)."""+ make_project(tmp_path)+ installer = FakeInstaller()++ man_v1 = _bundle("demo", ["ext-a", "ext-b"])+ install_bundle(tmp_path, _plan(man_v1), installer, manifest=man_v1)+ assert ("extensions", "ext-b") in installer.installed++ man_v2 = _bundle("demo", ["ext-a"], version="2.0.0")+ result = install_bundle(+ tmp_path, _plan(man_v2), installer, manifest=man_v2, refresh=True+ )++ # ext-b was dropped by v2 -> uninstalled and reported.+ assert ("extensions", "ext-b") in installer.remove_calls+ assert ("extensions", "ext-b") in {(c.kind, c.id) for c in result.uninstalled}+ assert ("extensions", "ext-b") not in installer.installed+ assert ("extensions", "ext-a") in installer.installed++ # The saved record lists only ext-a.+ rec = next(r for r in load_records(tmp_path) if r.bundle_id == "demo")+ keys = {(c.kind, c.id) for c in rec.contributed_components}+ assert ("extensions", "ext-a") in keys+ assert ("extensions", "ext-b") not in keys+++def test_update_keeps_component_still_needed_by_sibling_bundle(tmp_path: Path):+ """A dropped component still owned by another bundle stays installed."""+ make_project(tmp_path)+ installer = FakeInstaller()++ man_sib = _bundle("sibling", ["ext-b"])+ install_bundle(tmp_path, _plan(man_sib), installer, manifest=man_sib)++ man_v1 = _bundle("demo", ["ext-a", "ext-b"])+ install_bundle(tmp_path, _plan(man_v1), installer, manifest=man_v1)++ man_v2 = _bundle("demo", ["ext-a"], version="2.0.0")+ install_bundle(+ tmp_path, _plan(man_v2), installer, manifest=man_v2, refresh=True+ )++ # ext-b is still needed by 'sibling' -> not removed, stays installed.+ assert ("extensions", "ext-b") not in installer.remove_calls+ assert ("extensions", "ext-b") in installer.installed++ # But demo's record no longer attributes it.+ rec = next(r for r in load_records(tmp_path) if r.bundle_id == "demo")+ assert ("extensions", "ext-b") not in {+ (c.kind, c.id) for c in rec.contributed_components+ }