From b66405266c2226bfe0355f1c1ce6fe21fb5f8040 Mon Sep 17 00:00:00 2001 From: Sparsh Nagpal <0sparsh2@gmail.com> Date: Tue, 15 Sep 2026 10:22:48 -0400 Subject: [PATCH] Preflight scaffold plugin collisions --- agentbridge/scaffold.py | 10 ++++++++-- tests/test_scaffold.py | 21 +++++++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/agentbridge/scaffold.py b/agentbridge/scaffold.py index c7a56ae..5c0a345 100644 --- a/agentbridge/scaffold.py +++ b/agentbridge/scaffold.py @@ -61,9 +61,15 @@ def scaffold_adapter_plugin( ), } + collisions = [path for path in files if path.exists()] + if collisions and not force: + formatted = ", ".join(str(path) for path in collisions) + raise FileExistsError( + f"Scaffold target already exists at generated path(s): {formatted}; " + "pass force=True to overwrite" + ) + for path, content in files.items(): - if path.exists() and not force: - raise FileExistsError(f"{path} already exists; pass force=True to overwrite") path.parent.mkdir(parents=True, exist_ok=True) path.write_text(content, encoding="utf-8") created.append(ScaffoldedFile(path=path, created=True)) diff --git a/tests/test_scaffold.py b/tests/test_scaffold.py index 8927359..13a838b 100644 --- a/tests/test_scaffold.py +++ b/tests/test_scaffold.py @@ -62,3 +62,24 @@ def test_scaffold_adapter_plugin_does_not_overwrite_without_force(tmp_path) -> N assert "already exists" in str(exc) else: # pragma: no cover - defensive assertion style raise AssertionError("Expected existing files to fail without force") + + +def test_scaffold_adapter_plugin_preflights_collisions_before_writing(tmp_path) -> None: + target = tmp_path / "plugin" + package_dir = target / "agentbridge_custom" + package_dir.mkdir(parents=True) + (package_dir / "adapter.py").write_text("# existing adapter\n", encoding="utf-8") + + try: + scaffold_adapter_plugin(target, backend_name="custom") + except FileExistsError as exc: + message = str(exc) + assert "adapter.py" in message + assert "force=True" in message + else: # pragma: no cover - defensive assertion style + raise AssertionError("Expected existing adapter.py to fail without force") + + assert not (target / "pyproject.toml").exists() + assert not (target / "README.md").exists() + assert not (package_dir / "__init__.py").exists() + assert not (target / "tests" / "test_adapter.py").exists()