diff --git a/app/config/specifications.php b/app/config/specifications.php index 63ca3ea423..82f5633a96 100644 --- a/app/config/specifications.php +++ b/app/config/specifications.php @@ -1,6 +1,6 @@ [ diff --git a/app/init.php b/app/init.php index 90811013af..6b57035ce9 100644 --- a/app/init.php +++ b/app/init.php @@ -36,13 +36,13 @@ use Appwrite\Event\Realtime; use Appwrite\Event\StatsUsage; use Appwrite\Event\Webhook; use Appwrite\Extend\Exception; -use Appwrite\Functions\Specification; use Appwrite\GraphQL\Promises\Adapter\Swoole; use Appwrite\GraphQL\Schema; use Appwrite\Hooks\Hooks; use Appwrite\Network\Validator\Email; use Appwrite\Network\Validator\Origin; use Appwrite\OpenSSL\OpenSSL; +use Appwrite\Platform\Modules\Compute\Specification; use Appwrite\PubSub\Adapter\Redis as PubSub; use Appwrite\URL\URL as AppwriteURL; use Appwrite\Utopia\Request; diff --git a/src/Appwrite/Platform/Modules/Compute/Specification.php b/src/Appwrite/Platform/Modules/Compute/Specification.php index 8c9e9b9aad..cf48896a7b 100644 --- a/src/Appwrite/Platform/Modules/Compute/Specification.php +++ b/src/Appwrite/Platform/Modules/Compute/Specification.php @@ -1,6 +1,6 @@ addAction(ListUsage::getName(), new ListUsage()); $this->addAction(GetUsage::getName(), new GetUsage()); + + $this->addAction(ListSpecifications::getName(), new ListSpecifications()); } } diff --git a/tests/e2e/General/UsageTest.php b/tests/e2e/General/UsageTest.php index 00dc790869..a74101f50d 100644 --- a/tests/e2e/General/UsageTest.php +++ b/tests/e2e/General/UsageTest.php @@ -2,7 +2,7 @@ namespace Tests\E2E\General; -use Appwrite\Functions\Specification; +use Appwrite\Platform\Modules\Compute\Specification; use Appwrite\Tests\Retry; use CURLFile; use DateTime; diff --git a/tests/e2e/Services/Functions/FunctionsBase.php b/tests/e2e/Services/Functions/FunctionsBase.php index 9f0a5903f3..85e881e5eb 100644 --- a/tests/e2e/Services/Functions/FunctionsBase.php +++ b/tests/e2e/Services/Functions/FunctionsBase.php @@ -389,4 +389,13 @@ trait FunctionsBase return $deployment; } + + protected function listSpecifications(): mixed + { + $specifications = $this->client->call(Client::METHOD_GET, '/functions/specifications', array_merge([ + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders())); + + return $specifications; + } } diff --git a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php index 2056d1f689..472d6f430e 100644 --- a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php +++ b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php @@ -2,7 +2,7 @@ namespace Tests\E2E\Services\Functions; -use Appwrite\Functions\Specification; +use Appwrite\Platform\Modules\Compute\Specification; use Appwrite\Tests\Retry; use Tests\E2E\Client; use Tests\E2E\Scopes\ProjectCustom; @@ -22,6 +22,41 @@ class FunctionsCustomServerTest extends Scope use ProjectCustom; use SideServer; + public function testListSpecs(): void + { + $specifications = $this->listSpecifications(); + $this->assertEquals(200, $specifications['headers']['status-code']); + $this->assertGreaterThan(0, $specifications['body']['total']); + $this->assertArrayHasKey(0, $specifications['body']['specifications']); + $this->assertArrayHasKey('memory', $specifications['body']['specifications'][0]); + $this->assertArrayHasKey('cpus', $specifications['body']['specifications'][0]); + $this->assertArrayHasKey('enabled', $specifications['body']['specifications'][0]); + $this->assertArrayHasKey('slug', $specifications['body']['specifications'][0]); + + $function = $this->createFunction([ + 'functionId' => ID::unique(), + 'name' => 'Specs function', + 'runtime' => 'php-8.0', + 'specification' => $specifications['body']['specifications'][0]['slug'] + ]); + $this->assertEquals(201, $function['headers']['status-code']); + $this->assertEquals($specifications['body']['specifications'][0]['slug'], $function['body']['specification']); + + $function = $this->getFunction($function['body']['$id']); + $this->assertEquals(200, $function['headers']['status-code']); + $this->assertEquals($specifications['body']['specifications'][0]['slug'], $function['body']['specification']); + + $this->cleanupFunction($function['body']['$id']); + + $function = $this->createFunction([ + 'functionId' => ID::unique(), + 'name' => 'Specs function', + 'runtime' => 'php-8.0', + 'specification' => 'cheap-please' + ]); + $this->assertEquals(400, $function['headers']['status-code']); + } + public function testCreateFunction(): array { /** @@ -2006,14 +2041,14 @@ class FunctionsCustomServerTest extends Scope $this->assertEquals(201, $execution['headers']['status-code']); $this->assertStringContainsString('APPWRITE_FUNCTION_ID', $execution['body']['responseBody']); - $site = $this->updateFunction($functionId, [ + $function = $this->updateFunction($functionId, [ 'runtime' => 'node-18.0', 'name' => 'Duplicate Deployment Test', 'entrypoint' => 'index.js', 'commands' => 'rm index.js && mv maintenance.js index.js' ]); - $this->assertEquals(200, $site['headers']['status-code']); - $this->assertStringContainsString('maintenance.js', $site['body']['commands']); + $this->assertEquals(200, $function['headers']['status-code']); + $this->assertStringContainsString('maintenance.js', $function['body']['commands']); $deploymentId2 = $this->setupDuplicateDeployment($functionId, $deploymentId1); $this->assertNotEmpty($deploymentId2); diff --git a/tests/e2e/Services/Sites/SitesBase.php b/tests/e2e/Services/Sites/SitesBase.php index a7e0293409..78c65afe98 100644 --- a/tests/e2e/Services/Sites/SitesBase.php +++ b/tests/e2e/Services/Sites/SitesBase.php @@ -414,4 +414,13 @@ trait SitesBase return $deployment; } + + protected function listSpecifications(): mixed + { + $specifications = $this->client->call(Client::METHOD_GET, '/sites/specifications', array_merge([ + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders())); + + return $specifications; + } } diff --git a/tests/e2e/Services/Sites/SitesCustomServerTest.php b/tests/e2e/Services/Sites/SitesCustomServerTest.php index bd6236291c..891882b1f9 100644 --- a/tests/e2e/Services/Sites/SitesCustomServerTest.php +++ b/tests/e2e/Services/Sites/SitesCustomServerTest.php @@ -2,7 +2,7 @@ namespace Tests\E2E\Services\Sites; -use Appwrite\Sites\Specification; +use Appwrite\Platform\Modules\Compute\Specification; use Appwrite\Tests\Retry; use Tests\E2E\Client; use Tests\E2E\Scopes\ProjectCustom; @@ -20,6 +20,43 @@ class SitesCustomServerTest extends Scope use ProjectCustom; use SideServer; + public function testListSpecs(): void + { + $specifications = $this->listSpecifications(); + $this->assertEquals(200, $specifications['headers']['status-code']); + $this->assertGreaterThan(0, $specifications['body']['total']); + $this->assertArrayHasKey(0, $specifications['body']['specifications']); + $this->assertArrayHasKey('memory', $specifications['body']['specifications'][0]); + $this->assertArrayHasKey('cpus', $specifications['body']['specifications'][0]); + $this->assertArrayHasKey('enabled', $specifications['body']['specifications'][0]); + $this->assertArrayHasKey('slug', $specifications['body']['specifications'][0]); + + $site = $this->createSite([ + 'buildRuntime' => 'node-22', + 'framework' => 'other', + 'name' => 'Specs site', + 'siteId' => ID::unique(), + 'specification' => $specifications['body']['specifications'][0]['slug'] + ]); + $this->assertEquals(201, $site['headers']['status-code']); + $this->assertEquals($specifications['body']['specifications'][0]['slug'], $site['body']['specification']); + + $site = $this->getSite($site['body']['$id']); + $this->assertEquals(200, $site['headers']['status-code']); + $this->assertEquals($specifications['body']['specifications'][0]['slug'], $site['body']['specification']); + + $this->cleanupSite($site['body']['$id']); + + $site = $this->createSite([ + 'buildRuntime' => 'node-22', + 'framework' => 'other', + 'name' => 'Specs site', + 'siteId' => ID::unique(), + 'specification' => 'cheap-please' + ]); + $this->assertEquals(400, $site['headers']['status-code']); + } + public function testCreateSite(): void { /**