mirror of
https://github.com/nomadkaraoke/karaoke-gen.git
synced 2026-11-20 13:07:57 +09:00
## Bulk Mode — submit up to 100 karaoke jobs at once
Adds a **Bulk Mode** tab to the job-submission flow so users can make
karaoke versions of a whole album (or a typed list) in one go.
### Two ways in
- **By album** — MusicBrainz artist → album → tracklist.
Live/remix/bonus tracks and songs that already have a community version
on KaraokeNerds start **unticked** (re-tick anything). Auto-picks the
canonical edition, with an edition switcher.
- **By text** — up to 100 artist/title rows, each with a
community-version availability badge.
### Auto + review-queue model
Batch settings (auto-pick lossless / public-private / skip audio edit /
skip customization) drive auto-completion. The server runs each audio
search and **auto-selects only a confident lossless ("tier 1") match**;
everything else is parked in the existing `AWAITING_AUDIO_SELECTION`
state and surfaced as a review queue (reusing the existing
`AudioSearchDialog`). A popular full-FLAC album with all toggles on =
zero further prompts; the tab can be closed (searches run as a Cloud Run
Job).
### Credits
Gated upfront: requires `credits >= number_of_songs` (1/song minimum)
before any job is created; admins bypass. Duration deltas for long
tracks are charged per-song during processing as today.
### Backend
- `POST /api/bulk/submit`, `GET /api/bulk/{batch_id}`, `GET
/api/bulk/album/{artists,albums,tracklist}`, `POST
/api/bulk/availability`
- `bulk_search_worker` Cloud Run Job (`infrastructure/`:
`bulk-search-job`) — search → tier-1 auto-select (with duration-delta
charge) or park; per-job crash isolation; idempotent on retry
(charge_pending guard prevents double-charge)
- New `musicbrainz_service` (release lookup + extras detection); reuses
existing `karaokenerds_service` scraper (batch helper) for availability
— **no karaoke-decide change** (it has the `is_community` flag matching
"community-created"; see design doc)
- `pick_auto_selection` ports the frontend tier-1 confidence rule to the
backend (parity test)
### Frontend
- `components/job/bulk/*` (album/text modes, batch settings, submit bar,
batch progress + review queue); api client + types; 33-locale i18n
### Testing
- 40 new backend tests (foundations, MusicBrainz, lookup routes, submit
credit gate, search worker auto/park + credit math, progress) + frontend
Jest for the default-selection and credit-gate helpers
- Safe production E2E smoke
(`frontend/e2e/production/bulk-mode.spec.ts`) — read-only lookups + gate
rejection, does not spawn real jobs
- Full backend suite green (3588 passed); frontend typechecks clean (no
new errors)
### Deploy notes
- **Requires `pulumi up`** to create the `bulk-search-job` Cloud Run Job
before submit works in prod.
- Design + plan: `docs/archive/2026-06-18-bulk-mode-design.md`,
`-plan.md`
Docs: `docs/API.md` § Bulk Mode, `docs/LESSONS-LEARNED.md`.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
@coderabbitai ignore
---------
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
85 lines
2.8 KiB
Python
85 lines
2.8 KiB
Python
"""Tests for GET /api/bulk/{batch_id} progress summary."""
|
|
|
|
from unittest.mock import MagicMock
|
|
|
|
import pytest
|
|
from fastapi.testclient import TestClient
|
|
|
|
from backend.main import app
|
|
from backend.api.dependencies import require_auth, AuthResult, UserType
|
|
from backend.models.job import JobStatus
|
|
|
|
|
|
def _auth(is_admin=False, email="t@example.com"):
|
|
def _dep():
|
|
return AuthResult(
|
|
is_valid=True,
|
|
user_type=UserType.ADMIN if is_admin else UserType.STRIPE,
|
|
remaining_uses=999, message="ok", user_email=email, is_admin=is_admin,
|
|
)
|
|
return _dep
|
|
|
|
|
|
def _job(job_id, status, email="t@example.com", pending=False, auto=False, artist="A", title="T"):
|
|
j = MagicMock()
|
|
j.job_id = job_id
|
|
j.status = status
|
|
j.user_email = email
|
|
j.artist = artist
|
|
j.title = title
|
|
j.audio_search_artist = artist
|
|
j.audio_search_title = title
|
|
j.state_data = {"batch_id": "b1", "bulk_pending_search": pending, "bulk_auto_selected": auto}
|
|
return j
|
|
|
|
|
|
@pytest.fixture
|
|
def client():
|
|
c = TestClient(app)
|
|
yield c
|
|
app.dependency_overrides.clear()
|
|
|
|
|
|
def test_progress_buckets(client, monkeypatch):
|
|
app.dependency_overrides[require_auth] = _auth()
|
|
jm = MagicMock()
|
|
jm.list_jobs_by_batch_id.return_value = [
|
|
_job("j1", JobStatus.AWAITING_AUDIO_SELECTION),
|
|
_job("j2", JobStatus.DOWNLOADING_AUDIO, auto=True),
|
|
_job("j3", JobStatus.COMPLETE, auto=True),
|
|
_job("j4", JobStatus.SEARCHING_AUDIO, pending=True),
|
|
]
|
|
monkeypatch.setattr("backend.services.job_manager.JobManager", lambda: jm)
|
|
|
|
resp = client.get("/api/bulk/b1")
|
|
assert resp.status_code == 200, resp.text
|
|
data = resp.json()
|
|
assert data["total"] == 4
|
|
assert data["counts"]["awaiting_selection"] == 1
|
|
assert data["counts"]["processing"] == 1
|
|
assert data["counts"]["complete"] == 1
|
|
assert data["counts"]["searching"] == 1
|
|
j2 = next(j for j in data["jobs"] if j["job_id"] == "j2")
|
|
assert j2["auto_selected"] is True
|
|
|
|
|
|
def test_other_users_batch_is_404(client, monkeypatch):
|
|
app.dependency_overrides[require_auth] = _auth(email="me@example.com")
|
|
jm = MagicMock()
|
|
jm.list_jobs_by_batch_id.return_value = [_job("j1", JobStatus.COMPLETE, email="someone@else.com")]
|
|
monkeypatch.setattr("backend.services.job_manager.JobManager", lambda: jm)
|
|
|
|
resp = client.get("/api/bulk/b1")
|
|
assert resp.status_code == 404
|
|
|
|
|
|
def test_admin_sees_any_batch(client, monkeypatch):
|
|
app.dependency_overrides[require_auth] = _auth(is_admin=True, email="admin@example.com")
|
|
jm = MagicMock()
|
|
jm.list_jobs_by_batch_id.return_value = [_job("j1", JobStatus.COMPLETE, email="someone@else.com")]
|
|
monkeypatch.setattr("backend.services.job_manager.JobManager", lambda: jm)
|
|
|
|
resp = client.get("/api/bulk/b1")
|
|
assert resp.status_code == 200
|
|
assert resp.json()["total"] == 1
|