|
|
|
|
<?php
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
// Template fan-out is receipt-driven. This replaces the retired polling and
|
|
|
|
|
// reconcile-worker test with the invariants that make every import converge
|
|
|
|
|
// after one dispatch, including the daemon-loss deadline path.
|
|
|
|
|
$root = dirname(__DIR__);
|
|
|
|
|
$catalog = file_get_contents(
|
|
|
|
|
$root . '/app/Services/Cloud/CloudTemplateCatalogService.php'
|
|
|
|
|
);
|
|
|
|
|
$worker = file_get_contents(
|
|
|
|
|
$root . '/app/Services/Cloud/CloudWorkerService.php'
|
|
|
|
|
);
|
|
|
|
|
$jobs = file_get_contents($root . '/app/Services/Cloud/CloudJobService.php');
|
|
|
|
|
if (!is_string($catalog) || !is_string($worker) || !is_string($jobs)) {
|
|
|
|
|
throw new RuntimeException('Cannot read template task sources.');
|
|
|
|
|
}
|
|
|
|
|
$finishStart = strpos($catalog, 'public static function finishJobLocked(');
|
|
|
|
|
$finishEnd = $finishStart === false ? false : strpos(
|
|
|
|
|
$catalog,
|
|
|
|
|
'public static function settleRecoveredParentLocked(',
|
|
|
|
|
$finishStart
|
|
|
|
|
);
|
|
|
|
|
$finishMethod = $finishStart === false || $finishEnd === false ? '' : substr(
|
|
|
|
|
$catalog,
|
|
|
|
|
$finishStart,
|
|
|
|
|
$finishEnd - $finishStart
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$assert = static function (bool $condition, string $message): void {
|
|
|
|
|
if (!$condition) {
|
|
|
|
|
throw new RuntimeException($message);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
$assert(str_contains($catalog,
|
|
|
|
|
"CloudJobService::reserveAggregate(\n \$actor, 'template_import'")
|
|
|
|
|
&& str_contains($catalog,
|
|
|
|
|
"CloudJobService::reserveAgentMutation(\n \$actor, \$hostId, 'template_import_replica', 'POST',")
|
|
|
|
|
&& str_contains($catalog, "'/v1/templates', \$body")
|
|
|
|
|
&& str_contains($catalog, '], (int) $parent->id, $operationId')
|
|
|
|
|
&& str_contains($catalog,
|
|
|
|
|
'$replica->job_id = (int) $child->id;')
|
|
|
|
|
&& str_contains($catalog,
|
|
|
|
|
'return CloudJobService::acknowledgement($parent);'),
|
|
|
|
|
'Template import does not reserve one aggregate and one immutable child dispatch per host.');
|
|
|
|
|
|
|
|
|
|
$assert(str_contains($catalog,
|
|
|
|
|
"if ((string) \$job->kind === 'template_import_replica')")
|
|
|
|
|
&& str_contains($catalog,
|
|
|
|
|
'self::finishImportReplica($template, $replica, $status, $result,')
|
|
|
|
|
&& !str_contains($finishMethod, 'settleImportParent(')
|
|
|
|
|
&& !str_contains($finishMethod, 'settleMetadataParent(')
|
|
|
|
|
&& !str_contains($finishMethod, 'settleDeleteParent(')
|
|
|
|
|
&& str_contains($catalog,
|
|
|
|
|
'public static function settleRecoveredParentLocked(')
|
|
|
|
|
&& str_contains($catalog,
|
|
|
|
|
'self::settleImportParent(')
|
|
|
|
|
&& str_contains($worker,
|
|
|
|
|
'CloudJobService::reconcileAggregateParentEffectLocked(')
|
|
|
|
|
&& str_contains($catalog,
|
|
|
|
|
"CloudJobService::completeAggregateLocked(\$parent, 'succeeded',")
|
|
|
|
|
&& str_contains($catalog,
|
|
|
|
|
"CloudJobService::completeAggregateLocked(\$parent, 'failed', \$effect,"),
|
|
|
|
|
'Template completion does not defer aggregate publication until the child terminal effect is durable.');
|
|
|
|
|
|
|
|
|
|
$assert(str_contains($catalog,
|
|
|
|
|
"'error_code' => 'aggregate_deadline_exceeded'")
|
|
|
|
|
&& str_contains($catalog,
|
|
|
|
|
"CloudJobService::completeAggregateLocked(\$parent, 'failed', \$effect,")
|
|
|
|
|
&& str_contains($worker,
|
|
|
|
|
"->orderByRaw('CASE WHEN parent_job_id IS NULL THEN 1 ELSE 0 END')")
|
|
|
|
|
&& str_contains($worker,
|
|
|
|
|
'self::forceTerminalFailure((int) $child->id, $childToken,')
|
|
|
|
|
&& str_contains($worker,
|
|
|
|
|
"if (CloudJob::where('parent_job_id', (int) \$parent->id)")
|
|
|
|
|
&& str_contains($worker,
|
|
|
|
|
'CloudTemplateCatalogService::expireAggregateLocked($fresh);')
|
|
|
|
|
&& str_contains($worker,
|
|
|
|
|
"CloudJobService::completeAggregateLocked(\n \$fresh, 'failed'"),
|
|
|
|
|
'Absolute aggregate expiry can leave a child or public parent permanently active.');
|
|
|
|
|
|
|
|
|
|
$assert(!str_contains($worker, "'/reconcile'")
|
|
|
|
|
&& !preg_match('#/v1/operations/.+reconcile#', $worker)
|
|
|
|
|
&& !preg_match('/\breconcile(?:One|Job|Pending|Import|Delete)\b/i',
|
|
|
|
|
$catalog . "\n" . $worker)
|
|
|
|
|
&& str_contains($jobs, "\$job->execution_mode = 'agent';")
|
|
|
|
|
&& str_contains($worker, "->where('dispatch_attempts', 0)"),
|
|
|
|
|
'Template convergence retained a polling/reconcile mutation path.');
|
|
|
|
|
|
|
|
|
|
echo "Template single-dispatch receipt and deadline convergence checks passed.\n";
|