TenantAtlas/apps/platform/tests/Feature/Guards/TestLaneHistoryHydrationContractTest.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

108 lines
4.5 KiB
PHP

<?php
declare(strict_types=1);
use Tests\Support\TestLaneManifest;
use Tests\Support\TestLaneReport;
use Tests\Support\TestLaneTrendFixtures;
it('hydrates an explicit prior history file into the canonical lane artifact path', function (): void {
$sourceArtifactDirectory = TestLaneTrendFixtures::artifactDirectory('trend-history-hydration/source');
$targetArtifactDirectory = TestLaneTrendFixtures::artifactDirectory('trend-history-hydration/target');
$report = TestLaneTrendFixtures::buildReport(
laneId: 'fast-feedback',
wallClockSeconds: 182.4,
durationsByFile: [
'tests/Feature/Guards/TestLaneHistoryHydrationContractTest.php' => 14.2,
'tests/Feature/Guards/TestLaneArtifactsContractTest.php' => 9.8,
],
artifactDirectory: $sourceArtifactDirectory,
ciContext: [
'workflowId' => 'pr-fast-feedback',
'triggerClass' => 'pull-request',
'entryPointResolved' => true,
'workflowLaneMatched' => true,
],
comparisonProfile: 'shared-test-fixture-slimming',
);
$sourcePath = TestLaneManifest::absolutePath($sourceArtifactDirectory.'/seeded-fast-feedback.trend-history.json');
if (! is_dir(dirname($sourcePath))) {
mkdir(dirname($sourcePath), 0777, true);
}
file_put_contents($sourcePath, json_encode($report['trendHistoryArtifact'], JSON_PRETTY_PRINT | JSON_THROW_ON_ERROR));
$result = TestLaneReport::hydrateTrendHistory(
laneId: 'fast-feedback',
historyFile: $sourcePath,
artifactDirectory: $targetArtifactDirectory,
);
$hydratedArtifact = TestLaneTrendFixtures::readTrendHistory('fast-feedback', $targetArtifactDirectory);
expect($result['hydrated'])->toBeTrue()
->and($result['sourceType'])->toBe('history-file')
->and($hydratedArtifact['laneId'])->toBe('fast-feedback')
->and($hydratedArtifact['workflowProfile'])->toBe('pr-fast-feedback')
->and($hydratedArtifact['history'][0]['artifactRefs']['trendHistory'])->toBe($sourceArtifactDirectory.'/fast-feedback-latest.trend-history.json');
});
it('hydrates staged bundle directories and zip bundles using the canonical trend-history artifact name', function (): void {
$sourceArtifactDirectory = TestLaneTrendFixtures::artifactDirectory('trend-history-hydration/bundle-source');
$bundleDirectory = TestLaneManifest::absolutePath($sourceArtifactDirectory.'/bundle');
$targetArtifactDirectory = TestLaneTrendFixtures::artifactDirectory('trend-history-hydration/bundle-target');
$report = TestLaneTrendFixtures::buildReport(
laneId: 'confidence',
wallClockSeconds: 431.2,
durationsByFile: [
'tests/Feature/Baselines/BaselineCompareMatrixCompareAllActionTest.php' => 24.7,
'tests/Feature/Baselines/BaselineCompareMatrixBuilderTest.php' => 20.4,
],
artifactDirectory: $sourceArtifactDirectory,
ciContext: [
'workflowId' => 'main-confidence',
'triggerClass' => 'mainline-push',
'entryPointResolved' => true,
'workflowLaneMatched' => true,
],
);
if (! is_dir($bundleDirectory)) {
mkdir($bundleDirectory, 0777, true);
}
file_put_contents(
$bundleDirectory.'/confidence.trend-history.json',
json_encode($report['trendHistoryArtifact'], JSON_PRETTY_PRINT | JSON_THROW_ON_ERROR),
);
$directoryResult = TestLaneReport::hydrateTrendHistory(
laneId: 'confidence',
bundlePath: $bundleDirectory,
artifactDirectory: $targetArtifactDirectory,
);
$zipPath = $bundleDirectory.'/confidence-artifacts.zip';
$zip = new ZipArchive();
$zip->open($zipPath, ZipArchive::CREATE | ZipArchive::OVERWRITE);
$zip->addFile($bundleDirectory.'/confidence.trend-history.json', 'confidence.trend-history.json');
$zip->close();
$zipResult = TestLaneReport::hydrateTrendHistory(
laneId: 'confidence',
bundlePath: $zipPath,
artifactDirectory: $targetArtifactDirectory,
);
$hydratedArtifact = TestLaneTrendFixtures::readTrendHistory('confidence', $targetArtifactDirectory);
expect($directoryResult['hydrated'])->toBeTrue()
->and($directoryResult['sourceType'])->toBe('bundle-directory')
->and($zipResult['hydrated'])->toBeTrue()
->and($zipResult['sourceType'])->toBe('bundle-zip')
->and($hydratedArtifact['laneId'])->toBe('confidence')
->and($hydratedArtifact['history'][0]['workflowId'])->toBe('main-confidence');
});