test: enforce exact match live snippets
This commit is contained in:
@@ -9,37 +9,52 @@ if (!is_file($servicePath)) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$service = file_get_contents($servicePath);
|
$service = file_get_contents($servicePath);
|
||||||
$requiredTokens = [
|
$requiredSnippets = [
|
||||||
'class MatchLiveService',
|
'class MatchLiveService',
|
||||||
'public static function syncLegacyLiveUrl',
|
'public static function syncLegacyLiveUrl',
|
||||||
'public static function getLiveListForApi',
|
'public static function getLiveListForApi',
|
||||||
'public static function buildStreamOptions',
|
'public static function buildStreamOptions',
|
||||||
'source_url',
|
"'live_url' => \$row ? (string) \$row->source_url : ''",
|
||||||
'update_time',
|
"'update_time' => time()",
|
||||||
"order('create_time', 'asc')",
|
"->whereNull('delete_time')",
|
||||||
"order('id', 'asc')",
|
"->order('create_time', 'asc')",
|
||||||
'play_url_m3u8',
|
"->order('id', 'asc')",
|
||||||
'play_url_hd_m3u8',
|
"\$row['default_play_url'] = \$row['stream_options'][0]['url'] ?? '';",
|
||||||
'play_url_flv',
|
|
||||||
'play_url_hd_flv',
|
|
||||||
'M3U8',
|
|
||||||
'HD M3U8',
|
|
||||||
'FLV',
|
|
||||||
'HD FLV',
|
|
||||||
"if (\$url === '')",
|
"if (\$url === '')",
|
||||||
'default_play_url',
|
|
||||||
];
|
];
|
||||||
|
|
||||||
foreach ($requiredTokens as $needle) {
|
foreach ($requiredSnippets as $needle) {
|
||||||
if (strpos($service, $needle) === false) {
|
if (strpos($service, $needle) === false) {
|
||||||
fwrite(STDERR, "missing service token: {$needle}\n");
|
fwrite(STDERR, "missing service token: {$needle}\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strpos($service, "whereNull('delete_time')") === false && strpos($service, 'SoftDelete') === false) {
|
$whereNullCount = substr_count($service, "->whereNull('delete_time')");
|
||||||
fwrite(STDERR, "missing non-deleted row guard\n");
|
if ($whereNullCount < 2) {
|
||||||
|
fwrite(STDERR, "missing explicit delete_time guard on both queries\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$orderedOptionSnippets = [
|
||||||
|
"['label' => 'M3U8', 'field' => 'play_url_m3u8']",
|
||||||
|
"['label' => 'HD M3U8', 'field' => 'play_url_hd_m3u8']",
|
||||||
|
"['label' => 'FLV', 'field' => 'play_url_flv']",
|
||||||
|
"['label' => 'HD FLV', 'field' => 'play_url_hd_flv']",
|
||||||
|
];
|
||||||
|
|
||||||
|
$lastPos = -1;
|
||||||
|
foreach ($orderedOptionSnippets as $snippet) {
|
||||||
|
$pos = strpos($service, $snippet);
|
||||||
|
if ($pos === false) {
|
||||||
|
fwrite(STDERR, "missing ordered stream option snippet: {$snippet}\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
if ($pos <= $lastPos) {
|
||||||
|
fwrite(STDERR, "stream option order mismatch\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
$lastPos = $pos;
|
||||||
|
}
|
||||||
|
|
||||||
echo "service static checks passed\n";
|
echo "service static checks passed\n";
|
||||||
|
|||||||
@@ -9,8 +9,8 @@ class MatchLiveService
|
|||||||
{
|
{
|
||||||
public static function syncLegacyLiveUrl(int $matchId): void
|
public static function syncLegacyLiveUrl(int $matchId): void
|
||||||
{
|
{
|
||||||
// MatchLive uses SoftDelete, so default queries only return non-deleted rows.
|
|
||||||
$row = MatchLive::where('match_id', $matchId)
|
$row = MatchLive::where('match_id', $matchId)
|
||||||
|
->whereNull('delete_time')
|
||||||
->order('create_time', 'asc')
|
->order('create_time', 'asc')
|
||||||
->order('id', 'asc')
|
->order('id', 'asc')
|
||||||
->find();
|
->find();
|
||||||
@@ -23,8 +23,8 @@ class MatchLiveService
|
|||||||
|
|
||||||
public static function getLiveListForApi(int $matchId): array
|
public static function getLiveListForApi(int $matchId): array
|
||||||
{
|
{
|
||||||
// MatchLive uses SoftDelete, so default queries only return non-deleted rows.
|
|
||||||
$rows = MatchLive::where('match_id', $matchId)
|
$rows = MatchLive::where('match_id', $matchId)
|
||||||
|
->whereNull('delete_time')
|
||||||
->order('create_time', 'asc')
|
->order('create_time', 'asc')
|
||||||
->order('id', 'asc')
|
->order('id', 'asc')
|
||||||
->select()
|
->select()
|
||||||
|
|||||||
Reference in New Issue
Block a user