| 1 | from pathlib import Path |
| 2 | |
| 3 | from plugins._a0_acp.extensions.python.startup_migration._10_migrate_legacy_acp import ( |
| 4 | migrate_legacy_acp, |
| 5 | ) |
| 6 | |
| 7 | |
| 8 | def test_migrate_legacy_acp_removes_all_stale_plugin_roots(tmp_path: Path) -> None: |
| 9 | stale_roots = [ |
| 10 | tmp_path / "usr" / "plugins" / "a0_acp", |
| 11 | tmp_path / "usr" / "projects" / "demo" / ".a0proj" / "plugins" / "a0_acp", |
| 12 | tmp_path / "usr" / "agents" / "reviewer" / "plugins" / "a0_acp", |
| 13 | ] |
| 14 | bundled_config = tmp_path / "usr" / "plugins" / "_a0_acp" / "config.json" |
| 15 | |
| 16 | for root in stale_roots: |
| 17 | (root / ".git").mkdir(parents=True) |
| 18 | (root / "plugin.yaml").write_text("name: a0_acp\n", encoding="utf-8") |
| 19 | (root / ".git" / "config").write_text("[core]\n", encoding="utf-8") |
| 20 | bundled_config.parent.mkdir(parents=True) |
| 21 | bundled_config.write_text('{"enabled": true}\n', encoding="utf-8") |
| 22 | |
| 23 | result = migrate_legacy_acp(tmp_path) |
| 24 | |
| 25 | assert len(result["removed_roots"]) == len(stale_roots) |
| 26 | assert result["errors"] == [] |
| 27 | assert all(not root.exists() for root in stale_roots) |
| 28 | assert bundled_config.read_text(encoding="utf-8") == '{"enabled": true}\n' |
| 29 | assert migrate_legacy_acp(tmp_path) == {"removed_roots": [], "errors": []} |