项目文件夹

文件
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

124 行
3.6 KiB
Python

"""Shared pytest fixtures for PentestGPT tests."""
import tempfile
from pathlib import Path
import pytest
from pentestgpt.core.backend import AgentBackend, AgentMessage
from pentestgpt.core.config import PentestGPTConfig
from pentestgpt.core.events import EventBus
# =============================================================================
# Pytest Markers
# =============================================================================
def pytest_configure(config: pytest.Config) -> None:
"""Configure custom pytest markers."""
config.addinivalue_line("markers", "unit: Unit tests (fast, no external dependencies)")
config.addinivalue_line("markers", "integration: Integration tests (may use mocks)")
config.addinivalue_line("markers", "docker: Docker tests (requires Docker daemon)")
config.addinivalue_line("markers", "slow: Slow tests (skip with -m 'not slow')")
# =============================================================================
# EventBus Fixtures
# =============================================================================
@pytest.fixture(autouse=True)
def reset_event_bus():
"""Reset EventBus singleton before and after each test."""
EventBus.reset()
yield
EventBus.reset()
# =============================================================================
# Directory Fixtures
# =============================================================================
@pytest.fixture
def temp_sessions_dir():
"""Create a temporary directory for session storage."""
with tempfile.TemporaryDirectory() as tmpdir:
yield Path(tmpdir)
@pytest.fixture
def temp_working_dir():
"""Create a temporary working directory."""
with tempfile.TemporaryDirectory() as tmpdir:
yield Path(tmpdir)
# =============================================================================
# Configuration Fixtures
# =============================================================================
@pytest.fixture
def sample_config(temp_working_dir: Path) -> PentestGPTConfig:
"""Create a sample configuration for testing."""
return PentestGPTConfig(
target="test.example.com",
working_directory=temp_working_dir,
)
# =============================================================================
# Mock Backend
# =============================================================================
class MockBackend(AgentBackend):
"""Mock backend for testing agent controller."""
def __init__(self) -> None:
self._connected = False
self._messages: list[AgentMessage] = []
self._session_id = "mock-session-123"
async def connect(self) -> None:
"""Simulate connection."""
self._connected = True
async def disconnect(self) -> None:
"""Simulate disconnection."""
self._connected = False
async def query(self, prompt: str) -> None:
"""Simulate sending a query."""
pass
async def receive_messages(self):
"""Yield preset messages."""
for msg in self._messages:
yield msg
@property
def session_id(self) -> str:
"""Get mock session ID."""
return self._session_id
@property
def supports_resume(self) -> bool:
"""Mock does not support resume."""
return False
async def resume(self, session_id: str) -> bool:
"""Mock resume always fails."""
return False
def set_messages(self, messages: list[AgentMessage]) -> None:
"""Set messages to be returned by receive_messages."""
self._messages = messages
@pytest.fixture
def mock_backend() -> MockBackend:
"""Create a mock backend for testing."""
return MockBackend()