|
| 1 | +"""Artifact-free integration and its normal management lifecycle.""" |
| 2 | + |
| 3 | +import json |
| 4 | + |
| 5 | +import pytest |
| 6 | +from typer.testing import CliRunner |
| 7 | + |
| 8 | +from specify_cli import app |
| 9 | +from specify_cli.integrations import get_integration |
| 10 | +from specify_cli.integrations.manifest import IntegrationManifest |
| 11 | + |
| 12 | + |
| 13 | +def test_none_setup_produces_no_files(tmp_path): |
| 14 | + integration = get_integration("none") |
| 15 | + assert integration is not None |
| 16 | + assert integration.multi_install_safe |
| 17 | + assert integration.registrar_config is None |
| 18 | + assert integration.list_command_templates() == [] |
| 19 | + manifest = IntegrationManifest("none", tmp_path) |
| 20 | + before = list(tmp_path.iterdir()) |
| 21 | + assert integration.setup(tmp_path, manifest) == [] |
| 22 | + assert manifest.files == {} |
| 23 | + assert list(tmp_path.iterdir()) == before |
| 24 | + |
| 25 | + |
| 26 | +@pytest.mark.parametrize("integration_args", [[], ["--integration", "none"]]) |
| 27 | +def test_none_lifecycle(tmp_path, monkeypatch, integration_args): |
| 28 | + runner = CliRunner() |
| 29 | + monkeypatch.setenv("SPECKIT_INTEGRATION_DEFAULT", "none") |
| 30 | + project = tmp_path / "project" |
| 31 | + |
| 32 | + def run(*arguments): |
| 33 | + result = runner.invoke(app, list(arguments)) |
| 34 | + assert result.exit_code == 0, result.output |
| 35 | + |
| 36 | + def state(): |
| 37 | + return json.loads((project / ".specify/integration.json").read_text()) |
| 38 | + |
| 39 | + run("init", str(project), "--non-interactive", *integration_args) |
| 40 | + monkeypatch.chdir(project) |
| 41 | + assert state()["integration"] == "none" |
| 42 | + assert state()["installed_integrations"] == ["none"] |
| 43 | + options = json.loads((project / ".specify/init-options.json").read_text()) |
| 44 | + assert options["ai"] == options["integration"] == "none" |
| 45 | + assert IntegrationManifest.load("none", project).files == {} |
| 46 | + assert not (project / ".github").exists() |
| 47 | + user_file = project / "AGENTS.md" |
| 48 | + user_file.write_text("User-owned instructions\n") |
| 49 | + run("integration", "install", "copilot", "--force") |
| 50 | + assert state()["integration"] == "none" |
| 51 | + run("integration", "use", "copilot") |
| 52 | + run("integration", "uninstall", "copilot") |
| 53 | + assert state()["integration"] == "none" |
| 54 | + run("integration", "upgrade", "none") |
| 55 | + run("integration", "uninstall", "none") |
| 56 | + assert not (project / ".specify/integration.json").exists() |
| 57 | + assert not (project / ".specify/integrations/none.manifest.json").exists() |
| 58 | + assert (project / ".specify/templates/spec-template.md").is_file() |
| 59 | + run("integration", "install", "none") |
| 60 | + run("integration", "switch", "copilot") |
| 61 | + assert state()["installed_integrations"] == ["copilot"] |
| 62 | + run("integration", "switch", "none") |
| 63 | + assert state()["installed_integrations"] == ["none"] |
| 64 | + assert IntegrationManifest.load("none", project).files == {} |
| 65 | + assert not (project / ".github").exists() |
| 66 | + assert user_file.read_text() == "User-owned instructions\n" |
| 67 | + result = runner.invoke(app, [ |
| 68 | + "integration", "upgrade", "none", "--integration-options=--skills", |
| 69 | + ]) |
| 70 | + assert result.exit_code == 1, result.output |
| 71 | + assert "Unknown integration option" in result.output |
| 72 | + assert IntegrationManifest.load("none", project).files == {} |
| 73 | + |
| 74 | + |
| 75 | +@pytest.mark.parametrize("force", [False, True]) |
| 76 | +def test_none_teardown_preserves_unowned_dispatcher(tmp_path, force): |
| 77 | + integration = get_integration("none") |
| 78 | + manifest = IntegrationManifest("none", tmp_path) |
| 79 | + manifest.save() |
| 80 | + dispatcher = tmp_path / ".specify/events.py" |
| 81 | + dispatcher.write_text("# User-owned dispatcher\n") |
| 82 | + |
| 83 | + assert integration.teardown(tmp_path, manifest, force=force) == ([], []) |
| 84 | + assert dispatcher.read_text() == "# User-owned dispatcher\n" |
| 85 | + assert not (tmp_path / ".specify/integrations/none.manifest.json").exists() |
| 86 | + |
| 87 | + |
| 88 | +def test_none_coexists_with_a_safe_agent_without_force(tmp_path, monkeypatch): |
| 89 | + runner = CliRunner() |
| 90 | + project = tmp_path / "project" |
| 91 | + result = runner.invoke(app, [ |
| 92 | + "init", str(project), "--integration", "none", "--non-interactive", |
| 93 | + ]) |
| 94 | + assert result.exit_code == 0, result.output |
| 95 | + monkeypatch.chdir(project) |
| 96 | + result = runner.invoke(app, ["integration", "install", "kiro-cli"]) |
| 97 | + assert result.exit_code == 0, result.output |
| 98 | + state = json.loads((project / ".specify/integration.json").read_text()) |
| 99 | + assert state["integration"] == "none" |
| 100 | + assert state["installed_integrations"] == ["none", "kiro-cli"] |
| 101 | + result = runner.invoke(app, ["integration", "status", "--json"]) |
| 102 | + assert result.exit_code == 0, result.output |
| 103 | + assert json.loads(result.output)["status"] == "ok" |
| 104 | + result = runner.invoke(app, ["integration", "install", "copilot"]) |
| 105 | + assert result.exit_code == 1, result.output |
| 106 | + assert "multi-install safe" in result.output |
0 commit comments