Fix deployment single chunk content range

Fixes CLOUD-3JN6
This commit is contained in:
Chirag Aggarwal
2026-04-22 16:05:12 +05:30
parent 0aab3e9a43
commit e7d9ef74c4
4 changed files with 90 additions and 0 deletions
@@ -206,6 +206,12 @@ class Create extends Action
if ($chunk === -1) {
$chunk = $chunks;
}
} else {
// Guard against manually setting range header for single chunk upload
if ($chunks === -1) {
$chunks = 1;
$chunk = 1;
}
}
$chunksUploaded = $deviceForFunctions->upload($fileTmpName, $path, $chunk, $chunks, $metadata);
@@ -208,6 +208,12 @@ class Create extends Action
if ($chunk === -1) {
$chunk = $chunks;
}
} else {
// Guard against manually setting range header for single chunk upload
if ($chunks === -1) {
$chunks = 1;
$chunk = 1;
}
}
$chunksUploaded = $deviceForSites->upload($fileTmpName, $path, $chunk, $chunks, $metadata);
@@ -567,6 +567,44 @@ class FunctionsCustomServerTest extends Scope
}, 120000, 500);
}
public function testCreateDeploymentWithSingleContentRangeChunk(): void
{
$functionId = $this->setupFunction([
'functionId' => ID::unique(),
'name' => 'Test Single Chunk Range',
'execute' => [Role::user($this->getUser()['$id'])->toString()],
'runtime' => 'node-22',
'entrypoint' => 'index.js',
'timeout' => 10,
]);
$code = $this->packageFunction('basic');
$size = \filesize($code->getFilename());
$deployment = $this->client->call(Client::METHOD_POST, '/functions/' . $functionId . '/deployments', array_merge([
'content-type' => 'multipart/form-data',
'x-appwrite-project' => $this->getProject()['$id'],
'content-range' => 'bytes 0-' . ($size - 1) . '/' . $size,
], $this->getHeaders()), [
'code' => $code,
'activate' => true,
]);
$this->assertEquals(202, $deployment['headers']['status-code']);
$this->assertNotEmpty($deployment['body']['$id']);
$deploymentId = $deployment['body']['$id'];
$this->assertEventually(function () use ($functionId, $deploymentId) {
$deployment = $this->getDeployment($functionId, $deploymentId);
$this->assertEquals(200, $deployment['headers']['status-code']);
$this->assertEquals('ready', $deployment['body']['status']);
}, 120000, 500);
$this->cleanupFunction($functionId);
}
public function testCreateFunctionAndDeploymentFromTemplate()
{
@@ -868,6 +868,46 @@ class SitesCustomServerTest extends Scope
// // TODO: Implement testCreateDeploymentFromCLI() later
// }
public function testCreateDeploymentWithSingleContentRangeChunk(): void
{
$siteId = $this->setupSite([
'buildRuntime' => 'node-22',
'fallbackFile' => '',
'framework' => 'other',
'name' => 'Test Site Single Chunk Range',
'outputDirectory' => './',
'providerBranch' => 'main',
'providerRootDirectory' => './',
'siteId' => ID::unique()
]);
$code = $this->packageSite('static-single-file');
$size = \filesize($code->getFilename());
$deployment = $this->client->call(Client::METHOD_POST, '/sites/' . $siteId . '/deployments', array_merge([
'content-type' => 'multipart/form-data',
'x-appwrite-project' => $this->getProject()['$id'],
'content-range' => 'bytes 0-' . ($size - 1) . '/' . $size,
], $this->getHeaders()), [
'code' => $code,
'activate' => true,
]);
$this->assertEquals(202, $deployment['headers']['status-code']);
$this->assertNotEmpty($deployment['body']['$id']);
$deploymentId = $deployment['body']['$id'];
$this->assertEventually(function () use ($siteId, $deploymentId) {
$deployment = $this->getDeployment($siteId, $deploymentId);
$this->assertEquals(200, $deployment['headers']['status-code']);
$this->assertEquals('ready', $deployment['body']['status']);
}, 120000, 500);
$this->cleanupSite($siteId);
}
public function testCreateDeployment()
{
$siteId = $this->setupSite([