Skip to content

test(cppa_youtube_script_tracker): expand coverage for services, phases, fetcher, and failure classification#200

Merged
wpak-ai merged 2 commits into
cppalliance:developfrom
snowfox1003:tests/youtube-script-tracker-edge-cases
May 12, 2026
Merged

test(cppa_youtube_script_tracker): expand coverage for services, phases, fetcher, and failure classification#200
wpak-ai merged 2 commits into
cppalliance:developfrom
snowfox1003:tests/youtube-script-tracker-edge-cases

Conversation

@snowfox1003
Copy link
Copy Markdown
Collaborator

@snowfox1003 snowfox1003 commented May 12, 2026

Summary

Adds and extends tests for cppa_youtube_script_tracker so services, management command phases, YouTube Data API fetcher paths, and classify_failure behavior are covered without real network or yt-dlp runs (mocks/stubs only).

Scope

  • Services: sparse metadata defaults, unparseable datetime handling, channel title not cleared by empty update.
  • Command: Phase 2/3 failure paths (download_vtt None/exception), _persist_fetched_video / _process_queue error paths, transcript enrichment edge cases, Pinecone skip paths, stdout messaging, dry-run sync_pinecone.
  • Fetcher: pagination (nextPageToken), thin/malformed API payloads, dedupe, search None break.
  • Failure classification: documents current classify_failure mappings for ValueError, ImportError, QuotaExceededError, and googleapiclient.errors.HttpError (UNKNOWN) per existing core/errors.py.

How tested

  • pytest cppa_youtube_script_tracker/tests/
  • Full suite with coverage gate (same as CI).

Notes

  • No production behavior changes; tests only.
  • Eval / ticket: [link or ID]

Checklist

  • No real YouTube API calls or live yt-dlp in tests
  • CI green (including --cov-fail-under=90)

Closes #185

Summary by CodeRabbit

  • Tests
    • Added comprehensive tests for error classification, data fetching/pagination, video detail handling, and management command flows (including dry-run, transcript/persistence edge cases, queue parsing, logging, and skip-counting).
    • Added DB tests ensuring service-layer defaults and resilient handling of missing or malformed metadata.

Review Change Stack

@snowfox1003 snowfox1003 self-assigned this May 12, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 12, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 9a471467-5c6e-4fe0-8c5c-2eacacf19e89

📥 Commits

Reviewing files that changed from the base of the PR and between c2f65e3 and 725f7d1.

📒 Files selected for processing (1)
  • cppa_youtube_script_tracker/tests/test_run_command.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • cppa_youtube_script_tracker/tests/test_run_command.py

📝 Walkthrough

Walkthrough

Adds new pytest coverage across the YouTube tracker: exception classification, fetcher query/formatting/pagination behavior, service persistence defaults and datetime parsing, and extensive management-command flow and error-path tests.

Changes

YouTube Tracker Test Coverage

Layer / File(s) Summary
Error classification tests
cppa_youtube_script_tracker/tests/test_failure_classification.py
New tests for classify_failure exception categorization and a _FakeResp helper; verifies ValueError (missing API key) => VALIDATION, and ImportError, QuotaExceededError, HttpError => UNKNOWN.
Data fetching and query processing
cppa_youtube_script_tracker/tests/test_fetcher.py
Adds tests: query deduplication (_build_queries), _fetch_search_page param propagation (pageToken, channelId), _format_video_data defaults when fields missing, _process_one_channel_query pagination, empty-id filtering, non-video item handling, and early exit when search returns None.
Service layer persistence defaults
cppa_youtube_script_tracker/tests/test_services.py
DB tests for get_or_create_video/get_or_create_channel: sparse metadata defaulting (empty strings, zero duration, None for counts/datetimes), unparseable datetimes become None, and empty channel title doesn't clear existing title.
Management command workflows and error handling
cppa_youtube_script_tracker/tests/test_run_command.py
Extensive command tests: import of _persist_fetched_video; dry-run pinecone skip; phase-3 transcript failure cases; persistence/queue exception handling preserving queue JSON and counting skipped items; speaker enrichment no-ops and warning paths; stdout phase messaging; pinecone sync edge cases and exception logging; phase error propagation; tag blank filtering; queue parse error logging; counters and validation-error handling.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related issues

Possibly related PRs

Suggested labels

enhancement

Suggested reviewers

  • wpak-ai

Poem

🐇 A rabbit hops through tests at night,

mocking APIs until they’re right.
Defaults set and errors penned,
Each flaky path gets one more friend.
Hooray — the tracker sleeps well tonight.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 4.17% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title directly and specifically describes the main change: expanding test coverage for four key modules (services, phases, fetcher, and failure classification) in the cppa_youtube_script_tracker.
Linked Issues check ✅ Passed The PR comprehensively addresses all coding objectives from issue #185: test files created under cppa_youtube_script_tracker/tests/ covering service layer, management command phases, fetcher, and failure classification; all external dependencies mocked; edge cases covered; no production behavior changes.
Out of Scope Changes check ✅ Passed All changes are strictly test-only additions (four new test modules and extensions to existing tests). No production code modifications or scope creep outside the linked issue objectives are present.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
cppa_youtube_script_tracker/tests/test_run_command.py (1)

464-477: ⚡ Quick win

Add an explicit assertion for the “resolve_speakers returns empty” path.

Right now this test only verifies no exception. Add a before/after link count assertion so regressions in link creation are caught.

Proposed enhancement
 `@pytest.mark.django_db`
 def test_enrich_speakers_from_transcript_resolve_empty(monkeypatch, tmp_path):
@@
     tr = tmp_path / "some.vtt"
     tr.write_text("WEBVTT\n\nnote\n", encoding="utf-8")
     monkeypatch.setattr(f"{_CMD}.resolve_speakers", lambda **_k: [])
+    from cppa_youtube_script_tracker.models import YouTubeVideoSpeaker
+    before = YouTubeVideoSpeaker.objects.filter(video=video).count()

     _enrich_speakers_from_transcript(video, str(tr))
+    assert YouTubeVideoSpeaker.objects.filter(video=video).count() == before
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@cppa_youtube_script_tracker/tests/test_run_command.py` around lines 464 -
477, The test test_enrich_speakers_from_transcript_resolve_empty should assert
that no new speaker links are created when resolve_speakers returns an empty
list: record the initial count of any related link model (e.g., count of
speaker/video links or YouTubeVideo.speakers relation) before calling
_enrich_speakers_from_transcript(video, str(tr)), then call the function and
assert the count is unchanged afterwards; reference the test name, the
monkeypatched resolve_speakers, and the target function
_enrich_speakers_from_transcript to locate where to add the before/after
assertions.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@cppa_youtube_script_tracker/tests/test_run_command.py`:
- Around line 579-590: The test assigns the return tuple from _persist_video to
a variable named created that is never used, causing RUF059; update the
assignment to use a throwaway name like _created or _ (e.g., change "created,
skipped = _persist_video(...)" to "_created, skipped = _persist_video(...)" or
"_, skipped = _persist_video(...)" ) so the unused value is ignored while
leaving the call to _persist_video and subsequent assertion on skipped
unchanged.

---

Nitpick comments:
In `@cppa_youtube_script_tracker/tests/test_run_command.py`:
- Around line 464-477: The test
test_enrich_speakers_from_transcript_resolve_empty should assert that no new
speaker links are created when resolve_speakers returns an empty list: record
the initial count of any related link model (e.g., count of speaker/video links
or YouTubeVideo.speakers relation) before calling
_enrich_speakers_from_transcript(video, str(tr)), then call the function and
assert the count is unchanged afterwards; reference the test name, the
monkeypatched resolve_speakers, and the target function
_enrich_speakers_from_transcript to locate where to add the before/after
assertions.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 7f162c43-0135-420b-a1d2-fb684d6ad17f

📥 Commits

Reviewing files that changed from the base of the PR and between 4df863f and c2f65e3.

📒 Files selected for processing (4)
  • cppa_youtube_script_tracker/tests/test_failure_classification.py
  • cppa_youtube_script_tracker/tests/test_fetcher.py
  • cppa_youtube_script_tracker/tests/test_run_command.py
  • cppa_youtube_script_tracker/tests/test_services.py

Comment thread cppa_youtube_script_tracker/tests/test_run_command.py Outdated
@snowfox1003 snowfox1003 requested a review from jonathanMLDev May 12, 2026 20:30
@snowfox1003 snowfox1003 requested a review from wpak-ai May 12, 2026 20:42
@wpak-ai wpak-ai merged commit f8d43cd into cppalliance:develop May 12, 2026
4 checks passed
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 YouTube Tracker

3 participants