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

fix(extensions): preserve keep-config leftover on reinstall (data loss)

Open jawwad-ali opened this issue 4 months ago • 3 comments

Description

extension remove --keep-config deliberately preserves the top-level *-config.yml / *-config.local.yml in the extension dir and drops the registry entry, so the user can reinstall and keep their configuration. But a subsequent install_from_directory silently destroys it:

if dest_dir.exists():
    shutil.rmtree(dest_dir)   # wipes the preserved config
...
if did_remove:                # only runs on the --force path
    ...restore from .backup...

After a keep-config remove the registry reports not installed, so the reinstall is not a --force removal → did_remove is False → the restore block never runs → the config is gone. Reproduced on main @ 92b7cf7: a user config (api_key: MY-CUSTOMIZED-VALUE) survives remove(keep_config=True) but is wiped by the next reinstall — the file doesn't even exist afterward. This is data loss that directly contradicts the feature's promise.

Fix

Before the rmtree, capture any top-level *-config.yml / *-config.local.yml from the existing dest_dir (in-memory), and write them back after the fresh copytree — using the same *-config filter and symlink guard the --force restore path already applies. The --force .backup restore still takes precedence for that path; this only covers the in-place keep-config leftover.

Testing

New test_reinstall_preserves_keep_config_leftover: install → write custom config → remove(keep_config=True) → reinstall (no force) → assert the custom config survives. Fails before (config file gone after reinstall — verified by source-stash), passes after. Full tests/test_extensions.py: 327 passed, 3 skipped (no regressions; keep_config=False/.backup path unaffected). uvx ruff check clean.

AI Disclosure

  • [x] I did use AI assistance (describe below)

Found and fixed with Claude Code (Claude Fable 5) under my direction. AI traced the keep-config leftover through the reinstall path and found the restore only fires on --force; I reproduced the data loss, verified fail-before/pass-after and the full suite, and reviewed the diff.

jawwad-ali avatar Jul 06 '26 20:07 jawwad-ali

Please address Copilot feedback

mnriem avatar Jul 09 '26 12:07 mnriem

Please address Copilot feedback and resolve test & lint errors

mnriem avatar Jul 10 '26 16:07 mnriem

Please address Copilot feedback

mnriem avatar Jul 13 '26 21:07 mnriem

Please address Copilot feedback

mnriem avatar Jul 14 '26 16:07 mnriem

Please address Copilot feedback

mnriem avatar Jul 17 '26 20:07 mnriem

Closing this as superseded by #3449 ("Fix reinstall-overwrites-kept-config: preserve config on plain reinstall after --keep-config"), which merged the same fix — and more thoroughly than this PR: it adds a crash-safe rescue-staging directory with a completion marker, copytree-failure recovery, and symlink-safe config restore. Rebasing this branch onto current main now conflicts directly with that implementation, and the remaining review comments were chasing TOCTOU edge cases in an approach main has already replaced. No reason to keep a competing/redundant PR open — #3449 covers it. Thanks!

jawwad-ali avatar Jul 21 '26 16:07 jawwad-ali