Skip to content

fix(init): keep other installed integrations on re-init - #5536

Merged
mnriem merged 3 commits into
github:mainfrom
kartsan03:fix/init-force-keep-installed-integrations
Nov 25, 2026
Merged

mnriem merged 3 commits into
github:mainfrom
kartsan03:fix/init-force-keep-installed-integrations

Conversation

@kartsan03

@kartsan03 kartsan03 commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Description

specify init --here --force --integration <key> forgets every other installed integration. It rewrites .specify/integration.json with only the selected key in installed_integrations and only its entry in integration_settings. The other integration's files and manifest stay on disk, but integration status no longer lists it. integration upgrade <other> and integration uninstall <other> both exit 1 with Integration '<other>' is not installed., so the CLI can no longer refresh or remove those files.

docs/upgrade.md gives this command as the fallback for refreshing project files, and docs/integrations/cli.md documents installing more than one integration, so a project with two integrations hits this the first time it uses the fallback.

Repro:

specify init proj --integration claude --ignore-agent-tools --non-interactive --script sh
cd proj
specify integration install codex --script ps
specify init --here --force --integration claude --ignore-agent-tools --non-interactive
specify integration upgrade codex
After the re-init main (a4d5712) This PR
installed_integrations ["claude"] ["claude", "codex"]
Codex setting gone {"script": "ps", "invoke_separator": "-"}
.agents/skills/ still on disk still on disk
integration upgrade codex Error: Integration 'codex' is not installed., exit 1 upgraded, exit 0
integration uninstall codex same error, exit 1 uninstalled

I found it by following the upgrade guide on projects created with the released 0.16.5, 1.0.13, 1.1.3 and 1.2.6. All four behave the same, and so does a project created with main.

The fix: init reads the existing state with try_read_integration_json(), keeps its installed integrations and their settings, and updates only the selected integration's setting and the default. The selected integration's setting is rebuilt from the options passed to init, as docs/integrations/claude.md describes ("Re-running specify init likewise stores only the options passed to it"), so a re-init without --integration-options clears the ones stored before. A state file that can't be read still stops the run in the rollback journal, as on main. When the selected integration is a new one, it goes into the list next to the ones whose files are already on disk.

Testing

Set up this checkout's .venv and editable install using the local development guide. Run commands from the checkout root.

  • Tested locally with .venv/bin/specify --help (Windows PowerShell: .\.venv\Scripts\specify.exe --help)
  • Ran relevant existing tests with .venv/bin/python -m pytest tests -q (Windows PowerShell: .\.venv\Scripts\python.exe -m pytest tests -q); use affected test paths for focused checks and LC_ALL=en_US.UTF-8 on macOS
  • Tested with a sample project (if applicable)

New tests:

  • tests/specify_cli/test_command_init.py::test_reinit_keeps_other_installed_integrations: a Claude project with Codex installed is re-initialized with Claude (the default), Codex (the other installed one) or Gemini (a new one). The test checks installed_integrations, the default, the kept integration's setting, that the kept integration's manifest and files are unchanged byte for byte, integration status --json, and that integration upgrade of the kept integration succeeds. With the source reverted to main, all three cases fail (assert ['claude'] == ['claude', 'codex'], and the same for the other two).

  • tests/specify_cli/test_command_init.py::test_reinit_stores_only_the_options_passed_to_it: Claude installed with --no-model-invocation and Codex with --skills, then a re-init with Claude and no options. Claude's setting must equal a fresh init --integration claude, and Codex keeps --skills. It fails on 72c4a17 (the old options stay) and on main (Codex's setting is gone).

  • tests/specify_cli/integrations/test_installed_adapters.py, three tests for an external (catalog) adapter installed beside Claude, then a re-init with Claude:

    • test_reinit_keeps_installed_external_adapter: the adapter stays installed with its setting and record, and its package, manifest, packages.json and generated skills are unchanged byte for byte.
    • test_reinit_keeps_external_adapter_upgradeable_and_uninstallable: integration upgrade to 2.0.0 and then integration uninstall of the adapter both succeed, and the uninstall removes its package and files.
    • test_uninstalling_reinitialized_default_falls_back_to_external_adapter: integration uninstall claude selects the adapter as the new default.

    With the source reverted to main, all three fail: re-init drops the adapter's key, and the lifecycle cleanup removes its package.

Full suite on Linux, Python 3.13, with PowerShell 7.6 on PATH: 17430 passed, 308 skipped, 1 failed (pytest -n 2, 15 min). The failure, test_version_execution.py::TestWindowsUvToolEnvironment::test_non_windows_uv_tool_dry_run_still_previews_installer, fails the same way on main here: Rich wraps the dry-run output where my venv path is long. Ruff 0.15.0 (ruff check src tests) passes. I haven't run it on Windows or macOS.

AI Disclosure

  • I did not use AI assistance for this contribution
  • I did use AI assistance (fill in the disclosure below)

AI disclosure: Codex CLI (model: gpt-6.1-sol, reasoning effort xhigh, autonomous, offline sandbox) found the bug while running the steps in docs/upgrade.md on projects created by older releases, and wrote the fix and the test. Claude Code (model: claude-opus-5-5, autonomous) switched the state read to the non-raising helper, changed the test to use the state main writes, reran the repro with the real CLI on main and on the branch, ran the full suite and lint, and drafted this description. After the Copilot review, Claude Code (model: claude-opus-5-5, autonomous) reset the selected integration's options on re-init, added the test for it and reran the full suite. After the maintainer review, Claude Code (model: claude-opus-5-5, autonomous) added the external adapter tests and reran the full suite. Each commit carries its Assisted-by: trailers.

`specify init --here --force --integration <key>` wrote
`.specify/integration.json` with only the selected integration, so a
project with two integrations lost the other one's entry and settings.
Its files and manifest stayed on disk, but `integration status` no
longer listed it, and `integration upgrade <other>` exited 1 with
"Integration '<other>' is not installed". docs/upgrade.md gives this
command as the fallback for refreshing project files.

Read the existing state first, keep its installed integrations and
their settings, and refresh only the selected integration's setting and
the default.

Assisted-by: Codex (model: gpt-6.1-sol, autonomous)
Assisted-by: Claude Code (model: claude-opus-5-5, autonomous)
@kartsan03
kartsan03 requested a review from mnriem as a code owner November 23, 2026 18:04
Copilot AI adaptive review requested due to automatic review settings November 23, 2026 18:04

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Re-initialization without integration options retains stale settings for the selected integration, causing a later upgrade to restore behavior contrary to documented replacement semantics.

1 open issue
What changed in this PR

This PR fixes Specify CLI re-initialization so refreshing one integration does not make other installed integrations disappear from project state.

Changes:

  • Preserve installed integration keys and other integrations’ settings while updating the selected integration and default.
  • Add regression cases for selecting the default, another installed integration, or a new integration, checking retained files, status, and upgrade behavior.

Review and summary generated by GitHub Copilot (model unknown; autonomous) for the requesting reviewer (identity unavailable). Tests were not run during this review.

File Description
tests/​specify_cli/​test_command_init.py Adds parameterized regression coverage for preserving integrations during re-init.
src/​specify_cli/​command_init.py Reads existing integration state and retains installed keys and settings during re-init.

Review effort: Balanced (adaptive)

Comment thread src/specify_cli/command_init.py Resolved
@mnriem

mnriem commented Nov 23, 2026

Copy link
Copy Markdown
Collaborator

Please address Copilot feedback

…ration

Re-init kept the other installed integrations by starting from the
stored settings, but that also kept the selected integration's old
options: re-initializing Claude without `--integration-options` after
`--no-model-invocation` left `no_model_invocation: true` in state, and
the next upgrade applied it again. Rebuild the selected integration's
setting from the options passed to init, as docs/integrations/claude.md
describes, and keep the others.

Assisted-by: Claude Code (model: claude-opus-5-5, autonomous)
@kartsan03

Copy link
Copy Markdown
Contributor Author

Fixed in 9685f2a. Re-init now rebuilds the selected integration's setting from the options passed to it, as docs/integrations/claude.md describes, and still keeps the settings of the other installed integrations. Before, it started from the stored setting, so re-initializing Claude without --integration-options after --no-model-invocation left no_model_invocation: true in integration.json, and the next integration upgrade claude would apply it again.

New test test_reinit_stores_only_the_options_passed_to_it installs Claude with --no-model-invocation and Codex with --skills, re-initializes Claude without options, and checks that Claude's setting matches a fresh init --integration claude while Codex keeps --skills. It fails on 72c4a17 and passes now.

Full suite: 17427 passed, 308 skipped, and the same path-length failure in test_version_execution.py that main has in my checkout. Ruff is clean. The description is updated.

Drafted on behalf of @kartsan03 by Claude Code (model: claude-opus-5-5, autonomous); it also wrote the change and ran the tests.

Copilot AI adaptive review requested due to automatic review settings November 23, 2026 18:34

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Retaining installed integration keys interacts with re-init and external-lifecycle package cleanup, creating upgrade/uninstall implications that require broader review.

No open issues 🎉

1 resolved since last review

Review effort: Balanced (adaptive)

@mnriem mnriem added the triage-must-have Verdict: high-value, important work for Spec Kit — do first label Nov 23, 2026
@mnriem

mnriem commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

Thanks for addressing the options-reset issue. The deeper review found no blocking defect at 9685f2a8, but the external-adapter interaction deserves committed regression coverage: re-init previously dropped the adapter’s installed key, which caused lifecycle cleanup to remove its executable package. Could you add tests confirming that re-init preserves an installed external adapter’s package, settings, and generated files; that it remains upgradeable and uninstallable afterward; and that uninstalling the re-initialized default correctly selects the retained adapter as fallback? These cases passed in the additional review checks, with the corresponding regressions failing before the fix.

Drafted for @mnriem by GitHub Copilot (model: gpt-6.1-sol, autonomous review and test execution; human review pending).

Before the fix, re-init dropped an installed external adapter's key,
and the lifecycle cleanup then removed the adapter's package. Add
regressions: a re-initialized default keeps the adapter's package,
setting and generated files; the adapter still upgrades and
uninstalls; and uninstalling the default falls back to it.

Assisted-by: Claude Code (model: claude-opus-5-5, autonomous)
@kartsan03

Copy link
Copy Markdown
Contributor Author

Added in 051736e (tests only). The three new tests in tests/specify_cli/integrations/test_installed_adapters.py install Claude as the default and the catalog adapter sample-agent beside it, then re-initialize Claude with init --here --force:

  • test_reinit_keeps_installed_external_adapter: both keys stay installed and Claude stays the default. The adapter keeps its setting and record, and its package, manifest, packages.json and generated skills are unchanged byte for byte.
  • test_reinit_keeps_external_adapter_upgradeable_and_uninstallable: integration upgrade sample-agent to 2.0.0 succeeds. integration uninstall sample-agent then removes its package, record, manifest and skills, and Claude stays installed.
  • test_uninstalling_reinitialized_default_falls_back_to_external_adapter: integration uninstall claude makes sample-agent the active and default integration, and its skills, record and registration stay.

With src/specify_cli/command_init.py reverted to main, all three fail: assert ['claude'] == ['claude', 'sample-agent'], Integration 'sample-agent' is not installed., and integration.json missing after the uninstall.

Full suite: 17430 passed, 308 skipped, and the same path-length failure in test_version_execution.py as before. Ruff is clean. The description lists the new tests.

Drafted on behalf of @kartsan03 by Claude Code (model: claude-opus-5-5, autonomous); it also wrote the tests and ran them.

Copilot AI adaptive review requested due to automatic review settings November 24, 2026 22:29

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Preserving the installed set during re-init affects external-package retention, later upgrades and uninstalls, and default fallback, requiring cross-command lifecycle analysis beyond a limited local review.

No open issues 🎉

Review effort: Balanced (adaptive)

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Preserving multi-integration state affects external package retention, upgrades, uninstalls, and default fallback, creating interacting lifecycle consequences beyond the limited scope of conservative automated approval.

No open issues 🎉

Review effort: Balanced

@mnriem
mnriem merged commit dfe33ea into github:main Nov 25, 2026
14 checks passed
@mnriem

mnriem commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

triage-must-have Verdict: high-value, important work for Spec Kit — do first

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants