Introducing a new way to review your PRs.

Read the announcement

greydgl / pentestgpt

Automated Penetration Testing Agentic Framework Powered by Large Language Models

View on GitHub

13 documents · Updated Nov 16, 2026

docs / repository-test-suite

Repository Test Suite

Overview

The repository-level pytest suite lives under tests/…/*.py and is configured by pyproject.toml, which sets testpaths = ["tests"], adds the repository root to pythonpath, enables pytest-asyncio auto mode for async tests, and enforces strict marker/config validation. tests/conftest.py registers the suite markers used by the files here: unit, integration, docker, and slow.

The active top-level tests primarily exercise the unified_agent compatibility layer. tests/test_agent.py uses an in-memory FakeBackend to validate UnifiedAgent.run, UnifiedAgent.stream, run_sync, option propagation, workspace preparation, skill/tool preparation, and SuperAgent fan-out concurrency without invoking real model backends. It maps back to unified_agent.agent, unified_agent.events, unified_agent.task, and unified_agent.types behavior by asserting the unified result aggregates assistant text, tool calls, file changes, usage, cost, session IDs, and error fallback semantics.

Backend adapter tests are split by implementation. tests/test_claude_backend.py checks unified_agent.backends.claude_code: sandbox policies map to Claude Code permission modes and tool allow/deny lists; tool-server specs become stdio MCP config; instructions preserve the native Claude Code preset; output schema, resume, max-turn, model, env, effort, and partial-message options pass through; and SDK message types normalize into SessionStarted, Reasoning, AssistantText, ToolCall, ToolResult, TextDelta, and TurnCompleted events. tests/test_codex_backend.py covers unified_agent.backends.codex: MCP server TOML overrides, sandbox and thread kwargs, effort validation, Codex notification normalization, token usage accumulation, structured-output parsing from final text, unknown notifications becoming RawEvent, and failure aggregation into TurnCompleted.error.

Tooling and skill tests share a small importable fixture registry in tests/fixture_registry.py. That fixture defines a ToolRegistry("unified") with sync add_numbers and async echo_upper tools, and is reused by tests/test_tools.py, tests/test_tool_server.py, tests/test_agent.py, and backend MCP option tests. tests/test_tools.py validates tool registration constraints, registry-spec round trips, registry resolution errors, and build_tool_server_spec command/PYTHONPATH construction. tests/test_tool_server.py validates that unified_agent.tool_server.build_server exposes the fixture registry and includes a @pytest.mark.slow stdio subprocess round trip through mcp.client.stdio, which is the closest non-Docker integration boundary for the same server process the agents launch.

Prompt/task and skill-file behavior are covered separately. tests/test_task.py verifies unified_agent.task.Task rendering for raw instructions, embedded context files, extra context, backend-specific skill hints, missing context files, truncation of very large context files, and coercion from strings. tests/test_skills.py covers unified_agent.skills loading/linting/installing: SKILL.md frontmatter validation, name and description rules, warnings for Claude-only syntax, discovery order, symlink installation into both .claude/skills and .agents/skills, stale symlink replacement, force behavior for real directories, copy mode, and empty-source errors.

Legacy tests under tests/legacy/ map to pentestgpt_legacy.llm. tests/…/test_registry.py asserts model/provider registry invariants, aliases, dynamic ollama: resolution, provider coverage, and uniqueness. tests/…/test_config.py validates credential and base-URL lookup, including alias env vars and keyless Ollama. tests/…/test_factory.py checks model-to-provider/client construction for OpenAI-compatible, DeepSeek, Anthropic, unknown models, missing credentials, Ollama, and nonempty model listing. tests/…/test_client.py uses a fake async provider to test the synchronous LLMClient conversation bridge, system prompt forwarding, continued conversation history, and history trimming.

tests/…/test_flag_detection.py is a self-contained compatibility test for historical CTF flag scoring patterns rather than a direct import of production code. It defines local FLAG_PATTERNS and detect_flags helpers, then marks the class @pytest.mark.unit and verifies common flag{}, FLAG{}, HTB{}, CTF{}, generic CTF, 32-character hex, duplicate suppression, empty/no-flag behavior, and several false-positive boundaries.

Docker integration tests are isolated under tests/docker/ and are both @pytest.mark.docker and @pytest.mark.slow. tests/…/test_docker_build.py expects Dockerfile, docker-compose.yml, scripts/config.sh, and scripts/entrypoint.sh at the repository root; it validates compose config, basic Dockerfile contents, bash syntax for scripts, and can run a full docker compose build with a 10-minute timeout. tests/…/test_container_health.py starts docker compose up -d, assumes the container is named pentestgpt, and probes /workspace, Python, uv, nmap, curl, git, netcat, ripgrep, tmux, the pentester user, sudo, importability of unified_agent and pentestgpt_legacy, and optional Claude Code CLI availability before tearing the compose stack down.

Coupling

Risks

  • tests/…/test_container_health.py relies on a fixed compose container name pentestgpt; if docker-compose.yml changes the service/container naming, the fixture can skip or fail even when the container is healthy.
  • tests/…/test_flag_detection.py duplicates flag-detection logic locally instead of importing production code; if the implementation changes elsewhere, this test can keep passing while real flag scoring diverges.
  • tests/test_tool_server.py has a slow stdio subprocess test that depends on importability of tests.fixture_registry:REG through the generated PYTHONPATH; changes to package layout or test invocation environment can break only the subprocess path while in-process registry tests still pass.