Testing Reference
Audience: Developers — Contributors modifying or testing the
hpilotcodebase.
This guide covers the test suite, end-to-end smoke tests, the mock LLM API server, and Unix daemon fixtures.
Unit Test Files
Key unit test files in tests/unit/ include:
test_config_parsing.py— Configuration loading and validationtest_cli_commands.py— CLI command dispatch and behaviortest_pipeline_stage_execution.py— Pipeline stage executionevaluation/test_contracts_events_prompts.py— post-run contract evaluationtest_adapter_registry.py— Harness adapter registrytest_completions.py— Shell completion script generation and dynamic completer wiringtest_daemon_lock.py— Daemon lock file management and stale-lock recoverytest_mcp_dispatcher.py— bounded worker dispatch, cancellation semantics, and atomic-write completiontest_client_reconnect.pyandtest_daemon_replay_sequences.py— cursor replay, repeated disconnects, exactly-once consumption, replay gaps, and handoff ordering
Run focused reliability tests while implementing:
uv run pytest tests/unit/test_mcp_dispatcher.py tests/unit/test_client_reconnect.py tests/unit/test_daemon_replay_sequences.py
uv run pytest tests/integration/test_serve_mcp_reliability.py --run-integrationThe combined regression uses synchronized barriers rather than sleeps to hold a file worker while daemon traffic, a durable write, a submit disconnect/resume, and persistent diagnostic correlation proceed on the shared loop. It also asserts one server-side modifying-tool start so ambiguous transport loss never causes an automatic write retry.
Smoke Tests
For a dedicated verify-stage smoke test that runs from Review Plan through Verify using a minimal feature prompt and the bundled mock LLM API (target runtime: under 90 seconds):
scripts/e2e-verify-smoke.sh [--harness claude]This is the preferred CI smoke test for exercising hpilot's verify-stage contract and routing infrastructure.
- By default it uses
harness: mock(no external binaries or API keys needed). - Pass
--harness claudeto exercise the Claude Code adapter path with all LLM calls still routed through the mock API server. - Creates a fresh workspace under
.tmp/e2e-verify/and points the verifier to the mock API (does not touch~/.hpilot/config.yaml). - Starts the bundled mock LLM API server (
scripts/.e2e_mock_llm_api.py) in allow mode. - Runs the final five simple scaffold stages (Review Plan → Implement → Review Code → Review Docs → Verify).
- Skips Plan because the required planning artifacts are pre-written.
- Asserts artifact presence, Verify contract, and minimal generated-code footprint.
Mock API Server
The mock API server (scripts/.e2e_mock_llm_api.py) is an OpenAI-compatible HTTP server for testing. It:
- Returns deterministic
approve/blockdecisions for verifier calls. - Returns stage-specific responses from a JSON config file for harness-backed stage calls.
Standalone Mock API Usage
Start the mock API server alongside a pipeline run:
python3 scripts/.e2e_mock_llm_api.py \
--config .hpilot/mock-stage-config.json \
--hook-mode allowThe server prints its URL to stdout on startup. Point the verifier at that URL and use any string as the API key.
- The mock server's
--hook-mode allowflag causes all verifier calls to returnapprove; use--hook-mode blockforblockdecisions. This flag controls mock verifier responses and is unrelated to hpilot's removed agent-hook runtime. - Stage-agent calls are routed by stage name extracted from the prompt. Provide a JSON config file mapping stage names to response strings.
Example config JSON:
{
"Plan": "Write the spec and plan.",
"Review Plan": "IMPLEMENTATION_READY",
"Implement": "# Summary\n\nDone.",
"Review Code": "APPROVED",
"Review Docs": "APPROVED",
"Verify": "APPROVED",
"_fallback": "PASS",
"claude": {
"Plan": "Write the spec and plan.",
"Review Plan": "IMPLEMENTATION_READY",
"Implement": "# Summary\n\nDone.",
"Review Code": "APPROVED",
"Review Docs": "APPROVED",
"Verify": "APPROVED"
}
}The top-level entries cover all harnesses; the "claude" section overrides specific stage responses for Claude Code tool prompts.
Unix daemon review fixtures
Use scripts/unix-daemon-review-fixture.sh setup to allocate a short /tmp/cvuds.* base containing isolated workspaces a and b, a private external socket parent, deterministic two-stage, 60-second cancellation, and large-output command pipelines, and two batch plans. The fixture uses command stages and never makes paid harness calls. Record the printed base path.
Start a foreground daemon owned by the fixture with scripts/unix-daemon-review-fixture.sh start BASE a, or use start-background in place of start to exercise detached readiness; the script records only the exact child handle it created, waits for a real status health exchange, and prints the canonical workspace, Unix endpoint, and owned handle. Run the same command for workspace b to exercise isolation. In a workspace, use hpilot submit --config hpilot.yaml, hpilot submit --config long.yaml, hpilot submit --config large.yaml, and hpilot submit --path plans --config hpilot.yaml for deterministic short, long-running, multi-stage, large-output, and batch cases. Use the task IDs printed by submit for attach, logs, cancel, and end operations.
Stop a fixture with scripts/unix-daemon-review-fixture.sh stop BASE a. Simulate an ungraceful exit only with scripts/unix-daemon-review-fixture.sh crash BASE a; this sends SIGKILL solely to the exact PID recorded by that fixture and never scans for processes or removes a daemon lock. Restart with start to exercise recorded stale-socket recovery. After a crash, replacement-safe cleanup can be inspected with the focused tests/unit/test_unix_socket_lifecycle.py scenarios; connection loss, replay gaps, accepted-task non-resubmission, and pending batch behavior are deterministic in tests/unit/test_client_reconnect.py and tests/unit/test_batch_submit.py. Run those tests directly rather than disrupting the active workspace daemon.
Use scripts/unix-daemon-review-fixture.sh cleanup BASE only after all fixture-owned daemons have stopped. Cleanup consults each recorded child handle and removes only the supplied disposable base. Never point the fixture at a live project, signal PID 1 or PID 2, scan and signal hpilot processes, or delete .hpilot/daemon.lock.
Focused lifecycle regressions in tests/unit/test_unix_socket_lifecycle.py and tests/unit/test_unix_daemon_transport.py cover replacement sockets during failed startup, cleanup errors releasing endpoint locks, symlinked default runtime directories, and coordinated teardown after either listener fails. These tests use disposable paths and in-process fault injection.