## Summary - add the checked-in Spec 208 heavy-suite classification and family manifest with config-driven lane generation, attribution, and budget reporting - update Pest grouping, guard coverage, wrapper/report contracts, and spec artifacts for the segmented lane model - complete the targeted follow-up pass that re-homes the remaining in-scope confidence hotspots into explicit heavy-governance families ## Acceptance - confidence is repaired and now measures 389.613832s, down from 587.446894s and below the 450s lane budget - confidence is also slightly below the post-Spec-207 baseline of 394.383441s (delta -4.769609s) - this closes the central Spec 208 acceptance issue that had kept the spec open ## Intentionally Re-homed Families - finding-bulk-actions-workflow - drift-bulk-triage-all-matching - baseline-profile-start-surfaces - workspace-settings-slice-management - findings-workflow-surfaces - workspace-only-admin-surface-independence ## Explicit Residual Risk - heavy-governance now measures 318.296962s, above its documented 300s threshold - the cost was not removed; it was moved into the correct lane and made visible on clearly named heavy families - this is documented residual debt, not an open Spec 208 failure ## Validation - focused guard/support validation: 206 passed (3607 assertions) - lane wrapper/report validation completed for confidence and heavy-governance - no full-suite run was performed in this pass by request Co-authored-by: Ahmed Darrazi <ahmed.darrazi@live.de> Reviewed-on: #241
122 lines
4.4 KiB
PHP
122 lines
4.4 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Support;
|
|
|
|
use InvalidArgumentException;
|
|
|
|
final class TestLaneBudget
|
|
{
|
|
public function __construct(
|
|
public readonly int $thresholdSeconds,
|
|
public readonly string $baselineSource,
|
|
public readonly string $enforcement,
|
|
public readonly string $lifecycleState,
|
|
public readonly ?int $baselineDeltaTargetPercent = null,
|
|
public readonly ?string $notes = null,
|
|
public readonly ?string $reviewCadence = null,
|
|
) {
|
|
}
|
|
|
|
/**
|
|
* @param array<string, mixed> $budget
|
|
*/
|
|
public static function fromArray(array $budget): self
|
|
{
|
|
if (! isset($budget['thresholdSeconds'], $budget['baselineSource'], $budget['enforcement'], $budget['lifecycleState'])) {
|
|
throw new InvalidArgumentException('Budget declarations must define thresholdSeconds, baselineSource, enforcement, and lifecycleState.');
|
|
}
|
|
|
|
return new self(
|
|
thresholdSeconds: (int) $budget['thresholdSeconds'],
|
|
baselineSource: (string) $budget['baselineSource'],
|
|
enforcement: (string) $budget['enforcement'],
|
|
lifecycleState: (string) $budget['lifecycleState'],
|
|
baselineDeltaTargetPercent: isset($budget['baselineDeltaTargetPercent']) ? (int) $budget['baselineDeltaTargetPercent'] : null,
|
|
notes: isset($budget['notes']) ? (string) $budget['notes'] : null,
|
|
reviewCadence: isset($budget['reviewCadence']) ? (string) $budget['reviewCadence'] : null,
|
|
);
|
|
}
|
|
|
|
/**
|
|
* @return array<string, int|float|string>
|
|
*/
|
|
public function evaluate(float $measuredSeconds): array
|
|
{
|
|
$budgetStatus = 'within-budget';
|
|
|
|
if ($measuredSeconds > $this->thresholdSeconds) {
|
|
$budgetStatus = in_array($this->enforcement, ['report-only', 'warn'], true)
|
|
? 'warning'
|
|
: 'over-budget';
|
|
}
|
|
|
|
return array_filter([
|
|
'thresholdSeconds' => $this->thresholdSeconds,
|
|
'baselineSource' => $this->baselineSource,
|
|
'enforcement' => $this->enforcement,
|
|
'lifecycleState' => $this->lifecycleState,
|
|
'baselineDeltaTargetPercent' => $this->baselineDeltaTargetPercent,
|
|
'measuredSeconds' => round($measuredSeconds, 6),
|
|
'budgetStatus' => $budgetStatus,
|
|
'notes' => $this->notes,
|
|
'reviewCadence' => $this->reviewCadence,
|
|
], static fn (mixed $value): bool => $value !== null);
|
|
}
|
|
|
|
/**
|
|
* @param array<string, mixed> $budgetTarget
|
|
* @return array<string, int|float|string>
|
|
*/
|
|
public static function evaluateBudgetTarget(array $budgetTarget, float $measuredSeconds): array
|
|
{
|
|
if (! isset($budgetTarget['targetType'], $budgetTarget['targetId'])) {
|
|
throw new InvalidArgumentException('Budget targets must define targetType and targetId.');
|
|
}
|
|
|
|
$evaluation = self::fromArray($budgetTarget)->evaluate($measuredSeconds);
|
|
|
|
return array_merge([
|
|
'budgetId' => (string) ($budgetTarget['budgetId'] ?? sprintf('%s-%s', $budgetTarget['targetType'], $budgetTarget['targetId'])),
|
|
'targetType' => (string) $budgetTarget['targetType'],
|
|
'targetId' => (string) $budgetTarget['targetId'],
|
|
], $evaluation);
|
|
}
|
|
|
|
/**
|
|
* @param list<array<string, mixed>> $budgetTargets
|
|
* @param array<string, float> $classificationTotals
|
|
* @param array<string, float> $familyTotals
|
|
* @return list<array<string, int|float|string>>
|
|
*/
|
|
public static function evaluateBudgetTargets(
|
|
array $budgetTargets,
|
|
float $laneSeconds,
|
|
array $classificationTotals,
|
|
array $familyTotals,
|
|
): array {
|
|
$evaluations = [];
|
|
|
|
foreach ($budgetTargets as $budgetTarget) {
|
|
$targetType = (string) ($budgetTarget['targetType'] ?? '');
|
|
$targetId = (string) ($budgetTarget['targetId'] ?? '');
|
|
|
|
if ($targetType === '' || $targetId === '') {
|
|
continue;
|
|
}
|
|
|
|
$measuredSeconds = match ($targetType) {
|
|
'lane' => $laneSeconds,
|
|
'classification' => (float) ($classificationTotals[$targetId] ?? 0.0),
|
|
'family' => (float) ($familyTotals[$targetId] ?? 0.0),
|
|
default => 0.0,
|
|
};
|
|
|
|
$evaluations[] = self::evaluateBudgetTarget($budgetTarget, $measuredSeconds);
|
|
}
|
|
|
|
return $evaluations;
|
|
}
|
|
|
|
} |