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 | from __future__ import annotations |
| 3 | |
| 4 | from agent_guard.config import GuardConfig |
| 5 | from agent_guard.evaluator import evaluate_command |
| 6 | from agent_guard.models import Decision, RiskLevel |
| 7 | |
| 8 | |
| 9 | def test_git_status_allow(config: GuardConfig) -> None: |
| 10 | assert evaluate_command("git status", config).decision == Decision.ALLOW |
| 11 | |
| 12 | |
| 13 | def test_git_diff_allow(config: GuardConfig) -> None: |
| 14 | assert evaluate_command("git diff", config).decision == Decision.ALLOW |
| 15 | |
| 16 | |
| 17 | def test_git_checkout_feature_allow(config: GuardConfig) -> None: |
| 18 | r = evaluate_command("git checkout feature", config) |
| 19 | assert r.decision == Decision.ALLOW |
| 20 | |
| 21 | |
| 22 | def test_git_reset_hard_warn(config: GuardConfig) -> None: |
| 23 | r = evaluate_command("git reset --hard HEAD", config) |
| 24 | assert r.decision == Decision.WARN |
| 25 | |
| 26 | |
| 27 | def test_git_clean_fdx(config: GuardConfig) -> None: |
| 28 | r = evaluate_command("git clean -fdx", config) |
| 29 | assert r.decision in {Decision.WARN, Decision.BLOCK} |
| 30 | assert r.risk.rank >= RiskLevel.HIGH.rank |
| 31 | |
| 32 | |
| 33 | def test_force_push_main_block(config: GuardConfig) -> None: |
| 34 | r = evaluate_command("git push --force origin main", config) |
| 35 | assert r.decision == Decision.BLOCK |
| 36 | assert r.risk == RiskLevel.CRITICAL |
| 37 | |
| 38 | |
| 39 | def test_push_feature_allow(config: GuardConfig) -> None: |
| 40 | r = evaluate_command("git push origin feature", config) |
| 41 | assert r.decision == Decision.ALLOW |