TenantAtlas/apps/platform/tests/Feature/Guards/TestLaneCommandContractTest.php
ahmido bf38ec1780
Some checks failed
Main Confidence / confidence (push) Failing after 3m36s
Spec 210: implement CI test matrix budget enforcement (#243)
## Summary
- add explicit Gitea workflow files for PR Fast Feedback, `dev` Confidence, Heavy Governance, and Browser lanes
- extend the repo-truth lane support seams with workflow profiles, trigger-aware budget enforcement, artifact publication contracts, CI summaries, and failure classification
- add deterministic artifact staging, new CI governance guard coverage, and Spec 210 planning/contracts/docs updates

## Validation
- `cd apps/platform && ./vendor/bin/sail bin pint --dirty --format agent`
- `cd apps/platform && ./vendor/bin/sail artisan test --compact tests/Feature/Guards/CiFastFeedbackWorkflowContractTest.php tests/Feature/Guards/CiConfidenceWorkflowContractTest.php tests/Feature/Guards/CiHeavyBrowserWorkflowContractTest.php tests/Feature/Guards/CiLaneFailureClassificationContractTest.php tests/Feature/Guards/FastFeedbackLaneContractTest.php tests/Feature/Guards/ConfidenceLaneContractTest.php tests/Feature/Guards/HeavyGovernanceLaneContractTest.php tests/Feature/Guards/BrowserLaneIsolationTest.php tests/Feature/Guards/FixtureLaneImpactBudgetTest.php tests/Feature/Guards/TestLaneManifestTest.php tests/Feature/Guards/TestLaneArtifactsContractTest.php tests/Feature/Guards/TestLaneCommandContractTest.php`
- `./scripts/platform-test-lane fast-feedback`
- `./scripts/platform-test-lane confidence`
- `./scripts/platform-test-lane heavy-governance`
- `./scripts/platform-test-lane browser`
- `./scripts/platform-test-report fast-feedback`
- `./scripts/platform-test-report confidence`

## Notes
- scheduled Heavy Governance and Browser workflows stay gated behind `TENANTATLAS_ENABLE_HEAVY_GOVERNANCE_SCHEDULE=1` and `TENANTATLAS_ENABLE_BROWSER_SCHEDULE=1`
- the remaining rollout evidence task is capturing the live Gitea run set this PR enables: PR Fast Feedback, `dev` Confidence, manual and scheduled Heavy Governance, and manual and scheduled Browser runs

Co-authored-by: Ahmed Darrazi <ahmed.darrazi@live.de>
Reviewed-on: #243
2026-04-17 18:04:35 +00:00

123 lines
7.6 KiB
PHP

<?php
declare(strict_types=1);
use Tests\Support\TestLaneManifest;
it('keeps composer lane commands wired to the checked-in lane inventory', function (): void {
$composer = json_decode((string) file_get_contents(base_path('composer.json')), true, 512, JSON_THROW_ON_ERROR);
$scripts = $composer['scripts'] ?? [];
expect($scripts)->toHaveKeys([
'test',
'test:fast',
'test:confidence',
'test:browser',
'test:heavy',
'test:profile',
'test:junit',
'test:report',
'test:report:confidence',
'test:report:browser',
'test:report:heavy',
'test:report:profile',
'sail:test',
])
->and(TestLaneManifest::commandRef('fast-feedback'))->toBe('test')
->and(TestLaneManifest::commandRef('confidence'))->toBe('test:confidence')
->and(TestLaneManifest::commandRef('browser'))->toBe('test:browser')
->and(TestLaneManifest::commandRef('heavy-governance'))->toBe('test:heavy')
->and(TestLaneManifest::commandRef('profiling'))->toBe('test:profile')
->and(TestLaneManifest::commandRef('junit'))->toBe('test:junit');
});
it('keeps the host-side lane runner and report scripts checked in at repo root', function (): void {
expect(file_exists(repo_path('scripts/platform-test-lane')))->toBeTrue()
->and(file_exists(repo_path('scripts/platform-test-report')))->toBeTrue()
->and(file_exists(repo_path('scripts/platform-test-artifacts')))->toBeTrue();
});
it('keeps heavy-governance baseline capture support inside the checked-in wrappers', function (): void {
$laneRunner = (string) file_get_contents(repo_path('scripts/platform-test-lane'));
$reportRunner = (string) file_get_contents(repo_path('scripts/platform-test-report'));
expect($laneRunner)->toContain('--capture-baseline', 'copy_heavy_baseline_artifacts', 'heavy-governance-baseline.${suffix}')
->and($reportRunner)->toContain('--capture-baseline', 'copy_heavy_baseline_artifacts', 'heavy-governance-baseline.${suffix}');
});
it('avoids expanding an empty forwarded-argument array in the lane runner', function (): void {
$laneRunner = (string) file_get_contents(repo_path('scripts/platform-test-lane'));
expect($laneRunner)
->toContain('if [[ ${#remaining_args[@]} -gt 0 ]]; then')
->and($laneRunner)->toContain('./vendor/bin/sail composer run --timeout=0 "${COMPOSER_SCRIPT}" -- "${remaining_args[@]}"')
->and($laneRunner)->toContain('./vendor/bin/sail composer run --timeout=0 "${COMPOSER_SCRIPT}"')
->and($laneRunner)->toContain('--workflow-id=')
->and($laneRunner)->toContain('--trigger-class=');
});
it('keeps CI workflow validation and wrong-lane drift detection in the checked-in manifest', function (): void {
$validExecution = TestLaneManifest::validateWorkflowExecution('pr-fast-feedback', 'fast-feedback');
$wrongLaneExecution = TestLaneManifest::validateWorkflowExecution('pr-fast-feedback', 'confidence');
expect($validExecution['valid'])->toBeTrue()
->and($validExecution['primaryFailureClassId'])->toBeNull()
->and($wrongLaneExecution['valid'])->toBeFalse()
->and($wrongLaneExecution['workflowLaneMatched'])->toBeFalse()
->and($wrongLaneExecution['primaryFailureClassId'])->toBe('wrapper-failure');
});
it('degrades invalid CI workflow context to wrapper-failure metadata instead of crashing the lane context lookup', function (): void {
$originalWorkflowId = getenv('TENANTATLAS_CI_WORKFLOW_ID');
$originalTriggerClass = getenv('TENANTATLAS_CI_TRIGGER_CLASS');
putenv('TENANTATLAS_CI_WORKFLOW_ID=missing-workflow-profile');
putenv('TENANTATLAS_CI_TRIGGER_CLASS=pull-request');
try {
$context = TestLaneManifest::currentCiContext('fast-feedback');
expect($context['entryPointResolved'])->toBeFalse()
->and($context['workflowLaneMatched'])->toBeFalse()
->and($context['primaryFailureClassId'])->toBe('wrapper-failure')
->and($context['unresolvedEntryPoints'])->toContain('workflow-profile');
} finally {
putenv($originalWorkflowId === false ? 'TENANTATLAS_CI_WORKFLOW_ID' : sprintf('TENANTATLAS_CI_WORKFLOW_ID=%s', $originalWorkflowId));
putenv($originalTriggerClass === false ? 'TENANTATLAS_CI_TRIGGER_CLASS' : sprintf('TENANTATLAS_CI_TRIGGER_CLASS=%s', $originalTriggerClass));
}
});
it('routes the foundational lane commands through stable artisan arguments', function (): void {
$fastFeedbackConfig = TestLaneManifest::laneConfigurationPath('fast-feedback');
$fastFeedbackContents = (string) file_get_contents(TestLaneManifest::absolutePath($fastFeedbackConfig));
$confidenceConfig = TestLaneManifest::laneConfigurationPath('confidence');
$confidenceContents = (string) file_get_contents(TestLaneManifest::absolutePath($confidenceConfig));
$browserConfig = TestLaneManifest::laneConfigurationPath('browser');
$browserContents = (string) file_get_contents(TestLaneManifest::absolutePath($browserConfig));
$heavyConfig = TestLaneManifest::laneConfigurationPath('heavy-governance');
$heavyContents = (string) file_get_contents(TestLaneManifest::absolutePath($heavyConfig));
expect(TestLaneManifest::buildCommand('fast-feedback'))->toContain('--parallel')
->and(TestLaneManifest::buildCommand('fast-feedback'))->toContain('--configuration='.$fastFeedbackConfig)
->and($fastFeedbackContents)->not->toContain('tests/Feature/Drift/DriftBulkAcknowledgeAllMatchingConfirmationTest.php')
->and($fastFeedbackContents)->not->toContain('tests/Feature/Findings/FindingBulkActionsTest.php')
->and($fastFeedbackContents)->not->toContain('tests/Feature/Guards/ActionSurfaceContractTest.php')
->and(TestLaneManifest::buildCommand('confidence'))->toContain('--configuration='.$confidenceConfig)
->and($confidenceContents)->toContain('tests/Feature/Baselines/BaselineCompareMatrixCompareAllActionTest.php')
->and($confidenceContents)->not->toContain('tests/Feature/Drift/DriftBulkAcknowledgeAllMatchingConfirmationTest.php')
->and($confidenceContents)->not->toContain('tests/Feature/Filament/BaselineActionAuthorizationTest.php')
->and($confidenceContents)->not->toContain('tests/Feature/Filament/BaselineProfileCaptureStartSurfaceTest.php')
->and($confidenceContents)->not->toContain('tests/Feature/Filament/BaselineProfileCompareStartSurfaceTest.php')
->and($confidenceContents)->not->toContain('tests/Feature/Findings/FindingBulkActionsTest.php')
->and($confidenceContents)->not->toContain('tests/Feature/Guards/ActionSurfaceContractTest.php')
->and(TestLaneManifest::buildCommand('browser'))->toContain('--configuration='.$browserConfig)
->and($browserContents)->toContain('tests/Browser/Spec190BaselineCompareMatrixSmokeTest.php')
->and(TestLaneManifest::buildCommand('heavy-governance'))->toContain('--configuration='.$heavyConfig)
->and($heavyContents)->toContain('tests/Feature/Drift/DriftBulkAcknowledgeAllMatchingConfirmationTest.php')
->and($heavyContents)->toContain('tests/Feature/Filament/BaselineActionAuthorizationTest.php')
->and($heavyContents)->toContain('tests/Feature/Filament/BaselineProfileCaptureStartSurfaceTest.php')
->and($heavyContents)->toContain('tests/Feature/Filament/BaselineProfileCompareStartSurfaceTest.php')
->and($heavyContents)->toContain('tests/Feature/Findings/FindingBulkActionsTest.php')
->and($heavyContents)->toContain('tests/Feature/Guards/ActionSurfaceContractTest.php')
->and(TestLaneManifest::buildCommand('junit'))->toContain('--parallel');
});