spec-kit
spec-kit copied to clipboard
[bug-fix] Fix bundle-update-force-mislead: add refresh() to DefaultPrimitiveInstaller
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()callsinstall_from_directorywithforce=Truetest_preset_refresh_calls_install_with_force— pins that_PresetKindManager.refresh()callsinstall_from_directorywithforce=Truetest_default_installer_refresh_dispatches_to_kind_manager— pins thatDefaultPrimitiveInstaller.refresh()reaches the kind manager'srefresh()and usesforce=Truetest_no_force_hint_in_bundler_error_on_refresh— regression test ensuringbundle update(refresh=True) on an already-installed bundle-owned extension no longer raises an error or surfaces the--forcehint
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 toinstall()(the existing fallback). The assessment noted these callables are "likely idempotent" — no behavioral change for these kinds.- The
_KindManagerProtocol was extended withrefresh(). This is backwards-compatible: existing test fakes implementing onlyinstall/removewill continue to pass (Protocol methods are not enforced at runtime in Python). - The
forceparameter was added toPresetManager.install_from_directory()andinstall_from_zip()rather than using remove+install at the bundler layer, to mirrorExtensionManager's pattern and keep atomicity within the preset manager.
Risks & Review Notes
- Preset force-overwrite atomicity:
PresetManager.install_from_directory(force=True)callsself.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 ininstall_from_directoryhandles partial failures during the copy/register phase. - Workflow/step idempotency: the fix delegates
refresh()toinstall()for workflows/steps. Ifworkflow_add/workflow_step_addare 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 · ◷
Please address Copilot feedback