From 41743b12997607195c37d1ef1b7d2f22d0a0cbad Mon Sep 17 00:00:00 2001 From: Mayank Agarwal Date: Mon, 19 May 2025 20:55:41 +0530 Subject: [PATCH 1/6] Add solution for function domain --- app/controllers/general.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/app/controllers/general.php b/app/controllers/general.php index 40f861ad8c..7eef9c3bb6 100644 --- a/app/controllers/general.php +++ b/app/controllers/general.php @@ -615,10 +615,19 @@ function router(App $utopia, Database $dbForPlatform, callable $getProjectDB, Sw } } + $maxLogLength = 100000; + $logs = $executionResponse['logs'] ?? ''; + $logsTruncated = false; + + if (\is_string($logs) && \strlen($logs) > $maxLogLength) { + $logs = \substr($logs, 0, $maxLogLength) . "\n[WARNING] Logs truncated. The output exceeded {$maxLogLength} characters."; + $logsTruncated = true; + } + /** Update execution status */ $status = $executionResponse['statusCode'] >= 500 ? 'failed' : 'completed'; $execution->setAttribute('status', $status); - $execution->setAttribute('logs', $executionResponse['logs']); + $execution->setAttribute('logs', $logs); $execution->setAttribute('errors', $executionResponse['errors']); $execution->setAttribute('responseStatusCode', $executionResponse['statusCode']); $execution->setAttribute('responseHeaders', $headersFiltered); From 492ff10ee7b8d3e7022387702587e0b3a1459d6e Mon Sep 17 00:00:00 2001 From: Mayank Agarwal Date: Mon, 19 May 2025 20:52:49 +0530 Subject: [PATCH 2/6] Add async=false solution --- .../Modules/Functions/Http/Executions/Create.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Executions/Create.php b/src/Appwrite/Platform/Modules/Functions/Http/Executions/Create.php index ef31d5a79c..0cebb986e2 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Executions/Create.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Executions/Create.php @@ -423,12 +423,21 @@ class Create extends Base } } + $maxLogLength = 100000; + $logs = $executionResponse['logs'] ?? ''; + $logsTruncated = false; + + if (\is_string($logs) && \strlen($logs) > $maxLogLength) { + $logs = \substr($logs, 0, $maxLogLength) . "\n[WARNING] Logs truncated. The output exceeded {$maxLogLength} characters."; + $logsTruncated = true; + } + /** Update execution status */ $status = $executionResponse['statusCode'] >= 500 ? 'failed' : 'completed'; $execution->setAttribute('status', $status); $execution->setAttribute('responseStatusCode', $executionResponse['statusCode']); $execution->setAttribute('responseHeaders', $headersFiltered); - $execution->setAttribute('logs', $executionResponse['logs']); + $execution->setAttribute('logs', $logs); $execution->setAttribute('errors', $executionResponse['errors']); $execution->setAttribute('duration', $executionResponse['duration']); } catch (\Throwable $th) { From 7e292813bc460f952868230ede45f2417f3ed439 Mon Sep 17 00:00:00 2001 From: Mayank Agarwal Date: Fri, 16 May 2025 15:40:59 +0530 Subject: [PATCH 3/6] Truncate logs in function worker --- src/Appwrite/Platform/Workers/Functions.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/Appwrite/Platform/Workers/Functions.php b/src/Appwrite/Platform/Workers/Functions.php index 2e25248d9a..ea30a0b8ff 100644 --- a/src/Appwrite/Platform/Workers/Functions.php +++ b/src/Appwrite/Platform/Workers/Functions.php @@ -549,15 +549,25 @@ class Functions extends Action $headersFiltered[] = [ 'name' => $key, 'value' => $value ]; } } + + $maxLogLength = 100000; + $logs = $executionResponse['logs'] ?? ''; + $logsTruncated = false; + + if (\is_string($logs) && \strlen($logs) > $maxLogLength) { + $logs = \substr($logs, 0, $maxLogLength) . "\n[WARNING] Logs truncated. The output exceeded {$maxLogLength} characters."; + $logsTruncated = true; + } /** Update execution status */ $execution ->setAttribute('status', $status) ->setAttribute('responseStatusCode', $executionResponse['statusCode']) ->setAttribute('responseHeaders', $headersFiltered) - ->setAttribute('logs', $executionResponse['logs']) - ->setAttribute('errors', $executionResponse['errors']) + ->setAttribute('logs', $logs) + ->setAttribute('errors', $executionResponse['errors'] . ($logsTruncated ? "\n[WARNING] Logs were truncated." : '')) ->setAttribute('duration', $executionResponse['duration']); + } catch (\Throwable $th) { $durationEnd = \microtime(true); $execution From 1bd6b6452cd468d99477ed8177d94eb6962cb371 Mon Sep 17 00:00:00 2001 From: Khushboo Verma Date: Wed, 20 Aug 2025 18:53:55 +0530 Subject: [PATCH 4/6] Fix PR changes --- app/controllers/general.php | 10 ++++--- app/init/constants.php | 1 + .../Functions/Http/Executions/Create.php | 9 +++--- src/Appwrite/Platform/Workers/Functions.php | 13 ++++---- .../Functions/FunctionsCustomServerTest.php | 30 +++++++++++++++++++ .../functions/log-truncation/index.js | 13 ++++++++ 6 files changed, 62 insertions(+), 14 deletions(-) create mode 100644 tests/resources/functions/log-truncation/index.js diff --git a/app/controllers/general.php b/app/controllers/general.php index 7eef9c3bb6..4753999fd7 100644 --- a/app/controllers/general.php +++ b/app/controllers/general.php @@ -615,13 +615,15 @@ function router(App $utopia, Database $dbForPlatform, callable $getProjectDB, Sw } } - $maxLogLength = 100000; + // Truncate logs if they exceed the limit + $maxLogLength = APP_FUNCTION_LOG_LENGTH_LIMIT; $logs = $executionResponse['logs'] ?? ''; - $logsTruncated = false; if (\is_string($logs) && \strlen($logs) > $maxLogLength) { - $logs = \substr($logs, 0, $maxLogLength) . "\n[WARNING] Logs truncated. The output exceeded {$maxLogLength} characters."; - $logsTruncated = true; + $warningMessage = "\n[WARNING] Logs truncated. The output exceeded {$maxLogLength} characters."; + $warningLength = \strlen($warningMessage); + $maxContentLength = $maxLogLength - $warningLength; + $logs = \substr($logs, 0, $maxContentLength) . $warningMessage; } /** Update execution status */ diff --git a/app/init/constants.php b/app/init/constants.php index 62d9f16853..40a23c8fef 100644 --- a/app/init/constants.php +++ b/app/init/constants.php @@ -143,6 +143,7 @@ const APP_AUTH_TYPE_KEY = 'Key'; const APP_AUTH_TYPE_ADMIN = 'Admin'; // Response related const MAX_OUTPUT_CHUNK_SIZE = 10 * 1024 * 1024; // 10MB +const APP_FUNCTION_LOG_LENGTH_LIMIT = 1000000; // Function headers const FUNCTION_ALLOWLIST_HEADERS_REQUEST = ['content-type', 'agent', 'content-length', 'host']; const FUNCTION_ALLOWLIST_HEADERS_RESPONSE = ['content-type', 'content-length']; diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Executions/Create.php b/src/Appwrite/Platform/Modules/Functions/Http/Executions/Create.php index 0cebb986e2..9a475bb257 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Executions/Create.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Executions/Create.php @@ -423,13 +423,14 @@ class Create extends Base } } - $maxLogLength = 100000; + $maxLogLength = APP_FUNCTION_LOG_LENGTH_LIMIT; $logs = $executionResponse['logs'] ?? ''; - $logsTruncated = false; if (\is_string($logs) && \strlen($logs) > $maxLogLength) { - $logs = \substr($logs, 0, $maxLogLength) . "\n[WARNING] Logs truncated. The output exceeded {$maxLogLength} characters."; - $logsTruncated = true; + $warningMessage = "\n[WARNING] Logs truncated. The output exceeded {$maxLogLength} characters."; + $warningLength = \strlen($warningMessage); + $maxContentLength = $maxLogLength - $warningLength; + $logs = \substr($logs, 0, $maxContentLength) . $warningMessage; } /** Update execution status */ diff --git a/src/Appwrite/Platform/Workers/Functions.php b/src/Appwrite/Platform/Workers/Functions.php index ea30a0b8ff..48313a2f8f 100644 --- a/src/Appwrite/Platform/Workers/Functions.php +++ b/src/Appwrite/Platform/Workers/Functions.php @@ -549,14 +549,15 @@ class Functions extends Action $headersFiltered[] = [ 'name' => $key, 'value' => $value ]; } } - - $maxLogLength = 100000; + + $maxLogLength = APP_FUNCTION_LOG_LENGTH_LIMIT; $logs = $executionResponse['logs'] ?? ''; - $logsTruncated = false; if (\is_string($logs) && \strlen($logs) > $maxLogLength) { - $logs = \substr($logs, 0, $maxLogLength) . "\n[WARNING] Logs truncated. The output exceeded {$maxLogLength} characters."; - $logsTruncated = true; + $warningMessage = "\n[WARNING] Logs truncated. The output exceeded {$maxLogLength} characters."; + $warningLength = \strlen($warningMessage); + $maxContentLength = $maxLogLength - $warningLength; + $logs = \substr($logs, 0, $maxContentLength) . $warningMessage; } /** Update execution status */ @@ -565,7 +566,7 @@ class Functions extends Action ->setAttribute('responseStatusCode', $executionResponse['statusCode']) ->setAttribute('responseHeaders', $headersFiltered) ->setAttribute('logs', $logs) - ->setAttribute('errors', $executionResponse['errors'] . ($logsTruncated ? "\n[WARNING] Logs were truncated." : '')) + ->setAttribute('errors', $executionResponse['errors']) ->setAttribute('duration', $executionResponse['duration']); } catch (\Throwable $th) { diff --git a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php index ff99033fdf..955635118b 100644 --- a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php +++ b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php @@ -2282,4 +2282,34 @@ class FunctionsCustomServerTest extends Scope $this->cleanupFunction($functionId); } + + public function testLogTruncation(): void + { + $functionId = $this->setupFunction([ + 'functionId' => ID::unique(), + 'name' => 'Test Log Truncation', + 'runtime' => 'node-22', + 'entrypoint' => 'index.js', + 'timeout' => 15, + ]); + + $this->setupDeployment($functionId, [ + 'code' => $this->packageFunction('log-truncation'), + 'activate' => true + ]); + + $execution = $this->createExecution($functionId, [ + 'async' => 'false' + ]); + + $this->assertEquals(201, $execution['headers']['status-code']); + $this->assertEquals(200, $execution['body']['responseStatusCode']); + + // Verify logs are truncated and warning message is present + $logs = $execution['body']['logs']; + $this->assertLessThanOrEqual(APP_FUNCTION_LOG_LENGTH_LIMIT, strlen($logs)); + $this->assertStringContainsString('[WARNING] Logs truncated', $logs); + + $this->cleanupFunction($functionId); + } } diff --git a/tests/resources/functions/log-truncation/index.js b/tests/resources/functions/log-truncation/index.js new file mode 100644 index 0000000000..b124cfa3dc --- /dev/null +++ b/tests/resources/functions/log-truncation/index.js @@ -0,0 +1,13 @@ +module.exports = async(context) => { + // Create a string that is 1000001 characters long (exceeds the 1000000 limit) + const longString = 'a'.repeat(1000001); + + context.log(longString); + + return context.res.json({ + motto: 'Build like a team of hundreds_', + learn: 'https://appwrite.io/docs', + connect: 'https://appwrite.io/discord', + getInspired: 'https://builtwith.appwrite.io', + }); + }; \ No newline at end of file From bc47ac7caaf41a4d788df84796acb7a6c5616a75 Mon Sep 17 00:00:00 2001 From: Khushboo Verma Date: Thu, 21 Aug 2025 12:49:31 +0530 Subject: [PATCH 5/6] Truncate logs and errors from beginning --- app/config/collections/projects.php | 4 +- app/controllers/general.php | 17 ++++++-- app/init/constants.php | 1 + .../Functions/Http/Executions/Create.php | 17 ++++++-- src/Appwrite/Platform/Workers/Functions.php | 17 ++++++-- .../Functions/FunctionsCustomServerTest.php | 40 ++++++++++++++++++- .../functions/error-truncation/index.js | 7 ++++ .../functions/log-truncation/index.js | 2 +- 8 files changed, 91 insertions(+), 14 deletions(-) create mode 100644 tests/resources/functions/error-truncation/index.js diff --git a/app/config/collections/projects.php b/app/config/collections/projects.php index ac14421382..3cda1a619e 100644 --- a/app/config/collections/projects.php +++ b/app/config/collections/projects.php @@ -1917,7 +1917,7 @@ return [ '$id' => ID::custom('errors'), 'type' => Database::VAR_STRING, 'format' => '', - 'size' => 1000000, + 'size' => APP_FUNCTION_ERROR_LENGTH_LIMIT, 'signed' => true, 'required' => false, 'default' => null, @@ -1928,7 +1928,7 @@ return [ '$id' => ID::custom('logs'), 'type' => Database::VAR_STRING, 'format' => '', - 'size' => 1000000, + 'size' => APP_FUNCTION_LOG_LENGTH_LIMIT, 'signed' => true, 'required' => false, 'default' => null, diff --git a/app/controllers/general.php b/app/controllers/general.php index 4753999fd7..b6c9df5577 100644 --- a/app/controllers/general.php +++ b/app/controllers/general.php @@ -620,17 +620,28 @@ function router(App $utopia, Database $dbForPlatform, callable $getProjectDB, Sw $logs = $executionResponse['logs'] ?? ''; if (\is_string($logs) && \strlen($logs) > $maxLogLength) { - $warningMessage = "\n[WARNING] Logs truncated. The output exceeded {$maxLogLength} characters."; + $warningMessage = "[WARNING] Logs truncated. The output exceeded {$maxLogLength} characters.\n"; $warningLength = \strlen($warningMessage); $maxContentLength = $maxLogLength - $warningLength; - $logs = \substr($logs, 0, $maxContentLength) . $warningMessage; + $logs = $warningMessage . \substr($logs, -$maxContentLength); + } + + // Truncate errors if they exceed the limit + $maxErrorLength = APP_FUNCTION_ERROR_LENGTH_LIMIT; + $errors = $executionResponse['errors'] ?? ''; + + if (\is_string($errors) && \strlen($errors) > $maxErrorLength) { + $warningMessage = "[WARNING] Errors truncated. The output exceeded {$maxErrorLength} characters.\n"; + $warningLength = \strlen($warningMessage); + $maxContentLength = $maxErrorLength - $warningLength; + $errors = $warningMessage . \substr($errors, -$maxContentLength); } /** Update execution status */ $status = $executionResponse['statusCode'] >= 500 ? 'failed' : 'completed'; $execution->setAttribute('status', $status); $execution->setAttribute('logs', $logs); - $execution->setAttribute('errors', $executionResponse['errors']); + $execution->setAttribute('errors', $errors); $execution->setAttribute('responseStatusCode', $executionResponse['statusCode']); $execution->setAttribute('responseHeaders', $headersFiltered); $execution->setAttribute('duration', $executionResponse['duration']); diff --git a/app/init/constants.php b/app/init/constants.php index 40a23c8fef..689ab69fa4 100644 --- a/app/init/constants.php +++ b/app/init/constants.php @@ -144,6 +144,7 @@ const APP_AUTH_TYPE_ADMIN = 'Admin'; // Response related const MAX_OUTPUT_CHUNK_SIZE = 10 * 1024 * 1024; // 10MB const APP_FUNCTION_LOG_LENGTH_LIMIT = 1000000; +const APP_FUNCTION_ERROR_LENGTH_LIMIT = 1000000; // Function headers const FUNCTION_ALLOWLIST_HEADERS_REQUEST = ['content-type', 'agent', 'content-length', 'host']; const FUNCTION_ALLOWLIST_HEADERS_RESPONSE = ['content-type', 'content-length']; diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Executions/Create.php b/src/Appwrite/Platform/Modules/Functions/Http/Executions/Create.php index 9a475bb257..64056b7db7 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Executions/Create.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Executions/Create.php @@ -427,10 +427,21 @@ class Create extends Base $logs = $executionResponse['logs'] ?? ''; if (\is_string($logs) && \strlen($logs) > $maxLogLength) { - $warningMessage = "\n[WARNING] Logs truncated. The output exceeded {$maxLogLength} characters."; + $warningMessage = "[WARNING] Logs truncated. The output exceeded {$maxLogLength} characters.\n"; $warningLength = \strlen($warningMessage); $maxContentLength = $maxLogLength - $warningLength; - $logs = \substr($logs, 0, $maxContentLength) . $warningMessage; + $logs = $warningMessage . \substr($logs, -$maxContentLength); + } + + // Truncate errors if they exceed the limit + $maxErrorLength = APP_FUNCTION_ERROR_LENGTH_LIMIT; + $errors = $executionResponse['errors'] ?? ''; + + if (\is_string($errors) && \strlen($errors) > $maxErrorLength) { + $warningMessage = "[WARNING] Errors truncated. The output exceeded {$maxErrorLength} characters.\n"; + $warningLength = \strlen($warningMessage); + $maxContentLength = $maxErrorLength - $warningLength; + $errors = $warningMessage . \substr($errors, -$maxContentLength); } /** Update execution status */ @@ -439,7 +450,7 @@ class Create extends Base $execution->setAttribute('responseStatusCode', $executionResponse['statusCode']); $execution->setAttribute('responseHeaders', $headersFiltered); $execution->setAttribute('logs', $logs); - $execution->setAttribute('errors', $executionResponse['errors']); + $execution->setAttribute('errors', $errors); $execution->setAttribute('duration', $executionResponse['duration']); } catch (\Throwable $th) { $durationEnd = \microtime(true); diff --git a/src/Appwrite/Platform/Workers/Functions.php b/src/Appwrite/Platform/Workers/Functions.php index 48313a2f8f..864d6451b8 100644 --- a/src/Appwrite/Platform/Workers/Functions.php +++ b/src/Appwrite/Platform/Workers/Functions.php @@ -554,10 +554,21 @@ class Functions extends Action $logs = $executionResponse['logs'] ?? ''; if (\is_string($logs) && \strlen($logs) > $maxLogLength) { - $warningMessage = "\n[WARNING] Logs truncated. The output exceeded {$maxLogLength} characters."; + $warningMessage = "[WARNING] Logs truncated. The output exceeded {$maxLogLength} characters.\n"; $warningLength = \strlen($warningMessage); $maxContentLength = $maxLogLength - $warningLength; - $logs = \substr($logs, 0, $maxContentLength) . $warningMessage; + $logs = $warningMessage . \substr($logs, -$maxContentLength); + } + + // Truncate errors if they exceed the limit + $maxErrorLength = APP_FUNCTION_ERROR_LENGTH_LIMIT; + $errors = $executionResponse['errors'] ?? ''; + + if (\is_string($errors) && \strlen($errors) > $maxErrorLength) { + $warningMessage = "[WARNING] Errors truncated. The output exceeded {$maxErrorLength} characters.\n"; + $warningLength = \strlen($warningMessage); + $maxContentLength = $maxErrorLength - $warningLength; + $errors = $warningMessage . \substr($errors, -$maxContentLength); } /** Update execution status */ @@ -566,7 +577,7 @@ class Functions extends Action ->setAttribute('responseStatusCode', $executionResponse['statusCode']) ->setAttribute('responseHeaders', $headersFiltered) ->setAttribute('logs', $logs) - ->setAttribute('errors', $executionResponse['errors']) + ->setAttribute('errors', $errors) ->setAttribute('duration', $executionResponse['duration']); } catch (\Throwable $th) { diff --git a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php index 955635118b..e0d87023d1 100644 --- a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php +++ b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php @@ -2305,10 +2305,46 @@ class FunctionsCustomServerTest extends Scope $this->assertEquals(201, $execution['headers']['status-code']); $this->assertEquals(200, $execution['body']['responseStatusCode']); - // Verify logs are truncated and warning message is present + // Verify logs are truncated and warning message is present at the beginning $logs = $execution['body']['logs']; $this->assertLessThanOrEqual(APP_FUNCTION_LOG_LENGTH_LIMIT, strlen($logs)); - $this->assertStringContainsString('[WARNING] Logs truncated', $logs); + $this->assertStringStartsWith('[WARNING] Logs truncated', $logs); + + $this->assertStringNotContainsString('z', $logs); + $this->assertStringContainsString('a', $logs); + + $this->cleanupFunction($functionId); + } + + public function testErrorTruncation(): void + { + $functionId = $this->setupFunction([ + 'functionId' => ID::unique(), + 'name' => 'Test Error Truncation', + 'runtime' => 'node-22', + 'entrypoint' => 'index.js', + 'timeout' => 15, + ]); + + $this->setupDeployment($functionId, [ + 'code' => $this->packageFunction('error-truncation'), + 'activate' => true + ]); + + $execution = $this->createExecution($functionId, [ + 'async' => 'false' + ]); + + $this->assertEquals(201, $execution['headers']['status-code']); + $this->assertEquals(500, $execution['body']['responseStatusCode']); + + // Verify errors are truncated and warning message is present at the beginning + $errors = $execution['body']['errors']; + $this->assertLessThanOrEqual(APP_FUNCTION_ERROR_LENGTH_LIMIT, strlen($errors)); + $this->assertStringStartsWith('[WARNING] Errors truncated', $errors); + + $this->assertStringNotContainsString('z', $errors); + $this->assertStringContainsString('a', $errors); $this->cleanupFunction($functionId); } diff --git a/tests/resources/functions/error-truncation/index.js b/tests/resources/functions/error-truncation/index.js new file mode 100644 index 0000000000..8bc08ed581 --- /dev/null +++ b/tests/resources/functions/error-truncation/index.js @@ -0,0 +1,7 @@ +module.exports = async(context) => { + // Create a string that is 1000001 characters long (exceeds the 1000000 limit) + const longString = 'z' + 'a'.repeat(1000000); + + // Throw an error with the long string + throw new Error(longString); + }; diff --git a/tests/resources/functions/log-truncation/index.js b/tests/resources/functions/log-truncation/index.js index b124cfa3dc..4df2593cf1 100644 --- a/tests/resources/functions/log-truncation/index.js +++ b/tests/resources/functions/log-truncation/index.js @@ -1,6 +1,6 @@ module.exports = async(context) => { // Create a string that is 1000001 characters long (exceeds the 1000000 limit) - const longString = 'a'.repeat(1000001); + const longString = 'z' + 'a'.repeat(1000000); context.log(longString); From 10eed78b7343eb69e413086c3f0af1268fa122a6 Mon Sep 17 00:00:00 2001 From: Khushboo Verma Date: Thu, 21 Aug 2025 14:32:48 +0530 Subject: [PATCH 6/6] Test truncation in one test --- .../Functions/FunctionsCustomServerTest.php | 29 ++----------------- .../functions/error-truncation/index.js | 7 ----- .../index.js | 1 + 3 files changed, 3 insertions(+), 34 deletions(-) delete mode 100644 tests/resources/functions/error-truncation/index.js rename tests/resources/functions/{log-truncation => log-error-truncation}/index.js (93%) diff --git a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php index e0d87023d1..6597f1af69 100644 --- a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php +++ b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php @@ -2283,7 +2283,7 @@ class FunctionsCustomServerTest extends Scope $this->cleanupFunction($functionId); } - public function testLogTruncation(): void + public function testLogAndErrorTruncation(): void { $functionId = $this->setupFunction([ 'functionId' => ID::unique(), @@ -2294,7 +2294,7 @@ class FunctionsCustomServerTest extends Scope ]); $this->setupDeployment($functionId, [ - 'code' => $this->packageFunction('log-truncation'), + 'code' => $this->packageFunction('log-error-truncation'), 'activate' => true ]); @@ -2313,31 +2313,6 @@ class FunctionsCustomServerTest extends Scope $this->assertStringNotContainsString('z', $logs); $this->assertStringContainsString('a', $logs); - $this->cleanupFunction($functionId); - } - - public function testErrorTruncation(): void - { - $functionId = $this->setupFunction([ - 'functionId' => ID::unique(), - 'name' => 'Test Error Truncation', - 'runtime' => 'node-22', - 'entrypoint' => 'index.js', - 'timeout' => 15, - ]); - - $this->setupDeployment($functionId, [ - 'code' => $this->packageFunction('error-truncation'), - 'activate' => true - ]); - - $execution = $this->createExecution($functionId, [ - 'async' => 'false' - ]); - - $this->assertEquals(201, $execution['headers']['status-code']); - $this->assertEquals(500, $execution['body']['responseStatusCode']); - // Verify errors are truncated and warning message is present at the beginning $errors = $execution['body']['errors']; $this->assertLessThanOrEqual(APP_FUNCTION_ERROR_LENGTH_LIMIT, strlen($errors)); diff --git a/tests/resources/functions/error-truncation/index.js b/tests/resources/functions/error-truncation/index.js deleted file mode 100644 index 8bc08ed581..0000000000 --- a/tests/resources/functions/error-truncation/index.js +++ /dev/null @@ -1,7 +0,0 @@ -module.exports = async(context) => { - // Create a string that is 1000001 characters long (exceeds the 1000000 limit) - const longString = 'z' + 'a'.repeat(1000000); - - // Throw an error with the long string - throw new Error(longString); - }; diff --git a/tests/resources/functions/log-truncation/index.js b/tests/resources/functions/log-error-truncation/index.js similarity index 93% rename from tests/resources/functions/log-truncation/index.js rename to tests/resources/functions/log-error-truncation/index.js index 4df2593cf1..7e94fa5028 100644 --- a/tests/resources/functions/log-truncation/index.js +++ b/tests/resources/functions/log-error-truncation/index.js @@ -3,6 +3,7 @@ module.exports = async(context) => { const longString = 'z' + 'a'.repeat(1000000); context.log(longString); + context.error(longString); return context.res.json({ motto: 'Build like a team of hundreds_',