mirror of
https://github.com/nomadkaraoke/karaoke-gen.git
synced 2026-12-05 17:38:25 +09:00
## Problem
Validator alert: `MP4-720p: missing 1632`. This was **NOMAD-1632 — Nat
King Cole – "Portrait of Jennie"** (job `21150e73`). Only the **720p**
variant was missing; MP4 and CDG were present and correct (so recycling
the brand code would have been *wrong*).
## Root cause — filename/title substring collision
The encoder produced and uploaded the 720p to GCS correctly (`… (Final
Karaoke Lossy 720p).mp4`), but `GCEEncodingBackend.encode()` mapped the
worker's returned file list to format keys by scanning the **whole
filename**, checking `"portrait"` (to detect the 9:16 portrait video)
**before** `"720p"`. The title contains "Portrait", so the 720p matched
the portrait branch → `mp4_720p` never set → `final_video_720p=None` →
`upload_to_public_share` **silently skips** a `None` path → published to
MP4/ + CDG/ with no MP4-720p/ entry. Deterministic for **any** song
whose artist/title contains a format word ("portrait", "720p", "4k",
"lossless", "vocals", …). Only the daily validator caught it, ~24h
later.
## Fix
- **`classify_encoded_output()`** — a shared, title-collision-proof
classifier that matches the trailing **format parenthetical only** (plus
system short-names), never artist/title text. Used by both
`GCEEncodingBackend.encode()` and `redistribute_video` (same latent
bug).
- **Completeness guard** (defense-in-depth) — `encode()` now returns
`success=False` (orchestrator raises → retry + immediate alert) if the
worker returns fewer formats than requested, so *any* partial-encode
cause fails loud instead of publishing an incomplete release.
- **Portrait Video download button** in `OutputLinks` (shown when the
job has `finals.portrait_1080x1920`) — the feature shipped but had no UI
download. Added the backend download filename suffix and the
`outputLinks.portrait` string translated to all 33 locales.
- Docs: `GDRIVE-VALIDATOR.md` History entry; version bump 0.222.1 →
0.222.2.
## Live gap remediation (already done, outside this PR)
The correct 720p already existed in GCS, so it was uploaded directly to
the `MP4-720p/` public-share folder as `NOMAD-1632 - Nat King Cole -
Portrait of Jennie.mp4` (verified present; mirror backfills nightly). No
re-render, no YouTube disruption. 1632 was **not** recycled.
## Testing
- `test_encoding_interface.py` — 37 pass, incl. a NOMAD-1632
reproduction (`Portrait of Jennie` 720p → `mp4_720p`),
title-with-"720p"/"4k" leakage cases, short-name coverage, and a
completeness-guard failure test.
- `OutputLinks.test.tsx` — portrait button show/hide (frontend unit
suite: 1252 pass).
- Orchestrator (82) + change-visibility (25) suites pass.
- Full backend unit run: 4373 pass (8 failures are pre-existing
`test_emulator_integration` env failures — emulator not running locally;
unrelated to this change).
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
- **New Features**
- Added downloadable portrait-format video output at 1080×1920.
- Added localized “Portrait Video” labels across supported languages.
- **Bug Fixes**
- Improved output recognition so video titles containing format terms
are classified correctly.
- Prevented incomplete encoding results from being published when a
requested format is missing.
- Corrected portrait-format filenames for clearer downloads.
- **Chores**
- Updated the application version to 0.222.2.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
---------
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
389 lines
12 KiB
TypeScript
389 lines
12 KiB
TypeScript
/**
|
|
* Tests for OutputLinks component
|
|
*
|
|
* Tests the download buttons and external links behavior,
|
|
* including hiding links when outputs have been deleted.
|
|
*/
|
|
|
|
import { render, screen } from '@testing-library/react'
|
|
import { OutputLinks } from '../job/OutputLinks'
|
|
import { Job } from '@/lib/api'
|
|
|
|
// Mock the hooks
|
|
jest.mock('@/lib/auth', () => ({
|
|
useAuth: jest.fn(() => ({ user: { role: 'user' } })),
|
|
}))
|
|
|
|
jest.mock('@/lib/tenant', () => ({
|
|
useTenant: jest.fn(() => ({
|
|
features: {
|
|
youtube_upload: true,
|
|
dropbox_upload: true,
|
|
},
|
|
})),
|
|
}))
|
|
|
|
// Mock the api module
|
|
jest.mock('@/lib/api', () => ({
|
|
api: {
|
|
getDownloadUrl: jest.fn((jobId, category, key) => `https://example.com/${jobId}/${category}/${key}`),
|
|
},
|
|
adminApi: {
|
|
getCompletionMessage: jest.fn(),
|
|
sendCompletionEmail: jest.fn(),
|
|
},
|
|
}))
|
|
|
|
describe('OutputLinks', () => {
|
|
const baseJob: Job = {
|
|
job_id: 'test-123',
|
|
status: 'complete',
|
|
progress: 100,
|
|
created_at: '2026-01-01T00:00:00Z',
|
|
updated_at: '2026-01-01T00:00:00Z',
|
|
artist: 'Test Artist',
|
|
title: 'Test Song',
|
|
file_urls: {
|
|
finals: {
|
|
lossy_4k_mp4: 'gs://bucket/finals/4k.mp4',
|
|
lossy_720p_mp4: 'gs://bucket/finals/720p.mp4',
|
|
portrait_1080x1920: 'gs://bucket/finals/portrait_1080x1920.mp4',
|
|
},
|
|
videos: {
|
|
with_vocals: 'gs://bucket/videos/with_vocals.mkv',
|
|
},
|
|
packages: {
|
|
cdg_zip: 'gs://bucket/packages/cdg.zip',
|
|
txt_zip: 'gs://bucket/packages/txt.zip',
|
|
},
|
|
},
|
|
state_data: {
|
|
youtube_url: 'https://youtube.com/watch?v=abc123',
|
|
dropbox_link: 'https://dropbox.com/s/xyz789',
|
|
},
|
|
}
|
|
|
|
beforeEach(() => {
|
|
jest.clearAllMocks()
|
|
// Reset to default non-admin user
|
|
const { useAuth } = require('@/lib/auth')
|
|
useAuth.mockReturnValue({ user: { role: 'user' } })
|
|
})
|
|
|
|
describe('when outputs are NOT deleted', () => {
|
|
it('shows download buttons when file_urls are present', () => {
|
|
render(<OutputLinks job={baseJob} />)
|
|
|
|
expect(screen.getByText('4K Video')).toBeInTheDocument()
|
|
expect(screen.getByText('720p Video')).toBeInTheDocument()
|
|
expect(screen.getByText('Portrait Video')).toBeInTheDocument()
|
|
expect(screen.getByText('With Vocals')).toBeInTheDocument()
|
|
expect(screen.getByText('CDG')).toBeInTheDocument()
|
|
expect(screen.getByText('TXT')).toBeInTheDocument()
|
|
})
|
|
|
|
it('hides the Portrait Video button when the job has no portrait output', () => {
|
|
const noPortrait = {
|
|
...baseJob,
|
|
file_urls: {
|
|
...baseJob.file_urls,
|
|
finals: {
|
|
lossy_4k_mp4: 'gs://bucket/finals/4k.mp4',
|
|
lossy_720p_mp4: 'gs://bucket/finals/720p.mp4',
|
|
},
|
|
},
|
|
}
|
|
render(<OutputLinks job={noPortrait} />)
|
|
|
|
expect(screen.getByText('720p Video')).toBeInTheDocument()
|
|
expect(screen.queryByText('Portrait Video')).not.toBeInTheDocument()
|
|
})
|
|
|
|
it('shows YouTube link when youtube_url is in state_data', () => {
|
|
render(<OutputLinks job={baseJob} />)
|
|
|
|
expect(screen.getByText('YouTube')).toBeInTheDocument()
|
|
})
|
|
|
|
it('hides GCS downloads + distribution links during a private->public re-render', () => {
|
|
// Making public deletes the finals and re-renders (status leaves
|
|
// "complete"), so the now-stale download + distribution links must go.
|
|
const reRenderJob: Job = {
|
|
...baseJob,
|
|
status: 'rendering_video',
|
|
state_data: {
|
|
...baseJob.state_data,
|
|
visibility_change_in_progress: true,
|
|
},
|
|
}
|
|
|
|
render(<OutputLinks job={reRenderJob} />)
|
|
|
|
expect(screen.queryByText('4K Video')).not.toBeInTheDocument()
|
|
expect(screen.queryByText('720p Video')).not.toBeInTheDocument()
|
|
expect(screen.queryByText('YouTube')).not.toBeInTheDocument()
|
|
expect(screen.queryByText('Dropbox')).not.toBeInTheDocument()
|
|
})
|
|
|
|
it('keeps GCS downloads but hides distribution links during a public->private change', () => {
|
|
// Making private is the fast path: it keeps the GCS finals and stays
|
|
// "complete", only tearing down + redistributing YouTube/Dropbox.
|
|
const toPrivateJob: Job = {
|
|
...baseJob,
|
|
status: 'complete',
|
|
state_data: {
|
|
...baseJob.state_data,
|
|
visibility_change_in_progress: true,
|
|
},
|
|
}
|
|
|
|
render(<OutputLinks job={toPrivateJob} />)
|
|
|
|
// Finals still available for download
|
|
expect(screen.getByText('4K Video')).toBeInTheDocument()
|
|
expect(screen.getByText('720p Video')).toBeInTheDocument()
|
|
// Distribution links torn down / redistributing
|
|
expect(screen.queryByText('YouTube')).not.toBeInTheDocument()
|
|
expect(screen.queryByText('Dropbox')).not.toBeInTheDocument()
|
|
})
|
|
|
|
it('shows Dropbox link when dropbox_link is in state_data', () => {
|
|
render(<OutputLinks job={baseJob} />)
|
|
|
|
expect(screen.getByText('Dropbox')).toBeInTheDocument()
|
|
})
|
|
})
|
|
|
|
describe('when outputs ARE deleted (outputs_deleted_at is set)', () => {
|
|
const deletedJob: Job = {
|
|
...baseJob,
|
|
outputs_deleted_at: '2026-01-15T10:00:00Z',
|
|
outputs_deleted_by: 'admin@example.com',
|
|
}
|
|
|
|
it('hides all download buttons', () => {
|
|
render(<OutputLinks job={deletedJob} />)
|
|
|
|
expect(screen.queryByText('4K Video')).not.toBeInTheDocument()
|
|
expect(screen.queryByText('720p Video')).not.toBeInTheDocument()
|
|
expect(screen.queryByText('With Vocals')).not.toBeInTheDocument()
|
|
expect(screen.queryByText('CDG')).not.toBeInTheDocument()
|
|
expect(screen.queryByText('TXT')).not.toBeInTheDocument()
|
|
})
|
|
|
|
it('hides YouTube link', () => {
|
|
render(<OutputLinks job={deletedJob} />)
|
|
|
|
expect(screen.queryByText('YouTube')).not.toBeInTheDocument()
|
|
})
|
|
|
|
it('hides Dropbox link', () => {
|
|
render(<OutputLinks job={deletedJob} />)
|
|
|
|
expect(screen.queryByText('Dropbox')).not.toBeInTheDocument()
|
|
})
|
|
|
|
it('still shows Admin link for admin users', () => {
|
|
// Mock admin user
|
|
const { useAuth } = require('@/lib/auth')
|
|
useAuth.mockReturnValue({ user: { role: 'admin' } })
|
|
|
|
render(<OutputLinks job={deletedJob} />)
|
|
|
|
// Admin link should still be visible even when outputs are deleted
|
|
expect(screen.getByText('Admin')).toBeInTheDocument()
|
|
})
|
|
})
|
|
|
|
describe('visibility change button', () => {
|
|
it('shows "Make Public" for private complete jobs', () => {
|
|
const privateJob: Job = {
|
|
...baseJob,
|
|
is_private: true,
|
|
}
|
|
|
|
render(<OutputLinks job={privateJob} />)
|
|
|
|
expect(screen.getByText('Make Public')).toBeInTheDocument()
|
|
expect(screen.queryByText('Make Private')).not.toBeInTheDocument()
|
|
})
|
|
|
|
it('shows "Make Private" for public complete jobs', () => {
|
|
const publicJob: Job = {
|
|
...baseJob,
|
|
is_private: false,
|
|
}
|
|
|
|
render(<OutputLinks job={publicJob} />)
|
|
|
|
expect(screen.getByText('Make Private')).toBeInTheDocument()
|
|
expect(screen.queryByText('Make Public')).not.toBeInTheDocument()
|
|
})
|
|
|
|
it('hides button when visibility change is in progress', () => {
|
|
const inProgressJob: Job = {
|
|
...baseJob,
|
|
state_data: {
|
|
...baseJob.state_data,
|
|
visibility_change_in_progress: true,
|
|
},
|
|
}
|
|
|
|
render(<OutputLinks job={inProgressJob} />)
|
|
|
|
expect(screen.queryByText('Make Public')).not.toBeInTheDocument()
|
|
expect(screen.queryByText('Make Private')).not.toBeInTheDocument()
|
|
})
|
|
|
|
it('hides button for non-complete jobs', () => {
|
|
const pendingJob: Job = {
|
|
...baseJob,
|
|
status: 'generating_video',
|
|
}
|
|
|
|
render(<OutputLinks job={pendingJob} />)
|
|
|
|
expect(screen.queryByText('Make Public')).not.toBeInTheDocument()
|
|
expect(screen.queryByText('Make Private')).not.toBeInTheDocument()
|
|
})
|
|
|
|
it('hides button for tenant jobs', () => {
|
|
const { useTenant } = require('@/lib/tenant')
|
|
useTenant.mockReturnValue({
|
|
tenantId: 'vocalstar',
|
|
features: { youtube_upload: true, dropbox_upload: true },
|
|
})
|
|
|
|
render(<OutputLinks job={baseJob} />)
|
|
|
|
expect(screen.queryByText('Make Public')).not.toBeInTheDocument()
|
|
expect(screen.queryByText('Make Private')).not.toBeInTheDocument()
|
|
})
|
|
})
|
|
|
|
describe('edge cases', () => {
|
|
it('shows nothing when job has no file_urls and no state_data (non-admin)', () => {
|
|
// Reset to non-admin user
|
|
const { useAuth } = require('@/lib/auth')
|
|
useAuth.mockReturnValue({ user: { role: 'user' } })
|
|
|
|
const emptyJob: Job = {
|
|
...baseJob,
|
|
status: 'generating_video',
|
|
file_urls: undefined,
|
|
state_data: undefined,
|
|
}
|
|
|
|
render(<OutputLinks job={emptyJob} />)
|
|
|
|
// Should show "No outputs available yet" for non-admin, non-complete job
|
|
expect(screen.getByText('No outputs available yet')).toBeInTheDocument()
|
|
})
|
|
|
|
it('shows Edit button for completed jobs with outputs', () => {
|
|
render(<OutputLinks job={baseJob} />)
|
|
|
|
expect(screen.getByText('Edit')).toBeInTheDocument()
|
|
})
|
|
|
|
it('hides Edit button when outputs are deleted', () => {
|
|
const deletedJob: Job = {
|
|
...baseJob,
|
|
outputs_deleted_at: '2026-01-15T10:00:00Z',
|
|
}
|
|
|
|
render(<OutputLinks job={deletedJob} />)
|
|
|
|
expect(screen.queryByText('Edit')).not.toBeInTheDocument()
|
|
})
|
|
|
|
it('hides Edit button for non-complete jobs', () => {
|
|
const pendingJob: Job = {
|
|
...baseJob,
|
|
status: 'pending',
|
|
}
|
|
|
|
render(<OutputLinks job={pendingJob} />)
|
|
|
|
expect(screen.queryByText('Edit')).not.toBeInTheDocument()
|
|
})
|
|
})
|
|
|
|
describe('With Vocals MP4 preference', () => {
|
|
it('prefers finals.with_vocals_mp4 over videos.with_vocals when both exist', () => {
|
|
const jobWithBoth: Job = {
|
|
...baseJob,
|
|
file_urls: {
|
|
finals: {
|
|
lossy_4k_mp4: 'gs://bucket/finals/4k.mp4',
|
|
with_vocals_mp4: 'gs://bucket/finals/with_vocals.mp4',
|
|
},
|
|
videos: {
|
|
with_vocals: 'gs://bucket/videos/with_vocals.mkv',
|
|
},
|
|
},
|
|
}
|
|
|
|
render(<OutputLinks job={jobWithBoth} />)
|
|
|
|
const vocalsLink = screen.getByText('With Vocals').closest('a')
|
|
expect(vocalsLink).toHaveAttribute('href',
|
|
expect.stringContaining('/finals/with_vocals_mp4')
|
|
)
|
|
})
|
|
|
|
it('falls back to videos.with_vocals when finals.with_vocals_mp4 is missing', () => {
|
|
render(<OutputLinks job={baseJob} />)
|
|
|
|
const vocalsLink = screen.getByText('With Vocals').closest('a')
|
|
expect(vocalsLink).toHaveAttribute('href',
|
|
expect.stringContaining('/videos/with_vocals')
|
|
)
|
|
})
|
|
|
|
it('shows With Vocals when only finals.with_vocals_mp4 exists (no legacy MKV)', () => {
|
|
const mp4OnlyJob: Job = {
|
|
...baseJob,
|
|
file_urls: {
|
|
finals: {
|
|
lossy_4k_mp4: 'gs://bucket/finals/4k.mp4',
|
|
with_vocals_mp4: 'gs://bucket/finals/with_vocals.mp4',
|
|
},
|
|
},
|
|
}
|
|
|
|
render(<OutputLinks job={mp4OnlyJob} />)
|
|
|
|
expect(screen.getByText('With Vocals')).toBeInTheDocument()
|
|
const vocalsLink = screen.getByText('With Vocals').closest('a')
|
|
expect(vocalsLink).toHaveAttribute('href',
|
|
expect.stringContaining('/finals/with_vocals_mp4')
|
|
)
|
|
})
|
|
})
|
|
|
|
describe('edge cases', () => {
|
|
it('handles partial file_urls gracefully', () => {
|
|
// Reset to non-admin user
|
|
const { useAuth } = require('@/lib/auth')
|
|
useAuth.mockReturnValue({ user: { role: 'user' } })
|
|
|
|
const partialJob: Job = {
|
|
...baseJob,
|
|
file_urls: {
|
|
finals: {
|
|
lossy_720p_mp4: 'gs://bucket/finals/720p.mp4',
|
|
},
|
|
},
|
|
state_data: undefined,
|
|
}
|
|
|
|
render(<OutputLinks job={partialJob} />)
|
|
|
|
expect(screen.getByText('720p Video')).toBeInTheDocument()
|
|
expect(screen.queryByText('4K Video')).not.toBeInTheDocument()
|
|
expect(screen.queryByText('YouTube')).not.toBeInTheDocument()
|
|
})
|
|
})
|
|
})
|