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/CloudStorageReplicaWorkerCo...

85 lines
4.4 KiB
PHTML

<?php
$root = dirname(__DIR__, 2);
$read = static function (string $path) use ($root): string {
$contents = file_get_contents($root . '/' . $path);
if (!is_string($contents)) {
throw new RuntimeException('Unable to read ' . $path);
}
return $contents;
};
$assert = static function (bool $condition, string $message): void {
if (!$condition) {
throw new RuntimeException($message);
}
};
$xcat = $read('web/app/Command/XCat.php');
$command = $read('web/app/Command/CloudStorageReplicaWorker.php');
$worker = $read('web/app/Services/Cloud/CloudStorageReplicaWorkerService.php');
$attention = $read('web/app/Services/Cloud/CloudStorageReplicaAttentionService.php');
$controller = $read('web/app/Controllers/Admin/ObjectStorageController.php');
$routes = $read('web/config/routes.php');
$view = $read('web/resources/views/venix/admin/object_storage.tpl');
$javascript = $read('web/public/cloud/admin-object-storage.js');
$unit = $read('deploy/virt-cloud-storage-replica-worker.service');
$assert(str_contains($xcat, "'cloudStorageReplicaWorker'")
&& str_contains($xcat, 'CloudStorageReplicaWorker::run'),
'Replica worker command is not reachable through xcat.');
$assert(str_contains($command, 'CloudStorageReplicaWorkerService')
&& str_contains($command, "in_array('--once'")
&& str_contains($command, 'CloudRuntimeHeartbeat')
&& str_contains($command, "'storage_replica'")
&& str_contains($command, 'observationErrors()')
&& str_contains($command, '$unresolved = true;')
&& str_contains($command, 'elseif (!$unresolved)')
&& str_contains($command, "error('storage_replica_failed')"),
'Replica worker command lost its loop, persistent warning, heartbeat, error observation, or --once mode.');
$assert(str_contains($unit,
'ExecStart=/usr/bin/php /home/virt-cloud/web/xcat cloudStorageReplicaWorker')
&& str_contains($unit, 'NoNewPrivileges=true')
&& str_contains($unit, 'ProtectSystem=strict')
&& str_contains($unit, 'LimitCORE=0'),
'Replica worker systemd unit is missing execution or hardening controls.');
$assert(str_contains($worker, "'object-replica-verify-v1'")
&& str_contains($worker, 'presignedVersionedGet')
&& str_contains($worker, 'markReplicaUnknown')
&& !str_contains($worker, 'CloudStoragePublicationOutboxService')
&& !str_contains($worker, 'storage_publication')
&& !str_contains($worker, "result_json ="),
'Worker lost exact-read reconciliation, retained publication work, or '
. 'bypasses sanitized persistence.');
$assert(str_contains($worker, 'findMultipartUploadsByExactObjectKey')
&& str_contains($worker, 'resumeMultipartUpload')
&& str_contains($worker, 'operation_available_at')
&& str_contains($worker, 'multipart_absence_confirmations')
&& str_contains($worker, 'rescheduleReplicaNotApplied')
&& !str_contains($worker, '->abortMultipart('),
'Worker lost read-only multipart recovery or reintroduced blind Abort.');
$assert(str_contains($worker, '$mixedVersionIdentity')
&& str_contains($worker, "replica_multipart_identity_ambiguous")
&& str_contains($worker, 'multipart_presence_confirmations')
&& str_contains($worker, 'replica_completion_inspection_unavailable'),
'Worker lost mixed-version rejection or unknown-effect replay fences.');
$assert(str_contains($worker, 'markMultipartAttention')
&& str_contains($worker, 'markReplicaAttention')
&& str_contains($worker, 'multipart_attention_confirmations')
&& str_contains($attention, 'CloudStorageArtifactService::reopenReplicaAttention')
&& str_contains($attention,
'CloudStorageArtifactService::reopenPrimaryPreparationAttention')
&& !str_contains($attention, 'abortMultipart')
&& !str_contains($attention, 'beginMultipart'),
'Multipart ambiguity lacks bounded attention or reintroduced remote mutation.');
$assert(str_contains($controller, 'retryReplicaAttention')
&& str_contains($routes, '/object-storage/replica-attention/{operation_id:')
&& str_contains($routes,
'retryReplicaAttention\')->add(new SuperAdmin())')
&& str_contains($view, 'os-attention-retry')
&& str_contains($javascript, 'initializeReplicaAttention')
&& str_contains($javascript, '不会终止会话或直接新建上传')
&& str_contains($javascript, '对象与会话的无效果证据稳定后'),
'Administrator replica-attention convergence entry is incomplete.');
echo "Storage replica worker contract tests passed.\n";