You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
virt/web/tests/CloudTrafficPoolRolloutRunb...

236 lines
11 KiB
PHP

<?php
$root = dirname(__DIR__, 2);
$read = static function (string $path) use ($root): string {
$value = file_get_contents($root . '/' . ltrim($path, '/'));
if (!is_string($value)) {
throw new RuntimeException('Unable to read ' . $path);
}
return $value;
};
$assert = static function (bool $condition, string $message): void {
if (!$condition) {
throw new RuntimeException($message);
}
};
$runbook = $read('docs/TRAFFIC_POOL_ROLLOUT.md');
$contract = $read('docs/TRAFFIC_POOL.md');
$deployment = $read('docs/DEPLOYMENT.md');
$agents = $read('AGENTS.md');
$pruning = $read('docs/PRUNING_REPORT.md');
$xcat = $read('web/app/Command/XCat.php');
$setup = $read('web/app/Command/CloudSetup.php');
$routes = $read('web/config/routes_cloud.php');
$mainRoutes = $read('web/config/routes.php');
$adminTrafficJs = $read('web/public/cloud/admin-traffic-pools.js');
$adminResourcesView = $read(
'web/resources/views/venix/admin/cloud/resources.tpl'
);
$assert(str_contains($runbook,
'`php xcat cloudInit` is a fresh-schema installer and validator')
&& str_contains($runbook, 'It is **not**')
&& str_contains($runbook, 'incremental database upgrade command')
&& str_contains($runbook, 'Do not run `cloudInit` to upgrade'),
'Runbook no longer preserves the clean-schema installation boundary.');
$assert(str_contains($setup, 'assertFreshSchemaBoundary(')
&& str_contains($setup, 'installedSchemaFingerprint('),
'CloudSetup no longer enforces the schema marker/fingerprint boundary.');
foreach ([
'do not update an active or scheduled period\'s `traffic_pool_group_id`',
'do not edit an order\'s frozen `spec_json`',
'do not use renewal as a migration mechanism',
'do not accept payment or attempt delivery for an old unfinished order',
'provisioning rejects it before Agent dispatch',
'Keep a legacy instance under lifecycle',
'Deleting it first is not a shortcut',
'separately reviewed one-time data repair',
'repair either condition by an unreviewed SQL backfill',
] as $boundary) {
$assert(str_contains($runbook, $boundary),
'Runbook lost the no-backfill boundary: ' . $boundary);
}
$assert(str_contains($contract,
'Region is coverage metadata, not an accounting')
&& str_contains($contract,
'exposes each group exactly once with its ordered coverage')
&& str_contains($contract,
'Never merge existing shadow or enforced')
&& str_contains($runbook,
'`traffic_pool_group_id` is the global commercial line identity')
&& str_contains($runbook,
'Region is coverage metadata only')
&& str_contains($runbook,
'`shadow` or `enforced` | Preserve the current group')
&& str_contains($runbook,
'One group may cover multiple regions'),
'Documentation lost the commercial-line identity or no-merge boundary.');
$disabled = strpos($runbook, '### 3.1 Disabled');
$shadow = strpos($runbook, '### 3.2 Shadow');
$readiness = strpos($runbook, '### 3.3 Readiness');
$enforced = strpos($runbook, '### 3.4 Enforced');
$assert($disabled !== false && $shadow !== false && $readiness !== false
&& $enforced !== false && $disabled < $shadow && $shadow < $readiness
&& $readiness < $enforced
&& str_contains($runbook, 'disabled -> shadow -> enforced'),
'Runbook no longer documents the ordered rollout state machine.');
$assert(str_contains($runbook, 'Shadow mode creates the real pool')
&& str_contains($runbook, 'immutable ledger')
&& str_contains($runbook, '`traffic_pool_exhausted` network')
&& str_contains($runbook, 'Enforced mode is irreversible'),
'Shadow/enforced side-effect boundaries are incomplete.');
foreach ([
'no_network_lines', 'line_frozen_identity_mismatch',
'pool_attention', 'projection_invalid', 'missing_entitlements',
'missing_pools', 'period_identity_mismatch', 'instance_not_ready',
'legacy_network_unsettled', 'usage_unsettled', 'cursor_missing',
'cursor_attention', 'traffic_sample_stale', 'traffic_scan_failures',
'policy_unsettled', 'traffic_restriction_present', 'network_job_unsettled',
] as $blocker) {
$assert(str_contains($runbook, '`' . $blocker . '`'),
'Runbook is missing readiness blocker: ' . $blocker);
}
$assert(str_contains($runbook, 'ready = true')
&& str_contains($runbook, 'can_enforce = true')
&& str_contains($runbook, 'blockers = []'),
'Runbook no longer requires the complete enforcement gate.');
$assert(str_contains($runbook,
'`pool_attention` and `cursor_attention` are different')
&& str_contains($runbook, 'they are not')
&& str_contains($runbook, 'cleared automatically')
&& str_contains($runbook, 'local, audited break-glass CLI')
&& !str_contains($runbook,
'no production UI, API or CLI resolver'),
'Runbook no longer requires explicit version-bound attention resolution.');
$inspectAt = strpos($runbook,
'cloudTrafficPoolAttention inspect --pool-id=N');
$repairAt = strpos($runbook, 'Repair the real counter or projection cause');
$freshInspectAt = strpos($runbook, 'Run `inspect` again');
$resolveAt = strpos($runbook, 'cloudTrafficPoolAttention resolve');
$inspectResolutionAt = strpos($runbook,
'cloudTrafficPoolAttention inspect-resolution');
$assert($inspectAt !== false && $repairAt !== false
&& $freshInspectAt !== false && $resolveAt !== false
&& $inspectResolutionAt !== false
&& $inspectAt < $repairAt && $repairAt < $freshInspectAt
&& $freshInspectAt < $resolveAt && $resolveAt < $inspectResolutionAt
&& str_contains($runbook, '--expected-version=V')
&& str_contains($runbook, '--resolution-key=UUID')
&& str_contains($runbook, '--apply')
&& str_contains($runbook, '--confirm=RESOLVE_TRAFFIC_POOL:N:V:UUID'),
'Runbook lost the inspect-repair-resolve break-glass sequence.');
$assert(str_contains($runbook,
'If stdout, SSH or the command response is lost, do not repeat `resolve`')
&& str_contains($runbook, '`committed=true`')
&& str_contains($runbook, '`committed=false`')
&& str_contains($runbook, 'exact command with the same UUID')
&& preg_match('/Never use one UUID for a different\s+pool/',
$runbook) === 1
&& str_contains($runbook, 'external incident/change ID')
&& str_contains($runbook,
'resolving attention may make the projection trustworthy'),
'Runbook lost response reconciliation, audit or network-impact rules.');
$assert(str_contains($runbook, 'retain the original `operation_id`')
&& str_contains($runbook, 'Never:')
&& str_contains($runbook,
'replay `network_suspend` or `network_resume`')
&& str_contains($runbook, 'Preserve the immutable ledger')
&& str_contains($runbook, 'derived projections forward')
&& str_contains($runbook,
'Do not stop lifecycle as a way to pause enforcement')
&& str_contains($runbook, 'stop `virt-cloud-worker.service`')
&& str_contains($runbook,
'`virt-cloud-policy-worker@N.service`')
&& str_contains($runbook, 'Keep')
&& str_contains($runbook, '`virt-cloud-lifecycle.service`')
&& str_contains($runbook, '`virt-cloud-recovery-worker.service`')
&& preg_match('/restore the\s+workers only after/', $runbook) === 1,
'Runbook lost unknown-effect or forward-repair safety rules.');
$assert(str_contains($runbook, 'there is no HTTP or UI')
&& !preg_match('/traffic[-_\/a-z]*attention|attention[-_\/a-z]*traffic/i',
$routes . "\n" . $mainRoutes)
&& !str_contains($adminTrafficJs, 'resolveAttention')
&& !str_contains($adminTrafficJs, 'cloudTrafficPoolAttention')
&& !str_contains($adminResourcesView, 'attention/resolve'),
'A second HTTP/UI attention resolver was exposed beside the local CLI.');
$controllerIterator = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator(
$root . '/web/app/Controllers',
FilesystemIterator::SKIP_DOTS
)
);
foreach ($controllerIterator as $controllerFile) {
if (!$controllerFile->isFile()
|| strtolower($controllerFile->getExtension()) !== 'php') {
continue;
}
$controllerSource = file_get_contents($controllerFile->getPathname());
$assert(is_string($controllerSource)
&& !str_contains(
$controllerSource,
'CloudTrafficPoolAccounting::resolveAttention('
),
'HTTP controller exposes the local-only attention resolver: '
. $controllerFile->getFilename());
}
foreach ([
'external incident/change ID', 'executing host', 'SSH/sudo operator',
'reason, pool ID', 'pool version and UUIDv4',
] as $auditEvidence) {
$assert(str_contains($runbook, $auditEvidence),
'Runbook lost attention audit evidence: ' . $auditEvidence);
}
foreach ([
'| `disabled`, no durable reference |',
'| `shadow`, no durable reference |',
'| `shadow`, durable period/pool reference |',
'| `enforced` | No rollback;',
'| Network operation has unknown effect |',
] as $matrixRow) {
$assert(str_contains($runbook, $matrixRow),
'Runbook rollback matrix is incomplete: ' . $matrixRow);
}
foreach ([
'cloudLifecycle', 'cloudWorker', '--policy-only', '--recovery-only',
] as $command) {
$assert(str_contains($runbook, $command)
&& str_contains($xcat, $command),
'Runbook command does not match XCat: ' . $command);
}
$assert(str_contains($xcat,
'cloudTrafficPoolAttention inspect --pool-id=N')
&& str_contains($xcat,
'cloudTrafficPoolAttention inspect-resolution --resolution-key=UUID')
&& str_contains($xcat,
'cloudTrafficPoolAttention resolve --pool-id=N'),
'Runbook attention commands are not all exposed by XCat help.');
$assert(str_contains($contract, 'TRAFFIC_POOL_ROLLOUT.md')
&& str_contains($deployment, 'TRAFFIC_POOL_ROLLOUT.md'),
'Traffic-pool contract or deployment guide does not link the runbook.');
$assert(str_contains($agents, 'strict FEFO')
&& str_contains($agents, 'unused bytes')
&& str_contains($agents, 'unlimited periods never join a finite pool')
&& str_contains($agents, 'Legacy unpooled periods keep')
&& str_contains($agents, 'every active finite instance'),
'Repository instructions contradict the shared traffic-pool contract.');
$assert(str_contains($pruning, '严格 FEFO')
&& str_contains($pruning, '权益到期只作废自身未用额度')
&& str_contains($pruning, '无限流量账期不贡献也不消费有限流量池')
&& str_contains($pruning, '全部活动有限流量实例')
&& str_contains($pruning, '旧的未入池账期仍按实例独立额度处理'),
'Retained feature boundaries contradict the shared traffic-pool contract.');
echo "Cloud traffic-pool rollout runbook contract passed.\n";