tests
The tests directory contains the test suite for repo-guide. It utilizes the pytest framework alongside click.testing to validate the command-line interface, prompt building logic, robust file handling, Git repository URL resolution, and the end-to-end documentation generation pipeline.
The primary entry point for tests in this directory is test_repo_guide.py.
How the Tests Work
The test suite is structured around a mix of unit tests for specific core classes and end-to-end integration tests using isolated file systems.
Mocking and Fixtures
test_repo: Apytestfixture that spins up a temporary, local Git repository on the fly. It writes a nested directory structure with python files (src/main.pyandsrc/utils/helpers.py), initializes Git, sets a mock GitHub remote URL (https://github.com/test/test_repo.git), and commits the files. This acts as a realistic workspace for testing how the tool processes directories and Git metadata.mock_model: A fixture that intercepts LLM calls by patchingllm.get_modelwith a dummy class. This allows testing the CLI and document generation pipeline without calling external AI APIs, returning predictable mock responses.
Core Test Coverage
The test cases in test_repo_guide.py target several critical operations of the system:
- CLI and Versioning: Validates that the command-line interface responds correctly to base flags like
--versioninside an isolated environment. - Prompt Construction: Verifies that the internal
DocGenerator._build_promptmethod constructs correctly structured XML layouts containing information about directories, subdirectories, local Readme content, and target files. It asserts that path relationships and contents are accurately formatted for the LLM. - Robust File Decoding: Tests how the documentation engine behaves when encountering files with problematic or unreadable encodings (such as bad UTF-16 bytes). It ensures that readable files are correctly collected into prompts while corrupted or binary files are skipped gracefully instead of crashing the process.
- Git URL Resolution: Evaluates how repository origins are translated into web URLs. It tests standard HTTPS configurations, subdirectory executions, and SSH-based remote definitions (including formats with organizational prefixes like
org-14957082@github.com:...). This ensures that generated file links in the output documentation resolve to the correct GitHub URL prefixes. - End-to-End Generation: Simulates full user execution by running the
repo-guideCLI directly against the mock repository using themock_modelfixture. It asserts that the system successfully writes the resulting documentation files (README.mdfiles) to the output directory with the expected folder structure.