spec-kit icon indicating copy to clipboard operation
spec-kit copied to clipboard

[bug-fix] Fix bundle-update-force-mislead: add refresh() to DefaultPrimitiveInstaller

Open github-actions[bot] opened this issue 4 months ago • 1 comments

Bug fix — bundle-update-force-mislead

Proposed fix for issue #3424, applying the remediation from the bug assessment.

Verdict: Valid · Severity: medium

Summary

DefaultPrimitiveInstaller lacked a refresh() method, so _refresh_component() fell back to install(), which rejects already-installed extensions with a leaked --force hint that bundle update does not support. This fix adds refresh() to all kind managers (passing force=True for extensions and presets) and wires it up through DefaultPrimitiveInstaller.

Changes

File Change Notes
src/specify_cli/bundler/services/adapters.py modified Added refresh() to DefaultPrimitiveInstaller; dispatches to the kind manager's refresh() hook
src/specify_cli/bundler/services/primitives.py modified Added refresh() to _KindManager Protocol; refactored _ExtensionKindManager.install() and _PresetKindManager.install() into _do_install(force) helpers; added refresh() (calls _do_install(force=True)) to both; added refresh() to _WorkflowKindManager and _StepKindManager (delegates to install())
src/specify_cli/presets/__init__.py modified Added force: bool = False parameter to install_from_directory() and install_from_zip(); when force=True and the preset is already installed, it removes the existing preset before reinstalling (mirrors ExtensionManager semantics)
tests/unit/test_bundler_primitives.py modified Added tests for _ExtensionKindManager.refresh() passing force=True, _PresetKindManager.refresh() passing force=True, DefaultPrimitiveInstaller.refresh() dispatching correctly, and a regression test verifying no --force hint surfaces in BundlerError on bundle update

Tests Added or Updated

  • test_extension_refresh_calls_install_with_force — pins that _ExtensionKindManager.refresh() calls install_from_directory with force=True
  • test_preset_refresh_calls_install_with_force — pins that _PresetKindManager.refresh() calls install_from_directory with force=True
  • test_default_installer_refresh_dispatches_to_kind_manager — pins that DefaultPrimitiveInstaller.refresh() reaches the kind manager's refresh() and uses force=True
  • test_no_force_hint_in_bundler_error_on_refresh — regression test ensuring bundle update (refresh=True) on an already-installed bundle-owned extension no longer raises an error or surfaces the --force hint

Local Verification

  • Commands run: python3 -c "import ast; ast.parse(open(f).read())" on all four changed files → all OK
  • No project test command was runnable in this environment (no installed dependencies); verified by code inspection and syntax checking.

Deviations from Assessment

  • _WorkflowKindManager.refresh() and _StepKindManager.refresh() are implemented as delegation to install() (the existing fallback). The assessment noted these callables are "likely idempotent" — no behavioral change for these kinds.
  • The _KindManager Protocol was extended with refresh(). This is backwards-compatible: existing test fakes implementing only install/remove will continue to pass (Protocol methods are not enforced at runtime in Python).
  • The force parameter was added to PresetManager.install_from_directory() and install_from_zip() rather than using remove+install at the bundler layer, to mirror ExtensionManager's pattern and keep atomicity within the preset manager.

Risks & Review Notes

  • Preset force-overwrite atomicity: PresetManager.install_from_directory(force=True) calls self.remove(manifest.id) before copying. If the subsequent install fails, the preset is gone — same risk as noted in the assessment. The existing rollback logic in install_from_directory handles partial failures during the copy/register phase.
  • Workflow/step idempotency: the fix delegates refresh() to install() for workflows/steps. If workflow_add/workflow_step_add are not idempotent for already-installed items, those kinds could still fail on refresh. This is a pre-existing condition for those kinds and is not worsened by this change.

Refs #3424 · cc @grafvonb

  • Fixes #3424

Generated by 🛠️ Fix Bug from Labeled Issue for issue #3424 · 1.7K AIC · ⌖ 16.4 AIC · ⊞ 35.6K · ◷

github-actions[bot] avatar Jul 10 '26 12:07 github-actions[bot]

Please address Copilot feedback

mnriem avatar Jul 10 '26 16:07 mnriem