From d7159ef483fa6a4756158d1b2961832c7d2b4c69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Fri, 22 Aug 2025 11:11:37 +0200 Subject: [PATCH 1/3] Add deploymentId to execution response model --- .../Utopia/Response/Model/Execution.php | 7 +++++ .../Functions/FunctionsCustomServerTest.php | 28 +++++++++++++++++-- .../Services/Sites/SitesCustomServerTest.php | 20 +++++++++++++ 3 files changed, 53 insertions(+), 2 deletions(-) diff --git a/src/Appwrite/Utopia/Response/Model/Execution.php b/src/Appwrite/Utopia/Response/Model/Execution.php index d7d30fe549..944f475bd1 100644 --- a/src/Appwrite/Utopia/Response/Model/Execution.php +++ b/src/Appwrite/Utopia/Response/Model/Execution.php @@ -38,12 +38,19 @@ class Execution extends Model 'example' => [Role::any()->toString()], 'array' => true, ]) + // TODO: Sites listLogs will not have this, and will need siteId instead ->addRule('functionId', [ 'type' => self::TYPE_STRING, 'description' => 'Function ID.', 'default' => '', 'example' => '5e5ea6g16897e', ]) + ->addRule('deploymentId', [ + 'type' => self::TYPE_STRING, + 'description' => 'Function\'s deployment ID used to create the execution.', + 'default' => '', + 'example' => '5e5ea5c16897e', + ]) ->addRule('trigger', [ 'type' => self::TYPE_STRING, 'description' => 'The trigger that caused the function to execute. Possible values can be: `http`, `schedule`, or `event`.', diff --git a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php index 6597f1af69..9d2e731d06 100644 --- a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php +++ b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php @@ -945,6 +945,29 @@ class FunctionsCustomServerTest extends Scope $this->assertEquals(1, $executions['body']['total']); $this->assertIsArray($executions['body']['executions']); $this->assertCount(1, $executions['body']['executions']); + $this->assertEquals($data['deploymentId'], $executions['body']['executions'][0]['deploymentId']); + + $executions = $this->listExecutions($data['functionId'], [ + 'queries' => [ + Query::equal('deploymentId', [$data['deploymentId']])->toString(), + ], + ]); + + $this->assertEquals(200, $executions['headers']['status-code']); + $this->assertEquals(1, $executions['body']['total']); + $this->assertIsArray($executions['body']['executions']); + $this->assertCount(1, $executions['body']['executions']); + + $executions = $this->listExecutions($data['functionId'], [ + 'queries' => [ + Query::equal('deploymentId', ['some-random-id'])->toString(), + ], + ]); + + $this->assertEquals(200, $executions['headers']['status-code']); + $this->assertEquals(0, $executions['body']['total']); + $this->assertIsArray($executions['body']['executions']); + $this->assertCount(0, $executions['body']['executions']); $executions = $this->listExecutions($data['functionId'], [ 'queries' => [ @@ -1034,8 +1057,9 @@ class FunctionsCustomServerTest extends Scope */ $execution = $this->getExecution($data['functionId'], $data['executionId']); - $this->assertEquals($execution['headers']['status-code'], 200); - $this->assertEquals($execution['body']['$id'], $data['executionId']); + $this->assertEquals(200, $execution['headers']['status-code']); + $this->assertEquals($data['executionId'], $execution['body']['$id']); + $this->assertEquals($data['deploymentId'], $execution['body']['deploymentId']); /** * Test for FAILURE diff --git a/tests/e2e/Services/Sites/SitesCustomServerTest.php b/tests/e2e/Services/Sites/SitesCustomServerTest.php index f76122c00a..33578485d2 100644 --- a/tests/e2e/Services/Sites/SitesCustomServerTest.php +++ b/tests/e2e/Services/Sites/SitesCustomServerTest.php @@ -1887,6 +1887,7 @@ class SitesCustomServerTest extends Scope Query::limit(1)->toString(), ]); $this->assertEquals(200, $logs['headers']['status-code']); + $this->assertStringContainsString($deploymentId, $logs['body']['executions'][0]['deploymentId']); $this->assertStringContainsString("GET", $logs['body']['executions'][0]['requestMethod']); $this->assertStringContainsString("/logs-inline", $logs['body']['executions'][0]['requestPath']); $this->assertStringContainsString("Log1", $logs['body']['executions'][0]['logs']); @@ -1895,6 +1896,24 @@ class SitesCustomServerTest extends Scope $this->assertStringContainsString("Error2", $logs['body']['executions'][0]['errors']); $log1Id = $logs['body']['executions'][0]['$id']; $this->assertNotEmpty($log1Id); + + $logs = $this->listLogs($siteId, [ + Query::orderDesc('$createdAt')->toString(), + Query::limit(1)->toString(), + Query::equal('deploymentId', [$deploymentId])->toString() + ]); + $this->assertEquals(200, $logs['headers']['status-code']); + $this->assertEquals(1, $logs['body']['total']); + $this->assertCount(1, $logs['body']['executions']); + + $logs = $this->listLogs($siteId, [ + Query::orderDesc('$createdAt')->toString(), + Query::limit(1)->toString(), + Query::equal('deploymentId', ['some-random-id'])->toString() + ]); + $this->assertEquals(200, $logs['headers']['status-code']); + $this->assertEquals(0, $logs['body']['total']); + $this->assertCount(0, $logs['body']['executions']); $response = $proxyClient->call(Client::METHOD_GET, '/logs-action'); $this->assertEquals(200, $response['headers']['status-code']); @@ -1905,6 +1924,7 @@ class SitesCustomServerTest extends Scope Query::limit(1)->toString(), ]); $this->assertEquals(200, $logs['headers']['status-code']); + $this->assertStringContainsString($deploymentId, $logs['body']['executions'][0]['deploymentId']); $this->assertStringContainsString("GET", $logs['body']['executions'][0]['requestMethod']); $this->assertStringContainsString("/logs-action", $logs['body']['executions'][0]['requestPath']); $this->assertStringContainsString("Log1", $logs['body']['executions'][0]['logs']); From ebf48655a0cf08ca13af3d072515f15d613c4caf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Fri, 22 Aug 2025 11:16:18 +0200 Subject: [PATCH 2/3] Formatting fix --- tests/e2e/Services/Sites/SitesCustomServerTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/e2e/Services/Sites/SitesCustomServerTest.php b/tests/e2e/Services/Sites/SitesCustomServerTest.php index 33578485d2..73935d9f81 100644 --- a/tests/e2e/Services/Sites/SitesCustomServerTest.php +++ b/tests/e2e/Services/Sites/SitesCustomServerTest.php @@ -1896,7 +1896,7 @@ class SitesCustomServerTest extends Scope $this->assertStringContainsString("Error2", $logs['body']['executions'][0]['errors']); $log1Id = $logs['body']['executions'][0]['$id']; $this->assertNotEmpty($log1Id); - + $logs = $this->listLogs($siteId, [ Query::orderDesc('$createdAt')->toString(), Query::limit(1)->toString(), @@ -1905,7 +1905,7 @@ class SitesCustomServerTest extends Scope $this->assertEquals(200, $logs['headers']['status-code']); $this->assertEquals(1, $logs['body']['total']); $this->assertCount(1, $logs['body']['executions']); - + $logs = $this->listLogs($siteId, [ Query::orderDesc('$createdAt')->toString(), Query::limit(1)->toString(), From 011a9cb7a36d9693dedd8d6348592efdea8b2cf5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Fri, 22 Aug 2025 11:31:14 +0200 Subject: [PATCH 3/3] Fix tests --- tests/e2e/Services/Sites/SitesCustomServerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/e2e/Services/Sites/SitesCustomServerTest.php b/tests/e2e/Services/Sites/SitesCustomServerTest.php index 73935d9f81..0e792d6c36 100644 --- a/tests/e2e/Services/Sites/SitesCustomServerTest.php +++ b/tests/e2e/Services/Sites/SitesCustomServerTest.php @@ -1903,7 +1903,7 @@ class SitesCustomServerTest extends Scope Query::equal('deploymentId', [$deploymentId])->toString() ]); $this->assertEquals(200, $logs['headers']['status-code']); - $this->assertEquals(1, $logs['body']['total']); + $this->assertGreaterThanOrEqual(1, $logs['body']['total']); $this->assertCount(1, $logs['body']['executions']); $logs = $this->listLogs($siteId, [