TenantAtlas/apps/platform/tests/Feature/Guards/TestLaneTrendSummaryContractTest.php
ahmido 81a07a41e4
Some checks failed
Main Confidence / confidence (push) Failing after 46s
feat: implement runtime trend recalibration reporting (#244)
## Summary
- implement Spec 211 runtime trend reporting with bounded lane history, drift classification, hotspot trend output, and recalibration evidence handling
- extend the repo-truth governance seams and workflow wrappers for comparable-bundle hydration, trend artifact publication, and contract-backed reporting
- add the Spec 211 planning artifacts, data model, quickstart, tasks, and repository contract documents

## Validation
- parsed `specs/211-runtime-trend-recalibration/contracts/test-runtime-trend-history.schema.json`
- parsed `specs/211-runtime-trend-recalibration/contracts/test-runtime-trend.logical.openapi.yaml`
- re-ran cross-artifact consistency analysis for the Spec 211 artifact set until no material findings remained
- no application test suite was re-run as part of this final commit/push/PR step

Co-authored-by: Ahmed Darrazi <ahmed.darrazi@live.de>
Reviewed-on: #244
2026-04-18 07:36:05 +00:00

98 lines
4.3 KiB
PHP

<?php
declare(strict_types=1);
use Tests\Support\TestLaneTrendFixtures;
function seededTrendHistoryArtifact(array $baseArtifact, array $seededWallClockSeconds): array
{
$templateRecord = $baseArtifact['history'][0];
$seededHistory = [];
foreach ($seededWallClockSeconds as $index => $seconds) {
$record = $templateRecord;
$record['runRef'] = sprintf('%s-seeded-%d', $templateRecord['laneId'], $index + 1);
$record['generatedAt'] = sprintf('2026-04-%02dT12:00:00+00:00', $index + 1);
$record['wallClockSeconds'] = round((float) $seconds, 6);
$seededHistory[] = $record;
}
$baseArtifact['history'] = $seededHistory;
return $baseArtifact;
}
it('keeps the trend summary bounded while exposing current, previous, baseline, and budget fields for fast-feedback and confidence', function (): void {
$scenarios = [
'fast-feedback' => [
'artifactDirectory' => TestLaneTrendFixtures::artifactDirectory('trend-summary/fast-feedback'),
'workflowId' => 'pr-fast-feedback',
'triggerClass' => 'pull-request',
'comparisonProfile' => 'shared-test-fixture-slimming',
'durationsByFile' => [
'tests/Feature/Guards/TestLaneTrendSummaryContractTest.php' => 12.6,
'tests/Feature/Guards/TestLaneArtifactsContractTest.php' => 8.4,
],
'seededHistory' => [176.73, 178.91, 181.22, 183.41, 185.07, 186.64],
'currentSeconds' => 188.18,
],
'confidence' => [
'artifactDirectory' => TestLaneTrendFixtures::artifactDirectory('trend-summary/confidence'),
'workflowId' => 'main-confidence',
'triggerClass' => 'mainline-push',
'comparisonProfile' => 'shared-test-fixture-slimming',
'durationsByFile' => [
'tests/Feature/Baselines/BaselineCompareMatrixCompareAllActionTest.php' => 24.3,
'tests/Feature/Baselines/BaselineCompareMatrixBuilderTest.php' => 20.4,
'tests/Feature/Rbac/OnboardingWizardUiEnforcementTest.php' => 16.1,
],
'seededHistory' => [394.38, 401.12, 407.05, 411.61, 419.24, 424.77],
'currentSeconds' => 431.81,
],
];
foreach ($scenarios as $laneId => $scenario) {
$baseReport = TestLaneTrendFixtures::buildReport(
laneId: $laneId,
wallClockSeconds: $scenario['seededHistory'][0],
durationsByFile: $scenario['durationsByFile'],
artifactDirectory: $scenario['artifactDirectory'],
ciContext: [
'workflowId' => $scenario['workflowId'],
'triggerClass' => $scenario['triggerClass'],
'entryPointResolved' => true,
'workflowLaneMatched' => true,
],
comparisonProfile: $scenario['comparisonProfile'],
);
TestLaneTrendFixtures::writeTrendHistory(
$laneId,
seededTrendHistoryArtifact($baseReport['trendHistoryArtifact'], $scenario['seededHistory']),
$scenario['artifactDirectory'],
);
$report = TestLaneTrendFixtures::buildReport(
laneId: $laneId,
wallClockSeconds: $scenario['currentSeconds'],
durationsByFile: $scenario['durationsByFile'],
artifactDirectory: $scenario['artifactDirectory'],
ciContext: [
'workflowId' => $scenario['workflowId'],
'triggerClass' => $scenario['triggerClass'],
'entryPointResolved' => true,
'workflowLaneMatched' => true,
],
comparisonProfile: $scenario['comparisonProfile'],
);
expect($report['trendHistoryArtifact']['history'])->toHaveCount(7)
->and($report['trendCurrentAssessment']['sampleCount'])->toBe(5)
->and($report['trendCurrentAssessment']['previousComparableRunRef'])->not->toBeNull()
->and($report['trendHistoryArtifact']['history'][0]['baselineSeconds'])->not->toBeNull()
->and($report['trendHistoryArtifact']['history'][0]['budgetSeconds'])->toEqual((float) $report['budgetThresholdSeconds'])
->and($report['trendCurrentAssessment']['summaryLine'])->not->toBe('')
->and($report['trendWarnings'])->toBeArray();
}
});