Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions adapters/opencode/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ def install(destination: Path) -> Path:
if destination.is_relative_to(ROOT):
raise ValueError("Install outside the source tree")
destination.mkdir(parents=True)
try:
return _install_into(destination)
except BaseException:
shutil.rmtree(destination, ignore_errors=True)
raise


def _install_into(destination: Path) -> Path:
bundle = destination / "bundle"
bundle.mkdir()
for directory in ("skills", "agents", "resources", "docs"):
Expand Down
17 changes: 17 additions & 0 deletions tests/unit/test_opencode_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,3 +187,20 @@ def test_env_matching_destination_is_rejected(tmp_path: Path, suffix: str) -> No
with pytest.raises(ValueError, match="read rules"):
ADAPTER["install"](tmp_path / suffix)
assert not list(tmp_path.iterdir())


def test_install_cleans_up_partial_destination_on_symlink_failure(
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
) -> None:
destination = tmp_path / "egm-oc"

def fail_symlink(self: Path, target: Path, target_is_directory: bool = False) -> None:
assert (destination / "bundle").is_dir()
raise OSError("symlinks disabled")

with monkeypatch.context() as patch:
patch.setattr(Path, "symlink_to", fail_symlink)
with pytest.raises(OSError, match="symlinks disabled"):
ADAPTER["install"](destination)
assert not destination.exists()
assert ADAPTER["install"](destination).is_file()
Loading