From 8d528ba5fea5126d7bc9d227ef191170712c75c1 Mon Sep 17 00:00:00 2001 From: hajimi Date: Sun, 21 Jun 2026 11:43:29 +0800 Subject: [PATCH] test: enforce exact match live snippets --- qa/backend/test_match_live_backend_static.php | 49 ++++++++++++------- .../common/service/match/MatchLiveService.php | 4 +- 2 files changed, 34 insertions(+), 19 deletions(-) diff --git a/qa/backend/test_match_live_backend_static.php b/qa/backend/test_match_live_backend_static.php index 5628356..6dd9c41 100644 --- a/qa/backend/test_match_live_backend_static.php +++ b/qa/backend/test_match_live_backend_static.php @@ -9,37 +9,52 @@ if (!is_file($servicePath)) { } $service = file_get_contents($servicePath); -$requiredTokens = [ +$requiredSnippets = [ 'class MatchLiveService', 'public static function syncLegacyLiveUrl', 'public static function getLiveListForApi', 'public static function buildStreamOptions', - 'source_url', - 'update_time', - "order('create_time', 'asc')", - "order('id', 'asc')", - 'play_url_m3u8', - 'play_url_hd_m3u8', - 'play_url_flv', - 'play_url_hd_flv', - 'M3U8', - 'HD M3U8', - 'FLV', - 'HD FLV', + "'live_url' => \$row ? (string) \$row->source_url : ''", + "'update_time' => time()", + "->whereNull('delete_time')", + "->order('create_time', 'asc')", + "->order('id', 'asc')", + "\$row['default_play_url'] = \$row['stream_options'][0]['url'] ?? '';", "if (\$url === '')", - 'default_play_url', ]; -foreach ($requiredTokens as $needle) { +foreach ($requiredSnippets as $needle) { if (strpos($service, $needle) === false) { fwrite(STDERR, "missing service token: {$needle}\n"); exit(1); } } -if (strpos($service, "whereNull('delete_time')") === false && strpos($service, 'SoftDelete') === false) { - fwrite(STDERR, "missing non-deleted row guard\n"); +$whereNullCount = substr_count($service, "->whereNull('delete_time')"); +if ($whereNullCount < 2) { + fwrite(STDERR, "missing explicit delete_time guard on both queries\n"); 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"; diff --git a/server/app/common/service/match/MatchLiveService.php b/server/app/common/service/match/MatchLiveService.php index 6ae53b5..45712bc 100644 --- a/server/app/common/service/match/MatchLiveService.php +++ b/server/app/common/service/match/MatchLiveService.php @@ -9,8 +9,8 @@ class MatchLiveService { public static function syncLegacyLiveUrl(int $matchId): void { - // MatchLive uses SoftDelete, so default queries only return non-deleted rows. $row = MatchLive::where('match_id', $matchId) + ->whereNull('delete_time') ->order('create_time', 'asc') ->order('id', 'asc') ->find(); @@ -23,8 +23,8 @@ class MatchLiveService public static function getLiveListForApi(int $matchId): array { - // MatchLive uses SoftDelete, so default queries only return non-deleted rows. $rows = MatchLive::where('match_id', $matchId) + ->whereNull('delete_time') ->order('create_time', 'asc') ->order('id', 'asc') ->select()