@ -745,5 +745,159 @@ namespace {
)->state === 'cancelled',
'Expired official download was not reaped without provider mutation.');
// A lost immutable PUT response plus an unavailable HEAD is effect
// unknown. The same intent must stay fenced until a later HEAD proves the
// exact object; recovery must not download or PUT the image again.
$actor['request_idempotency_key'] = 'multipart-template-intent-0011';
$unknownFetchHistory = [];
$unknownFetchStack = HandlerStack::create(new MockHandler([
new Response(200, [
'Content-Length' => (string) strlen($remoteBody),
'Content-Encoding' => 'identity',
], $remoteBody),
]));
$unknownFetchStack->push(Middleware::history($unknownFetchHistory));
$unknownStorageHistory = [];
$unknownStorageStack = HandlerStack::create(new MockHandler([
new ConnectException('put response lost',
new Request('PUT', 'https://objects.example.test')),
new ConnectException('head unavailable',
new Request('HEAD', 'https://objects.example.test')),
]));
$unknownStorageStack->push(Middleware::history($unknownStorageHistory));
try {
$workflow->importRemote(
array_replace($remoteInput, ['name' => 'Debian 13 unknown put']),
$actor,
new CloudTemplateRemoteFetcher(
new Client(['handler' => $unknownFetchStack]),
static fn (string $host): array => ['93.184.216.34']
),
new CloudObjectStorageS3Client(new Client([
'handler' => $unknownStorageStack,
]))
);
throw new \RuntimeException('An unknown immutable PUT was accepted.');
} catch (CloudError $error) {
$assert($error->httpStatus === 502,
'Unknown immutable PUT returned the wrong status.');
}
$unknownRemote = CloudTemplateImportIntent::query()
->where('request_idempotency_key',
'multipart-template-intent-0011')->firstOrFail();
$unknownDto = CloudTemplateImportWorkflow::dto($unknownRemote);
$assert((string) $unknownRemote->state === 'source_unknown'
& & $unknownDto['can_resume'] === true
& & $unknownDto['can_cancel'] === false
& & count($unknownFetchHistory) === 1
& & array_map(static fn (array $item): string =>
$item['request']->getMethod(), $unknownStorageHistory) === [
'PUT', 'HEAD',
],
'Unknown immutable PUT was not fenced on its original object key.');
$reconcileHistory = [];
$reconcileStack = HandlerStack::create(new MockHandler([
new Response(200, [
'Content-Length' => (string) strlen($remoteBody),
'ETag' => '"remote-unknown-etag"',
'x-amz-version-id' => 'remote-unknown-version',
]),
new Response(200, [
'Content-Length' => (string) strlen($remoteBody),
'ETag' => '"remote-unknown-etag"',
'x-amz-version-id' => 'remote-unknown-version',
]),
]));
$reconcileStack->push(Middleware::history($reconcileHistory));
$unknownAck = $workflow->resumeRemote(
(string) $unknownRemote->id,
$actor,
$emptyFetcher,
new CloudObjectStorageS3Client(new Client([
'handler' => $reconcileStack,
]))
);
$assert((int) ($unknownAck['task_id'] ?? 0) > 0
& & count($unknownFetchHistory) === 1
& & array_map(static fn (array $item): string =>
$item['request']->getMethod(), $reconcileHistory) === [
'HEAD', 'HEAD',
],
'Unknown immutable PUT recovery replayed a download or write.');
// If the reconciliation HEAD proves the PUT did not apply, retrying the
// same intent is safe and may fetch and publish that frozen key again.
$actor['request_idempotency_key'] = 'multipart-template-intent-0012';
$absentFetchStack = HandlerStack::create(new MockHandler([
new Response(200, [
'Content-Length' => (string) strlen($remoteBody),
'Content-Encoding' => 'identity',
], $remoteBody),
]));
$absentStorageHistory = [];
$absentStorageStack = HandlerStack::create(new MockHandler([
new ConnectException('put response lost',
new Request('PUT', 'https://objects.example.test')),
new Response(404),
]));
$absentStorageStack->push(Middleware::history($absentStorageHistory));
try {
$workflow->importRemote(
array_replace($remoteInput, ['name' => 'Debian 13 absent put']),
$actor,
new CloudTemplateRemoteFetcher(
new Client(['handler' => $absentFetchStack]),
static fn (string $host): array => ['93.184.216.34']
),
new CloudObjectStorageS3Client(new Client([
'handler' => $absentStorageStack,
]))
);
throw new \RuntimeException('A proven absent PUT was accepted.');
} catch (CloudError $error) {
$assert($error->httpStatus === 502,
'Proven absent immutable PUT returned the wrong status.');
}
$absentRemote = CloudTemplateImportIntent::query()
->where('request_idempotency_key',
'multipart-template-intent-0012')->firstOrFail();
$assert((string) $absentRemote->state === 'source_failed'
& & array_map(static fn (array $item): string =>
$item['request']->getMethod(), $absentStorageHistory) === [
'PUT', 'HEAD',
],
'Proven absent immutable PUT was not made safely retryable.');
$absentRetryStorage = new CloudObjectStorageS3Client(new Client([
'handler' => HandlerStack::create(new MockHandler([
new Response(200, [
'ETag' => '"remote-absent-retry-etag"',
'x-amz-version-id' => 'remote-absent-retry-version',
]),
new Response(200, [
'Content-Length' => (string) strlen($remoteBody),
'ETag' => '"remote-absent-retry-etag"',
'x-amz-version-id' => 'remote-absent-retry-version',
]),
])),
]));
$absentRetryAck = $workflow->resumeRemote(
(string) $absentRemote->id,
$actor,
new CloudTemplateRemoteFetcher(
new Client(['handler' => HandlerStack::create(new MockHandler([
new Response(200, [
'Content-Length' => (string) strlen($remoteBody),
'Content-Encoding' => 'identity',
], $remoteBody),
]))]),
static fn (string $host): array => ['93.184.216.34']
),
$absentRetryStorage
);
$assert((int) ($absentRetryAck['task_id'] ?? 0) > 0,
'A proven absent immutable PUT could not resume on the same intent.');
echo "Cloud-template resumable multipart import behavior passed.\n";
}