From 72c4a174b369ba1f8266d3318fb89df6bed28d35 Mon Sep 17 00:00:00 2001 From: kartsan03 Date: Mon, 23 Nov 2026 01:44:24 +0000 Subject: [PATCH 1/3] fix(init): keep other installed integrations on re-init `specify init --here --force --integration ` 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 ` exited 1 with "Integration '' 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) --- src/specify_cli/command_init.py | 15 +++++++++-- tests/specify_cli/test_command_init.py | 37 ++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 2 deletions(-) diff --git a/src/specify_cli/command_init.py b/src/specify_cli/command_init.py index a2fa33ee21..9a1c22a1c4 100644 --- a/src/specify_cli/command_init.py +++ b/src/specify_cli/command_init.py @@ -407,6 +407,10 @@ def init( invoke_prefix_for_integration as _invoke_prefix_for_integration, with_integration_setting as _with_integration_setting, ) + from .integration_state import ( + installed_integration_keys, + try_read_integration_json, + ) from .integrations._commands import ( _parse_integration_options, _write_integration_json, @@ -709,6 +713,13 @@ def init( from .integrations.manifest import IntegrationManifest tracker.start("integration") + # Re-init keeps the other installed integrations and their + # settings; only the selected one is refreshed. + current, _state_error = try_read_integration_json(project_path) + current = current or {} + installed_keys = installed_integration_keys(current) + if resolved_integration.key not in installed_keys: + installed_keys.append(resolved_integration.key) manifest = IntegrationManifest( resolved_integration.key, project_path, @@ -763,7 +774,7 @@ def init( ) manifest.save() integration_settings = _with_integration_setting( - {}, + current, resolved_integration.key, resolved_integration, script_type=selected_script, @@ -774,7 +785,7 @@ def init( _write_integration_json( project_path, resolved_integration.key, - [resolved_integration.key], + installed_keys, integration_settings, ) diff --git a/tests/specify_cli/test_command_init.py b/tests/specify_cli/test_command_init.py index f09f463f24..44c1187b71 100644 --- a/tests/specify_cli/test_command_init.py +++ b/tests/specify_cli/test_command_init.py @@ -142,6 +142,43 @@ def test_reinit_preserves_feature_numbering(tmp_path: Path, monkeypatch, numberi assert updated["here"] is True +@pytest.mark.parametrize("selected", ["claude", "codex", "gemini"]) +def test_reinit_keeps_other_installed_integrations(tmp_path, monkeypatch, selected): + """The upgrade-guide fallback must keep the other installed integrations.""" + monkeypatch.chdir(tmp_path) + runner = CliRunner() + args = ["--script", "sh", "--ignore-agent-tools", "--non-interactive"] + result = runner.invoke(app, ["init", "project", "--integration", "claude", *args]) + assert result.exit_code == 0, result.output + project = tmp_path / "project" + monkeypatch.chdir(project) + result = runner.invoke(app, ["integration", "install", "codex", "--script", "ps"]) + assert result.exit_code == 0, result.output + state_path = project / ".specify/integration.json" + before_state = json.loads(state_path.read_text(encoding="utf-8")) + retained = "claude" if selected == "codex" else "codex" + manifest_path = project / f".specify/integrations/{retained}.manifest.json" + before = {manifest_path: manifest_path.read_bytes()} + for relative in json.loads(before[manifest_path])["files"]: + path = project / relative + before[path] = path.read_bytes() + + result = runner.invoke(app, ["init", "--here", "--force", "--integration", selected, *args]) + + assert result.exit_code == 0, result.output + state = json.loads(state_path.read_text(encoding="utf-8")) + expected = ["claude", "codex"] + (["gemini"] if selected == "gemini" else []) + assert state["installed_integrations"] == expected + assert state["default_integration"] == selected + assert state["integration_settings"][retained] == before_state["integration_settings"][retained] + assert all(path.read_bytes() == content for path, content in before.items()) + result = runner.invoke(app, ["integration", "status", "--json"]) + assert result.exit_code == 0, result.output + assert json.loads(result.output)["installed_integrations"] == expected + result = runner.invoke(app, ["integration", "upgrade", retained]) + assert result.exit_code == 0, result.output + + @pytest.mark.parametrize("name", ["proj [v2]", "my[bold]app"]) def test_next_steps_cd_shows_the_real_project_name(tmp_path: Path, name: str): """The `cd` line must name the directory that was actually created.""" From 9685f2a81be11a8d9980797bdbd4b9c8338c0153 Mon Sep 17 00:00:00 2001 From: kartsan03 Date: Mon, 23 Nov 2026 18:25:09 +0000 Subject: [PATCH 2/3] fix(init): store only the passed options for the re-initialized integration 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) --- src/specify_cli/command_init.py | 10 +++++++-- tests/specify_cli/test_command_init.py | 31 ++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/src/specify_cli/command_init.py b/src/specify_cli/command_init.py index 9a1c22a1c4..1214cc376f 100644 --- a/src/specify_cli/command_init.py +++ b/src/specify_cli/command_init.py @@ -409,6 +409,7 @@ def init( ) from .integration_state import ( installed_integration_keys, + integration_settings as _stored_integration_settings, try_read_integration_json, ) from .integrations._commands import ( @@ -714,10 +715,15 @@ def init( tracker.start("integration") # Re-init keeps the other installed integrations and their - # settings; only the selected one is refreshed. + # settings; the selected one stores only the options passed here. current, _state_error = try_read_integration_json(project_path) current = current or {} installed_keys = installed_integration_keys(current) + other_settings = { + key: setting + for key, setting in _stored_integration_settings(current).items() + if key != resolved_integration.key + } if resolved_integration.key not in installed_keys: installed_keys.append(resolved_integration.key) manifest = IntegrationManifest( @@ -774,7 +780,7 @@ def init( ) manifest.save() integration_settings = _with_integration_setting( - current, + {"integration_settings": other_settings}, resolved_integration.key, resolved_integration, script_type=selected_script, diff --git a/tests/specify_cli/test_command_init.py b/tests/specify_cli/test_command_init.py index 44c1187b71..7dd683e4e7 100644 --- a/tests/specify_cli/test_command_init.py +++ b/tests/specify_cli/test_command_init.py @@ -179,6 +179,37 @@ def test_reinit_keeps_other_installed_integrations(tmp_path, monkeypatch, select assert result.exit_code == 0, result.output +def test_reinit_stores_only_the_options_passed_to_it(tmp_path, monkeypatch): + """Re-init replaces the selected integration's options and keeps the others'.""" + monkeypatch.chdir(tmp_path) + runner = CliRunner() + args = ["--script", "sh", "--ignore-agent-tools", "--non-interactive"] + result = runner.invoke(app, ["init", "fresh", "--integration", "claude", *args]) + assert result.exit_code == 0, result.output + fresh = json.loads((tmp_path / "fresh/.specify/integration.json").read_text(encoding="utf-8")) + result = runner.invoke(app, [ + "init", "project", "--integration", "claude", + "--integration-options=--no-model-invocation", *args, + ]) + assert result.exit_code == 0, result.output + project = tmp_path / "project" + monkeypatch.chdir(project) + result = runner.invoke(app, [ + "integration", "install", "codex", "--script", "ps", "--integration-options=--skills", + ]) + assert result.exit_code == 0, result.output + state_path = project / ".specify/integration.json" + before = json.loads(state_path.read_text(encoding="utf-8")) + assert before["integration_settings"]["claude"]["parsed_options"] == {"no_model_invocation": True} + + result = runner.invoke(app, ["init", "--here", "--force", "--integration", "claude", *args]) + + assert result.exit_code == 0, result.output + state = json.loads(state_path.read_text(encoding="utf-8")) + assert state["integration_settings"]["claude"] == fresh["integration_settings"]["claude"] + assert state["integration_settings"]["codex"] == before["integration_settings"]["codex"] + + @pytest.mark.parametrize("name", ["proj [v2]", "my[bold]app"]) def test_next_steps_cd_shows_the_real_project_name(tmp_path: Path, name: str): """The `cd` line must name the directory that was actually created.""" From 051736e21b2e45feb550ced871774789caaeb7fc Mon Sep 17 00:00:00 2001 From: kartsan03 Date: Tue, 24 Nov 2026 22:22:20 +0000 Subject: [PATCH 3/3] test(init): cover an external adapter kept across re-init 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) --- .../integrations/test_installed_adapters.py | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/tests/specify_cli/integrations/test_installed_adapters.py b/tests/specify_cli/integrations/test_installed_adapters.py index 5b0f80e8e1..8839f74d9e 100644 --- a/tests/specify_cli/integrations/test_installed_adapters.py +++ b/tests/specify_cli/integrations/test_installed_adapters.py @@ -1698,6 +1698,67 @@ def test_new_project_init_from_catalog_environment(tmp_path, server, monkeypatch assert KEY in read_records(project) +def adapter_files(project): + package = f".specify/integrations/packages/{KEY}/" + return { + path: content for path, content in snapshot(project).items() + if path.startswith((".sample-agent/", package)) + or path in {f".specify/integrations/{KEY}.manifest.json", ".specify/integrations/packages.json"} + } + + +def reinit_default_beside_adapter(tmp_path, server): + """Install Claude (default) and the external adapter, then re-init Claude.""" + publish(server) + project = catalog_project(tmp_path, server) + assert run(project, ["integration", "install", "claude"]).exit_code == 0 + install(project) + before = adapter_files(project) + setting = json.loads((project / ".specify/integration.json").read_text())["integration_settings"][KEY] + reinit = run(project, [ + "init", "--here", "--force", "--non-interactive", "--ignore-agent-tools", + "--integration", "claude", "--script", "py", + ]) + assert reinit.exit_code == 0, reinit.output + return project, before, setting + + +def test_reinit_keeps_installed_external_adapter(tmp_path, server): + project, before, setting = reinit_default_beside_adapter(tmp_path, server) + state = json.loads((project / ".specify/integration.json").read_text()) + assert state["installed_integrations"] == ["claude", KEY] + assert state["default_integration"] == "claude" + assert state["integration_settings"][KEY] == setting + assert KEY in read_records(project) + assert adapter_files(project) == before + + +def test_reinit_keeps_external_adapter_upgradeable_and_uninstallable(tmp_path, server): + project, _, _ = reinit_default_beside_adapter(tmp_path, server) + publish(server, version="2.0.0") + upgraded = run(project, ["integration", "upgrade", KEY, "--trust-integration"]) + assert upgraded.exit_code == 0, upgraded.output + assert read_records(project)[KEY]["version"] == "2.0.0" + removed = run(project, ["integration", "uninstall", KEY]) + assert removed.exit_code == 0, removed.output + assert adapter_files(project) == {} + state = json.loads((project / ".specify/integration.json").read_text()) + assert state["installed_integrations"] == ["claude"] + assert KEY not in INTEGRATION_REGISTRY + + +def test_uninstalling_reinitialized_default_falls_back_to_external_adapter(tmp_path, server): + project, _, _ = reinit_default_beside_adapter(tmp_path, server) + removed = run(project, ["integration", "uninstall", "claude"]) + assert removed.exit_code == 0, removed.output + state = json.loads((project / ".specify/integration.json").read_text()) + assert state["installed_integrations"] == [KEY] + assert state["integration"] == state["default_integration"] == KEY + assert not (project / ".claude/skills/speckit-plan/SKILL.md").exists() + assert (project / ".sample-agent/skills/speckit-plan/SKILL.md").is_file() + assert KEY in read_records(project) and KEY in INTEGRATION_REGISTRY + + @pytest.mark.parametrize("damaged_uninstall", [False, True]) @pytest.mark.parametrize("failed_commit", [False, True]) def test_extension_and_preset_contributions_follow_active_external_adapter(