Files
compras/scripts/check-distribution-visual-assets.php
T
nala 36dcfdf00c
tests / ci (push) Canceled after 0s
commit melhorias compras4
2026-11-22 16:28:03 +02:00

29 lines
1.5 KiB
PHP

<?php
$root = dirname(__DIR__);
$proof = json_decode(file_get_contents($root.'/storage/framework/testing/distribution-visual-running.json'), true, 32, JSON_THROW_ON_ERROR);
if ($proof['url'] !== 'http://127.0.0.1:8006' || ! preg_match('/^compras_receipts_test_[a-f0-9]{12}$/D', $proof['database'])) {
throw new LogicException('Only the private disposable QA review may be checked.');
}
$fonts = glob($root.'/storage/framework/testing/sgc-distribution-integrated-qa-20261122/assets/*.woff*');
if (count($fonts) !== 6) {
throw new RuntimeException('Expected six local candidate fonts.');
}
foreach ($fonts as $font) {
$url = $proof['url'].'/build/assets/'.rawurlencode(basename($font));
$stream = fopen($url, 'rb', false, stream_context_create(['http' => ['timeout' => 3]]));
if ($stream === false) {
throw new RuntimeException('Unable to read a private candidate font.');
}
$headers = stream_get_meta_data($stream)['wrapper_data'] ?? [];
$body = stream_get_contents($stream);
fclose($stream);
$woff2 = str_ends_with($font, '.woff2');
$type = $woff2 ? 'font/woff2' : 'font/woff';
if (! is_string($body) || ! str_starts_with($body, $woff2 ? 'wOF2' : 'wOFF')
|| ! in_array('Content-Type: '.$type, $headers, true) || hash('sha256', $body) !== hash_file('sha256', $font)) {
throw new RuntimeException('A candidate font is missing, corrupted or served with an invalid MIME type.');
}
}
echo json_encode(['private_font_regression_passed' => true, 'fonts' => count($fonts)], JSON_THROW_ON_ERROR).PHP_EOL;