From 20e3597a273635284a9c99d51297f2aff9e8014b Mon Sep 17 00:00:00 2001 From: Khushboo Verma <43381712+vermakhushboo@users.noreply.github.com> Date: Tue, 18 Mar 2025 13:04:44 +0530 Subject: [PATCH 1/4] WIP: Add test for empty source --- .../Services/Sites/SitesCustomServerTest.php | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/tests/e2e/Services/Sites/SitesCustomServerTest.php b/tests/e2e/Services/Sites/SitesCustomServerTest.php index 6ecb35d5a9..e6321bad32 100644 --- a/tests/e2e/Services/Sites/SitesCustomServerTest.php +++ b/tests/e2e/Services/Sites/SitesCustomServerTest.php @@ -2243,4 +2243,40 @@ class SitesCustomServerTest extends Scope $this->cleanupSite($siteId); } + + public function testEmptySiteSource(): void + { + $siteId = $this->setupSite([ + 'siteId' => ID::unique(), + 'name' => 'Empty source site', + 'framework' => 'other', + 'buildRuntime' => 'node-22', + 'outputDirectory' => './', + ]); + $this->assertNotEmpty($siteId); + + $site = $this->getSite($siteId); + $this->assertEquals('200', $site['headers']['status-code']); + $this->assertArrayHasKey('adapter', $site['body']); + $this->assertEmpty($site['body']['adapter']); + + $domain = $this->setupSiteDomain($siteId); + $this->assertNotEmpty($domain); + + $deploymentId = $this->setupDeployment($siteId, [ + 'code' => $this->packageSite('empty'), + 'activate' => 'true' + ]); + $this->assertNotEmpty($deploymentId); + + $site = $this->getSite($siteId); + $this->assertEquals('200', $site['headers']['status-code']); + + $proxyClient = new Client(); + $proxyClient->setEndpoint('http://' . $domain); + $response = $proxyClient->call(Client::METHOD_GET, '/'); + $this->assertEquals(200, $response['headers']['status-code']); + + $this->cleanupSite($siteId); + } } From 18022d680ba32c348e1895e8ba469a4257cc2dad Mon Sep 17 00:00:00 2001 From: Khushboo Verma <43381712+vermakhushboo@users.noreply.github.com> Date: Wed, 19 Mar 2025 16:22:38 +0530 Subject: [PATCH 2/4] Assert exception --- .../Services/Sites/SitesCustomServerTest.php | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/tests/e2e/Services/Sites/SitesCustomServerTest.php b/tests/e2e/Services/Sites/SitesCustomServerTest.php index 8c2a1c3970..ac6a74aeb5 100644 --- a/tests/e2e/Services/Sites/SitesCustomServerTest.php +++ b/tests/e2e/Services/Sites/SitesCustomServerTest.php @@ -2320,19 +2320,20 @@ class SitesCustomServerTest extends Scope $domain = $this->setupSiteDomain($siteId); $this->assertNotEmpty($domain); - $deploymentId = $this->setupDeployment($siteId, [ + $deployment = $this->createDeployment($siteId, [ 'code' => $this->packageSite('empty'), - 'activate' => 'true' + 'activate' => true ]); + $this->assertEquals(202, $deployment['headers']['status-code']); + + $deploymentId = $deployment['body']['$id']; $this->assertNotEmpty($deploymentId); - $site = $this->getSite($siteId); - $this->assertEquals('200', $site['headers']['status-code']); - - $proxyClient = new Client(); - $proxyClient->setEndpoint('http://' . $domain); - $response = $proxyClient->call(Client::METHOD_GET, '/'); - $this->assertEquals(200, $response['headers']['status-code']); + $this->assertEventually(function () use ($siteId, $deploymentId) { + $deployment = $this->getDeployment($siteId, $deploymentId); + $this->assertEquals('failed', $deployment['body']['status'], 'Deployment status is failed, deployment: ' . json_encode($deployment['body'], JSON_PRETTY_PRINT)); + $this->assertStringContainsString("ERROR: No source code found. Please ensure your source directory exists and isn't empty.", $deployment['body']['buildLogs']); + }, 100000, 500); $this->cleanupSite($siteId); } From 21f12879ef65960c557742c6e93b4ab962c8b669 Mon Sep 17 00:00:00 2001 From: Khushboo Verma <43381712+vermakhushboo@users.noreply.github.com> Date: Fri, 21 Mar 2025 12:11:29 +0530 Subject: [PATCH 3/4] Remove extra check --- tests/e2e/Services/Sites/SitesCustomServerTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/e2e/Services/Sites/SitesCustomServerTest.php b/tests/e2e/Services/Sites/SitesCustomServerTest.php index a6669d1e38..30bb73c40c 100644 --- a/tests/e2e/Services/Sites/SitesCustomServerTest.php +++ b/tests/e2e/Services/Sites/SitesCustomServerTest.php @@ -2363,7 +2363,6 @@ class SitesCustomServerTest extends Scope $this->assertEventually(function () use ($siteId, $deploymentId) { $deployment = $this->getDeployment($siteId, $deploymentId); $this->assertEquals('failed', $deployment['body']['status'], 'Deployment status is failed, deployment: ' . json_encode($deployment['body'], JSON_PRETTY_PRINT)); - $this->assertStringContainsString("ERROR: No source code found. Please ensure your source directory exists and isn't empty.", $deployment['body']['buildLogs']); }, 100000, 500); $this->cleanupSite($siteId); From baa1cb19c64f76492016537713aea8718b9742c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Mon, 14 Apr 2025 12:28:22 +0200 Subject: [PATCH 4/4] Re-add test, simplify --- composer.lock | 24 ++++++------ .../Services/Sites/SitesCustomServerTest.php | 37 +++++++++++++++++++ 2 files changed, 49 insertions(+), 12 deletions(-) diff --git a/composer.lock b/composer.lock index f33d83dc4c..f151523ffc 100644 --- a/composer.lock +++ b/composer.lock @@ -3705,16 +3705,16 @@ }, { "name": "utopia-php/fetch", - "version": "0.4.0", + "version": "0.4.1", "source": { "type": "git", "url": "https://github.com/utopia-php/fetch.git", - "reference": "46e791ff6a95864517750b9df6bbf4a17e3c9c4e" + "reference": "65095dac14037db0c822fb5e209e5bd3187a0303" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/fetch/zipball/46e791ff6a95864517750b9df6bbf4a17e3c9c4e", - "reference": "46e791ff6a95864517750b9df6bbf4a17e3c9c4e", + "url": "https://api.github.com/repos/utopia-php/fetch/zipball/65095dac14037db0c822fb5e209e5bd3187a0303", + "reference": "65095dac14037db0c822fb5e209e5bd3187a0303", "shasum": "" }, "require": { @@ -3738,9 +3738,9 @@ "description": "A simple library that provides an interface for making HTTP Requests.", "support": { "issues": "https://github.com/utopia-php/fetch/issues", - "source": "https://github.com/utopia-php/fetch/tree/0.4.0" + "source": "https://github.com/utopia-php/fetch/tree/0.4.1" }, - "time": "2025-03-11T21:06:56+00:00" + "time": "2025-04-14T07:34:27+00:00" }, { "name": "utopia-php/framework", @@ -3996,16 +3996,16 @@ }, { "name": "utopia-php/migration", - "version": "0.8.5", + "version": "0.8.6", "source": { "type": "git", "url": "https://github.com/utopia-php/migration.git", - "reference": "0dd95b148c581579ec05d2abbbdc13c2b4702331" + "reference": "84163e16edc0b2e64c34ad7b7c4cc5f05d762daf" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/migration/zipball/0dd95b148c581579ec05d2abbbdc13c2b4702331", - "reference": "0dd95b148c581579ec05d2abbbdc13c2b4702331", + "url": "https://api.github.com/repos/utopia-php/migration/zipball/84163e16edc0b2e64c34ad7b7c4cc5f05d762daf", + "reference": "84163e16edc0b2e64c34ad7b7c4cc5f05d762daf", "shasum": "" }, "require": { @@ -4046,9 +4046,9 @@ ], "support": { "issues": "https://github.com/utopia-php/migration/issues", - "source": "https://github.com/utopia-php/migration/tree/0.8.5" + "source": "https://github.com/utopia-php/migration/tree/0.8.6" }, - "time": "2025-04-09T05:21:09+00:00" + "time": "2025-04-14T08:22:09+00:00" }, { "name": "utopia-php/orchestration", diff --git a/tests/e2e/Services/Sites/SitesCustomServerTest.php b/tests/e2e/Services/Sites/SitesCustomServerTest.php index 35bc9bb410..ba0242bb20 100644 --- a/tests/e2e/Services/Sites/SitesCustomServerTest.php +++ b/tests/e2e/Services/Sites/SitesCustomServerTest.php @@ -9,6 +9,7 @@ use Tests\E2E\Client; use Tests\E2E\Scopes\ProjectCustom; use Tests\E2E\Scopes\Scope; use Tests\E2E\Scopes\SideServer; +use Utopia\CLI\Console; use Utopia\Database\Document; use Utopia\Database\Helpers\ID; use Utopia\Database\Query; @@ -2503,4 +2504,40 @@ class SitesCustomServerTest extends Scope $this->cleanupSite($siteId); } + + public function testEmptySiteSource(): void + { + $siteId = $this->setupSite([ + 'siteId' => ID::unique(), + 'name' => 'Empty source site', + 'framework' => 'other', + 'buildRuntime' => 'node-22', + 'outputDirectory' => './', + ]); + $this->assertNotEmpty($siteId); + + // Prepare empty site folder + // We cant use .gitkeep, because that would make deployment non-empty + $stdout = ''; + $stderr = ''; + $folderPath = realpath(__DIR__ . '/../../../resources/sites') . '/empty'; + Console::execute("mkdir -p $folderPath", '', $stdout, $stderr); + + $deployment = $this->createDeployment($siteId, [ + 'code' => $this->packageSite('empty'), + 'activate' => true + ]); + $this->assertEquals(202, $deployment['headers']['status-code']); + + $deploymentId = $deployment['body']['$id']; + $this->assertNotEmpty($deploymentId); + + $this->assertEventually(function () use ($siteId, $deploymentId) { + $deployment = $this->getDeployment($siteId, $deploymentId); + $this->assertEquals('failed', $deployment['body']['status'], 'Deployment status does not match: ' . json_encode($deployment['body'], JSON_PRETTY_PRINT)); + $this->assertStringContainsString('Error', $deployment['body']['buildLogs'], 'Deployment logs do not match: ' . json_encode($deployment['body'], JSON_PRETTY_PRINT)); + }, 100000, 500); + + $this->cleanupSite($siteId); + } }