mirror of
https://github.com/Cacti/cacti.git
synced 2026-10-26 04:58:21 +09:00
* fix(packaging): name archives from supplied metadata Signed-off-by: Thomas Vincent <thomasvincent@gmail.com> * fix(packaging): make archive leaf-name confinement explicit Signed-off-by: Thomas Vincent <thomasvincent@gmail.com> * test(e2e): move the pointer off the Deepness multiselect button Deepness sets a zero body margin, so the unhovered #ms-button sits at the viewport origin and headless Chromium on Linux intermittently applies :hover to it. Signed-off-by: Thomas Vincent <thomasvincent@gmail.com> * ci: pull pinned integration database from authenticated mirror Signed-off-by: Thomas Vincent <thomasvincent@gmail.com> --------- Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
62 lines
2.3 KiB
PHP
62 lines
2.3 KiB
PHP
<?php
|
|
// Copyright (C) 2004-2026 The Cacti Group. GPL-2.0-or-later.
|
|
|
|
// Loaded only by the disposable E2E image when coverage is explicitly enabled.
|
|
$requestCoverageDirectory = getenv('CACTI_PR_RAW_COVERAGE');
|
|
|
|
if ($requestCoverageDirectory !== false && $requestCoverageDirectory !== '') {
|
|
if (!function_exists('xdebug_start_code_coverage')) {
|
|
throw new RuntimeException('Request coverage requires Xdebug.');
|
|
}
|
|
xdebug_start_code_coverage(XDEBUG_CC_UNUSED | XDEBUG_CC_DEAD_CODE);
|
|
register_shutdown_function(static function () use ($requestCoverageDirectory) : void {
|
|
$contract = $GLOBALS['cacti_fixture_contract'] ?? null;
|
|
|
|
if ($contract !== null && ($contract['complete'] !== true || $contract['assertions'] < 1)) {
|
|
throw new RuntimeException('An incomplete fixture cannot publish request coverage.');
|
|
}
|
|
$data = xdebug_get_code_coverage();
|
|
|
|
foreach ($GLOBALS['cacti_fixture_source_map'] ?? [] as $temporary => $original) {
|
|
foreach ($data[$temporary] ?? [] as $line => $hits) {
|
|
$data[$original][$line] = max($hits, $data[$original][$line] ?? -2);
|
|
}
|
|
unset($data[$temporary]);
|
|
}
|
|
$root = realpath(dirname(__DIR__, 2));
|
|
$hashes = [];
|
|
$htmlSpans = [];
|
|
|
|
foreach ($data as $file => $lines) {
|
|
if (!str_starts_with($file, $root . '/') || str_contains($file, '/vendor/')) {
|
|
unset($data[$file]);
|
|
|
|
continue;
|
|
}
|
|
$hashes[$file] = hash_file('sha256', $file);
|
|
$htmlSpans[$file] = [];
|
|
|
|
// Zend records a literal HTML output opcode at the end of its block.
|
|
foreach (token_get_all(file_get_contents($file)) as $token) {
|
|
if (is_array($token) && $token[0] === T_INLINE_HTML) {
|
|
$htmlSpans[$file][] = [$token[2], $token[2] + substr_count($token[1], "\n")];
|
|
}
|
|
}
|
|
}
|
|
|
|
if ($contract !== null) {
|
|
$contract['hashes'] = [];
|
|
|
|
foreach ($contract['producers'] as $producer) {
|
|
$contract['hashes'][$producer] = hash_file('sha256', $root . '/' . $producer);
|
|
}
|
|
}
|
|
$prefix = $contract !== null ? $contract['name'] . '-' : '';
|
|
$path = $requestCoverageDirectory . '/' . $prefix . getmypid() . '-' . bin2hex(random_bytes(8)) . '.json';
|
|
|
|
if (file_put_contents($path, json_encode(['root' => $root, 'coverage' => $data, 'hashes' => $hashes, 'html_spans' => $htmlSpans, 'contract' => $contract], JSON_THROW_ON_ERROR)) === false) {
|
|
throw new RuntimeException('Could not preserve request coverage.');
|
|
}
|
|
});
|
|
}
|