Files
karaoke-gen/backend/tests/test_review_annotations.py
T
Andrew Beveridge ☄️andClaude Opus 4.6 221f26b0d8 UX overhaul: guidance & simplification across all 4 review stages (#421)
## Summary

Complete UX overhaul of the karaoke video generation review flow,
spanning 4 phases:

- **Phase 1 - Job Creation**: Guided audio source selection with 3-tier
confidence system, responsive stepper, renamed "Find Audio" to "Choose
Audio"
- **Phase 2 - Audio Selection**: Production E2E tests for guided job
creation flow
- **Phase 3 - Lyrics Review**: Guidance panel with workflow steps, gap
navigation scoped to visible lines, simplified review UI with edit
tracking and low-friction feedback
- **Phase 4 - Instrumental Review**: Responsive layout (waveform no
longer disappears on short viewports), canvas-rendered time ruler,
hover-to-highlight waveform regions, dedicated Alternate Instrumental
upload section with duration explanation, dismissable guidance panel

### Key changes
- Root layout switches from viewport-locked (`h-screen overflow-hidden`)
to scrollable (`min-h-screen`) — fixes waveform disappearing on short
viewports
- Bottom section stacks vertically on mobile/tablet, side-by-side on
desktop
- Time ruler rendered directly on canvas with auto-scaling tick
intervals
- Hovering mute region or segment buttons highlights the corresponding
waveform range
- Upload button moved from toolbar to dedicated section with context and
duration requirement
- 21 unit tests added for instrumental review components
- Guidance panels with dismissable tips across lyrics and instrumental
review

## Test plan
- [x] `npx next build` — no errors
- [x] `npx jest --testPathPattern="instrumental-review/__tests__"` —
21/21 pass
- [x] Visual testing at 4 viewports: desktop (1280x800), tablet
(768x1024), mobile (375x667), short (1280x400)
- [x] Hover highlight verified with Playwright MCP
- [x] Time ruler scales correctly at 1x and 2x zoom

@coderabbitai ignore

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-01 02:58:50 -05:00

120 lines
4.7 KiB
Python

"""
Unit tests for the annotations endpoint in review.py.
Tests the actual storage logic (not the stub version).
"""
import pytest
from unittest.mock import MagicMock, patch
from fastapi.testclient import TestClient
@pytest.fixture
def mock_storage():
"""Create a mock StorageService that tracks calls."""
storage = MagicMock()
storage.upload_json = MagicMock()
# Default: no existing annotations
storage.download_json = MagicMock(side_effect=Exception("Not found"))
return storage
@pytest.fixture
def client(mock_storage):
"""Create TestClient with mocked dependencies for review routes."""
mock_creds = MagicMock()
mock_creds.universe_domain = 'googleapis.com'
mock_jm = MagicMock()
mock_jm.get_job.return_value = MagicMock(
job_id="test-job",
status="in_review",
review_token="test-review-token"
)
def mock_jm_factory(*args, **kwargs):
return mock_jm
# Override review auth to bypass complex auth chain
async def fake_review_auth():
return ("test-job", "full")
with patch('backend.api.routes.jobs.job_manager', mock_jm), \
patch('backend.services.job_manager.JobManager', mock_jm_factory), \
patch('backend.services.firestore_service.firestore'), \
patch('backend.services.storage_service.storage'), \
patch('google.auth.default', return_value=(mock_creds, 'test-project')):
from backend.main import app
from backend.api.dependencies import require_review_auth
# Override review auth dependency (must use the same function object used by routes)
app.dependency_overrides[require_review_auth] = fake_review_auth
# Patch StorageService inside the review module
with patch('backend.api.routes.review.StorageService', return_value=mock_storage):
yield TestClient(app)
app.dependency_overrides.clear()
class TestSubmitAnnotations:
"""Tests for POST /api/review/{job_id}/v1/annotations."""
def test_submit_single_annotation(self, client, mock_storage):
"""Test submitting a single annotation stores to GCS."""
annotation = {"annotation_type": "SOUND_ALIKE", "original_text": "helo", "corrected_text": "hello"}
response = client.post("/api/review/test-job/v1/annotations", json=annotation)
assert response.status_code == 200
data = response.json()
assert data["status"] == "success"
assert data["saved_count"] == 1
def test_submit_batch_annotations(self, client, mock_storage):
"""Test submitting a batch of annotations."""
payload = {
"annotations": [
{"annotation_type": "SOUND_ALIKE", "original_text": "a"},
{"annotation_type": "EXTRA_WORDS", "original_text": "b"},
]
}
response = client.post("/api/review/test-job/v1/annotations", json=payload)
assert response.status_code == 200
data = response.json()
assert data["saved_count"] == 2
assert data["total_count"] == 2
def test_annotations_stored_to_correct_gcs_path(self, client, mock_storage):
"""Test annotations are stored at jobs/{job_id}/lyrics/annotations.json."""
client.post(
"/api/review/test-job/v1/annotations",
json={"annotation_type": "MANUAL_EDIT"}
)
mock_storage.upload_json.assert_called_once()
gcs_path = mock_storage.upload_json.call_args[0][0]
assert gcs_path == "jobs/test-job/lyrics/annotations.json"
def test_annotations_merged_with_existing(self, client, mock_storage):
"""Test new annotations are merged with existing ones."""
# Set up existing annotations
mock_storage.download_json.side_effect = None
mock_storage.download_json.return_value = {
"annotations": [{"annotation_type": "SOUND_ALIKE", "original_text": "existing"}]
}
payload = {"annotations": [{"annotation_type": "EXTRA_WORDS", "original_text": "new"}]}
response = client.post("/api/review/test-job/v1/annotations", json=payload)
data = response.json()
assert data["saved_count"] == 1
assert data["total_count"] == 2 # 1 existing + 1 new
# Verify merged data was uploaded
uploaded_data = mock_storage.upload_json.call_args[0][1]
assert len(uploaded_data["annotations"]) == 2
def test_annotations_fresh_when_no_existing(self, client, mock_storage):
"""Test annotations start fresh when no existing file."""
payload = {"annotations": [{"annotation_type": "NO_ERROR"}]}
response = client.post("/api/review/test-job/v1/annotations", json=payload)
assert response.json()["total_count"] == 1