fix: preserve .vscode/settings.json and script +x bit on integration upgrade (#3020)

* fix: preserve .vscode/settings.json and script +x bit on integration upgrade

During 'specify integration upgrade', Phase 2 stale-cleanup removes files
present in the old manifest but absent from the new one. Copilot's setup()
merges into an existing .vscode/settings.json and stops tracking it, so the
file was being deleted on upgrade (destroying user settings). Add a
stale_cleanup_exclusions() hook that integrations use to protect such
conditionally-tracked merge targets. Also restore the executable bit on
shared .sh scripts after the managed-refresh step on POSIX.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* fix: address review on stale-cleanup fix

- Normalize stale_cleanup_exclusions() to POSIX before subtracting from
  manifest keys, so exclusions built with os.path.join / backslashes still
  match on Windows.
- Strengthen test_upgrade_preserves_existing_vscode_settings to add a
  user-defined key and assert it survives the upgrade (via --force, exercising
  the merge + stale-cleanup path) instead of the brittle after == before check.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
Ben Buttigieg
2026-06-17 20:22:04 +01:00
committed by GitHub
parent affbf5ead5
commit 84db931f18
4 changed files with 86 additions and 1 deletions

View File

@@ -2272,6 +2272,58 @@ class TestIntegrationUpgrade:
f"found: {[f.name for f in core_remaining]}"
)
def test_upgrade_preserves_existing_vscode_settings(self, tmp_path):
"""Regression: copilot upgrade must not stale-delete .vscode/settings.json.
On init the file is created and recorded in the manifest. On upgrade,
setup() merges into the now-existing file and intentionally stops
tracking it, so without ``stale_cleanup_exclusions()`` the Phase 2
stale cleanup would delete it (destroying the user's settings).
"""
project = _init_project(tmp_path, "copilot")
settings = project / ".vscode" / "settings.json"
assert settings.is_file(), "init should create .vscode/settings.json"
before = json.loads(settings.read_text(encoding="utf-8"))
assert before, "settings.json should contain managed defaults"
# Simulate a user editing their settings: add a custom key that the
# integration does not manage. It must survive the upgrade.
before["editor.fontSize"] = 17
settings.write_text(json.dumps(before), encoding="utf-8")
result = _run_in_project(project, [
"integration", "upgrade", "copilot",
"--script", "sh", "--force",
])
assert result.exit_code == 0, result.output
assert settings.is_file(), ".vscode/settings.json must survive upgrade"
after = json.loads(settings.read_text(encoding="utf-8"))
assert after.get("editor.fontSize") == 17, (
"user-defined settings must be preserved after upgrade"
)
def test_upgrade_restores_executable_bit_on_shared_scripts(self, tmp_path):
"""Regression: scripts refreshed by the managed-refresh step stay +x."""
if os.name == "nt":
pytest.skip("POSIX execute bits are not meaningful on Windows")
project = _init_project(tmp_path, "copilot")
script = project / ".specify" / "scripts" / "bash" / "check-prerequisites.sh"
assert script.is_file()
# Simulate a perms-losing install (e.g. wheel extraction dropping +x).
script.chmod(0o644)
assert not (script.stat().st_mode & 0o111)
result = _run_in_project(project, [
"integration", "upgrade", "copilot",
"--script", "sh",
])
assert result.exit_code == 0, result.output
assert script.stat().st_mode & 0o111, (
"shared .sh scripts must be executable after upgrade"
)
# ── Full lifecycle ───────────────────────────────────────────────────