## Summary This PR implements Spec 206 end to end and establishes the first checked-in test suite governance foundation for the platform app. Key changes: - add manifest-backed test lanes for fast-feedback, confidence, browser, heavy-governance, profiling, and junit - add budget and report helpers plus app-local artifact generation under `apps/platform/storage/logs/test-lanes` - add repo-root Sail-friendly lane/report wrappers - switch the default contributor test path to the fast-feedback lane - introduce explicit fixture profiles and cheaper defaults for shared tenant/provider test setup - add minimal/heavy factory states for tenant and provider connection setup - migrate the first high-usage and provider-sensitive tests to explicit fixture profiles - document budgets, taxonomy rules, DB reset guidance, and the full Spec 206 plan/contracts/tasks set ## Validation Executed during implementation: - focused Spec 206 guard/support/factory validation pack: 31 passed - provider-sensitive regression pack: 29 passed - first high-usage caller migration pack: 120 passed - lane routing and wrapper validation succeeded - pint completed successfully Measured lane baselines captured in docs: - fast-feedback: 176.74s - confidence: 394.38s - heavy-governance: 83.66s - browser: 128.87s - junit: 380.14s - profiling: 2701.51s - full-suite baseline anchor: 2624.60s ## Notes - Livewire v4 / Filament v5 runtime behavior is unchanged by this PR. - No new runtime routes, product UI flows, or database migrations are introduced. - Panel provider registration remains unchanged in `bootstrap/providers.php`. Co-authored-by: Ahmed Darrazi <ahmed.darrazi@live.de> Reviewed-on: #239
231 lines
8.3 KiB
PHP
231 lines
8.3 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Support;
|
|
|
|
use SimpleXMLElement;
|
|
|
|
final class TestLaneReport
|
|
{
|
|
/**
|
|
* @return array{junit: string, summary: string, budget: string, report: string, profile: string}
|
|
*/
|
|
public static function artifactPaths(string $laneId, ?string $artifactDirectory = null): array
|
|
{
|
|
$directory = trim($artifactDirectory ?? TestLaneManifest::artifactDirectory(), '/');
|
|
|
|
return [
|
|
'junit' => sprintf('%s/%s-latest.junit.xml', $directory, $laneId),
|
|
'summary' => sprintf('%s/%s-latest.summary.md', $directory, $laneId),
|
|
'budget' => sprintf('%s/%s-latest.budget.json', $directory, $laneId),
|
|
'report' => sprintf('%s/%s-latest.report.json', $directory, $laneId),
|
|
'profile' => sprintf('%s/%s-latest.profile.txt', $directory, $laneId),
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @return array{slowestEntries: list<array{subject: string, durationSeconds: float, laneId: string}>, durationsByFile: array<string, float>}
|
|
*/
|
|
public static function parseJUnit(string $filePath, string $laneId): array
|
|
{
|
|
if (! is_file($filePath)) {
|
|
return [
|
|
'slowestEntries' => [],
|
|
'durationsByFile' => [],
|
|
];
|
|
}
|
|
|
|
$useInternalErrors = libxml_use_internal_errors(true);
|
|
$xml = simplexml_load_file($filePath);
|
|
libxml_clear_errors();
|
|
libxml_use_internal_errors($useInternalErrors);
|
|
|
|
if (! $xml instanceof SimpleXMLElement) {
|
|
return [
|
|
'slowestEntries' => [],
|
|
'durationsByFile' => [],
|
|
];
|
|
}
|
|
|
|
$slowestEntries = [];
|
|
$durationsByFile = [];
|
|
|
|
foreach ($xml->xpath('//testcase') ?: [] as $testcase) {
|
|
$rawSubject = trim((string) ($testcase['file'] ?? ''));
|
|
$subject = $rawSubject !== '' ? $rawSubject : trim((string) ($testcase['name'] ?? 'unknown-testcase'));
|
|
$duration = (float) ($testcase['time'] ?? 0.0);
|
|
$normalizedFile = explode('::', $subject)[0];
|
|
|
|
$slowestEntries[] = [
|
|
'subject' => $subject,
|
|
'durationSeconds' => round($duration, 6),
|
|
'laneId' => $laneId,
|
|
];
|
|
|
|
$durationsByFile[$normalizedFile] = round(($durationsByFile[$normalizedFile] ?? 0.0) + $duration, 6);
|
|
}
|
|
|
|
usort($slowestEntries, static fn (array $left, array $right): int => $right['durationSeconds'] <=> $left['durationSeconds']);
|
|
|
|
return [
|
|
'slowestEntries' => array_slice($slowestEntries, 0, 10),
|
|
'durationsByFile' => $durationsByFile,
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @param list<array{subject: string, durationSeconds: float, laneId: string}> $slowestEntries
|
|
* @param array<string, float> $durationsByFile
|
|
* @return array<string, mixed>
|
|
*/
|
|
public static function buildReport(
|
|
string $laneId,
|
|
float $wallClockSeconds,
|
|
array $slowestEntries,
|
|
array $durationsByFile,
|
|
?string $artifactDirectory = null,
|
|
): array {
|
|
$lane = TestLaneManifest::lane($laneId);
|
|
$budget = TestLaneBudget::fromArray($lane['budget']);
|
|
$budgetEvaluation = $budget->evaluate($wallClockSeconds);
|
|
$artifactPaths = self::artifactPaths($laneId, $artifactDirectory);
|
|
$artifacts = [];
|
|
|
|
foreach ($lane['artifacts'] as $artifactMode) {
|
|
$relativePath = match ($artifactMode) {
|
|
'summary' => $artifactPaths['summary'],
|
|
'junit-xml' => $artifactPaths['junit'],
|
|
'profile-top' => $artifactPaths['profile'],
|
|
'budget-report' => $artifactPaths['budget'],
|
|
default => null,
|
|
};
|
|
|
|
if (! is_string($relativePath)) {
|
|
continue;
|
|
}
|
|
|
|
$artifacts[] = [
|
|
'artifactMode' => $artifactMode,
|
|
'relativePath' => $relativePath,
|
|
'machineReadable' => in_array($artifactMode, ['junit-xml', 'budget-report'], true),
|
|
];
|
|
}
|
|
|
|
$report = [
|
|
'laneId' => $laneId,
|
|
'finishedAt' => gmdate('c'),
|
|
'wallClockSeconds' => round($wallClockSeconds, 6),
|
|
'budgetThresholdSeconds' => $budget->thresholdSeconds,
|
|
'budgetBaselineSource' => $budget->baselineSource,
|
|
'budgetEnforcement' => $budget->enforcement,
|
|
'budgetLifecycleState' => $budget->lifecycleState,
|
|
'budgetStatus' => $budgetEvaluation['budgetStatus'],
|
|
'slowestEntries' => array_values($slowestEntries),
|
|
'familyBudgetEvaluations' => TestLaneBudget::evaluateFamilyBudgets(TestLaneManifest::familyBudgets(), $durationsByFile),
|
|
'artifacts' => $artifacts,
|
|
];
|
|
|
|
if ($budget->baselineDeltaTargetPercent !== null) {
|
|
$report['baselineDeltaTargetPercent'] = $budget->baselineDeltaTargetPercent;
|
|
}
|
|
|
|
return $report;
|
|
}
|
|
|
|
/**
|
|
* @param array<string, mixed> $report
|
|
* @return array{summary: string, budget: string, report: string, profile: string}
|
|
*/
|
|
public static function writeArtifacts(
|
|
string $laneId,
|
|
array $report,
|
|
?string $profileOutput = null,
|
|
?string $artifactDirectory = null,
|
|
): array {
|
|
$artifactPaths = self::artifactPaths($laneId, $artifactDirectory);
|
|
|
|
self::ensureDirectory(dirname(TestLaneManifest::absolutePath($artifactPaths['summary'])));
|
|
|
|
file_put_contents(
|
|
TestLaneManifest::absolutePath($artifactPaths['summary']),
|
|
self::buildSummaryMarkdown($report),
|
|
);
|
|
|
|
file_put_contents(
|
|
TestLaneManifest::absolutePath($artifactPaths['budget']),
|
|
json_encode([
|
|
'laneId' => $report['laneId'],
|
|
'wallClockSeconds' => $report['wallClockSeconds'],
|
|
'budgetThresholdSeconds' => $report['budgetThresholdSeconds'],
|
|
'budgetBaselineSource' => $report['budgetBaselineSource'],
|
|
'budgetEnforcement' => $report['budgetEnforcement'],
|
|
'budgetLifecycleState' => $report['budgetLifecycleState'],
|
|
'budgetStatus' => $report['budgetStatus'],
|
|
'familyBudgetEvaluations' => $report['familyBudgetEvaluations'],
|
|
], JSON_PRETTY_PRINT | JSON_THROW_ON_ERROR),
|
|
);
|
|
|
|
file_put_contents(
|
|
TestLaneManifest::absolutePath($artifactPaths['report']),
|
|
json_encode($report, JSON_PRETTY_PRINT | JSON_THROW_ON_ERROR),
|
|
);
|
|
|
|
if (is_string($profileOutput) && trim($profileOutput) !== '') {
|
|
file_put_contents(TestLaneManifest::absolutePath($artifactPaths['profile']), $profileOutput);
|
|
}
|
|
|
|
return $artifactPaths;
|
|
}
|
|
|
|
/**
|
|
* @return array<string, mixed>
|
|
*/
|
|
public static function finalizeLane(string $laneId, float $wallClockSeconds, string $capturedOutput = ''): array
|
|
{
|
|
$artifactPaths = self::artifactPaths($laneId);
|
|
$parsed = self::parseJUnit(TestLaneManifest::absolutePath($artifactPaths['junit']), $laneId);
|
|
$report = self::buildReport(
|
|
laneId: $laneId,
|
|
wallClockSeconds: $wallClockSeconds,
|
|
slowestEntries: $parsed['slowestEntries'],
|
|
durationsByFile: $parsed['durationsByFile'],
|
|
);
|
|
|
|
self::writeArtifacts($laneId, $report, $capturedOutput);
|
|
|
|
return $report;
|
|
}
|
|
|
|
/**
|
|
* @param array<string, mixed> $report
|
|
*/
|
|
private static function buildSummaryMarkdown(array $report): string
|
|
{
|
|
$lines = [
|
|
'# Test Lane Summary',
|
|
'',
|
|
sprintf('- Lane: %s', $report['laneId']),
|
|
sprintf('- Finished: %s', $report['finishedAt']),
|
|
sprintf('- Wall clock: %.2f seconds', (float) $report['wallClockSeconds']),
|
|
sprintf('- Budget: %d seconds (%s)', (int) $report['budgetThresholdSeconds'], $report['budgetStatus']),
|
|
'',
|
|
'## Slowest entries',
|
|
];
|
|
|
|
foreach ($report['slowestEntries'] as $entry) {
|
|
$lines[] = sprintf('- %s (%.2fs)', $entry['subject'], (float) $entry['durationSeconds']);
|
|
}
|
|
|
|
return implode(PHP_EOL, $lines).PHP_EOL;
|
|
}
|
|
|
|
private static function ensureDirectory(string $directory): void
|
|
{
|
|
if (is_dir($directory)) {
|
|
return;
|
|
}
|
|
|
|
mkdir($directory, 0777, true);
|
|
}
|
|
} |