Testing Strategy
Relevant source files
The following files were used as context for generating this wiki page:
The abx-dl testing strategy is designed to ensure the reliability of a high-concurrency CLI tool that interacts with external binaries and diverse web environments. The strategy encompasses automated unit and integration tests using pytest, manual verification procedures in isolated environments, and continuous integration (CI) workflows that validate plugin execution and deployment readiness.
The scope of testing covers core CLI command routing, plugin discovery and hook execution, configuration management, and the visual integrity of the Rich-based terminal user interface (TUI).
Automated Testing Framework
The project utilizes pytest as its primary testing framework, supplemented by several plugins to handle parallel execution and HTTP mocking.
Test Configuration and Dependencies
Testing requirements are defined in pyproject.toml under the [project.optional-dependencies] dev section and configured via [tool.pytest.ini_options].
| Dependency | Purpose |
|---|---|
pytest | Core testing framework |
pytest-httpserver | Mocking HTTP responses for downloader tests |
pytest-xdist | Running tests in parallel across multiple CPU cores |
flask | Used for server-side testing and web UI validation |
Sources: pyproject.toml:93-100, pyproject.toml:132-133
Test Execution Commands
The project provides standardized commands for running tests with varying levels of verbosity and failure handling.
# Standard test run
uv run pytest tests/
# Verbose run with stdout capture disabled (useful for debugging TUI)
uv run pytest -xvs tests/
Sources: CLAUDE.md:28-30
Testing Architecture
The testing architecture relies on strict isolation between the host environment and the test execution environment to prevent configuration leakage.
Isolated CLI Environment
In tests/test_cli.py, a specialized helper function _cli_env is used to construct a clean environment for every CLI test. It strips existing ABX_ENV_KEYS from the environment and redirects configuration and library directories to a temporary path provided by pytest.
The diagram shows how the test suite isolates the abx-dl execution environment.
Sources: tests/test_cli.py:42-83
CLI Subprocess Validation
The function _run_cli executes the abx-dl module in a separate process, allowing the test suite to validate actual command-line behavior, exit codes, and standard output/error streams.
The sequence shows the end-to-end flow of a CLI integration test.
Sources: tests/test_cli.py:86-98
Detailed Testing Sections
Plugin System Testing
Plugin discovery and hook categorization are validated in tests/test_plugins.py. These tests ensure that:
- Hooks are correctly parsed from filenames (e.g., identifying background vs. finite hooks).
- Dependencies and binary providers are correctly filtered and included.
- Transitive dependencies (e.g.,
ublockrequiringchromeandpuppeteer) are properly resolved.
Key validation functions:
test_parse_hook_filename_marks_bg_hooks: Validates regex for.bgsuffix.test_filter_plugins_includes_transitive_provider_dependencies: Verifies deep dependency resolution.
Sources: tests/test_plugins.py:4-46
TUI and Formatting Validation
The project uses rich for terminal output. Testing involves validating the logic that transforms raw hook output into formatted TUI elements.
- Output Compaction: Tests like
test_compact_output_collapses_whitespace_and_truncatesensure text is readable. - Size Formatting:
test_render_output_size_cell_uses_expected_threshold_stylesvalidates color-coding based on file size thresholds (Green < 2MB, Yellow < 50MB, etc.). - Progress Tracking:
test_advance_progress_expands_total_for_extra_completed_hooksensures the progress bar scales if hooks dynamically register extra work.
Sources: tests/test_cli.py:106-160, tests/test_cli.py:408-416
Limit and State Management
Logic for stopping crawls based on constraints is tested through the CrawlLimitState class.
- URL Limits: Validates that snapshots are blocked once
max_urlsis reached. - Size Limits: Validates that processes are flagged for termination if
max_sizeis exceeded.
Sources: tests/test_cli.py:433-448
Manual Testing Strategy
Manual testing is recommended for verifying browser-based plugins (like Chrome) and TUI interactivity that may be difficult to capture in automated subprocess tests.
Isolated Local Testing
Developers are instructed to use a temporary directory to simulate a fresh install:
- Create and enter a temporary directory.
- Run
abx-dl dlwith specific plugins. - Manually inspect the
index.jsonland directory structure. - Verify content extraction (e.g., using
jqto parse results).
Sources: CLAUDE.md:12-24
Continuous Integration (CI/CD)
The project automates testing and deployment via GitHub Actions.
| Workflow | Trigger | Primary Action |
|---|---|---|
test.yml | PR / Push to Main | Runs parallel plugin tests to ensure no regressions in extraction logic. |
publish.yml | Git Tag (vX.Y.Z) | Automatically publishes the package to PyPI. |
Sources: CLAUDE.md:52-55
Linting and Type Checking
In addition to functional tests, the project enforces code quality via static analysis tools:
- Ruff: Used for both linting (
ruff check) and formatting (ruff format). - Mypy: Performs static type checking to ensure type safety across the
abx_dlpackage.
Sources: CLAUDE.md:34-38, pyproject.toml:135-141
Conclusion
The abx-dl testing strategy combines high-level CLI integration tests with granular unit tests for internal logic. By focusing on environment isolation and TUI formatting accuracy, the suite ensures that the tool remains reliable even as the underlying plugin ecosystem evolves. Continuous validation via GitHub Actions provides the final layer of assurance before releases are published to PyPI.