Files
saqel/backend/scripts/test_video_coverage_validator.php
T

36 lines
1.7 KiB
PHP

<?php
declare(strict_types=1);
// Pure local validation: no database, network, files written, or AI calls.
require_once dirname(__DIR__) . '/app/Services/VideoCoverageValidator.php';
use App\Services\VideoCoverageValidator;
$sha = str_repeat('a', 64);
$valid = [
'video_sha256' => $sha,
'markdown_sha256' => str_repeat('b', 64),
'truncated' => false,
'gaps' => [],
'segments' => [
['start_seconds'=>0,'end_seconds'=>30,'transcript_ref'=>'t1','visual_ref'=>'v1'],
['start_seconds'=>30,'end_seconds'=>60,'transcript_ref'=>'t2','visual_ref'=>'v2'],
],
];
$cases = [
[$valid, true],
[array_replace($valid, ['truncated'=>true]), false],
[array_replace($valid, ['gaps'=>[[30,31]]]), false],
[array_replace($valid, ['video_sha256'=>str_repeat('c',64)]), false],
[array_replace($valid, ['segments'=>[['start_seconds'=>1,'end_seconds'=>60,'transcript_ref'=>'t','visual_ref'=>'v']]]), false],
[array_replace($valid, ['segments'=>[['start_seconds'=>0,'end_seconds'=>59,'transcript_ref'=>'t','visual_ref'=>'v']]]), false],
[array_replace($valid, ['segments'=>[['start_seconds'=>0,'end_seconds'=>30,'transcript_ref'=>'t','visual_ref'=>'v'],['start_seconds'=>31,'end_seconds'=>60,'transcript_ref'=>'t','visual_ref'=>'v']]]), false],
[array_replace($valid, ['segments'=>[['start_seconds'=>0,'end_seconds'=>60,'transcript_ref'=>'','visual_ref'=>'v']]]), false],
];
foreach ($cases as $index => [$coverage, $expected]) {
if (VideoCoverageValidator::valid($coverage, 60, $sha) !== $expected) {
throw new RuntimeException("Coverage case {$index} failed");
}
}
echo 'PASS ' . count($cases) . " video coverage cases\n";