Skip to content

test: add coverage for fetch_indexes_from_main - #45

Open
darthmelonder wants to merge 1 commit into
redhat-community-ai-tools:mainfrom
darthmelonder:tests/fetch-indexes-from-main
Open

test: add coverage for fetch_indexes_from_main#45
darthmelonder wants to merge 1 commit into
redhat-community-ai-tools:mainfrom
darthmelonder:tests/fetch-indexes-from-main

Conversation

@darthmelonder

Copy link
Copy Markdown

Summary

  • Adds a TestFetchIndexesFromMain class in tests/test_doc_index.py covering fetch_indexes_from_main() in src/doc_index.py.
  • Nine test methods across the happy path and every failure mode the function handles: git fetch failure, no index tracked on the base branch (empty ls-tree stdout), ls-tree non-zero return, git checkout failure, and unexpected exceptions.
  • Also covers configuration paths: custom DOCS_BASE_BRANCH, empty DOCS_BASE_BRANCH fallback to main, and DOCS_SUBFOLDER producing prefixed index paths (docs/.doc-index).
  • Matches the mocking style of the adjacent TestCheckoutDocsFromBaseBranch class — uses patch("doc_index.run_command_safe") with a class-level _mock_git helper that returns a side_effect simulating the three git commands.
  • The _mock_git helper raises AssertionError on any git command it doesn't explicitly handle, so future refactors that introduce a new git call will fail the tests loudly rather than silently pass with a benign default.
  • Verifies the diagnostic log strings introduced by fix: improve index fetch diagnostics and use targeted ls-tree #41 ("No cached indexes/summaries found", "Could not fetch", "Could not checkout indexes", "Error fetching indexes from main") via capsys, so a regression in the diagnostic output is caught.

Closes #42

Test plan

  • All 393 tests pass (was 384 before this change — 9 new tests added, no existing test modified).
  • Coverage remains above the 60% floor (currently 65.59%).
  • uv run ruff check src/ tests/ — clean.
  • uv run ruff format --check src/ tests/ — clean.
  • Fail-fast helper verified: no existing test path triggers the unexpected-command assertion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add test coverage for fetch_indexes_from_main() after PR #41 refactoring

1 participant