AI coding agents can edit files, run shell commands, and touch infrastructure. One bad rm -rf, force-push, or docker compose down -v can wipe hours of work or production data.
| 1 | # SPDX-License-Identifier: MIT |
| 2 | """Shared fixtures.""" |
| 3 | |
| 4 | from __future__ import annotations |
| 5 | |
| 6 | from pathlib import Path |
| 7 | |
| 8 | import pytest |
| 9 | |
| 10 | from agent_guard.config import GuardConfig |
| 11 | from agent_guard.models import Decision, PolicyMode |
| 12 | |
| 13 | |
| 14 | @pytest.fixture |
| 15 | def project_root(tmp_path: Path) -> Path: |
| 16 | (tmp_path / "src").mkdir() |
| 17 | (tmp_path / "tests").mkdir() |
| 18 | (tmp_path / ".git").mkdir() |
| 19 | (tmp_path / ".env").write_text("JWT_SECRET=placeholder\n", encoding="utf-8") |
| 20 | return tmp_path |
| 21 | |
| 22 | |
| 23 | @pytest.fixture |
| 24 | def config(project_root: Path) -> GuardConfig: |
| 25 | return GuardConfig( |
| 26 | project_root=project_root, |
| 27 | mode=PolicyMode.DEFAULT, |
| 28 | protected_hosts=["production.example.com", "api.production.example.com"], |
| 29 | rules={ |
| 30 | "destructive_filesystem": Decision.BLOCK, |
| 31 | "destructive_git": Decision.WARN, |
| 32 | "protected_branch_force_push": Decision.BLOCK, |
| 33 | "secret_access": Decision.BLOCK, |
| 34 | "docker_volume_delete": Decision.BLOCK, |
| 35 | "production_network": Decision.BLOCK, |
| 36 | "database_destructive": Decision.BLOCK, |
| 37 | "shell_chain_destructive": Decision.WARN, |
| 38 | }, |
| 39 | ) |