|
3 | 3 | import json |
4 | 4 | import os |
5 | 5 |
|
| 6 | +import pytest |
6 | 7 | import yaml |
7 | 8 |
|
8 | 9 | from tests.conftest import strip_ansi |
@@ -288,6 +289,66 @@ def test_shared_infra_warns_when_manifest_cannot_be_decoded(self, tmp_path, caps |
288 | 289 | assert "Could not read shared infrastructure manifest" in captured.out |
289 | 290 | assert "A new shared manifest will be created" in captured.out |
290 | 291 |
|
| 292 | + @pytest.mark.skipif(not hasattr(os, "symlink"), reason="symlinks are unavailable") |
| 293 | + def test_shared_infra_refuses_symlinked_script_destination(self, tmp_path): |
| 294 | + """Shared script refreshes must not follow destination symlinks.""" |
| 295 | + from specify_cli import _install_shared_infra |
| 296 | + |
| 297 | + project = tmp_path / "symlink-script-test" |
| 298 | + project.mkdir() |
| 299 | + (project / ".specify").mkdir() |
| 300 | + |
| 301 | + outside = tmp_path / "outside-script.sh" |
| 302 | + outside.write_text("# outside\n", encoding="utf-8") |
| 303 | + scripts_dir = project / ".specify" / "scripts" / "bash" |
| 304 | + scripts_dir.mkdir(parents=True) |
| 305 | + os.symlink(outside, scripts_dir / "common.sh") |
| 306 | + |
| 307 | + with pytest.raises(ValueError, match="Refusing to overwrite symlinked"): |
| 308 | + _install_shared_infra(project, "sh", force=True) |
| 309 | + |
| 310 | + assert outside.read_text(encoding="utf-8") == "# outside\n" |
| 311 | + |
| 312 | + @pytest.mark.skipif(not hasattr(os, "symlink"), reason="symlinks are unavailable") |
| 313 | + def test_shared_infra_refuses_symlinked_template_destination(self, tmp_path): |
| 314 | + """Shared template installs must not follow destination symlinks.""" |
| 315 | + from specify_cli import _install_shared_infra |
| 316 | + |
| 317 | + project = tmp_path / "symlink-template-test" |
| 318 | + project.mkdir() |
| 319 | + (project / ".specify").mkdir() |
| 320 | + |
| 321 | + outside = tmp_path / "outside-template.md" |
| 322 | + outside.write_text("# outside\n", encoding="utf-8") |
| 323 | + templates_dir = project / ".specify" / "templates" |
| 324 | + templates_dir.mkdir(parents=True) |
| 325 | + os.symlink(outside, templates_dir / "plan-template.md") |
| 326 | + |
| 327 | + with pytest.raises(ValueError, match="Refusing to overwrite symlinked"): |
| 328 | + _install_shared_infra(project, "sh", force=True) |
| 329 | + |
| 330 | + assert outside.read_text(encoding="utf-8") == "# outside\n" |
| 331 | + |
| 332 | + @pytest.mark.skipif(not hasattr(os, "symlink"), reason="symlinks are unavailable") |
| 333 | + def test_shared_template_refresh_refuses_symlinked_destination(self, tmp_path): |
| 334 | + """Template-only refreshes must not follow destination symlinks.""" |
| 335 | + from specify_cli import _refresh_shared_templates |
| 336 | + |
| 337 | + project = tmp_path / "symlink-refresh-test" |
| 338 | + project.mkdir() |
| 339 | + (project / ".specify").mkdir() |
| 340 | + |
| 341 | + outside = tmp_path / "outside-refresh.md" |
| 342 | + outside.write_text("# outside\n", encoding="utf-8") |
| 343 | + templates_dir = project / ".specify" / "templates" |
| 344 | + templates_dir.mkdir(parents=True) |
| 345 | + os.symlink(outside, templates_dir / "plan-template.md") |
| 346 | + |
| 347 | + with pytest.raises(ValueError, match="Refusing to overwrite symlinked"): |
| 348 | + _refresh_shared_templates(project, invoke_separator=".", force=True) |
| 349 | + |
| 350 | + assert outside.read_text(encoding="utf-8") == "# outside\n" |
| 351 | + |
291 | 352 | def test_shared_infra_no_warning_when_forced(self, tmp_path, capsys): |
292 | 353 | """No skip warning when force=True (all files overwritten).""" |
293 | 354 | from specify_cli import _install_shared_infra |
|
0 commit comments