项目文件夹

文件
Gelei Deng e238d701f2 feat: 🎸 version 1.0 agentic workflow (#325)
* feat: 🎸 version 1.0 agentic workflow

Major rewrite of PentestGPT to use an agentic pipeline architecture:
Core Changes: - New event-driven architecture with EventBus for
TUI-agent decoupling - Implemented AgentController with 5-state
lifecycle (IDLE->RUNNING->PAUSED->COMPLETED->ERROR) - Added AgentBackend
interface with ClaudeCodeBackend implementation - Session management
with file-based persistence for resumable pentests - Langfuse
integration for observability and tracing Interface: - New Textual-based
TUI with real-time activity feed - Keyboard shortcuts: F1 help, Ctrl+P
pause, Ctrl+Q quit - Enhanced CLI with --target, --instruction,
--non-interactive, --debug flags Project Structure: - Moved legacy
multi-LLM version (v0.15) to legacy/ directory - New pentestgpt/core/
for agent, controller, events, session modules - New
pentestgpt/interface/ for TUI and CLI components - New
pentestgpt/benchmark/ for xbow benchmark integration - Comprehensive
test suite in tests/ with unit and integration tests DevOps: - Docker
support with Ubuntu 24.04 container - GitHub Actions CI/CD pipeline -
Makefile with dev commands (test, lint, format, typecheck) - Added
xbow-validation-benchmarks as submodule

* style: format code with Black

This commit fixes the style issues introduced in abe3be0 according to the output
from Black.

Details: https://github.com/GreyDGL/PentestGPT/pull/325

* fix: 🐛 fix test pipeline

* feat: 🎸 update format

* feat: 🎸 update

---------

Co-authored-by: deepsource-autofix[bot] <62050782+deepsource-autofix[bot]@users.noreply.github.com>
2025-12-13 01:57:24 +08:00

105 行
3.6 KiB
Python

"""Tests for Docker build process.
Docker tests that verify the Dockerfile and docker-compose configuration
are valid and can build successfully.
"""
import subprocess
from pathlib import Path
import pytest
# Project root directory
PROJECT_ROOT = Path(__file__).parent.parent.parent
@pytest.mark.docker
@pytest.mark.slow
class TestDockerBuild:
"""Tests for Docker build process."""
def test_dockerfile_exists(self):
"""Test that Dockerfile exists in project root."""
dockerfile = PROJECT_ROOT / "Dockerfile"
assert dockerfile.exists(), "Dockerfile not found in project root"
def test_docker_compose_exists(self):
"""Test that docker-compose.yml exists in project root."""
compose_file = PROJECT_ROOT / "docker-compose.yml"
assert compose_file.exists(), "docker-compose.yml not found in project root"
def test_docker_compose_config_valid(self):
"""Test that docker-compose configuration is valid."""
result = subprocess.run(
["docker", "compose", "config"],
cwd=PROJECT_ROOT,
capture_output=True,
text=True,
timeout=30,
)
assert result.returncode == 0, f"docker compose config failed: {result.stderr}"
def test_dockerfile_syntax_valid(self):
"""Test that Dockerfile has valid syntax using docker build --check."""
# Use docker build with --check flag (available in recent Docker versions)
# If not available, just verify the file can be parsed
dockerfile = PROJECT_ROOT / "Dockerfile"
content = dockerfile.read_text()
# Basic syntax checks
assert "FROM" in content, "Dockerfile must have a FROM instruction"
assert "ubuntu" in content.lower(), "Expected Ubuntu base image"
def test_docker_image_builds(self):
"""Test that Docker image builds successfully.
Note: This test is slow and requires Docker to be running.
It's marked with @pytest.mark.slow for optional skipping.
"""
result = subprocess.run(
["docker", "compose", "build"],
cwd=PROJECT_ROOT,
capture_output=True,
text=True,
timeout=600, # 10 minute timeout for build
)
# Check build succeeded
assert result.returncode == 0, f"Docker build failed:\n{result.stderr}"
def test_scripts_exist(self):
"""Test that required scripts exist."""
scripts_dir = PROJECT_ROOT / "scripts"
# Check config.sh
config_script = scripts_dir / "config.sh"
assert config_script.exists(), "scripts/config.sh not found"
# Check entrypoint.sh
entrypoint_script = scripts_dir / "entrypoint.sh"
assert entrypoint_script.exists(), "scripts/entrypoint.sh not found"
def test_entrypoint_script_syntax(self):
"""Test that entrypoint.sh has valid bash syntax."""
entrypoint = PROJECT_ROOT / "scripts" / "entrypoint.sh"
result = subprocess.run(
["bash", "-n", str(entrypoint)],
capture_output=True,
text=True,
timeout=10,
)
assert result.returncode == 0, f"entrypoint.sh syntax error: {result.stderr}"
def test_config_script_syntax(self):
"""Test that config.sh has valid bash syntax."""
config_script = PROJECT_ROOT / "scripts" / "config.sh"
result = subprocess.run(
["bash", "-n", str(config_script)],
capture_output=True,
text=True,
timeout=10,
)
assert result.returncode == 0, f"config.sh syntax error: {result.stderr}"