Spaces:
Paused
Paused
File size: 1,960 Bytes
2276d59 c1b2559 2276d59 65fc551 2276d59 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | import { expect } from 'vitest';
import { Expected } from './schema.js';
import { VideoInfo } from '../../src/types/index.js';
// dynamic assertions
export function assertOutcome(actual: VideoInfo | null, expected: Expected) {
if (expected.status === 'error') {
expect(actual, 'Actual data should be null for error cases').toBeNull();
return;
}
if (expected.status === 'ok') {
expect(actual, 'Actual data should be defined').toBeDefined();
}
// check metadata
if (expected.title && actual?.title) {
expect(
actual.title.toLowerCase(),
`Title mismatch for ${actual.title}`
).toContain(expected.title.toLowerCase());
}
// check ISRC
if (expected.mustHaveIsrc) {
expect(
actual?.isrc,
'ISRC matching failed - unique Phantom intelligence not found'
).toBeTruthy();
expect(typeof actual?.isrc).toBe('string');
}
// check grounding
if (expected.mustHaveChords) {
const actualWithIntelligence = actual as Record<string, unknown>;
const hasChords =
actualWithIntelligence.chordsSheet || actualWithIntelligence.chords;
expect(
hasChords,
'Grounding failed - Chords/Lyrics sheet not generated'
).toBeTruthy();
}
// check integrity
if (expected.type && actual?.formats) {
const hasVideo = actual.formats.some(
(format) => format.vcodec && format.vcodec !== 'none'
);
const hasAudio = actual.formats.some(
(format) =>
(format.acodec && format.acodec !== 'none') ||
!format.vcodec ||
format.vcodec === 'none'
);
if (expected.type === 'video') {
expect(hasVideo, 'Expected a video stream but none found').toBe(true);
}
if (expected.type === 'audio') {
expect(hasAudio, 'Expected an audio stream but none found').toBe(true);
}
}
// provider verification
if (actual?.extractorKey) {
console.log(`[Assert] Verified ${actual.extractorKey} logic flow.`);
}
}
|