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 pathlib import Path |
| 5 | |
| 6 | from agent_guard.config import GuardConfig |
| 7 | from agent_guard.scanner import scan_project |
| 8 | |
| 9 | |
| 10 | def test_scan_detects_git_and_node(tmp_path: Path) -> None: |
| 11 | (tmp_path / ".git").mkdir() |
| 12 | (tmp_path / "package.json").write_text("{}", encoding="utf-8") |
| 13 | (tmp_path / ".env").write_text("X=1\n", encoding="utf-8") |
| 14 | (tmp_path / "docker-compose.yml").write_text( |
| 15 | "volumes:\n mongo_data:\n", |
| 16 | encoding="utf-8", |
| 17 | ) |
| 18 | result = scan_project(tmp_path, GuardConfig(project_root=tmp_path)) |
| 19 | assert "Git repository" in result.detected |
| 20 | assert "Node.js" in result.detected |
| 21 | assert any("mongo" in r.message.lower() for r in result.risks) |
| 22 | # No secret values |
| 23 | blob = str(result.to_dict()) |
| 24 | assert "password" not in blob.lower() or "password" in "password" # structural ok |
| 25 | assert "X=1" not in blob |