From c1ee2f2b411fb63056bfebec1569f6d441ea5f6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Fri, 7 Mar 2025 21:04:24 +0100 Subject: [PATCH] Failing test fixes --- app/config/collections/projects.php | 33 +++++++++++-- .../Functions/Http/Deployments/Delete.php | 4 +- .../Http/Deployments/Download/Get.php | 2 +- .../Http/Deployments/Duplicate/Create.php | 2 +- .../Modules/Sites/Http/Deployments/Create.php | 4 +- .../Modules/Sites/Http/Deployments/Delete.php | 4 +- .../Sites/Http/Deployments/Download/Get.php | 2 +- .../Http/Deployments/Duplicate/Create.php | 2 +- src/Appwrite/Platform/Workers/Deletes.php | 2 +- .../Functions/FunctionsCustomServerTest.php | 46 ++++++------------- .../Services/Sites/SitesCustomServerTest.php | 23 ++++------ 11 files changed, 65 insertions(+), 59 deletions(-) diff --git a/app/config/collections/projects.php b/app/config/collections/projects.php index 671bf4b6ff..fb8af40348 100644 --- a/app/config/collections/projects.php +++ b/app/config/collections/projects.php @@ -1240,7 +1240,7 @@ return [ '$id' => ID::custom('type'), 'type' => Database::VAR_STRING, 'format' => '', - 'size' => 2048, + 'size' => 32, 'signed' => true, 'required' => true, 'default' => null, @@ -1607,9 +1607,23 @@ return [ 'orders' => [], ], [ - '$id' => ID::custom('_key_size'), + '$id' => ID::custom('_key_sourceSize'), 'type' => Database::INDEX_KEY, - 'attributes' => ['size'], + 'attributes' => ['sourceSize'], + 'lengths' => [], + 'orders' => [Database::ORDER_ASC], + ], + [ + '$id' => ID::custom('_key_buildSize'), + 'type' => Database::INDEX_KEY, + 'attributes' => ['buildSize'], + 'lengths' => [], + 'orders' => [Database::ORDER_ASC], + ], + [ + '$id' => ID::custom('_key_buildDuration'), + 'type' => Database::INDEX_KEY, + 'attributes' => ['buildDuration'], 'lengths' => [], 'orders' => [Database::ORDER_ASC], ], @@ -1620,6 +1634,19 @@ return [ 'lengths' => [], 'orders' => [Database::ORDER_ASC], ], + [ + '$id' => ID::custom('_key_type'), + 'type' => Database::INDEX_KEY, + 'attributes' => ['type'], + 'lengths' => [32], + 'orders' => [Database::ORDER_ASC], + ], [ + '$id' => ID::custom('_key_status'), + 'type' => Database::INDEX_KEY, + 'attributes' => ['status'], + 'lengths' => [16], + 'orders' => [Database::ORDER_ASC], + ], ], ], diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Delete.php b/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Delete.php index 5bde7903d9..c02c470980 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Delete.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Delete.php @@ -83,8 +83,8 @@ class Delete extends Action throw new Exception(Exception::GENERAL_SERVER_ERROR, 'Failed to remove deployment from DB'); } - if (!empty($deployment->getAttribute('path', ''))) { - if (!($deviceForFunctions->delete($deployment->getAttribute('path', '')))) { + if (!empty($deployment->getAttribute('sourcePath', ''))) { + if (!($deviceForFunctions->delete($deployment->getAttribute('sourcePath', '')))) { throw new Exception(Exception::GENERAL_SERVER_ERROR, 'Failed to remove deployment from storage'); } } diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Download/Get.php b/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Download/Get.php index d528bc9995..4fa279a3d7 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Download/Get.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Download/Get.php @@ -85,7 +85,7 @@ class Get extends Action $device = $deviceForBuilds; break; case 'source': - $path = $deployment->getAttribute('path', ''); + $path = $deployment->getAttribute('sourcePath', ''); $device = $deviceForFunctions; break; } diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Duplicate/Create.php b/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Duplicate/Create.php index 05730c42e9..b942ba9ab7 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Duplicate/Create.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Duplicate/Create.php @@ -77,7 +77,7 @@ class Create extends Action throw new Exception(Exception::DEPLOYMENT_NOT_FOUND); } - $path = $deployment->getAttribute('path'); + $path = $deployment->getAttribute('sourcePath'); if (empty($path) || !$deviceForFunctions->exists($path)) { throw new Exception(Exception::DEPLOYMENT_NOT_FOUND); } diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Create.php b/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Create.php index 3405f8a03c..a899e1aa3e 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Create.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Create.php @@ -224,7 +224,7 @@ class Create extends Action 'resourceInternalId' => $site->getInternalId(), 'resourceId' => $site->getId(), 'resourceType' => 'sites', - 'buildCommands' => $commands, + 'buildCommands' => \implode(' && ', $commands), 'buildOutput' => $outputDirectory, 'sourcePath' => $path, 'sourceSize' => $fileSize, @@ -271,7 +271,7 @@ class Create extends Action 'resourceInternalId' => $site->getInternalId(), 'resourceId' => $site->getId(), 'resourceType' => 'sites', - 'buildCommands' => $commands, + 'buildCommands' => \implode(' && ', $commands), 'buildOutput' => $outputDirectory, 'sourcePath' => $path, 'sourceSize' => $fileSize, diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Delete.php b/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Delete.php index fe16dafae1..7065ac1917 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Delete.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Delete.php @@ -83,8 +83,8 @@ class Delete extends Action throw new Exception(Exception::GENERAL_SERVER_ERROR, 'Failed to remove deployment from DB'); } - if (!empty($deployment->getAttribute('path', ''))) { - if (!($deviceForSites->delete($deployment->getAttribute('path', '')))) { + if (!empty($deployment->getAttribute('sourcePath', ''))) { + if (!($deviceForSites->delete($deployment->getAttribute('sourcePath', '')))) { throw new Exception(Exception::GENERAL_SERVER_ERROR, 'Failed to remove deployment from storage'); } } diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Download/Get.php b/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Download/Get.php index 1d84288203..6d969f883f 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Download/Get.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Download/Get.php @@ -84,7 +84,7 @@ class Get extends Action $device = $deviceForBuilds; break; case 'source': - $path = $deployment->getAttribute('path', ''); + $path = $deployment->getAttribute('sourcePath', ''); $device = $deviceForSites; break; } diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Duplicate/Create.php b/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Duplicate/Create.php index c2e6df64dd..f32056cbe9 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Duplicate/Create.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Duplicate/Create.php @@ -78,7 +78,7 @@ class Create extends Action throw new Exception(Exception::DEPLOYMENT_NOT_FOUND); } - $path = $deployment->getAttribute('path'); + $path = $deployment->getAttribute('sourcePath'); if (empty($path) || !$deviceForSites->exists($path)) { throw new Exception(Exception::DEPLOYMENT_NOT_FOUND); } diff --git a/src/Appwrite/Platform/Workers/Deletes.php b/src/Appwrite/Platform/Workers/Deletes.php index fe12c90c4a..a875f9e940 100644 --- a/src/Appwrite/Platform/Workers/Deletes.php +++ b/src/Appwrite/Platform/Workers/Deletes.php @@ -976,7 +976,7 @@ class Deletes extends Action private function deleteDeploymentFiles(Device $device, Document $deployment): void { $deploymentId = $deployment->getId(); - $deploymentPath = $deployment->getAttribute('path', ''); + $deploymentPath = $deployment->getAttribute('sourcePath', ''); if (empty($deploymentPath)) { Console::info("No deployment files for deployment " . $deploymentId); diff --git a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php index c79fd59923..e9e7a5c7d8 100644 --- a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php +++ b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php @@ -382,7 +382,7 @@ class FunctionsCustomServerTest extends Scope $lastDeployment = $deployments['body']['deployments'][0]; $this->assertNotEmpty($lastDeployment['$id']); - $this->assertEquals(0, $lastDeployment['size']); + $this->assertEquals(0, $lastDeployment['sourceSize']); $deploymentId = $lastDeployment['$id']; @@ -598,10 +598,10 @@ class FunctionsCustomServerTest extends Scope $this->assertNotEmpty($largeTag['body']['$id']); $this->assertEquals(true, (new DatetimeValidator())->isValid($largeTag['body']['$createdAt'])); $this->assertEquals('index.php', $largeTag['body']['entrypoint']); - $this->assertGreaterThan(1024 * 1024 * 5, $largeTag['body']['size']); // ~7MB video file - $this->assertLessThan(1024 * 1024 * 10, $largeTag['body']['size']); // ~7MB video file + $this->assertGreaterThan(1024 * 1024 * 5, $largeTag['body']['sourceSize']); // ~7MB video file + $this->assertLessThan(1024 * 1024 * 10, $largeTag['body']['sourceSize']); // ~7MB video file - $deploymentSize = $largeTag['body']['size']; + $deploymentSize = $largeTag['body']['sourceSize']; $deploymentId = $largeTag['body']['$id']; $this->assertEventually(function () use ($functionId, $deploymentId, $deploymentSize) { @@ -609,7 +609,7 @@ class FunctionsCustomServerTest extends Scope $this->assertEquals(200, $deployment['headers']['status-code']); $this->assertEquals('ready', $deployment['body']['status']); - $this->assertEquals($deploymentSize, $deployment['body']['size']); + $this->assertEquals($deploymentSize, $deployment['body']['sourceSize']); $this->assertGreaterThan(1024 * 1024 * 10, $deployment['body']['buildSize']); // ~7MB video file + 10MB sample file }, 500000, 1000); @@ -655,7 +655,7 @@ class FunctionsCustomServerTest extends Scope $this->assertEquals($deployments['body']['total'], 3); $this->assertIsArray($deployments['body']['deployments']); $this->assertCount(3, $deployments['body']['deployments']); - $this->assertArrayHasKey('size', $deployments['body']['deployments'][0]); + $this->assertArrayHasKey('sourceSize', $deployments['body']['deployments'][0]); $this->assertArrayHasKey('buildSize', $deployments['body']['deployments'][0]); $deployments = $this->listDeployments($functionId, [ @@ -676,24 +676,6 @@ class FunctionsCustomServerTest extends Scope $this->assertEquals($deployments['headers']['status-code'], 200); $this->assertCount(2, $deployments['body']['deployments']); - $deployments = $this->listDeployments($functionId, [ - 'queries' => [ - Query::equal('entrypoint', ['index.php'])->toString(), - ], - ]); - - $this->assertEquals($deployments['headers']['status-code'], 200); - $this->assertCount(3, $deployments['body']['deployments']); - - $deployments = $this->listDeployments($functionId, [ - 'queries' => [ - Query::equal('entrypoint', ['index.js'])->toString(), - ], - ]); - - $this->assertEquals($deployments['headers']['status-code'], 200); - $this->assertCount(0, $deployments['body']['deployments']); - $deployments = $this->listDeployments($functionId, [ 'search' => 'php-8.0' ]); @@ -744,7 +726,7 @@ class FunctionsCustomServerTest extends Scope $functionId, [ 'queries' => [ - Query::greaterThan('size', 10000)->toString(), + Query::greaterThan('sourceSize', 10000)->toString(), ], ] ); @@ -756,7 +738,7 @@ class FunctionsCustomServerTest extends Scope $functionId, [ 'queries' => [ - Query::greaterThan('size', 0)->toString(), + Query::greaterThan('sourceSize', 0)->toString(), ], ] ); @@ -768,7 +750,7 @@ class FunctionsCustomServerTest extends Scope $functionId, [ 'queries' => [ - Query::greaterThan('size', -100)->toString(), + Query::greaterThan('sourceSize', -100)->toString(), ], ] ); @@ -789,16 +771,16 @@ class FunctionsCustomServerTest extends Scope $this->assertEquals(200, $deployments['headers']['status-code']); $this->assertGreaterThanOrEqual(1, $deployments['body']['total']); $this->assertNotEmpty($deployments['body']['deployments'][0]['$id']); - $this->assertNotEmpty($deployments['body']['deployments'][0]['size']); + $this->assertNotEmpty($deployments['body']['deployments'][0]['sourceSize']); $deploymentId = $deployments['body']['deployments'][0]['$id']; - $deploymentSize = $deployments['body']['deployments'][0]['size']; + $deploymentSize = $deployments['body']['deployments'][0]['sourceSize']; $deployments = $this->listDeployments( $functionId, [ 'queries' => [ - Query::equal('size', [$deploymentSize])->toString(), + Query::equal('sourceSize', [$deploymentSize])->toString(), ], ] ); @@ -815,7 +797,7 @@ class FunctionsCustomServerTest extends Scope if (!empty($matchingDeployment)) { $deployment = reset($matchingDeployment); - $this->assertEquals($deploymentSize, $deployment['size']); + $this->assertEquals($deploymentSize, $deployment['sourceSize']); } return $data; @@ -835,7 +817,7 @@ class FunctionsCustomServerTest extends Scope $this->assertGreaterThan(0, $deployment['body']['buildDuration']); $this->assertNotEmpty($deployment['body']['status']); $this->assertNotEmpty($deployment['body']['buildLogs']); - $this->assertArrayHasKey('size', $deployment['body']); + $this->assertArrayHasKey('sourceSize', $deployment['body']); $this->assertArrayHasKey('buildSize', $deployment['body']); /** diff --git a/tests/e2e/Services/Sites/SitesCustomServerTest.php b/tests/e2e/Services/Sites/SitesCustomServerTest.php index 57f5f56bf5..b52847f665 100644 --- a/tests/e2e/Services/Sites/SitesCustomServerTest.php +++ b/tests/e2e/Services/Sites/SitesCustomServerTest.php @@ -598,7 +598,7 @@ class SitesCustomServerTest extends Scope $lastDeployment = $deployments['body']['deployments'][0]; $this->assertNotEmpty($lastDeployment['$id']); - $this->assertEquals(0, $lastDeployment['size']); + $this->assertEquals(0, $lastDeployment['sourceSize']); $deploymentId = $lastDeployment['$id']; @@ -709,9 +709,6 @@ class SitesCustomServerTest extends Scope }, 100000, 250); $deployment = $this->cancelDeployment($siteId, $deploymentId); - \var_dump($siteId); - \var_dump($deploymentId); - \var_dump($deployment); $this->assertEquals(200, $deployment['headers']['status-code']); $this->assertEquals('canceled', $deployment['body']['status']); @@ -815,7 +812,7 @@ class SitesCustomServerTest extends Scope $this->assertEquals($deployments['body']['total'], 2); $this->assertIsArray($deployments['body']['deployments']); $this->assertCount(2, $deployments['body']['deployments']); - $this->assertArrayHasKey('size', $deployments['body']['deployments'][0]); + $this->assertArrayHasKey('sourceSize', $deployments['body']['deployments'][0]); $this->assertArrayHasKey('buildSize', $deployments['body']['deployments'][0]); $deployments = $this->listDeployments($siteId, [ @@ -876,7 +873,7 @@ class SitesCustomServerTest extends Scope $siteId, [ 'queries' => [ - Query::greaterThan('size', 10000)->toString(), + Query::greaterThan('sourceSize', 10000)->toString(), ], ] ); @@ -888,7 +885,7 @@ class SitesCustomServerTest extends Scope $siteId, [ 'queries' => [ - Query::greaterThan('size', 0)->toString(), + Query::greaterThan('sourceSize', 0)->toString(), ], ] ); @@ -900,7 +897,7 @@ class SitesCustomServerTest extends Scope $siteId, [ 'queries' => [ - Query::greaterThan('size', -100)->toString(), + Query::greaterThan('sourceSize', -100)->toString(), ], ] ); @@ -921,16 +918,16 @@ class SitesCustomServerTest extends Scope $this->assertEquals(200, $deployments['headers']['status-code']); $this->assertGreaterThanOrEqual(1, $deployments['body']['total']); $this->assertNotEmpty($deployments['body']['deployments'][0]['$id']); - $this->assertNotEmpty($deployments['body']['deployments'][0]['size']); + $this->assertNotEmpty($deployments['body']['deployments'][0]['sourceSize']); $deploymentId = $deployments['body']['deployments'][0]['$id']; - $deploymentSize = $deployments['body']['deployments'][0]['size']; + $deploymentSize = $deployments['body']['deployments'][0]['sourceSize']; $deployments = $this->listDeployments( $siteId, [ 'queries' => [ - Query::equal('size', [$deploymentSize])->toString(), + Query::equal('sourceSize', [$deploymentSize])->toString(), ], ] ); @@ -947,7 +944,7 @@ class SitesCustomServerTest extends Scope if (!empty($matchingDeployment)) { $deployment = reset($matchingDeployment); - $this->assertEquals($deploymentSize, $deployment['size']); + $this->assertEquals($deploymentSize, $deployment['sourceSize']); } $this->cleanupDeployment($siteId, $deploymentIdActive); @@ -992,7 +989,7 @@ class SitesCustomServerTest extends Scope $this->assertGreaterThan(0, $deployment['body']['buildDuration']); $this->assertNotEmpty($deployment['body']['status']); $this->assertNotEmpty($deployment['body']['buildLogs']); - $this->assertArrayHasKey('size', $deployment['body']); + $this->assertArrayHasKey('sourceSize', $deployment['body']); $this->assertArrayHasKey('buildSize', $deployment['body']); /**