mirror of
https://github.com/nomadkaraoke/karaoke-gen.git
synced 2026-11-20 13:07:57 +09:00
fix(review): save the sync mark after the timing; show and revoke an existing mark (CodeRabbit)
- correction-data returns state_data.sync_reference, so the checkbox starts from the saved mark and un-ticking it sends verified=false. - The modal passes the mark to onSubmit. LyricsAnalyzer saves it only after submitCorrections succeeds, so a failed submit can't leave a mark on unsaved timing. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012RYLVVVPsvPbXFhRYY5VSJ
This commit is contained in:
1 parent
43d273ee37
commit
57d8a51d4e
5 files changed
+47
-38
No files matched your search
@@ -909,6 +909,10 @@ async def get_correction_data(
|
||||
# "evidenced" gaps and offers the reference lines for insertion.
|
||||
corrections_data['vocal_gaps'] = job.state_data.get('vocal_gaps') or None
|
||||
|
||||
# Admin "perfectly synced" mark (word-timing reference set), so a re-review
|
||||
# shows the existing mark and can revoke it.
|
||||
corrections_data['sync_reference'] = job.state_data.get('sync_reference') or None
|
||||
|
||||
# Per-screen skip (C1): tell the frontend whether each review half is
|
||||
# confidently auto-resolved, so it can skip the instrumental screen (or the
|
||||
# lyrics screen). Derived from the stored auto-approval verdict + the job's
|
||||
|
||||
@@ -117,6 +117,7 @@ interface ApiClient {
|
||||
getWaveformData?: (numPoints?: number) => Promise<{ amplitudes: number[]; duration_seconds?: number; duration?: number }>
|
||||
// Optional: separation-status poll for stems that land after page load (cloud mode).
|
||||
getInstrumentalState?: LyricsReviewApiClient['getInstrumentalState']
|
||||
setSyncReference?: LyricsReviewApiClient['setSyncReference']
|
||||
completeReview: () => Promise<{ status: string; job_status: string; message: string }>
|
||||
// Review session methods (optional - available in cloud mode)
|
||||
saveReviewSession?: LyricsReviewApiClient['saveReviewSession']
|
||||
@@ -1151,7 +1152,9 @@ export default function LyricsAnalyzer({
|
||||
}, [saveSession])
|
||||
|
||||
// Submit to server (save corrections, don't complete review yet)
|
||||
const handleSubmitToServer = useCallback(async () => {
|
||||
const handleSubmitToServer = useCallback(async (
|
||||
opts?: { syncReference?: { verified: boolean; notes?: string } },
|
||||
) => {
|
||||
if (!apiClient) return
|
||||
|
||||
// Block submission of lyrics that still have no timing (e.g. custom lyrics
|
||||
@@ -1172,6 +1175,16 @@ export default function LyricsAnalyzer({
|
||||
// 1. Save corrections (not final submission yet), including current duet flag
|
||||
await apiClient.submitCorrections(dataToSubmit, isDuet)
|
||||
|
||||
// 1b. Admin "perfectly synced" mark — only now that the timing it vouches for
|
||||
// is saved. Best-effort: never blocks or fails the review.
|
||||
if (opts?.syncReference && apiClient.setSyncReference) {
|
||||
try {
|
||||
await apiClient.setSyncReference(opts.syncReference.verified, opts.syncReference.notes)
|
||||
} catch (error) {
|
||||
console.error('Failed to save sync reference mark:', error)
|
||||
}
|
||||
}
|
||||
|
||||
// 2. Save edit log (non-blocking)
|
||||
if (editLog.entries.length > 0) {
|
||||
try {
|
||||
|
||||
+14
-24
@@ -22,12 +22,7 @@ const data = {
|
||||
} as unknown as CorrectionData
|
||||
|
||||
function client() {
|
||||
return {
|
||||
generatePreviewVideo: jest.fn(),
|
||||
getPreviewVideoStatus: jest.fn(),
|
||||
getPreviewVideoUrl: jest.fn(),
|
||||
setSyncReference: jest.fn().mockResolvedValue(undefined),
|
||||
}
|
||||
return { generatePreviewVideo: jest.fn(), getPreviewVideoStatus: jest.fn(), getPreviewVideoUrl: jest.fn() }
|
||||
}
|
||||
|
||||
function setRole(role: string | null) {
|
||||
@@ -43,39 +38,34 @@ describe('ReviewChangesModal sync-reference mark (admin only)', () => {
|
||||
expect(screen.queryByTestId('sync-reference')).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('records the mark with notes when an admin ticks it and submits', async () => {
|
||||
it('passes the mark with notes to onSubmit when an admin ticks it', async () => {
|
||||
setRole('admin')
|
||||
const api = client()
|
||||
const onSubmit = jest.fn()
|
||||
render(<ReviewChangesModal open onClose={jest.fn()} onSubmit={onSubmit} data={data} apiClient={api} />)
|
||||
render(<ReviewChangesModal open onClose={jest.fn()} onSubmit={onSubmit} data={data} apiClient={client()} />)
|
||||
await userEvent.click(screen.getByTestId('sync-reference-checkbox'))
|
||||
await userEvent.type(screen.getByTestId('sync-reference-notes'), 'spot-checked')
|
||||
await userEvent.click(screen.getByRole('button', { name: /proceed to instrumental/i }))
|
||||
expect(api.setSyncReference).toHaveBeenCalledWith(true, 'spot-checked')
|
||||
expect(onSubmit).toHaveBeenCalled()
|
||||
expect(onSubmit).toHaveBeenCalledWith({ syncReference: { verified: true, notes: 'spot-checked' } })
|
||||
})
|
||||
|
||||
it('sends nothing when the admin leaves it unticked', async () => {
|
||||
it('sends no mark when the admin leaves it unticked', async () => {
|
||||
setRole('admin')
|
||||
const api = client()
|
||||
const onSubmit = jest.fn()
|
||||
render(<ReviewChangesModal open onClose={jest.fn()} onSubmit={onSubmit} data={data} apiClient={api} />)
|
||||
render(<ReviewChangesModal open onClose={jest.fn()} onSubmit={onSubmit} data={data} apiClient={client()} />)
|
||||
expect(screen.getByTestId('sync-reference')).toBeInTheDocument()
|
||||
await userEvent.click(screen.getByRole('button', { name: /proceed to instrumental/i }))
|
||||
expect(api.setSyncReference).not.toHaveBeenCalled()
|
||||
expect(onSubmit).toHaveBeenCalled()
|
||||
expect(onSubmit).toHaveBeenCalledWith()
|
||||
})
|
||||
|
||||
it('still submits the review when saving the mark fails', async () => {
|
||||
it('starts ticked from a saved mark and sends verified=false when revoked', async () => {
|
||||
setRole('admin')
|
||||
const api = client()
|
||||
api.setSyncReference.mockRejectedValue(new Error('network'))
|
||||
const onSubmit = jest.fn()
|
||||
const err = jest.spyOn(console, 'error').mockImplementation(() => {})
|
||||
render(<ReviewChangesModal open onClose={jest.fn()} onSubmit={onSubmit} data={data} apiClient={api} />)
|
||||
await userEvent.click(screen.getByTestId('sync-reference-checkbox'))
|
||||
const marked = { ...data, sync_reference: { verified: true, notes: 'old note' } } as CorrectionData
|
||||
render(<ReviewChangesModal open onClose={jest.fn()} onSubmit={onSubmit} data={marked} apiClient={client()} />)
|
||||
const box = screen.getByTestId('sync-reference-checkbox') as HTMLInputElement
|
||||
expect(box.checked).toBe(true)
|
||||
await userEvent.click(box)
|
||||
await userEvent.click(screen.getByRole('button', { name: /proceed to instrumental/i }))
|
||||
expect(onSubmit).toHaveBeenCalled()
|
||||
err.mockRestore()
|
||||
expect(onSubmit).toHaveBeenCalledWith({ syncReference: { verified: false, notes: 'old note' } })
|
||||
})
|
||||
})
|
||||
@@ -30,7 +30,6 @@ interface ApiClient {
|
||||
getPreviewVideoUrl: (hash: string) => string
|
||||
getWaveformData?: (numPoints?: number) => Promise<WaveformDataResult>
|
||||
refreshInstrumentalUrls?: () => Promise<InstrumentalOption[]>
|
||||
setSyncReference?: (verified: boolean, notes?: string) => Promise<void>
|
||||
}
|
||||
|
||||
interface ReviewChangesModalProps {
|
||||
@@ -43,7 +42,9 @@ interface ReviewChangesModalProps {
|
||||
/** Late-stems poll state: `waiting` = audio separation still running, so the
|
||||
* instrumental choice isn't available yet; `gave_up` = it didn't arrive in time. */
|
||||
stemsStatus?: LateInstrumentalStatus
|
||||
onSubmit: () => void
|
||||
/** `syncReference` is set only for admins who ticked (or un-ticked a previously
|
||||
* saved) "perfectly synced" mark; the caller saves it after the timing is saved. */
|
||||
onSubmit: (opts?: { syncReference?: { verified: boolean; notes?: string } }) => void
|
||||
isSubmitting?: boolean
|
||||
apiClient?: ApiClient | null
|
||||
timingOffsetMs?: number
|
||||
@@ -155,21 +156,20 @@ export default function ReviewChangesModal({
|
||||
}
|
||||
|
||||
// Admin-only "perfectly synced" mark: verified jobs join the word-timing reference
|
||||
// set used to train and evaluate the aligner. Unticked = unverified (nothing sent).
|
||||
// set used to train and evaluate the aligner. Unticked = unverified. Starts from
|
||||
// the saved mark so a re-review can see and revoke it.
|
||||
const isAdmin = useAuth((s) => s.user?.role === 'admin')
|
||||
const [syncVerified, setSyncVerified] = useState(false)
|
||||
const [syncNotes, setSyncNotes] = useState('')
|
||||
const canMarkSync = isAdmin && !!apiClient?.setSyncReference
|
||||
const savedVerified = !!data.sync_reference?.verified
|
||||
const [syncVerified, setSyncVerified] = useState(savedVerified)
|
||||
const [syncNotes, setSyncNotes] = useState(data.sync_reference?.notes || '')
|
||||
|
||||
const handleSubmit = () => {
|
||||
if (isSubmitting) return
|
||||
if (canMarkSync && syncVerified) {
|
||||
// Best-effort: never block or fail the review on the reference mark.
|
||||
apiClient!.setSyncReference!(true, syncNotes.trim() || undefined).catch((err) =>
|
||||
console.error('Failed to save sync reference mark', err)
|
||||
)
|
||||
if (isAdmin && (syncVerified || savedVerified)) {
|
||||
onSubmit({ syncReference: { verified: syncVerified, notes: syncNotes.trim() || undefined } })
|
||||
} else {
|
||||
onSubmit()
|
||||
}
|
||||
onSubmit()
|
||||
}
|
||||
|
||||
return (
|
||||
@@ -319,7 +319,7 @@ export default function ReviewChangesModal({
|
||||
</div>
|
||||
)}
|
||||
|
||||
{canMarkSync && (
|
||||
{isAdmin && (
|
||||
<div className="rounded-md border border-dashed p-3 text-sm space-y-2" data-testid="sync-reference">
|
||||
<label className="flex items-start gap-2 cursor-pointer">
|
||||
<input
|
||||
|
||||
@@ -189,6 +189,8 @@ export interface CorrectionData {
|
||||
// Absent/null when the job wasn't analyzed. Read-only: the review UI derives
|
||||
// which gaps are still open from the current segments, never mutates this.
|
||||
vocal_gaps?: VocalGapsResult | null
|
||||
// Admin "perfectly synced" mark (word-timing reference set), if one was saved.
|
||||
sync_reference?: { verified: boolean; by?: string; at?: string; notes?: string | null } | null
|
||||
// Replay mode (read-only re-open of a completed job via ?replay=true). Present
|
||||
// only in replay; carries the reviewer's ordered edit log for narration.
|
||||
replay?: {
|
||||
|
||||
Reference in new issue
Block a user