import { describe, expect, it } from 'vitest'; import { chooseBest, scoreCandidateFile } from '../src/lib/scoring.js'; const candidate: any = { id: 'c1', provider: 'opensubtitles', displayName: 'x', downloadType: 'archiveZip', downloadUrl: 'https://example.com/subtitle.zip', lang: 'tr', releaseHints: ['1080p', 'x265', 'flux'], scoreHints: [], isHI: false, isForced: false }; describe('scoring', () => { it('scores tv season/episode match strongly', () => { const s = scoreCandidateFile('/tmp/show.S01E02.1080p.srt', 'srt', candidate, { type: 'tv', title: 'show', season: 1, episode: 2, release: 'FLUX', languages: ['tr'] }); expect(s?.score).toBeGreaterThan(100); }); it('disqualifies wrong episode for tv', () => { const s = scoreCandidateFile('/tmp/show.S01E03.srt', 'srt', candidate, { type: 'tv', title: 'show', season: 1, episode: 2, languages: ['tr'] }); expect(s).toBeNull(); }); it('returns ambiguous when top scores are close', () => { const d = chooseBest([ { id: 'a', candidateId: 'a', provider: 'x', filePath: '/a', ext: 'srt', lang: 'tr', score: 90, reasons: [] }, { id: 'b', candidateId: 'b', provider: 'x', filePath: '/b', ext: 'srt', lang: 'tr', score: 88, reasons: [] } ] as any); expect(d.status).toBe('AMBIGUOUS'); }); });