mirror of
https://github.com/nomadkaraoke/karaoke-gen.git
synced 2026-11-26 00:49:05 +09:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c55ab62ae8 | ||
|
|
f07655e1a5 | ||
|
|
bb27ab8289 | ||
|
|
9734dc2044 |
No files matched your search
@@ -85,9 +85,13 @@ class AudioSearchRequest(BaseModel):
|
||||
# Auto-download mode
|
||||
auto_download: bool = Field(False, description="Automatically select best result and download")
|
||||
|
||||
# Processing options (CDG/TXT require style config, disabled by default)
|
||||
enable_cdg: bool = Field(False, description="Generate CDG+MP3 package (requires style config)")
|
||||
enable_txt: bool = Field(False, description="Generate TXT+MP3 package (requires style config)")
|
||||
# Theme configuration
|
||||
theme_id: Optional[str] = Field(None, description="Theme ID to use (e.g., 'nomad', 'default'). If set, CDG/TXT are enabled by default.")
|
||||
color_overrides: Optional[Dict[str, str]] = Field(None, description="Color overrides: artist_color, title_color, sung_lyrics_color, unsung_lyrics_color (hex #RRGGBB)")
|
||||
|
||||
# Processing options (CDG/TXT require style config or theme, disabled by default unless theme is set)
|
||||
enable_cdg: Optional[bool] = Field(None, description="Generate CDG+MP3 package. Default: True if theme_id set, False otherwise")
|
||||
enable_txt: Optional[bool] = Field(None, description="Generate TXT+MP3 package. Default: True if theme_id set, False otherwise")
|
||||
|
||||
# Finalisation options
|
||||
brand_prefix: Optional[str] = Field(None, description="Brand code prefix (e.g., NOMAD)")
|
||||
@@ -180,6 +184,35 @@ class AudioSelectResponse(BaseModel):
|
||||
selected_provider: str
|
||||
|
||||
|
||||
def _resolve_cdg_txt_defaults(
|
||||
theme_id: Optional[str],
|
||||
enable_cdg: Optional[bool],
|
||||
enable_txt: Optional[bool]
|
||||
) -> Tuple[bool, bool]:
|
||||
"""
|
||||
Resolve CDG/TXT settings based on theme and explicit settings.
|
||||
|
||||
When a theme is selected, CDG and TXT are enabled by default.
|
||||
Explicit True/False values always override the default.
|
||||
|
||||
Args:
|
||||
theme_id: Theme identifier (if any)
|
||||
enable_cdg: Explicit CDG setting (None means use default)
|
||||
enable_txt: Explicit TXT setting (None means use default)
|
||||
|
||||
Returns:
|
||||
Tuple of (resolved_enable_cdg, resolved_enable_txt)
|
||||
"""
|
||||
# Default based on whether theme is set
|
||||
default_enabled = theme_id is not None
|
||||
|
||||
# Explicit values override defaults, None uses default
|
||||
resolved_cdg = enable_cdg if enable_cdg is not None else default_enabled
|
||||
resolved_txt = enable_txt if enable_txt is not None else default_enabled
|
||||
|
||||
return resolved_cdg, resolved_txt
|
||||
|
||||
|
||||
def extract_request_metadata(request: Request, created_from: str = "audio_search") -> Dict[str, Any]:
|
||||
"""Extract metadata from request for job tracking."""
|
||||
headers = dict(request.headers)
|
||||
@@ -461,13 +494,20 @@ async def search_audio(
|
||||
|
||||
# Extract request metadata
|
||||
request_metadata = extract_request_metadata(request, created_from="audio_search")
|
||||
|
||||
|
||||
# Resolve CDG/TXT defaults based on theme
|
||||
resolved_cdg, resolved_txt = _resolve_cdg_txt_defaults(
|
||||
body.theme_id, body.enable_cdg, body.enable_txt
|
||||
)
|
||||
|
||||
# Create job
|
||||
job_create = JobCreate(
|
||||
artist=body.artist,
|
||||
title=body.title,
|
||||
enable_cdg=body.enable_cdg,
|
||||
enable_txt=body.enable_txt,
|
||||
theme_id=body.theme_id,
|
||||
color_overrides=body.color_overrides or {},
|
||||
enable_cdg=resolved_cdg,
|
||||
enable_txt=resolved_txt,
|
||||
brand_prefix=effective_brand_prefix,
|
||||
enable_youtube_upload=effective_enable_youtube_upload,
|
||||
youtube_description=effective_youtube_description,
|
||||
|
||||
@@ -798,6 +798,166 @@ class TestRemoteDownloadPath:
|
||||
assert result.filepath == "/tmp/test.flac"
|
||||
|
||||
|
||||
class TestAudioSearchThemeSupport:
|
||||
"""Test theme support in audio search requests.
|
||||
|
||||
These tests verify that theme_id and color_overrides are properly:
|
||||
1. Accepted in AudioSearchRequest model
|
||||
2. Passed through to JobCreate
|
||||
3. Result in correct CDG/TXT defaults when theme is set
|
||||
"""
|
||||
|
||||
def test_audio_search_request_accepts_theme_id(self):
|
||||
"""Test AudioSearchRequest model has theme_id field."""
|
||||
from backend.api.routes.audio_search import AudioSearchRequest
|
||||
|
||||
request = AudioSearchRequest(
|
||||
artist="Test Artist",
|
||||
title="Test Song",
|
||||
theme_id="nomad"
|
||||
)
|
||||
|
||||
assert request.theme_id == "nomad"
|
||||
|
||||
def test_audio_search_request_accepts_color_overrides(self):
|
||||
"""Test AudioSearchRequest model has color_overrides field."""
|
||||
from backend.api.routes.audio_search import AudioSearchRequest
|
||||
|
||||
request = AudioSearchRequest(
|
||||
artist="Test Artist",
|
||||
title="Test Song",
|
||||
theme_id="nomad",
|
||||
color_overrides={
|
||||
"artist_color": "#ff0000",
|
||||
"title_color": "#00ff00",
|
||||
}
|
||||
)
|
||||
|
||||
assert request.color_overrides["artist_color"] == "#ff0000"
|
||||
assert request.color_overrides["title_color"] == "#00ff00"
|
||||
|
||||
def test_audio_search_request_theme_defaults_cdg_txt(self):
|
||||
"""Test that when theme_id is set, CDG/TXT defaults to enabled.
|
||||
|
||||
This is the key behavior: selecting a theme should automatically
|
||||
enable CDG and TXT output formats.
|
||||
"""
|
||||
from backend.api.routes.audio_search import AudioSearchRequest, _resolve_cdg_txt_defaults
|
||||
|
||||
# When theme_id is set, enable_cdg/enable_txt should default to True
|
||||
request = AudioSearchRequest(
|
||||
artist="Test Artist",
|
||||
title="Test Song",
|
||||
theme_id="nomad"
|
||||
# enable_cdg and enable_txt are None (not specified)
|
||||
)
|
||||
|
||||
resolved_cdg, resolved_txt = _resolve_cdg_txt_defaults(
|
||||
request.theme_id, request.enable_cdg, request.enable_txt
|
||||
)
|
||||
|
||||
assert resolved_cdg is True, "CDG should be enabled by default when theme is set"
|
||||
assert resolved_txt is True, "TXT should be enabled by default when theme is set"
|
||||
|
||||
def test_audio_search_request_no_theme_no_cdg_txt(self):
|
||||
"""Test that without theme_id, CDG/TXT defaults to disabled."""
|
||||
from backend.api.routes.audio_search import AudioSearchRequest, _resolve_cdg_txt_defaults
|
||||
|
||||
request = AudioSearchRequest(
|
||||
artist="Test Artist",
|
||||
title="Test Song"
|
||||
# No theme_id, no enable_cdg, no enable_txt
|
||||
)
|
||||
|
||||
resolved_cdg, resolved_txt = _resolve_cdg_txt_defaults(
|
||||
request.theme_id, request.enable_cdg, request.enable_txt
|
||||
)
|
||||
|
||||
assert resolved_cdg is False, "CDG should be disabled by default without theme"
|
||||
assert resolved_txt is False, "TXT should be disabled by default without theme"
|
||||
|
||||
def test_explicit_cdg_txt_overrides_theme_default(self):
|
||||
"""Test that explicit enable_cdg/enable_txt values override theme defaults."""
|
||||
from backend.api.routes.audio_search import AudioSearchRequest, _resolve_cdg_txt_defaults
|
||||
|
||||
# Theme set (would default to True), but explicitly disabled
|
||||
request = AudioSearchRequest(
|
||||
artist="Test Artist",
|
||||
title="Test Song",
|
||||
theme_id="nomad",
|
||||
enable_cdg=False,
|
||||
enable_txt=False,
|
||||
)
|
||||
|
||||
resolved_cdg, resolved_txt = _resolve_cdg_txt_defaults(
|
||||
request.theme_id, request.enable_cdg, request.enable_txt
|
||||
)
|
||||
|
||||
assert resolved_cdg is False, "Explicit False should override theme default"
|
||||
assert resolved_txt is False, "Explicit False should override theme default"
|
||||
|
||||
def test_explicit_cdg_txt_enables_without_theme(self):
|
||||
"""Test that explicit True enables CDG/TXT even without theme."""
|
||||
from backend.api.routes.audio_search import AudioSearchRequest, _resolve_cdg_txt_defaults
|
||||
|
||||
# No theme (would default to False), but explicitly enabled
|
||||
request = AudioSearchRequest(
|
||||
artist="Test Artist",
|
||||
title="Test Song",
|
||||
enable_cdg=True,
|
||||
enable_txt=True,
|
||||
)
|
||||
|
||||
resolved_cdg, resolved_txt = _resolve_cdg_txt_defaults(
|
||||
request.theme_id, request.enable_cdg, request.enable_txt
|
||||
)
|
||||
|
||||
assert resolved_cdg is True, "Explicit True should enable CDG without theme"
|
||||
assert resolved_txt is True, "Explicit True should enable TXT without theme"
|
||||
|
||||
def test_job_create_receives_theme_from_audio_search(self):
|
||||
"""Test that JobCreate model can receive theme_id and color_overrides."""
|
||||
job_create = JobCreate(
|
||||
artist="Test Artist",
|
||||
title="Test Song",
|
||||
theme_id="nomad",
|
||||
color_overrides={
|
||||
"artist_color": "#ff0000",
|
||||
"sung_lyrics_color": "#00ff00"
|
||||
},
|
||||
enable_cdg=True,
|
||||
enable_txt=True,
|
||||
)
|
||||
|
||||
assert job_create.theme_id == "nomad"
|
||||
assert job_create.color_overrides["artist_color"] == "#ff0000"
|
||||
assert job_create.color_overrides["sung_lyrics_color"] == "#00ff00"
|
||||
assert job_create.enable_cdg is True
|
||||
assert job_create.enable_txt is True
|
||||
|
||||
def test_job_model_stores_theme_configuration(self):
|
||||
"""Test Job model stores theme configuration correctly."""
|
||||
job = Job(
|
||||
job_id="test123",
|
||||
status=JobStatus.PENDING,
|
||||
created_at=datetime.utcnow(),
|
||||
updated_at=datetime.utcnow(),
|
||||
artist="Test Artist",
|
||||
title="Test Song",
|
||||
theme_id="nomad",
|
||||
color_overrides={
|
||||
"artist_color": "#ff0000"
|
||||
},
|
||||
enable_cdg=True,
|
||||
enable_txt=True,
|
||||
)
|
||||
|
||||
assert job.theme_id == "nomad"
|
||||
assert job.color_overrides["artist_color"] == "#ff0000"
|
||||
assert job.enable_cdg is True
|
||||
assert job.enable_txt is True
|
||||
|
||||
|
||||
class TestFlacfetchIntegration:
|
||||
"""
|
||||
Integration tests that verify flacfetch imports work correctly.
|
||||
|
||||
@@ -0,0 +1,593 @@
|
||||
import { test, expect, Page, BrowserContext } from '@playwright/test';
|
||||
|
||||
/**
|
||||
* E2E tests for the theme system functionality.
|
||||
* Tests run against gen.nomadkaraoke.com (production).
|
||||
*
|
||||
* These tests validate the full user flow including:
|
||||
* - Theme selection in job creation
|
||||
* - Lyrics review UI with preview video
|
||||
* - Theme styles applied correctly (not black background)
|
||||
* - Instrumental selection via UI
|
||||
*
|
||||
* IMPORTANT: Set KARAOKE_ACCESS_TOKEN environment variable:
|
||||
* KARAOKE_ACCESS_TOKEN=your-token npx playwright test production-theme-system.spec.ts --config=playwright.production.config.ts
|
||||
*/
|
||||
|
||||
const ACCESS_TOKEN = process.env.KARAOKE_ACCESS_TOKEN;
|
||||
const PROD_URL = 'https://gen.nomadkaraoke.com';
|
||||
const API_URL = 'https://api.nomadkaraoke.com';
|
||||
|
||||
// Helper to authenticate the page by setting localStorage token
|
||||
async function authenticatePage(page: Page) {
|
||||
if (!ACCESS_TOKEN) {
|
||||
throw new Error('KARAOKE_ACCESS_TOKEN environment variable is required for production tests');
|
||||
}
|
||||
|
||||
await page.addInitScript((token) => {
|
||||
localStorage.setItem('karaoke_access_token', token);
|
||||
}, ACCESS_TOKEN);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Helper to wait for job to reach a specific status
|
||||
async function waitForJobStatus(
|
||||
request: any,
|
||||
jobId: string,
|
||||
targetStatuses: string[],
|
||||
maxWaitMs: number = 300000,
|
||||
pollIntervalMs: number = 5000
|
||||
): Promise<any> {
|
||||
const startTime = Date.now();
|
||||
|
||||
while (Date.now() - startTime < maxWaitMs) {
|
||||
const response = await request.get(`${API_URL}/api/jobs/${jobId}`, {
|
||||
headers: { 'Authorization': `Bearer ${ACCESS_TOKEN}` }
|
||||
});
|
||||
|
||||
if (!response.ok()) {
|
||||
throw new Error(`Failed to get job status: ${response.status()}`);
|
||||
}
|
||||
|
||||
const job = await response.json();
|
||||
console.log(`Job ${jobId} status: ${job.status}`);
|
||||
|
||||
if (targetStatuses.includes(job.status)) {
|
||||
return job;
|
||||
}
|
||||
|
||||
if (job.status === 'failed') {
|
||||
throw new Error(`Job failed: ${job.error_message || 'Unknown error'}`);
|
||||
}
|
||||
|
||||
await new Promise(resolve => setTimeout(resolve, pollIntervalMs));
|
||||
}
|
||||
|
||||
throw new Error(`Timeout waiting for job ${jobId} to reach status: ${targetStatuses.join(', ')}`);
|
||||
}
|
||||
|
||||
// Helper to check if a pixel color is NOT black (has styled background)
|
||||
function isNotBlackPixel(r: number, g: number, b: number, threshold: number = 30): boolean {
|
||||
// A pixel is considered "not black" if any channel is above the threshold
|
||||
return r > threshold || g > threshold || b > threshold;
|
||||
}
|
||||
|
||||
test.describe('Theme System E2E Tests', () => {
|
||||
test.beforeEach(async ({ page }) => {
|
||||
await authenticatePage(page);
|
||||
});
|
||||
|
||||
test('Themes API returns available themes', async ({ request }) => {
|
||||
const response = await request.get(`${API_URL}/api/themes`, {
|
||||
headers: {
|
||||
'Authorization': `Bearer ${ACCESS_TOKEN}`
|
||||
}
|
||||
});
|
||||
|
||||
expect(response.ok()).toBeTruthy();
|
||||
|
||||
const data = await response.json();
|
||||
console.log('Themes API response:', JSON.stringify(data, null, 2));
|
||||
|
||||
// Verify response structure
|
||||
expect(data).toHaveProperty('themes');
|
||||
expect(Array.isArray(data.themes)).toBeTruthy();
|
||||
expect(data.themes.length).toBeGreaterThan(0);
|
||||
|
||||
// Verify theme structure
|
||||
const firstTheme = data.themes[0];
|
||||
expect(firstTheme).toHaveProperty('id');
|
||||
expect(firstTheme).toHaveProperty('name');
|
||||
expect(firstTheme).toHaveProperty('description');
|
||||
|
||||
console.log('Available themes:');
|
||||
for (const theme of data.themes) {
|
||||
console.log(` - ${theme.id}: ${theme.name}`);
|
||||
}
|
||||
});
|
||||
|
||||
test('Theme detail API returns theme configuration', async ({ request }) => {
|
||||
const listResponse = await request.get(`${API_URL}/api/themes`, {
|
||||
headers: { 'Authorization': `Bearer ${ACCESS_TOKEN}` }
|
||||
});
|
||||
expect(listResponse.ok()).toBeTruthy();
|
||||
const listData = await listResponse.json();
|
||||
|
||||
if (listData.themes.length === 0) {
|
||||
test.skip();
|
||||
return;
|
||||
}
|
||||
|
||||
const themeId = listData.themes[0].id;
|
||||
console.log(`Fetching details for theme: ${themeId}`);
|
||||
|
||||
const detailResponse = await request.get(`${API_URL}/api/themes/${themeId}`, {
|
||||
headers: { 'Authorization': `Bearer ${ACCESS_TOKEN}` }
|
||||
});
|
||||
|
||||
expect(detailResponse.ok()).toBeTruthy();
|
||||
|
||||
const detailData = await detailResponse.json();
|
||||
expect(detailData).toHaveProperty('theme');
|
||||
const theme = detailData.theme;
|
||||
|
||||
expect(theme).toHaveProperty('id', themeId);
|
||||
expect(theme).toHaveProperty('name');
|
||||
expect(theme).toHaveProperty('style_params');
|
||||
|
||||
if (theme.style_params) {
|
||||
console.log('Style params sections:', Object.keys(theme.style_params));
|
||||
}
|
||||
});
|
||||
|
||||
test('Theme selector appears in job submission UI', async ({ page }) => {
|
||||
test.setTimeout(60000);
|
||||
|
||||
await page.goto(PROD_URL);
|
||||
await page.waitForLoadState('networkidle');
|
||||
|
||||
await page.screenshot({ path: 'test-results/theme-01-homepage.png', fullPage: true });
|
||||
|
||||
// Click on the Search tab
|
||||
await page.getByRole('tab', { name: /search/i }).click();
|
||||
await page.waitForTimeout(1000);
|
||||
|
||||
await page.screenshot({ path: 'test-results/theme-02-search-tab.png', fullPage: true });
|
||||
|
||||
// Look for "Video Theme" label (updated to match actual UI)
|
||||
const themeLabel = page.locator('text=Video Theme').or(page.locator('text=Theme'));
|
||||
const themeSelectVisible = await themeLabel.first().isVisible({ timeout: 5000 }).catch(() => false);
|
||||
|
||||
expect(themeSelectVisible).toBeTruthy();
|
||||
console.log('Theme selector found in UI');
|
||||
|
||||
// Verify the UI is accessible
|
||||
expect(await page.locator('h1').textContent()).toContain('Karaoke Generator');
|
||||
});
|
||||
|
||||
test('Can select a theme from dropdown', async ({ page }) => {
|
||||
test.setTimeout(60000);
|
||||
|
||||
await page.goto(PROD_URL);
|
||||
await page.waitForLoadState('networkidle');
|
||||
|
||||
await page.getByRole('tab', { name: /search/i }).click();
|
||||
await page.waitForTimeout(2000);
|
||||
|
||||
await page.screenshot({ path: 'test-results/theme-05-before-select.png', fullPage: true });
|
||||
|
||||
// Find and click the theme selector (Radix UI Select)
|
||||
const themeSelect = page.locator('button[role="combobox"]').first();
|
||||
|
||||
if (await themeSelect.isVisible({ timeout: 3000 })) {
|
||||
await themeSelect.click();
|
||||
await page.waitForTimeout(500);
|
||||
await page.screenshot({ path: 'test-results/theme-06-dropdown-open.png', fullPage: true });
|
||||
|
||||
// Look for theme options
|
||||
const options = page.locator('[role="option"]');
|
||||
const optionCount = await options.count();
|
||||
console.log(`Found ${optionCount} theme options`);
|
||||
|
||||
if (optionCount > 0) {
|
||||
const optionTexts = await options.allTextContents();
|
||||
console.log('Theme options:', optionTexts.join(', '));
|
||||
|
||||
// Select the first theme
|
||||
await options.first().click();
|
||||
await page.waitForTimeout(500);
|
||||
|
||||
await page.screenshot({ path: 'test-results/theme-07-theme-selected.png', fullPage: true });
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
test.describe('Full Job Flow with Theme - UI Based', () => {
|
||||
/**
|
||||
* This test creates a real job and follows the entire flow through the UI:
|
||||
* 1. Create job with theme via Search tab
|
||||
* 2. Select audio source via UI
|
||||
* 3. Review lyrics via UI (new tab)
|
||||
* 4. Generate preview video
|
||||
* 5. Validate theme styles are applied (not black background)
|
||||
* 6. Complete review via UI
|
||||
*
|
||||
* NOTE: This test creates real jobs in production. Use sparingly.
|
||||
*/
|
||||
test('Complete job flow with theme via UI', async ({ page, context, request }) => {
|
||||
test.setTimeout(600000); // 10 minutes for full flow
|
||||
|
||||
// Skip if no access token
|
||||
if (!ACCESS_TOKEN) {
|
||||
test.skip();
|
||||
return;
|
||||
}
|
||||
|
||||
await authenticatePage(page);
|
||||
|
||||
// Step 1: Navigate to Search tab and create job
|
||||
console.log('Step 1: Creating job via Search tab');
|
||||
await page.goto(PROD_URL);
|
||||
await page.waitForLoadState('networkidle');
|
||||
|
||||
await page.getByRole('tab', { name: /search/i }).click();
|
||||
await page.waitForTimeout(2000);
|
||||
|
||||
// Fill in a short, well-known song for faster processing
|
||||
await page.getByLabel('Artist').fill('Rick Astley');
|
||||
await page.getByLabel('Title').fill('Never Gonna Give You Up');
|
||||
|
||||
// Ensure a theme is selected (should be auto-selected)
|
||||
const themeSelect = page.locator('button[role="combobox"]').first();
|
||||
if (await themeSelect.isVisible({ timeout: 3000 })) {
|
||||
const selectedText = await themeSelect.textContent();
|
||||
console.log(`Current theme selection: ${selectedText}`);
|
||||
|
||||
// If no theme selected, select one
|
||||
if (selectedText?.includes('Select')) {
|
||||
await themeSelect.click();
|
||||
await page.waitForTimeout(500);
|
||||
const firstOption = page.locator('[role="option"]').first();
|
||||
await firstOption.click();
|
||||
await page.waitForTimeout(500);
|
||||
}
|
||||
}
|
||||
|
||||
await page.screenshot({ path: 'test-results/flow-01-form-filled.png', fullPage: true });
|
||||
|
||||
// Click Search & Create button
|
||||
const searchButton = page.getByRole('button', { name: /search.*create/i });
|
||||
await searchButton.click();
|
||||
|
||||
// Wait for search results to appear
|
||||
console.log('Waiting for audio search results...');
|
||||
await page.waitForTimeout(5000);
|
||||
|
||||
// Look for audio selection cards or list
|
||||
await page.screenshot({ path: 'test-results/flow-02-audio-results.png', fullPage: true });
|
||||
|
||||
// Check if we have audio results
|
||||
const audioCards = page.locator('[data-testid="audio-result"]').or(
|
||||
page.locator('.audio-result')
|
||||
).or(
|
||||
page.locator('button:has-text("Select")')
|
||||
);
|
||||
|
||||
const hasAudioResults = await audioCards.first().isVisible({ timeout: 30000 }).catch(() => false);
|
||||
|
||||
if (hasAudioResults) {
|
||||
console.log('Step 2: Selecting audio source via UI');
|
||||
// Click the first select button
|
||||
await audioCards.first().click();
|
||||
await page.waitForTimeout(2000);
|
||||
} else {
|
||||
// Check if job was auto-started (auto_download mode)
|
||||
console.log('No audio selection UI found - checking if job auto-started');
|
||||
}
|
||||
|
||||
await page.screenshot({ path: 'test-results/flow-03-after-audio-select.png', fullPage: true });
|
||||
|
||||
// Get the job ID from the URL or page content
|
||||
const currentUrl = page.url();
|
||||
let jobId: string | null = null;
|
||||
|
||||
// Try to extract job ID from URL
|
||||
const jobIdMatch = currentUrl.match(/jobs?[\/=]([a-f0-9-]+)/i);
|
||||
if (jobIdMatch) {
|
||||
jobId = jobIdMatch[1];
|
||||
}
|
||||
|
||||
// If not in URL, look for it in the page
|
||||
if (!jobId) {
|
||||
const jobIdElement = page.locator('[data-job-id]').or(
|
||||
page.locator('text=/Job ID:.*[a-f0-9-]+/i')
|
||||
);
|
||||
if (await jobIdElement.isVisible({ timeout: 5000 }).catch(() => false)) {
|
||||
const text = await jobIdElement.textContent();
|
||||
const match = text?.match(/[a-f0-9]{8,}/i);
|
||||
if (match) {
|
||||
jobId = match[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
console.log(`Job ID: ${jobId || 'not found yet'}`);
|
||||
|
||||
// Wait for job to reach in_review status
|
||||
if (jobId) {
|
||||
console.log('Step 3: Waiting for job to reach lyrics review stage');
|
||||
const job = await waitForJobStatus(request, jobId, ['in_review', 'awaiting_instrumental_selection'], 300000);
|
||||
console.log(`Job reached status: ${job.status}`);
|
||||
|
||||
// Verify theme was applied to job
|
||||
expect(job.theme_id).toBeTruthy();
|
||||
console.log(`Job theme_id: ${job.theme_id}`);
|
||||
|
||||
await page.screenshot({ path: 'test-results/flow-04-awaiting-review.png', fullPage: true });
|
||||
|
||||
// Step 4: Click "Review Lyrics" button to open lyrics review UI
|
||||
console.log('Step 4: Opening lyrics review UI');
|
||||
|
||||
// Refresh page to see updated job status
|
||||
await page.reload();
|
||||
await page.waitForLoadState('networkidle');
|
||||
await page.waitForTimeout(2000);
|
||||
|
||||
// Look for Review Lyrics button
|
||||
const reviewButton = page.getByRole('button', { name: /review.*lyrics/i }).or(
|
||||
page.getByRole('link', { name: /review.*lyrics/i })
|
||||
).or(
|
||||
page.locator('a:has-text("Review Lyrics")')
|
||||
);
|
||||
|
||||
if (await reviewButton.isVisible({ timeout: 10000 })) {
|
||||
// Set up page listener before clicking to avoid race condition
|
||||
const pagePromise = context.waitForEvent('page', { timeout: 5000 }).catch(() => null);
|
||||
await reviewButton.click();
|
||||
const newPage = await pagePromise;
|
||||
|
||||
const lyricsPage = newPage || page;
|
||||
|
||||
// Wait for lyrics review page to load
|
||||
await lyricsPage.waitForLoadState('networkidle');
|
||||
await lyricsPage.waitForTimeout(3000);
|
||||
|
||||
await lyricsPage.screenshot({ path: 'test-results/flow-05-lyrics-review-page.png', fullPage: true });
|
||||
|
||||
// Step 5: Scroll to bottom of lyrics review UI
|
||||
console.log('Step 5: Scrolling to bottom of lyrics review');
|
||||
await lyricsPage.evaluate(() => window.scrollTo(0, document.body.scrollHeight));
|
||||
await lyricsPage.waitForTimeout(1000);
|
||||
|
||||
await lyricsPage.screenshot({ path: 'test-results/flow-06-lyrics-bottom.png', fullPage: true });
|
||||
|
||||
// Step 6: Click Preview Video button
|
||||
console.log('Step 6: Generating preview video');
|
||||
const previewButton = lyricsPage.getByRole('button', { name: /preview.*video/i }).or(
|
||||
lyricsPage.locator('button:has-text("Preview")')
|
||||
);
|
||||
|
||||
if (await previewButton.isVisible({ timeout: 5000 })) {
|
||||
await previewButton.click();
|
||||
|
||||
// Wait for preview video to generate (this can take a while)
|
||||
console.log('Waiting for preview video to render...');
|
||||
await lyricsPage.waitForTimeout(30000); // 30 seconds initial wait
|
||||
|
||||
// Look for video element
|
||||
const videoElement = lyricsPage.locator('video').first();
|
||||
const videoVisible = await videoElement.isVisible({ timeout: 60000 }).catch(() => false);
|
||||
|
||||
if (videoVisible) {
|
||||
console.log('Preview video element found');
|
||||
await lyricsPage.screenshot({ path: 'test-results/flow-07-preview-video.png', fullPage: true });
|
||||
|
||||
// Step 7: Validate theme styles (check for non-black pixels in video area)
|
||||
console.log('Step 7: Validating theme styles in preview');
|
||||
|
||||
// Take a screenshot of just the video area
|
||||
const videoBox = await videoElement.boundingBox();
|
||||
if (videoBox) {
|
||||
const screenshot = await lyricsPage.screenshot({
|
||||
clip: {
|
||||
x: videoBox.x,
|
||||
y: videoBox.y,
|
||||
width: Math.min(videoBox.width, 400),
|
||||
height: Math.min(videoBox.height, 300)
|
||||
}
|
||||
});
|
||||
|
||||
// Save the video screenshot for manual inspection
|
||||
await lyricsPage.screenshot({
|
||||
path: 'test-results/flow-08-video-frame.png',
|
||||
clip: videoBox
|
||||
});
|
||||
|
||||
console.log('Video frame captured for style validation');
|
||||
// Note: Full pixel analysis would require image processing library
|
||||
// For now, we rely on visual inspection of screenshots
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Step 8: Complete the review
|
||||
console.log('Step 8: Completing lyrics review');
|
||||
const completeButton = lyricsPage.getByRole('button', { name: /complete.*review/i }).or(
|
||||
lyricsPage.locator('button:has-text("Complete Review")')
|
||||
);
|
||||
|
||||
if (await completeButton.isVisible({ timeout: 5000 })) {
|
||||
await completeButton.click();
|
||||
await lyricsPage.waitForTimeout(3000);
|
||||
await lyricsPage.screenshot({ path: 'test-results/flow-09-after-complete.png', fullPage: true });
|
||||
}
|
||||
|
||||
// Close the lyrics review page if it's a new tab
|
||||
if (newPage && newPage !== page) {
|
||||
await newPage.close();
|
||||
}
|
||||
}
|
||||
|
||||
// Step 9: Handle instrumental selection if needed
|
||||
const updatedJob = await waitForJobStatus(
|
||||
request,
|
||||
jobId,
|
||||
['awaiting_instrumental_selection', 'separating', 'processing', 'completed', 'failed'],
|
||||
60000
|
||||
).catch(() => null);
|
||||
|
||||
if (updatedJob?.status === 'awaiting_instrumental_selection') {
|
||||
console.log('Step 9: Handling instrumental selection via UI');
|
||||
|
||||
await page.reload();
|
||||
await page.waitForLoadState('networkidle');
|
||||
await page.waitForTimeout(2000);
|
||||
|
||||
await page.screenshot({ path: 'test-results/flow-10-instrumental-selection.png', fullPage: true });
|
||||
|
||||
// Look for instrumental selection UI
|
||||
const instrumentalButton = page.getByRole('button', { name: /select.*instrumental/i }).or(
|
||||
page.locator('button:has-text("Select")').first()
|
||||
);
|
||||
|
||||
if (await instrumentalButton.isVisible({ timeout: 10000 })) {
|
||||
await instrumentalButton.click();
|
||||
await page.waitForTimeout(2000);
|
||||
await page.screenshot({ path: 'test-results/flow-11-after-instrumental.png', fullPage: true });
|
||||
}
|
||||
}
|
||||
|
||||
console.log('Full job flow with theme completed successfully');
|
||||
} else {
|
||||
console.log('Could not determine job ID - test incomplete');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
test.describe('Theme Style Validation', () => {
|
||||
/**
|
||||
* Tests that validate theme styles are actually being applied,
|
||||
* not just that the UI accepts theme selection.
|
||||
*/
|
||||
|
||||
test('Job created via Search tab has theme_id set', async ({ page, request }) => {
|
||||
test.setTimeout(120000);
|
||||
|
||||
if (!ACCESS_TOKEN) {
|
||||
test.skip();
|
||||
return;
|
||||
}
|
||||
|
||||
await authenticatePage(page);
|
||||
await page.goto(PROD_URL);
|
||||
await page.waitForLoadState('networkidle');
|
||||
|
||||
await page.getByRole('tab', { name: /search/i }).click();
|
||||
await page.waitForTimeout(2000);
|
||||
|
||||
// Fill form
|
||||
await page.getByLabel('Artist').fill('Test Artist E2E');
|
||||
await page.getByLabel('Title').fill('Test Song E2E');
|
||||
|
||||
// Ensure theme is selected
|
||||
const themeSelect = page.locator('button[role="combobox"]').first();
|
||||
let selectedThemeId: string | null = null;
|
||||
|
||||
if (await themeSelect.isVisible({ timeout: 3000 })) {
|
||||
await themeSelect.click();
|
||||
await page.waitForTimeout(500);
|
||||
|
||||
// Get the first theme option
|
||||
const firstOption = page.locator('[role="option"]').first();
|
||||
const optionText = await firstOption.textContent();
|
||||
console.log(`Selecting theme: ${optionText}`);
|
||||
|
||||
await firstOption.click();
|
||||
await page.waitForTimeout(500);
|
||||
}
|
||||
|
||||
// Submit form - use the actual button text
|
||||
await page.getByRole('button', { name: /search.*create/i }).click();
|
||||
|
||||
// Wait a moment for job to be created
|
||||
await page.waitForTimeout(5000);
|
||||
|
||||
// Get recent jobs and find our test job
|
||||
const jobsResponse = await request.get(`${API_URL}/api/jobs`, {
|
||||
headers: { 'Authorization': `Bearer ${ACCESS_TOKEN}` }
|
||||
});
|
||||
|
||||
if (jobsResponse.ok()) {
|
||||
const jobsData = await jobsResponse.json();
|
||||
const jobs = jobsData.jobs || jobsData;
|
||||
|
||||
// Find a job with our test artist/title
|
||||
const testJob = Array.isArray(jobs)
|
||||
? jobs.find((j: any) => j.artist === 'Test Artist E2E' && j.title === 'Test Song E2E')
|
||||
: null;
|
||||
|
||||
if (testJob) {
|
||||
console.log(`Found test job: ${testJob.job_id}`);
|
||||
console.log(`Job theme_id: ${testJob.theme_id}`);
|
||||
console.log(`Job enable_cdg: ${testJob.enable_cdg}`);
|
||||
console.log(`Job enable_txt: ${testJob.enable_txt}`);
|
||||
|
||||
// CRITICAL ASSERTION: Theme must be set for jobs created via Search tab
|
||||
expect(testJob.theme_id).toBeTruthy();
|
||||
|
||||
// When theme is set, CDG and TXT should be enabled by default
|
||||
expect(testJob.enable_cdg).toBe(true);
|
||||
expect(testJob.enable_txt).toBe(true);
|
||||
} else {
|
||||
console.log('Test job not found in recent jobs');
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
test('Theme style_params are passed to job', async ({ request }) => {
|
||||
// This test verifies the backend correctly associates theme style_params with jobs
|
||||
|
||||
// First, get available themes
|
||||
const themesResponse = await request.get(`${API_URL}/api/themes`, {
|
||||
headers: { 'Authorization': `Bearer ${ACCESS_TOKEN}` }
|
||||
});
|
||||
|
||||
expect(themesResponse.ok()).toBeTruthy();
|
||||
const { themes } = await themesResponse.json();
|
||||
|
||||
if (themes.length === 0) {
|
||||
test.skip();
|
||||
return;
|
||||
}
|
||||
|
||||
const themeId = themes[0].id;
|
||||
|
||||
// Get theme details to verify style_params structure
|
||||
const themeDetailResponse = await request.get(`${API_URL}/api/themes/${themeId}`, {
|
||||
headers: { 'Authorization': `Bearer ${ACCESS_TOKEN}` }
|
||||
});
|
||||
|
||||
expect(themeDetailResponse.ok()).toBeTruthy();
|
||||
const { theme } = await themeDetailResponse.json();
|
||||
|
||||
// Verify theme has required style sections for video rendering
|
||||
expect(theme.style_params).toHaveProperty('intro');
|
||||
expect(theme.style_params).toHaveProperty('karaoke');
|
||||
expect(theme.style_params).toHaveProperty('end');
|
||||
|
||||
// Verify karaoke section has background (not black)
|
||||
const karaokeStyle = theme.style_params.karaoke;
|
||||
const hasBackground = karaokeStyle.background_image ||
|
||||
(karaokeStyle.background_color && karaokeStyle.background_color !== '#000000');
|
||||
|
||||
console.log(`Theme ${themeId} karaoke background_image: ${karaokeStyle.background_image}`);
|
||||
console.log(`Theme ${themeId} karaoke background_color: ${karaokeStyle.background_color}`);
|
||||
|
||||
// For non-default themes, we expect a background image or non-black color
|
||||
if (themeId !== 'default') {
|
||||
expect(hasBackground).toBeTruthy();
|
||||
}
|
||||
});
|
||||
});
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
[tool.poetry]
|
||||
name = "karaoke-gen"
|
||||
version = "0.76.10"
|
||||
version = "0.76.11"
|
||||
description = "Generate karaoke videos with synchronized lyrics. Handles the entire process from downloading audio and lyrics to creating the final video with title screens."
|
||||
authors = ["Andrew Beveridge <andrew@beveridge.uk>"]
|
||||
license = "MIT"
|
||||
|
||||
Reference in new issue
Block a user