From 7d785e7963eee062036c5cbdadea1d729088fc9b Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Mon, 15 Jun 2026 19:12:27 +0400 Subject: [PATCH 01/31] fix: disable build cache --- src/Appwrite/Platform/Modules/Functions/Workers/Builds.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php b/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php index 2550db36e2..d01d82e2e7 100644 --- a/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php +++ b/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php @@ -732,7 +732,8 @@ class Builds extends Action variables: $vars, command: $command, outputDirectory: $outputDirectory ?? '', - cacheKey: $cacheKey + // temporarily disable build cache + // cacheKey: $cacheKey ); } catch (ExecutorTimeout $error) { From 4a9e9e050895ab4025c67a2d99ba1ee5a811ee3c Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Mon, 15 Jun 2026 19:29:45 +0400 Subject: [PATCH 02/31] fix: remove unused build cache capture --- src/Appwrite/Platform/Modules/Functions/Workers/Builds.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php b/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php index d01d82e2e7..3c8219cdf5 100644 --- a/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php +++ b/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php @@ -704,7 +704,7 @@ class Builds extends Action $span = Span::current(); Co::join([ - Co\go(function () use ($executor, &$response, $project, $deployment, $source, $resource, $runtime, $vars, $command, $cacheKey, $cpus, $memory, $timeout, &$err, $version, $span) { + Co\go(function () use ($executor, &$response, $project, $deployment, $source, $resource, $runtime, $vars, $command, $cpus, $memory, $timeout, &$err, $version, $span) { try { if ($version === 'v2') { $command = 'tar -zxf /tmp/code.tar.gz -C /usr/code && cd /usr/local/src/ && ./build.sh'; From fac754c6560876c560907694e5c29a5795fcdb73 Mon Sep 17 00:00:00 2001 From: Chirag Aggarwal Date: Tue, 16 Jun 2026 12:27:41 +0530 Subject: [PATCH 03/31] Add mails and messaging telemetry: send counters and span attributes (#12590) * (feat): add mails and messaging send telemetry counters and span attributes * (fix): address review - optional telemetry injection, cached counter, snake_case metric attribute * Update messaging telemetry integration * Move mails telemetry to messaging library * Restore mails worker spacing * Use constants for mail templates --- app/controllers/api/account.php | 4 ++ app/init/constants.php | 11 ++++ composer.json | 2 +- composer.lock | 17 ++++--- src/Appwrite/Bus/Listeners/Mails.php | 1 + src/Appwrite/Event/Message/Mail.php | 3 ++ .../Http/Account/MFA/Challenges/Create.php | 1 + .../Http/Project/SMTP/Tests/Create.php | 1 + .../Modules/Teams/Http/Memberships/Create.php | 1 + .../Platform/Workers/Certificates.php | 1 + src/Appwrite/Platform/Workers/Mails.php | 18 ++++++- src/Appwrite/Platform/Workers/Messaging.php | 50 +++++++++++++++++-- src/Appwrite/Platform/Workers/Migrations.php | 1 + src/Appwrite/Platform/Workers/Webhooks.php | 1 + tests/unit/Messaging/MessagingFanoutTest.php | 1 + 15 files changed, 98 insertions(+), 15 deletions(-) diff --git a/app/controllers/api/account.php b/app/controllers/api/account.php index a050e97b17..5ecae9c635 100644 --- a/app/controllers/api/account.php +++ b/app/controllers/api/account.php @@ -2405,6 +2405,7 @@ Http::post('/v1/account/tokens/magic-url') project: $project, recipient: $email, subject: $subject, + template: MAIL_TEMPLATE_MAGIC_URL, body: $body, preview: $preview, smtp: $smtpConfig, @@ -2751,6 +2752,7 @@ Http::post('/v1/account/tokens/email') project: $project, recipient: $email, subject: $subject, + template: MAIL_TEMPLATE_OTP, bodyTemplate: $bodyTemplate, body: $body, preview: $preview, @@ -3868,6 +3870,7 @@ Http::post('/v1/account/recovery') recipient: $profile->getAttribute('email', ''), name: $profile->getAttribute('name', ''), subject: $subject, + template: MAIL_TEMPLATE_RECOVERY, body: $body, preview: $preview, smtp: $smtpConfig, @@ -4222,6 +4225,7 @@ Http::post('/v1/account/verifications/email') recipient: $user->getAttribute('email'), name: $user->getAttribute('name') ?? '', subject: $subject, + template: MAIL_TEMPLATE_VERIFICATION, bodyTemplate: $bodyTemplate, body: $body, preview: $preview, diff --git a/app/init/constants.php b/app/init/constants.php index 4fe7c418a9..66d56a321c 100644 --- a/app/init/constants.php +++ b/app/init/constants.php @@ -271,6 +271,17 @@ const FUNCTION_ALLOWLIST_HEADERS_RESPONSE = ['content-type', 'content-length']; const MESSAGE_TYPE_EMAIL = 'email'; const MESSAGE_TYPE_SMS = 'sms'; const MESSAGE_TYPE_PUSH = 'push'; +const MAIL_TEMPLATE_CERTIFICATE_FAILED = 'certificate-failed'; +const MAIL_TEMPLATE_DATA_EXPORT = 'data-export'; +const MAIL_TEMPLATE_INVITATION = 'invitation'; +const MAIL_TEMPLATE_MAGIC_URL = 'magic-url'; +const MAIL_TEMPLATE_MFA_CHALLENGE = 'mfa-challenge'; +const MAIL_TEMPLATE_OTP = 'otp'; +const MAIL_TEMPLATE_RECOVERY = 'recovery'; +const MAIL_TEMPLATE_SESSION_ALERT = 'session-alert'; +const MAIL_TEMPLATE_SMTP_TEST = 'smtp-test'; +const MAIL_TEMPLATE_VERIFICATION = 'verification'; +const MAIL_TEMPLATE_WEBHOOK_FAILED = 'webhook-failed'; // API key types const API_KEY_STANDARD = 'standard'; const API_KEY_EPHEMERAL = 'ephemeral'; diff --git a/composer.json b/composer.json index af7575c671..f6e2a35066 100644 --- a/composer.json +++ b/composer.json @@ -76,7 +76,7 @@ "utopia-php/locale": "0.8.*", "utopia-php/lock": "0.2.*", "utopia-php/logger": "0.8.*", - "utopia-php/messaging": "1.0.*", + "utopia-php/messaging": "^1.1", "utopia-php/migration": "1.*", "utopia-php/platform": "^1.0@RC", "utopia-php/pools": "1.*", diff --git a/composer.lock b/composer.lock index 703189e5f9..97674ae904 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "fe6368e3d42f385c63d7e5e2e911febd", + "content-hash": "2dfcf2f234c0ef563a0ee4b47534ddc5", "packages": [ { "name": "adhocore/jwt", @@ -4354,16 +4354,16 @@ }, { "name": "utopia-php/messaging", - "version": "1.0.0", + "version": "1.1.0", "source": { "type": "git", "url": "https://github.com/utopia-php/messaging.git", - "reference": "1aca8968c3bf3c78c428a399dfe97cbe9b366ec4" + "reference": "2a8e82cda89b373833e10923ae959f56466300a3" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/messaging/zipball/1aca8968c3bf3c78c428a399dfe97cbe9b366ec4", - "reference": "1aca8968c3bf3c78c428a399dfe97cbe9b366ec4", + "url": "https://api.github.com/repos/utopia-php/messaging/zipball/2a8e82cda89b373833e10923ae959f56466300a3", + "reference": "2a8e82cda89b373833e10923ae959f56466300a3", "shasum": "" }, "require": { @@ -4371,7 +4371,8 @@ "ext-openssl": "*", "giggsey/libphonenumber-for-php-lite": "9.0.23", "php": ">=8.1.0", - "phpmailer/phpmailer": "6.9.1" + "phpmailer/phpmailer": "6.9.1", + "utopia-php/telemetry": "^0.4" }, "require-dev": { "laravel/pint": "1.*", @@ -4399,9 +4400,9 @@ ], "support": { "issues": "https://github.com/utopia-php/messaging/issues", - "source": "https://github.com/utopia-php/messaging/tree/1.0.0" + "source": "https://github.com/utopia-php/messaging/tree/1.1.0" }, - "time": "2026-06-02T14:54:22+00:00" + "time": "2026-06-16T03:44:58+00:00" }, { "name": "utopia-php/migration", diff --git a/src/Appwrite/Bus/Listeners/Mails.php b/src/Appwrite/Bus/Listeners/Mails.php index eb36e0d394..948394d8b6 100644 --- a/src/Appwrite/Bus/Listeners/Mails.php +++ b/src/Appwrite/Bus/Listeners/Mails.php @@ -143,6 +143,7 @@ class Mails extends Listener project: $project, recipient: $event->user['email'], subject: $subject, + template: MAIL_TEMPLATE_SESSION_ALERT, bodyTemplate: __DIR__ . '/../../../../app/config/locale/templates/' . $smtpBaseTemplate . '.tpl', body: $body, preview: $preview, diff --git a/src/Appwrite/Event/Message/Mail.php b/src/Appwrite/Event/Message/Mail.php index aeeea8a616..b823f107da 100644 --- a/src/Appwrite/Event/Message/Mail.php +++ b/src/Appwrite/Event/Message/Mail.php @@ -12,6 +12,7 @@ final class Mail extends Base public readonly string $recipient = '', public readonly string $name = '', public readonly string $subject = '', + public readonly string $template = '', public readonly string $bodyTemplate = '', public readonly string $body = '', public readonly string $preview = '', @@ -33,6 +34,7 @@ final class Mail extends Base 'recipient' => $this->recipient, 'name' => $this->name, 'subject' => $this->subject, + 'template' => $this->template, 'bodyTemplate' => $this->bodyTemplate, 'body' => $this->body, 'preview' => $this->preview, @@ -52,6 +54,7 @@ final class Mail extends Base recipient: $data['recipient'] ?? '', name: $data['name'] ?? '', subject: $data['subject'] ?? '', + template: $data['template'] ?? '', bodyTemplate: $data['bodyTemplate'] ?? '', body: $data['body'] ?? '', preview: $data['preview'] ?? '', diff --git a/src/Appwrite/Platform/Modules/Account/Http/Account/MFA/Challenges/Create.php b/src/Appwrite/Platform/Modules/Account/Http/Account/MFA/Challenges/Create.php index 27d6f3e088..da6055fffd 100644 --- a/src/Appwrite/Platform/Modules/Account/Http/Account/MFA/Challenges/Create.php +++ b/src/Appwrite/Platform/Modules/Account/Http/Account/MFA/Challenges/Create.php @@ -336,6 +336,7 @@ class Create extends Action project: $project, recipient: $user->getAttribute('email'), subject: $subject, + template: MAIL_TEMPLATE_MFA_CHALLENGE, bodyTemplate: $bodyTemplate, body: $body, preview: $preview, diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/SMTP/Tests/Create.php b/src/Appwrite/Platform/Modules/Project/Http/Project/SMTP/Tests/Create.php index df5b650d5d..689ebcb097 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/SMTP/Tests/Create.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/SMTP/Tests/Create.php @@ -152,6 +152,7 @@ class Create extends Action project: $project, recipient: $email, subject: $subject, + template: MAIL_TEMPLATE_SMTP_TEST, bodyTemplate: APP_CE_CONFIG_DIR . '/locale/templates/email-base-styled.tpl', body: $template->render(), smtp: [ diff --git a/src/Appwrite/Platform/Modules/Teams/Http/Memberships/Create.php b/src/Appwrite/Platform/Modules/Teams/Http/Memberships/Create.php index 19d9237ff1..92db118c46 100644 --- a/src/Appwrite/Platform/Modules/Teams/Http/Memberships/Create.php +++ b/src/Appwrite/Platform/Modules/Teams/Http/Memberships/Create.php @@ -418,6 +418,7 @@ class Create extends Action recipient: $invitee->getAttribute('email'), name: $invitee->getAttribute('name', ''), subject: $subject, + template: MAIL_TEMPLATE_INVITATION, body: $body, preview: $preview, smtp: $smtpConfig, diff --git a/src/Appwrite/Platform/Workers/Certificates.php b/src/Appwrite/Platform/Workers/Certificates.php index 4a31216599..89da7d01de 100644 --- a/src/Appwrite/Platform/Workers/Certificates.php +++ b/src/Appwrite/Platform/Workers/Certificates.php @@ -572,6 +572,7 @@ class Certificates extends Action recipient: System::getEnv('_APP_EMAIL_CERTIFICATES', System::getEnv('_APP_SYSTEM_SECURITY_EMAIL_ADDRESS')), name: 'Appwrite Administrator', subject: $subject, + template: MAIL_TEMPLATE_CERTIFICATE_FAILED, bodyTemplate: __DIR__ . '/../../../../app/config/locale/templates/email-base-styled.tpl', body: $body, preview: $preview, diff --git a/src/Appwrite/Platform/Workers/Mails.php b/src/Appwrite/Platform/Workers/Mails.php index 5cd4639988..48cb58722d 100644 --- a/src/Appwrite/Platform/Workers/Mails.php +++ b/src/Appwrite/Platform/Workers/Mails.php @@ -14,7 +14,9 @@ use Utopia\Messaging\Messages\Email\Attachment; use Utopia\Platform\Action; use Utopia\Queue\Message; use Utopia\Registry\Registry; +use Utopia\Span\Span; use Utopia\System\System; +use Utopia\Telemetry\Adapter as Telemetry; class Mails extends Action { @@ -39,6 +41,7 @@ class Mails extends Action ->inject('project') ->inject('register') ->inject('log') + ->inject('telemetry') ->callback($this->action(...)); } @@ -55,10 +58,11 @@ class Mails extends Action * @param Document $project * @param Registry $register * @param Log $log + * @param Telemetry $telemetry * @return void * @throws Exception */ - public function action(Message $message, Document $project, Registry $register, Log $log): void + public function action(Message $message, Document $project, Registry $register, Log $log, Telemetry $telemetry): void { Runtime::setHookFlags(SWOOLE_HOOK_ALL ^ SWOOLE_HOOK_TCP); $payload = $message->getPayload(); @@ -81,6 +85,12 @@ class Mails extends Action $recipient = $payload['recipient']; $subject = $payload['subject']; + $template = $payload['template'] ?? 'unknown'; + $recipientDomain = \strtolower(\substr(\strrchr($recipient, '@') ?: '', 1)); + + Span::add('mail.template', $template); + Span::add('mail.smtp_type', $type); + Span::add('mail.recipient_domain', $recipientDomain); $variables = $payload['variables']; $variables['host'] = $protocol . '://' . $hostname; $name = $payload['name']; @@ -150,6 +160,7 @@ class Mails extends Action keepAlive: true, timelimit: 30, ); + $adapter->setTelemetry($telemetry); // Resolve from/replyTo using fallback hierarchy: Custom options > SMTP config > Defaults $defaultFromEmail = System::getEnv('_APP_SYSTEM_EMAIL_ADDRESS', APP_EMAIL_TEAM); @@ -202,14 +213,19 @@ class Mails extends Action attachments: $attachments, html: true, ); + $emailMessage->setOrigin(MESSAGE_SEND_TYPE_INTERNAL); try { $adapter->send($emailMessage); } catch (\Throwable $error) { + Span::add('mail.status', 'failure'); + if ($type === 'smtp') { throw new Exception('Error sending mail: ' . $error->getMessage(), 401); } throw new Exception('Error sending mail: ' . $error->getMessage(), 500); } + + Span::add('mail.status', 'success'); } } diff --git a/src/Appwrite/Platform/Workers/Messaging.php b/src/Appwrite/Platform/Workers/Messaging.php index ddd7edf641..2a827f82cb 100644 --- a/src/Appwrite/Platform/Workers/Messaging.php +++ b/src/Appwrite/Platform/Workers/Messaging.php @@ -49,6 +49,7 @@ use Utopia\Storage\Device; use Utopia\Storage\Device\Local; use Utopia\Storage\Storage; use Utopia\System\System; +use Utopia\Telemetry\Adapter as Telemetry; use function Swoole\Coroutine\batch; @@ -56,6 +57,8 @@ class Messaging extends Action { private ?SMSAdapter $adapter = null; + private Telemetry $telemetry; + public static function getName(): string { return 'messaging'; @@ -74,6 +77,7 @@ class Messaging extends Action ->inject('dbForProject') ->inject('deviceForFiles') ->inject('publisherForUsage') + ->inject('telemetry') ->callback($this->action(...)); } @@ -84,6 +88,7 @@ class Messaging extends Action * @param Database $dbForProject * @param Device $deviceForFiles * @param UsagePublisher $publisherForUsage + * @param Telemetry $telemetry * @return void * @throws \Exception */ @@ -93,9 +98,12 @@ class Messaging extends Action Log $log, Database $dbForProject, Device $deviceForFiles, - UsagePublisher $publisherForUsage + UsagePublisher $publisherForUsage, + Telemetry $telemetry ): void { Runtime::setHookFlags(SWOOLE_HOOK_ALL ^ SWOOLE_HOOK_TCP); + + $this->telemetry = $telemetry; $payload = $message->getPayload(); if (empty($payload)) { @@ -143,6 +151,8 @@ class Messaging extends Action $userIds = $message->getAttribute('users', []); $providerType = $message->getAttribute('providerType'); + Span::add('message.provider_type', $providerType); + $default = $dbForProject->findOne('providers', [ Query::equal('enabled', [true]), Query::equal('type', [$providerType]), @@ -268,6 +278,11 @@ class Messaging extends Action $message->setAttribute('search', "{$message->getAttribute('search')} {$provider->getAttribute('name')} {$provider->getAttribute('provider')} {$provider->getAttribute('type')}"); } + Span::add('message.providers', \implode(',', \array_unique(\array_map( + fn (Document $provider) => $provider->getAttribute('provider'), + \array_values($providers) + )))); + $message->setAttribute('deliveredTotal', $deliveredTotal); $message->setAttribute('deliveredAt', DateTime::now()); @@ -533,6 +548,7 @@ class Messaging extends Action ] = $this->retrySend($batch, $message, $provider, $providerType, $adapter, $dbForProject, $deviceForFiles, $project); $failed = $recipients - $delivered; + $usage = new UsageContext(); $usage ->addMetric(METRIC_MESSAGES, $recipients) @@ -758,12 +774,16 @@ class Messaging extends Action $messageData = clone $message; $messageData->setAttribute('to', $to); - return match ($providerType) { + $data = match ($providerType) { MESSAGE_TYPE_SMS => $this->buildSmsMessage($messageData, $provider), MESSAGE_TYPE_PUSH => $this->buildPushMessage($messageData), MESSAGE_TYPE_EMAIL => $this->buildEmailMessage($dbForProject, $messageData, $provider, $deviceForFiles, $project), default => throw new \Exception('Provider with the requested ID is of the incorrect type') }; + + $data->setOrigin(MESSAGE_SEND_TYPE_EXTERNAL); + + return $data; } private function sendInternalSMSMessage(Document $message, Document $project, array $recipients, Log $log): void @@ -802,6 +822,7 @@ class Messaging extends Action $message->getAttribute('data')['content'], $from ); + $sms->setOrigin(MESSAGE_SEND_TYPE_INTERNAL); $this->adapter->send($sms); } @@ -811,7 +832,7 @@ class Messaging extends Action { $credentials = $provider->getAttribute('credentials'); - return match ($provider->getAttribute('provider')) { + $adapter = match ($provider->getAttribute('provider')) { 'mock' => (new Mock('username', 'password'))->setEndpoint('http://request-catcher-sms:5000/'), 'twilio' => new Twilio( $credentials['accountSid'] ?? '', @@ -848,6 +869,12 @@ class Messaging extends Action ), default => null }; + + if ($adapter !== null) { + $adapter->setTelemetry($this->telemetry); + } + + return $adapter; } protected function getPushAdapter(Document $provider): ?PushAdapter @@ -855,7 +882,7 @@ class Messaging extends Action $credentials = $provider->getAttribute('credentials'); $options = $provider->getAttribute('options'); - return match ($provider->getAttribute('provider')) { + $adapter = match ($provider->getAttribute('provider')) { 'mock' => new Mock('username', 'password'), 'apns' => new APNS( $credentials['authKey'] ?? '', @@ -867,6 +894,12 @@ class Messaging extends Action 'fcm' => new FCM(\json_encode($credentials['serviceAccountJSON'])), default => null }; + + if ($adapter !== null) { + $adapter->setTelemetry($this->telemetry); + } + + return $adapter; } protected function getEmailAdapter(Document $provider): ?EmailAdapter @@ -875,7 +908,7 @@ class Messaging extends Action $options = $provider->getAttribute('options', []); $apiKey = $credentials['apiKey'] ?? ''; - return match ($provider->getAttribute('provider')) { + $adapter = match ($provider->getAttribute('provider')) { 'mock' => new Mock('username', 'password'), 'smtp' => new SMTP( $credentials['host'] ?? '', @@ -901,6 +934,12 @@ class Messaging extends Action ), default => null }; + + if ($adapter !== null) { + $adapter->setTelemetry($this->telemetry); + } + + return $adapter; } private function buildEmailMessage( @@ -1117,6 +1156,7 @@ class Messaging extends Action $defaultProvider = $this->createProviderFromDSN($defaultDSN); $adapter = $this->getSmsAdapter($defaultProvider); $geosms = new GEOSMS($adapter); + $geosms->setTelemetry($this->telemetry); /** @var DSN $localDSN */ foreach ($localDSNs as $localDSN) { diff --git a/src/Appwrite/Platform/Workers/Migrations.php b/src/Appwrite/Platform/Workers/Migrations.php index a6f65fc742..825caf764d 100644 --- a/src/Appwrite/Platform/Workers/Migrations.php +++ b/src/Appwrite/Platform/Workers/Migrations.php @@ -947,6 +947,7 @@ class Migrations extends Action recipient: $user->getAttribute('email'), name: $user->getAttribute('name', $user->getAttribute('email')), subject: $subject, + template: MAIL_TEMPLATE_DATA_EXPORT, bodyTemplate: __DIR__ . '/../../../../app/config/locale/templates/email-base-styled.tpl', body: $emailBody, preview: $preview, diff --git a/src/Appwrite/Platform/Workers/Webhooks.php b/src/Appwrite/Platform/Workers/Webhooks.php index d91425d59b..593fd39767 100644 --- a/src/Appwrite/Platform/Workers/Webhooks.php +++ b/src/Appwrite/Platform/Workers/Webhooks.php @@ -272,6 +272,7 @@ class Webhooks extends Action recipient: $user->getAttribute('email'), name: $user->getAttribute('name', ''), subject: $subject, + template: MAIL_TEMPLATE_WEBHOOK_FAILED, body: $body->render(), preview: $preview, variables: ['user' => $user->getAttribute('name', '')], diff --git a/tests/unit/Messaging/MessagingFanoutTest.php b/tests/unit/Messaging/MessagingFanoutTest.php index 78172a5a0e..75f01b902b 100644 --- a/tests/unit/Messaging/MessagingFanoutTest.php +++ b/tests/unit/Messaging/MessagingFanoutTest.php @@ -558,6 +558,7 @@ class ScriptedEmailAdapter extends EmailAdapter */ public function __construct(private readonly array $script = []) { + parent::__construct(); } public function getName(): string From c9f0719783f323798a24b0d2a351fadc43ff08d5 Mon Sep 17 00:00:00 2001 From: harsh mahajan Date: Tue, 16 Jun 2026 12:31:41 +0530 Subject: [PATCH 04/31] test: add e2e test for cross-project installation validation --- .../e2e/Services/VCS/VCSConsoleClientTest.php | 92 +++++++++++++++++++ 1 file changed, 92 insertions(+) diff --git a/tests/e2e/Services/VCS/VCSConsoleClientTest.php b/tests/e2e/Services/VCS/VCSConsoleClientTest.php index 041f825cee..f3d41ebda4 100644 --- a/tests/e2e/Services/VCS/VCSConsoleClientTest.php +++ b/tests/e2e/Services/VCS/VCSConsoleClientTest.php @@ -715,6 +715,98 @@ final class VCSConsoleClientTest extends Scope ], $this->getHeaders())); } + public function testCrossProjectInstallationRejected(): void + { + $installationId = $this->setupInstallation(); + + // Create a second project + $team = $this->client->call(Client::METHOD_POST, '/teams', [ + 'origin' => 'http://localhost', + 'content-type' => 'application/json', + 'cookie' => 'a_session_console=' . $this->getRoot()['session'], + 'x-appwrite-project' => 'console', + ], ['teamId' => ID::unique(), 'name' => 'Cross Project Team']); + + $project2 = $this->client->call(Client::METHOD_POST, '/projects', [ + 'origin' => 'http://localhost', + 'content-type' => 'application/json', + 'cookie' => 'a_session_console=' . $this->getRoot()['session'], + 'x-appwrite-project' => 'console', + ], [ + 'projectId' => ID::unique(), + 'name' => 'Cross Project Test', + 'teamId' => $team['body']['$id'], + 'region' => System::getEnv('_APP_REGION', 'default'), + ]); + + $this->assertEquals(201, $project2['headers']['status-code']); + $project2Id = $project2['body']['$id']; + + $key = $this->client->call(Client::METHOD_POST, '/projects/' . $project2Id . '/keys', [ + 'origin' => 'http://localhost', + 'content-type' => 'application/json', + 'cookie' => 'a_session_console=' . $this->getRoot()['session'], + 'x-appwrite-project' => 'console', + ], [ + 'keyId' => ID::unique(), + 'name' => 'Test Key', + 'scopes' => ['functions.write', 'sites.write'], + ]); + + $headers2 = [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $project2Id, + 'x-appwrite-key' => $key['body']['secret'], + ]; + + // createFunction with installation from project 1 → should fail + $function = $this->client->call(Client::METHOD_POST, '/functions', $headers2, [ + 'functionId' => ID::unique(), + 'name' => 'Test Cross', + 'runtime' => 'php-8.0', + 'entrypoint' => 'index.php', + 'installationId' => $installationId, + 'providerRepositoryId' => $this->providerRepositoryId, + 'providerBranch' => 'main', + ]); + + $this->assertEquals(404, $function['headers']['status-code']); + + // createSite with installation from project 1 → should fail + $site = $this->client->call(Client::METHOD_POST, '/sites', $headers2, [ + 'siteId' => ID::unique(), + 'name' => 'Test Cross Site', + 'framework' => 'other', + 'buildRuntime' => 'node-22', + 'installationId' => $installationId, + 'providerRepositoryId' => $this->providerRepositoryId3, + 'providerBranch' => 'main', + ]); + + $this->assertEquals(404, $site['headers']['status-code']); + + // Create a function in project 2 (no VCS), then try updateFunction with cross-project installation + $fn = $this->client->call(Client::METHOD_POST, '/functions', $headers2, [ + 'functionId' => ID::unique(), + 'name' => 'Test No VCS', + 'runtime' => 'php-8.0', + 'entrypoint' => 'index.php', + ]); + + $this->assertEquals(201, $fn['headers']['status-code']); + + $updated = $this->client->call(Client::METHOD_PUT, '/functions/' . $fn['body']['$id'], $headers2, [ + 'name' => 'Test No VCS', + 'runtime' => 'php-8.0', + 'entrypoint' => 'index.php', + 'installationId' => $installationId, + 'providerRepositoryId' => $this->providerRepositoryId, + 'providerBranch' => 'main', + ]); + + $this->assertEquals(404, $updated['headers']['status-code']); + } + public function testCreateRepository(): void { $installationId = $this->setupInstallation(); From 9a14d9b441972bb90350b40c536ac9d19f49d3d9 Mon Sep 17 00:00:00 2001 From: Chirag Aggarwal Date: Tue, 16 Jun 2026 12:39:00 +0530 Subject: [PATCH 05/31] Expose ping in SDK specs (#12604) --- app/controllers/general.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/general.php b/app/controllers/general.php index 94caf4760d..9ff704ca20 100644 --- a/app/controllers/general.php +++ b/app/controllers/general.php @@ -14,6 +14,7 @@ use Appwrite\Event\Publisher\Delete as DeletePublisher; use Appwrite\Extend\Exception as AppwriteException; use Appwrite\Network\Cors; use Appwrite\Platform\Appwrite; +use Appwrite\SDK\AuthType; use Appwrite\SDK\Method; use Appwrite\SDK\Response as SDKResponse; use Appwrite\Transformation\Adapter\Preview; @@ -1662,11 +1663,10 @@ Http::get('/v1/ping') namespace: 'ping', group: null, name: 'get', - hide: true, description: << Date: Tue, 16 Jun 2026 12:50:33 +0530 Subject: [PATCH 06/31] test: fix cross-project installation test setup and coverage --- .../e2e/Services/VCS/VCSConsoleClientTest.php | 130 ++++++++++-------- 1 file changed, 72 insertions(+), 58 deletions(-) diff --git a/tests/e2e/Services/VCS/VCSConsoleClientTest.php b/tests/e2e/Services/VCS/VCSConsoleClientTest.php index f3d41ebda4..e936013a90 100644 --- a/tests/e2e/Services/VCS/VCSConsoleClientTest.php +++ b/tests/e2e/Services/VCS/VCSConsoleClientTest.php @@ -718,40 +718,34 @@ final class VCSConsoleClientTest extends Scope public function testCrossProjectInstallationRejected(): void { $installationId = $this->setupInstallation(); - - // Create a second project - $team = $this->client->call(Client::METHOD_POST, '/teams', [ + $consoleHeaders = [ 'origin' => 'http://localhost', 'content-type' => 'application/json', 'cookie' => 'a_session_console=' . $this->getRoot()['session'], 'x-appwrite-project' => 'console', - ], ['teamId' => ID::unique(), 'name' => 'Cross Project Team']); + ]; - $project2 = $this->client->call(Client::METHOD_POST, '/projects', [ - 'origin' => 'http://localhost', - 'content-type' => 'application/json', - 'cookie' => 'a_session_console=' . $this->getRoot()['session'], - 'x-appwrite-project' => 'console', - ], [ + $team = $this->client->call(Client::METHOD_POST, '/teams', $consoleHeaders, [ + 'teamId' => ID::unique(), + 'name' => 'Cross Project Team', + ]); + $this->assertEquals(201, $team['headers']['status-code']); + + $project2 = $this->client->call(Client::METHOD_POST, '/projects', $consoleHeaders, [ 'projectId' => ID::unique(), 'name' => 'Cross Project Test', 'teamId' => $team['body']['$id'], 'region' => System::getEnv('_APP_REGION', 'default'), ]); - $this->assertEquals(201, $project2['headers']['status-code']); $project2Id = $project2['body']['$id']; - $key = $this->client->call(Client::METHOD_POST, '/projects/' . $project2Id . '/keys', [ - 'origin' => 'http://localhost', - 'content-type' => 'application/json', - 'cookie' => 'a_session_console=' . $this->getRoot()['session'], - 'x-appwrite-project' => 'console', - ], [ + $key = $this->client->call(Client::METHOD_POST, '/projects/' . $project2Id . '/keys', $consoleHeaders, [ 'keyId' => ID::unique(), 'name' => 'Test Key', 'scopes' => ['functions.write', 'sites.write'], ]); + $this->assertEquals(201, $key['headers']['status-code']); $headers2 = [ 'content-type' => 'application/json', @@ -759,52 +753,72 @@ final class VCSConsoleClientTest extends Scope 'x-appwrite-key' => $key['body']['secret'], ]; - // createFunction with installation from project 1 → should fail - $function = $this->client->call(Client::METHOD_POST, '/functions', $headers2, [ - 'functionId' => ID::unique(), - 'name' => 'Test Cross', - 'runtime' => 'php-8.0', - 'entrypoint' => 'index.php', - 'installationId' => $installationId, - 'providerRepositoryId' => $this->providerRepositoryId, - 'providerBranch' => 'main', - ]); + try { + // createFunction with installation from project 1 → should fail + $function = $this->client->call(Client::METHOD_POST, '/functions', $headers2, [ + 'functionId' => ID::unique(), + 'name' => 'Test Cross', + 'runtime' => 'php-8.0', + 'entrypoint' => 'index.php', + 'installationId' => $installationId, + 'providerRepositoryId' => $this->providerRepositoryId, + 'providerBranch' => 'main', + ]); + $this->assertEquals(404, $function['headers']['status-code']); - $this->assertEquals(404, $function['headers']['status-code']); + // createSite with installation from project 1 → should fail + $site = $this->client->call(Client::METHOD_POST, '/sites', $headers2, [ + 'siteId' => ID::unique(), + 'name' => 'Test Cross Site', + 'framework' => 'other', + 'buildRuntime' => 'node-22', + 'installationId' => $installationId, + 'providerRepositoryId' => $this->providerRepositoryId3, + 'providerBranch' => 'main', + ]); + $this->assertEquals(404, $site['headers']['status-code']); - // createSite with installation from project 1 → should fail - $site = $this->client->call(Client::METHOD_POST, '/sites', $headers2, [ - 'siteId' => ID::unique(), - 'name' => 'Test Cross Site', - 'framework' => 'other', - 'buildRuntime' => 'node-22', - 'installationId' => $installationId, - 'providerRepositoryId' => $this->providerRepositoryId3, - 'providerBranch' => 'main', - ]); + // updateFunction with cross-project installation → should fail + $fn = $this->client->call(Client::METHOD_POST, '/functions', $headers2, [ + 'functionId' => ID::unique(), + 'name' => 'Test No VCS', + 'runtime' => 'php-8.0', + 'entrypoint' => 'index.php', + ]); + $this->assertEquals(201, $fn['headers']['status-code']); - $this->assertEquals(404, $site['headers']['status-code']); + $updated = $this->client->call(Client::METHOD_PUT, '/functions/' . $fn['body']['$id'], $headers2, [ + 'name' => 'Test No VCS', + 'runtime' => 'php-8.0', + 'entrypoint' => 'index.php', + 'installationId' => $installationId, + 'providerRepositoryId' => $this->providerRepositoryId, + 'providerBranch' => 'main', + ]); + $this->assertEquals(404, $updated['headers']['status-code']); - // Create a function in project 2 (no VCS), then try updateFunction with cross-project installation - $fn = $this->client->call(Client::METHOD_POST, '/functions', $headers2, [ - 'functionId' => ID::unique(), - 'name' => 'Test No VCS', - 'runtime' => 'php-8.0', - 'entrypoint' => 'index.php', - ]); + // updateSite with cross-project installation → should fail + $siteNoVcs = $this->client->call(Client::METHOD_POST, '/sites', $headers2, [ + 'siteId' => ID::unique(), + 'name' => 'Test No VCS Site', + 'framework' => 'other', + 'buildRuntime' => 'node-22', + ]); + $this->assertEquals(201, $siteNoVcs['headers']['status-code']); - $this->assertEquals(201, $fn['headers']['status-code']); - - $updated = $this->client->call(Client::METHOD_PUT, '/functions/' . $fn['body']['$id'], $headers2, [ - 'name' => 'Test No VCS', - 'runtime' => 'php-8.0', - 'entrypoint' => 'index.php', - 'installationId' => $installationId, - 'providerRepositoryId' => $this->providerRepositoryId, - 'providerBranch' => 'main', - ]); - - $this->assertEquals(404, $updated['headers']['status-code']); + $updatedSite = $this->client->call(Client::METHOD_PUT, '/sites/' . $siteNoVcs['body']['$id'], $headers2, [ + 'name' => 'Test No VCS Site', + 'framework' => 'other', + 'buildRuntime' => 'node-22', + 'installationId' => $installationId, + 'providerRepositoryId' => $this->providerRepositoryId3, + 'providerBranch' => 'main', + ]); + $this->assertEquals(404, $updatedSite['headers']['status-code']); + } finally { + $this->client->call(Client::METHOD_DELETE, '/projects/' . $project2Id, $consoleHeaders); + $this->client->call(Client::METHOD_DELETE, '/teams/' . $team['body']['$id'], $consoleHeaders); + } } public function testCreateRepository(): void From b2ae1eaf6f5151686b7273871d87a73797f8f8cb Mon Sep 17 00:00:00 2001 From: harsh mahajan Date: Tue, 16 Jun 2026 12:59:00 +0530 Subject: [PATCH 07/31] fix: reject cross-project installationId on VCS attach --- .../Functions/Http/Functions/Create.php | 4 ++ .../Functions/Http/Functions/Update.php | 4 ++ .../Modules/Sites/Http/Sites/Create.php | 4 ++ .../Modules/Sites/Http/Sites/Update.php | 4 ++ .../e2e/Services/VCS/VCSConsoleClientTest.php | 66 +++++++++++-------- 5 files changed, 53 insertions(+), 29 deletions(-) diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Functions/Create.php b/src/Appwrite/Platform/Modules/Functions/Http/Functions/Create.php index 601025c794..2692eaf630 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Functions/Create.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Functions/Create.php @@ -218,6 +218,10 @@ class Create extends Base throw new Exception(Exception::INSTALLATION_NOT_FOUND); } + if (!empty($installationId) && $installation->getAttribute('projectId') !== $project->getId()) { + throw new Exception(Exception::INSTALLATION_NOT_FOUND); + } + if (!empty($providerRepositoryId) && (empty($installationId) || empty($providerBranch))) { throw new Exception(Exception::GENERAL_ARGUMENT_INVALID, 'When connecting to VCS (Version Control System), you need to provide "installationId" and "providerBranch".'); } diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Functions/Update.php b/src/Appwrite/Platform/Modules/Functions/Http/Functions/Update.php index fd89651800..323d460aab 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Functions/Update.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Functions/Update.php @@ -165,6 +165,10 @@ class Update extends Base throw new Exception(Exception::INSTALLATION_NOT_FOUND); } + if (!empty($installationId) && $installation->getAttribute('projectId') !== $project->getId()) { + throw new Exception(Exception::INSTALLATION_NOT_FOUND); + } + if (!empty($providerRepositoryId) && (empty($installationId) || empty($providerBranch))) { throw new Exception(Exception::GENERAL_ARGUMENT_INVALID, 'When connecting to VCS (Version Control System), you need to provide "installationId" and "providerBranch".'); } diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Sites/Create.php b/src/Appwrite/Platform/Modules/Sites/Http/Sites/Create.php index e167c88af2..a774c31a0f 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Sites/Create.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Sites/Create.php @@ -150,6 +150,10 @@ class Create extends Base throw new Exception(Exception::INSTALLATION_NOT_FOUND); } + if (!empty($installationId) && $installation->getAttribute('projectId') !== $project->getId()) { + throw new Exception(Exception::INSTALLATION_NOT_FOUND); + } + if (!empty($providerRepositoryId) && (empty($installationId) || empty($providerBranch))) { throw new Exception(Exception::GENERAL_ARGUMENT_INVALID, 'When connecting to VCS (Version Control System), you need to provide "installationId" and "providerBranch".'); } diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Sites/Update.php b/src/Appwrite/Platform/Modules/Sites/Http/Sites/Update.php index be585ffdab..bda471886a 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Sites/Update.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Sites/Update.php @@ -169,6 +169,10 @@ class Update extends Base throw new Exception(Exception::INSTALLATION_NOT_FOUND); } + if (!empty($installationId) && $installation->getAttribute('projectId') !== $project->getId()) { + throw new Exception(Exception::INSTALLATION_NOT_FOUND); + } + if (!empty($providerRepositoryId) && (empty($installationId) || empty($providerBranch))) { throw new Exception(Exception::GENERAL_ARGUMENT_INVALID, 'When connecting to VCS (Version Control System), you need to provide "installationId" and "providerBranch".'); } diff --git a/tests/e2e/Services/VCS/VCSConsoleClientTest.php b/tests/e2e/Services/VCS/VCSConsoleClientTest.php index e936013a90..f0942771ea 100644 --- a/tests/e2e/Services/VCS/VCSConsoleClientTest.php +++ b/tests/e2e/Services/VCS/VCSConsoleClientTest.php @@ -725,35 +725,39 @@ final class VCSConsoleClientTest extends Scope 'x-appwrite-project' => 'console', ]; - $team = $this->client->call(Client::METHOD_POST, '/teams', $consoleHeaders, [ - 'teamId' => ID::unique(), - 'name' => 'Cross Project Team', - ]); - $this->assertEquals(201, $team['headers']['status-code']); - - $project2 = $this->client->call(Client::METHOD_POST, '/projects', $consoleHeaders, [ - 'projectId' => ID::unique(), - 'name' => 'Cross Project Test', - 'teamId' => $team['body']['$id'], - 'region' => System::getEnv('_APP_REGION', 'default'), - ]); - $this->assertEquals(201, $project2['headers']['status-code']); - $project2Id = $project2['body']['$id']; - - $key = $this->client->call(Client::METHOD_POST, '/projects/' . $project2Id . '/keys', $consoleHeaders, [ - 'keyId' => ID::unique(), - 'name' => 'Test Key', - 'scopes' => ['functions.write', 'sites.write'], - ]); - $this->assertEquals(201, $key['headers']['status-code']); - - $headers2 = [ - 'content-type' => 'application/json', - 'x-appwrite-project' => $project2Id, - 'x-appwrite-key' => $key['body']['secret'], - ]; + $teamId = null; + $project2Id = null; try { + $team = $this->client->call(Client::METHOD_POST, '/teams', $consoleHeaders, [ + 'teamId' => ID::unique(), + 'name' => 'Cross Project Team', + ]); + $this->assertEquals(201, $team['headers']['status-code']); + $teamId = $team['body']['$id']; + + $project2 = $this->client->call(Client::METHOD_POST, '/projects', $consoleHeaders, [ + 'projectId' => ID::unique(), + 'name' => 'Cross Project Test', + 'teamId' => $teamId, + 'region' => System::getEnv('_APP_REGION', 'default'), + ]); + $this->assertEquals(201, $project2['headers']['status-code']); + $project2Id = $project2['body']['$id']; + + $key = $this->client->call(Client::METHOD_POST, '/projects/' . $project2Id . '/keys', $consoleHeaders, [ + 'keyId' => ID::unique(), + 'name' => 'Test Key', + 'scopes' => ['functions.write', 'sites.write'], + ]); + $this->assertEquals(201, $key['headers']['status-code']); + + $headers2 = [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $project2Id, + 'x-appwrite-key' => $key['body']['secret'], + ]; + // createFunction with installation from project 1 → should fail $function = $this->client->call(Client::METHOD_POST, '/functions', $headers2, [ 'functionId' => ID::unique(), @@ -816,8 +820,12 @@ final class VCSConsoleClientTest extends Scope ]); $this->assertEquals(404, $updatedSite['headers']['status-code']); } finally { - $this->client->call(Client::METHOD_DELETE, '/projects/' . $project2Id, $consoleHeaders); - $this->client->call(Client::METHOD_DELETE, '/teams/' . $team['body']['$id'], $consoleHeaders); + if ($project2Id !== null) { + $this->client->call(Client::METHOD_DELETE, '/projects/' . $project2Id, $consoleHeaders); + } + if ($teamId !== null) { + $this->client->call(Client::METHOD_DELETE, '/teams/' . $teamId, $consoleHeaders); + } } } From ec9383e8c1fa514c02ec5f39ad3c779141198353 Mon Sep 17 00:00:00 2001 From: harsh mahajan Date: Tue, 16 Jun 2026 13:26:13 +0530 Subject: [PATCH 08/31] ci: trigger VCS tests with credentials From 5b999ea2fa66acf0c2e08d7a019061dfc01bdd42 Mon Sep 17 00:00:00 2001 From: harsh mahajan Date: Tue, 16 Jun 2026 14:01:04 +0530 Subject: [PATCH 09/31] fix: validate preserved installation ownership in update paths --- .../Functions/Http/Functions/Update.php | 12 ++++--- .../Modules/Sites/Http/Sites/Update.php | 12 ++++--- .../e2e/Services/VCS/VCSConsoleClientTest.php | 32 +++++++++---------- 3 files changed, 32 insertions(+), 24 deletions(-) diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Functions/Update.php b/src/Appwrite/Platform/Modules/Functions/Http/Functions/Update.php index 323d460aab..52943d7ab9 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Functions/Update.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Functions/Update.php @@ -165,10 +165,6 @@ class Update extends Base throw new Exception(Exception::INSTALLATION_NOT_FOUND); } - if (!empty($installationId) && $installation->getAttribute('projectId') !== $project->getId()) { - throw new Exception(Exception::INSTALLATION_NOT_FOUND); - } - if (!empty($providerRepositoryId) && (empty($installationId) || empty($providerBranch))) { throw new Exception(Exception::GENERAL_ARGUMENT_INVALID, 'When connecting to VCS (Version Control System), you need to provide "installationId" and "providerBranch".'); } @@ -186,6 +182,10 @@ class Update extends Base $isConnected = !empty($function->getAttribute('providerRepositoryId', '')); + if (!empty($installationId) && $installation->getAttribute('projectId') !== $project->getId()) { + throw new Exception(Exception::INSTALLATION_NOT_FOUND); + } + // Omitted providerRepositoryId (null) on a connected function — preserve existing VCS values if ($isConnected && $providerRepositoryId === null) { $providerRepositoryId = $function->getAttribute('providerRepositoryId', ''); @@ -197,6 +197,10 @@ class Update extends Base $installation = $dbForPlatform->getDocument('installations', $installationId); } + if (!empty($installationId) && $installation->getAttribute('projectId') !== $project->getId()) { + throw new Exception(Exception::INSTALLATION_NOT_FOUND); + } + // Git disconnect logic. Disconnecting only when providerRepositoryId is empty, allowing for continue updates without disconnecting git if ($isConnected && ($providerRepositoryId !== null && empty($providerRepositoryId))) { $repositories = $dbForPlatform->find('repositories', [ diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Sites/Update.php b/src/Appwrite/Platform/Modules/Sites/Http/Sites/Update.php index bda471886a..4b1e030be0 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Sites/Update.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Sites/Update.php @@ -169,10 +169,6 @@ class Update extends Base throw new Exception(Exception::INSTALLATION_NOT_FOUND); } - if (!empty($installationId) && $installation->getAttribute('projectId') !== $project->getId()) { - throw new Exception(Exception::INSTALLATION_NOT_FOUND); - } - if (!empty($providerRepositoryId) && (empty($installationId) || empty($providerBranch))) { throw new Exception(Exception::GENERAL_ARGUMENT_INVALID, 'When connecting to VCS (Version Control System), you need to provide "installationId" and "providerBranch".'); } @@ -186,6 +182,10 @@ class Update extends Base $isConnected = !empty($site->getAttribute('providerRepositoryId', '')); + if (!empty($installationId) && $installation->getAttribute('projectId') !== $project->getId()) { + throw new Exception(Exception::INSTALLATION_NOT_FOUND); + } + // Omitted providerRepositoryId (null) on a connected site — preserve existing VCS values if ($isConnected && $providerRepositoryId === null) { $providerRepositoryId = $site->getAttribute('providerRepositoryId', ''); @@ -197,6 +197,10 @@ class Update extends Base $installation = $dbForPlatform->getDocument('installations', $installationId); } + if (!empty($installationId) && $installation->getAttribute('projectId') !== $project->getId()) { + throw new Exception(Exception::INSTALLATION_NOT_FOUND); + } + // Git disconnect logic. Disconnecting only when providerRepositoryId is empty, allowing for continue updates without disconnecting git if ($isConnected && ($providerRepositoryId !== null && empty($providerRepositoryId))) { $repositories = $dbForPlatform->find('repositories', [ diff --git a/tests/e2e/Services/VCS/VCSConsoleClientTest.php b/tests/e2e/Services/VCS/VCSConsoleClientTest.php index f0942771ea..b553a59ebd 100644 --- a/tests/e2e/Services/VCS/VCSConsoleClientTest.php +++ b/tests/e2e/Services/VCS/VCSConsoleClientTest.php @@ -22,11 +22,11 @@ final class VCSConsoleClientTest extends Scope use ProjectCustom; use SideConsole; - public string $providerInstallationId = '42954928'; // appwrite-test - public string $providerRepositoryId = '705764267'; // ruby-starter (public) - public string $providerRepositoryId2 = '708688544'; // function1.4 (private) - public string $providerRepositoryId3 = '943139433'; // svelte-starter (public) - public string $providerRepositoryId4 = '943245292'; // templates-for-sites (public) + public string $providerInstallationId = '140618770'; // appwrite-test + public string $providerRepositoryId = '1263962253'; // ruby-starter (public) + public string $providerRepositoryId2 = '1263962253'; // function1.4 (private) + public string $providerRepositoryId3 = '1263962253'; // svelte-starter (public) + public string $providerRepositoryId4 = '1263962253'; // templates-for-sites (public) private static array $cachedInstallationId = []; private static array $cachedFunctionData = []; @@ -75,7 +75,7 @@ final class VCSConsoleClientTest extends Scope 'functionId' => ID::unique(), 'name' => 'Test', 'execute' => [Role::user($this->getUser()['$id'])->toString()], - 'runtime' => 'php-8.0', + 'runtime' => 'node-22', 'entrypoint' => 'index.php', 'events' => [ 'users.*.create', @@ -600,7 +600,7 @@ final class VCSConsoleClientTest extends Scope 'functionId' => ID::unique(), 'name' => 'Test', 'execute' => [Role::user($this->getUser()['$id'])->toString()], - 'runtime' => 'php-8.0', + 'runtime' => 'node-22', 'entrypoint' => 'index.php', 'events' => [ 'users.*.create', @@ -615,9 +615,9 @@ final class VCSConsoleClientTest extends Scope $this->assertEquals(201, $function['headers']['status-code']); $this->assertEquals('Test', $function['body']['name']); - $this->assertEquals('php-8.0', $function['body']['runtime']); + $this->assertEquals('node-22', $function['body']['runtime']); $this->assertEquals('index.php', $function['body']['entrypoint']); - $this->assertEquals('705764267', $function['body']['providerRepositoryId']); + $this->assertEquals('1263962253', $function['body']['providerRepositoryId']); $this->assertEquals('main', $function['body']['providerBranch']); } @@ -632,7 +632,7 @@ final class VCSConsoleClientTest extends Scope 'functionId' => ID::unique(), 'name' => 'Test', 'execute' => [Role::user($this->getUser()['$id'])->toString()], - 'runtime' => 'php-8.0', + 'runtime' => 'node-22', 'entrypoint' => 'index.php', 'events' => [ 'users.*.create', @@ -647,9 +647,9 @@ final class VCSConsoleClientTest extends Scope $this->assertEquals(200, $function['headers']['status-code']); $this->assertEquals('Test', $function['body']['name']); - $this->assertEquals('php-8.0', $function['body']['runtime']); + $this->assertEquals('node-22', $function['body']['runtime']); $this->assertEquals('index.php', $function['body']['entrypoint']); - $this->assertEquals('708688544', $function['body']['providerRepositoryId']); + $this->assertEquals('1263962253', $function['body']['providerRepositoryId']); $this->assertEquals('main', $function['body']['providerBranch']); } @@ -663,7 +663,7 @@ final class VCSConsoleClientTest extends Scope 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ 'name' => 'Test', - 'runtime' => 'php-8.0', + 'runtime' => 'node-22', 'entrypoint' => 'index.php', 'timeout' => 10, ]); @@ -762,7 +762,7 @@ final class VCSConsoleClientTest extends Scope $function = $this->client->call(Client::METHOD_POST, '/functions', $headers2, [ 'functionId' => ID::unique(), 'name' => 'Test Cross', - 'runtime' => 'php-8.0', + 'runtime' => 'node-22', 'entrypoint' => 'index.php', 'installationId' => $installationId, 'providerRepositoryId' => $this->providerRepositoryId, @@ -786,14 +786,14 @@ final class VCSConsoleClientTest extends Scope $fn = $this->client->call(Client::METHOD_POST, '/functions', $headers2, [ 'functionId' => ID::unique(), 'name' => 'Test No VCS', - 'runtime' => 'php-8.0', + 'runtime' => 'node-22', 'entrypoint' => 'index.php', ]); $this->assertEquals(201, $fn['headers']['status-code']); $updated = $this->client->call(Client::METHOD_PUT, '/functions/' . $fn['body']['$id'], $headers2, [ 'name' => 'Test No VCS', - 'runtime' => 'php-8.0', + 'runtime' => 'node-22', 'entrypoint' => 'index.php', 'installationId' => $installationId, 'providerRepositoryId' => $this->providerRepositoryId, From a9edcd74bd1509688a300d295139442c9e542b98 Mon Sep 17 00:00:00 2001 From: harsh mahajan Date: Tue, 16 Jun 2026 14:02:33 +0530 Subject: [PATCH 10/31] fix: remove redundant post-preservation ownership check --- .../Platform/Modules/Functions/Http/Functions/Update.php | 4 ---- src/Appwrite/Platform/Modules/Sites/Http/Sites/Update.php | 4 ---- 2 files changed, 8 deletions(-) diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Functions/Update.php b/src/Appwrite/Platform/Modules/Functions/Http/Functions/Update.php index 52943d7ab9..e9e14a6e22 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Functions/Update.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Functions/Update.php @@ -197,10 +197,6 @@ class Update extends Base $installation = $dbForPlatform->getDocument('installations', $installationId); } - if (!empty($installationId) && $installation->getAttribute('projectId') !== $project->getId()) { - throw new Exception(Exception::INSTALLATION_NOT_FOUND); - } - // Git disconnect logic. Disconnecting only when providerRepositoryId is empty, allowing for continue updates without disconnecting git if ($isConnected && ($providerRepositoryId !== null && empty($providerRepositoryId))) { $repositories = $dbForPlatform->find('repositories', [ diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Sites/Update.php b/src/Appwrite/Platform/Modules/Sites/Http/Sites/Update.php index 4b1e030be0..1edc5ce87c 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Sites/Update.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Sites/Update.php @@ -197,10 +197,6 @@ class Update extends Base $installation = $dbForPlatform->getDocument('installations', $installationId); } - if (!empty($installationId) && $installation->getAttribute('projectId') !== $project->getId()) { - throw new Exception(Exception::INSTALLATION_NOT_FOUND); - } - // Git disconnect logic. Disconnecting only when providerRepositoryId is empty, allowing for continue updates without disconnecting git if ($isConnected && ($providerRepositoryId !== null && empty($providerRepositoryId))) { $repositories = $dbForPlatform->find('repositories', [ From a7cb1148e910293b7e72531bc88e4e03d6ab1901 Mon Sep 17 00:00:00 2001 From: harsh mahajan Date: Tue, 16 Jun 2026 14:07:34 +0530 Subject: [PATCH 11/31] test: restore original CI credentials in VCS test file --- .../e2e/Services/VCS/VCSConsoleClientTest.php | 98 +++++++++---------- 1 file changed, 45 insertions(+), 53 deletions(-) diff --git a/tests/e2e/Services/VCS/VCSConsoleClientTest.php b/tests/e2e/Services/VCS/VCSConsoleClientTest.php index b553a59ebd..e936013a90 100644 --- a/tests/e2e/Services/VCS/VCSConsoleClientTest.php +++ b/tests/e2e/Services/VCS/VCSConsoleClientTest.php @@ -22,11 +22,11 @@ final class VCSConsoleClientTest extends Scope use ProjectCustom; use SideConsole; - public string $providerInstallationId = '140618770'; // appwrite-test - public string $providerRepositoryId = '1263962253'; // ruby-starter (public) - public string $providerRepositoryId2 = '1263962253'; // function1.4 (private) - public string $providerRepositoryId3 = '1263962253'; // svelte-starter (public) - public string $providerRepositoryId4 = '1263962253'; // templates-for-sites (public) + public string $providerInstallationId = '42954928'; // appwrite-test + public string $providerRepositoryId = '705764267'; // ruby-starter (public) + public string $providerRepositoryId2 = '708688544'; // function1.4 (private) + public string $providerRepositoryId3 = '943139433'; // svelte-starter (public) + public string $providerRepositoryId4 = '943245292'; // templates-for-sites (public) private static array $cachedInstallationId = []; private static array $cachedFunctionData = []; @@ -75,7 +75,7 @@ final class VCSConsoleClientTest extends Scope 'functionId' => ID::unique(), 'name' => 'Test', 'execute' => [Role::user($this->getUser()['$id'])->toString()], - 'runtime' => 'node-22', + 'runtime' => 'php-8.0', 'entrypoint' => 'index.php', 'events' => [ 'users.*.create', @@ -600,7 +600,7 @@ final class VCSConsoleClientTest extends Scope 'functionId' => ID::unique(), 'name' => 'Test', 'execute' => [Role::user($this->getUser()['$id'])->toString()], - 'runtime' => 'node-22', + 'runtime' => 'php-8.0', 'entrypoint' => 'index.php', 'events' => [ 'users.*.create', @@ -615,9 +615,9 @@ final class VCSConsoleClientTest extends Scope $this->assertEquals(201, $function['headers']['status-code']); $this->assertEquals('Test', $function['body']['name']); - $this->assertEquals('node-22', $function['body']['runtime']); + $this->assertEquals('php-8.0', $function['body']['runtime']); $this->assertEquals('index.php', $function['body']['entrypoint']); - $this->assertEquals('1263962253', $function['body']['providerRepositoryId']); + $this->assertEquals('705764267', $function['body']['providerRepositoryId']); $this->assertEquals('main', $function['body']['providerBranch']); } @@ -632,7 +632,7 @@ final class VCSConsoleClientTest extends Scope 'functionId' => ID::unique(), 'name' => 'Test', 'execute' => [Role::user($this->getUser()['$id'])->toString()], - 'runtime' => 'node-22', + 'runtime' => 'php-8.0', 'entrypoint' => 'index.php', 'events' => [ 'users.*.create', @@ -647,9 +647,9 @@ final class VCSConsoleClientTest extends Scope $this->assertEquals(200, $function['headers']['status-code']); $this->assertEquals('Test', $function['body']['name']); - $this->assertEquals('node-22', $function['body']['runtime']); + $this->assertEquals('php-8.0', $function['body']['runtime']); $this->assertEquals('index.php', $function['body']['entrypoint']); - $this->assertEquals('1263962253', $function['body']['providerRepositoryId']); + $this->assertEquals('708688544', $function['body']['providerRepositoryId']); $this->assertEquals('main', $function['body']['providerBranch']); } @@ -663,7 +663,7 @@ final class VCSConsoleClientTest extends Scope 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ 'name' => 'Test', - 'runtime' => 'node-22', + 'runtime' => 'php-8.0', 'entrypoint' => 'index.php', 'timeout' => 10, ]); @@ -725,44 +725,40 @@ final class VCSConsoleClientTest extends Scope 'x-appwrite-project' => 'console', ]; - $teamId = null; - $project2Id = null; + $team = $this->client->call(Client::METHOD_POST, '/teams', $consoleHeaders, [ + 'teamId' => ID::unique(), + 'name' => 'Cross Project Team', + ]); + $this->assertEquals(201, $team['headers']['status-code']); + + $project2 = $this->client->call(Client::METHOD_POST, '/projects', $consoleHeaders, [ + 'projectId' => ID::unique(), + 'name' => 'Cross Project Test', + 'teamId' => $team['body']['$id'], + 'region' => System::getEnv('_APP_REGION', 'default'), + ]); + $this->assertEquals(201, $project2['headers']['status-code']); + $project2Id = $project2['body']['$id']; + + $key = $this->client->call(Client::METHOD_POST, '/projects/' . $project2Id . '/keys', $consoleHeaders, [ + 'keyId' => ID::unique(), + 'name' => 'Test Key', + 'scopes' => ['functions.write', 'sites.write'], + ]); + $this->assertEquals(201, $key['headers']['status-code']); + + $headers2 = [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $project2Id, + 'x-appwrite-key' => $key['body']['secret'], + ]; try { - $team = $this->client->call(Client::METHOD_POST, '/teams', $consoleHeaders, [ - 'teamId' => ID::unique(), - 'name' => 'Cross Project Team', - ]); - $this->assertEquals(201, $team['headers']['status-code']); - $teamId = $team['body']['$id']; - - $project2 = $this->client->call(Client::METHOD_POST, '/projects', $consoleHeaders, [ - 'projectId' => ID::unique(), - 'name' => 'Cross Project Test', - 'teamId' => $teamId, - 'region' => System::getEnv('_APP_REGION', 'default'), - ]); - $this->assertEquals(201, $project2['headers']['status-code']); - $project2Id = $project2['body']['$id']; - - $key = $this->client->call(Client::METHOD_POST, '/projects/' . $project2Id . '/keys', $consoleHeaders, [ - 'keyId' => ID::unique(), - 'name' => 'Test Key', - 'scopes' => ['functions.write', 'sites.write'], - ]); - $this->assertEquals(201, $key['headers']['status-code']); - - $headers2 = [ - 'content-type' => 'application/json', - 'x-appwrite-project' => $project2Id, - 'x-appwrite-key' => $key['body']['secret'], - ]; - // createFunction with installation from project 1 → should fail $function = $this->client->call(Client::METHOD_POST, '/functions', $headers2, [ 'functionId' => ID::unique(), 'name' => 'Test Cross', - 'runtime' => 'node-22', + 'runtime' => 'php-8.0', 'entrypoint' => 'index.php', 'installationId' => $installationId, 'providerRepositoryId' => $this->providerRepositoryId, @@ -786,14 +782,14 @@ final class VCSConsoleClientTest extends Scope $fn = $this->client->call(Client::METHOD_POST, '/functions', $headers2, [ 'functionId' => ID::unique(), 'name' => 'Test No VCS', - 'runtime' => 'node-22', + 'runtime' => 'php-8.0', 'entrypoint' => 'index.php', ]); $this->assertEquals(201, $fn['headers']['status-code']); $updated = $this->client->call(Client::METHOD_PUT, '/functions/' . $fn['body']['$id'], $headers2, [ 'name' => 'Test No VCS', - 'runtime' => 'node-22', + 'runtime' => 'php-8.0', 'entrypoint' => 'index.php', 'installationId' => $installationId, 'providerRepositoryId' => $this->providerRepositoryId, @@ -820,12 +816,8 @@ final class VCSConsoleClientTest extends Scope ]); $this->assertEquals(404, $updatedSite['headers']['status-code']); } finally { - if ($project2Id !== null) { - $this->client->call(Client::METHOD_DELETE, '/projects/' . $project2Id, $consoleHeaders); - } - if ($teamId !== null) { - $this->client->call(Client::METHOD_DELETE, '/teams/' . $teamId, $consoleHeaders); - } + $this->client->call(Client::METHOD_DELETE, '/projects/' . $project2Id, $consoleHeaders); + $this->client->call(Client::METHOD_DELETE, '/teams/' . $team['body']['$id'], $consoleHeaders); } } From 0a6c7e0d2ea6d9b1f9928753cbdc4eb50fbe5f9e Mon Sep 17 00:00:00 2001 From: Chirag Aggarwal Date: Tue, 16 Jun 2026 14:34:21 +0530 Subject: [PATCH 12/31] Run CI on merged PRs (#12606) --- .github/workflows/ci.yml | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 96b579c006..c2bd7ea4a7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,6 +12,9 @@ env: on: pull_request: + push: + branches: + - 1.9.x workflow_dispatch: inputs: response_format: @@ -705,7 +708,7 @@ jobs: benchmark: name: Benchmark - if: github.event_name == 'pull_request' + if: github.event_name == 'pull_request' || github.event_name == 'push' runs-on: ubuntu-latest needs: build permissions: @@ -747,9 +750,11 @@ jobs: - name: Prepare benchmark before id: benchmark_before_prepare continue-on-error: true + env: + BENCHMARK_BEFORE_SHA: ${{ github.event_name == 'pull_request' && github.event.pull_request.base.sha || github.event.before }} run: | - git fetch --depth=1 origin ${{ github.event.pull_request.base.sha }} - git worktree add --detach /tmp/appwrite-benchmark-before ${{ github.event.pull_request.base.sha }} + git fetch --depth=1 origin "${BENCHMARK_BEFORE_SHA}" + git worktree add --detach /tmp/appwrite-benchmark-before "${BENCHMARK_BEFORE_SHA}" docker build \ --cache-from ${{ env.IMAGE }}:after \ --target development \ @@ -871,8 +876,8 @@ jobs: if: always() uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 env: - BENCHMARK_BASE_REF: ${{ github.event.pull_request.base.ref }} - BENCHMARK_HEAD_REF: ${{ github.event.pull_request.head.ref }} + BENCHMARK_BASE_REF: ${{ github.event_name == 'pull_request' && github.event.pull_request.base.ref || github.event.before }} + BENCHMARK_HEAD_REF: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.ref || github.sha }} with: script: | const comment = require('./.github/workflows/benchmark-comment.js'); From 2540732ac0e14976ef0715b213d9997f55c43072 Mon Sep 17 00:00:00 2001 From: harsh mahajan Date: Tue, 16 Jun 2026 18:42:50 +0530 Subject: [PATCH 13/31] fix: bump utopia-php/vcs to 4.2.3 --- composer.lock | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/composer.lock b/composer.lock index 97674ae904..484402325d 100644 --- a/composer.lock +++ b/composer.lock @@ -5130,16 +5130,16 @@ }, { "name": "utopia-php/vcs", - "version": "4.2.2", + "version": "4.2.3", "source": { "type": "git", "url": "https://github.com/utopia-php/vcs.git", - "reference": "bb42584d3efb95ff4eb241605bb15165c56974de" + "reference": "598cbd2793a5a6394493f1046743e75ec6544a57" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/vcs/zipball/bb42584d3efb95ff4eb241605bb15165c56974de", - "reference": "bb42584d3efb95ff4eb241605bb15165c56974de", + "url": "https://api.github.com/repos/utopia-php/vcs/zipball/598cbd2793a5a6394493f1046743e75ec6544a57", + "reference": "598cbd2793a5a6394493f1046743e75ec6544a57", "shasum": "" }, "require": { @@ -5173,9 +5173,9 @@ ], "support": { "issues": "https://github.com/utopia-php/vcs/issues", - "source": "https://github.com/utopia-php/vcs/tree/4.2.2" + "source": "https://github.com/utopia-php/vcs/tree/4.2.3" }, - "time": "2026-06-10T08:08:48+00:00" + "time": "2026-06-16T12:14:08+00:00" }, { "name": "utopia-php/websocket", From c38c8e1f4d8cd49ab1381fb4cb90a4ceb800a45f Mon Sep 17 00:00:00 2001 From: Chirag Aggarwal Date: Wed, 17 Jun 2026 09:25:56 +0530 Subject: [PATCH 14/31] fix: refine impersonation security scheme definitions (#12610) Compact the X-Appwrite-Impersonate-User-{Id,Email,Phone} header descriptions to a short phrase matching the other security schemes (they previously carried a multi-sentence paragraph that rendered poorly in the docs). Mark the impersonation schemes with a new x-appwrite.optional flag. Location methods (downloads, previews, views, avatars) include these schemes so impersonation can pass through as a URL query param, but they are optional; the flag lets SDK doc generation skip them in examples instead of showing setImpersonateUserId('') as required auth. --- src/Appwrite/Platform/Tasks/Specs.php | 45 +++++++++++++++++++++------ 1 file changed, 36 insertions(+), 9 deletions(-) diff --git a/src/Appwrite/Platform/Tasks/Specs.php b/src/Appwrite/Platform/Tasks/Specs.php index bd2a03ecf0..e7f5167611 100644 --- a/src/Appwrite/Platform/Tasks/Specs.php +++ b/src/Appwrite/Platform/Tasks/Specs.php @@ -180,20 +180,29 @@ class Specs extends Action 'ImpersonateUserId' => [ 'type' => 'apiKey', 'name' => 'X-Appwrite-Impersonate-User-Id', - 'description' => 'Impersonate a user by ID on an already user-authenticated request. Requires the current request to be authenticated as a user with impersonator capability; X-Appwrite-Key alone is not sufficient. Impersonator users are intentionally granted users.read so they can discover a target before impersonation begins. Internal audit logs still attribute actions to the original impersonator and record the impersonated target only in internal audit payload data.', + 'description' => 'Impersonate a user by ID', 'in' => 'header', + 'x-appwrite' => [ + 'optional' => true, + ], ], 'ImpersonateUserEmail' => [ 'type' => 'apiKey', 'name' => 'X-Appwrite-Impersonate-User-Email', - 'description' => 'Impersonate a user by email on an already user-authenticated request. Requires the current request to be authenticated as a user with impersonator capability; X-Appwrite-Key alone is not sufficient. Impersonator users are intentionally granted users.read so they can discover a target before impersonation begins. Internal audit logs still attribute actions to the original impersonator and record the impersonated target only in internal audit payload data.', + 'description' => 'Impersonate a user by email', 'in' => 'header', + 'x-appwrite' => [ + 'optional' => true, + ], ], 'ImpersonateUserPhone' => [ 'type' => 'apiKey', 'name' => 'X-Appwrite-Impersonate-User-Phone', - 'description' => 'Impersonate a user by phone on an already user-authenticated request. Requires the current request to be authenticated as a user with impersonator capability; X-Appwrite-Key alone is not sufficient. Impersonator users are intentionally granted users.read so they can discover a target before impersonation begins. Internal audit logs still attribute actions to the original impersonator and record the impersonated target only in internal audit payload data.', + 'description' => 'Impersonate a user by phone', 'in' => 'header', + 'x-appwrite' => [ + 'optional' => true, + ], ], ], APP_SDK_PLATFORM_SERVER => [ @@ -258,20 +267,29 @@ class Specs extends Action 'ImpersonateUserId' => [ 'type' => 'apiKey', 'name' => 'X-Appwrite-Impersonate-User-Id', - 'description' => 'Impersonate a user by ID on an already user-authenticated request. Requires the current request to be authenticated as a user with impersonator capability; X-Appwrite-Key alone is not sufficient. Impersonator users are intentionally granted users.read so they can discover a target before impersonation begins. Internal audit logs still attribute actions to the original impersonator and record the impersonated target only in internal audit payload data.', + 'description' => 'Impersonate a user by ID', 'in' => 'header', + 'x-appwrite' => [ + 'optional' => true, + ], ], 'ImpersonateUserEmail' => [ 'type' => 'apiKey', 'name' => 'X-Appwrite-Impersonate-User-Email', - 'description' => 'Impersonate a user by email on an already user-authenticated request. Requires the current request to be authenticated as a user with impersonator capability; X-Appwrite-Key alone is not sufficient. Impersonator users are intentionally granted users.read so they can discover a target before impersonation begins. Internal audit logs still attribute actions to the original impersonator and record the impersonated target only in internal audit payload data.', + 'description' => 'Impersonate a user by email', 'in' => 'header', + 'x-appwrite' => [ + 'optional' => true, + ], ], 'ImpersonateUserPhone' => [ 'type' => 'apiKey', 'name' => 'X-Appwrite-Impersonate-User-Phone', - 'description' => 'Impersonate a user by phone on an already user-authenticated request. Requires the current request to be authenticated as a user with impersonator capability; X-Appwrite-Key alone is not sufficient. Impersonator users are intentionally granted users.read so they can discover a target before impersonation begins. Internal audit logs still attribute actions to the original impersonator and record the impersonated target only in internal audit payload data.', + 'description' => 'Impersonate a user by phone', 'in' => 'header', + 'x-appwrite' => [ + 'optional' => true, + ], ], ], APP_SDK_PLATFORM_CONSOLE => [ @@ -336,20 +354,29 @@ class Specs extends Action 'ImpersonateUserId' => [ 'type' => 'apiKey', 'name' => 'X-Appwrite-Impersonate-User-Id', - 'description' => 'Impersonate a user by ID on an already user-authenticated request. Requires the current request to be authenticated as a user with impersonator capability; X-Appwrite-Key alone is not sufficient. Impersonator users are intentionally granted users.read so they can discover a target before impersonation begins. Internal audit logs still attribute actions to the original impersonator and record the impersonated target only in internal audit payload data.', + 'description' => 'Impersonate a user by ID', 'in' => 'header', + 'x-appwrite' => [ + 'optional' => true, + ], ], 'ImpersonateUserEmail' => [ 'type' => 'apiKey', 'name' => 'X-Appwrite-Impersonate-User-Email', - 'description' => 'Impersonate a user by email on an already user-authenticated request. Requires the current request to be authenticated as a user with impersonator capability; X-Appwrite-Key alone is not sufficient. Impersonator users are intentionally granted users.read so they can discover a target before impersonation begins. Internal audit logs still attribute actions to the original impersonator and record the impersonated target only in internal audit payload data.', + 'description' => 'Impersonate a user by email', 'in' => 'header', + 'x-appwrite' => [ + 'optional' => true, + ], ], 'ImpersonateUserPhone' => [ 'type' => 'apiKey', 'name' => 'X-Appwrite-Impersonate-User-Phone', - 'description' => 'Impersonate a user by phone on an already user-authenticated request. Requires the current request to be authenticated as a user with impersonator capability; X-Appwrite-Key alone is not sufficient. Impersonator users are intentionally granted users.read so they can discover a target before impersonation begins. Internal audit logs still attribute actions to the original impersonator and record the impersonated target only in internal audit payload data.', + 'description' => 'Impersonate a user by phone', 'in' => 'header', + 'x-appwrite' => [ + 'optional' => true, + ], ], ], ]; From 53b2dea1243d8c9aa82af7e5a43989588ad776f7 Mon Sep 17 00:00:00 2001 From: Chirag Aggarwal Date: Wed, 17 Jun 2026 13:23:44 +0530 Subject: [PATCH 15/31] Add batch execution upserts (#12611) --- src/Appwrite/Event/Message/Executions.php | 39 ++++++++++++++++++++ src/Appwrite/Event/Publisher/Execution.php | 3 +- src/Appwrite/Platform/Workers/Executions.php | 38 ++++++++++++++----- 3 files changed, 70 insertions(+), 10 deletions(-) create mode 100644 src/Appwrite/Event/Message/Executions.php diff --git a/src/Appwrite/Event/Message/Executions.php b/src/Appwrite/Event/Message/Executions.php new file mode 100644 index 0000000000..b6fbf64b91 --- /dev/null +++ b/src/Appwrite/Event/Message/Executions.php @@ -0,0 +1,39 @@ + $executions + */ + public function __construct( + public readonly Document $project, + public readonly array $executions, + ) { + } + + public function toArray(): array + { + return [ + 'project' => $this->project->getArrayCopy(), + 'executions' => \array_map( + fn (Document $execution) => $execution->getArrayCopy(), + $this->executions + ), + ]; + } + + public static function fromArray(array $data): static + { + return new self( + project: new Document($data['project'] ?? []), + executions: \array_map( + fn (array $execution) => new Document($execution), + $data['executions'] ?? [] + ), + ); + } +} diff --git a/src/Appwrite/Event/Publisher/Execution.php b/src/Appwrite/Event/Publisher/Execution.php index 05ea28d540..60470fcb9d 100644 --- a/src/Appwrite/Event/Publisher/Execution.php +++ b/src/Appwrite/Event/Publisher/Execution.php @@ -3,6 +3,7 @@ namespace Appwrite\Event\Publisher; use Appwrite\Event\Message\Execution as ExecutionMessage; +use Appwrite\Event\Message\Executions as ExecutionsMessage; use Utopia\Queue\Publisher; use Utopia\Queue\Queue; @@ -15,7 +16,7 @@ readonly class Execution extends Base parent::__construct($publisher); } - public function enqueue(ExecutionMessage $message): string|bool + public function enqueue(ExecutionMessage|ExecutionsMessage $message): string|bool { return $this->publish($this->queue, $message); } diff --git a/src/Appwrite/Platform/Workers/Executions.php b/src/Appwrite/Platform/Workers/Executions.php index 8dbf10cae6..30b4a43a55 100644 --- a/src/Appwrite/Platform/Workers/Executions.php +++ b/src/Appwrite/Platform/Workers/Executions.php @@ -3,6 +3,7 @@ namespace Appwrite\Platform\Workers; use Appwrite\Event\Message\Execution; +use Appwrite\Event\Message\Executions as ExecutionsMessage; use Exception; use Utopia\Database\Database; use Utopia\Platform\Action; @@ -11,6 +12,8 @@ use Utopia\Span\Span; class Executions extends Action { + private const int UPSERT_BATCH_SIZE = 100; + public static function getName(): string { return 'executions'; @@ -33,19 +36,36 @@ class Executions extends Action Message $message, Database $dbForProject, ): void { - $executionMessage = Execution::fromArray($message->getPayload()); - $execution = $executionMessage->execution; + $payload = $message->getPayload(); + $isBatch = isset($payload['executions']) && \is_array($payload['executions']); - if ($execution->isEmpty()) { - throw new Exception('Missing execution'); + if ($isBatch) { + $executionMessage = ExecutionsMessage::fromArray($payload); + $executions = \array_values(\array_filter( + $executionMessage->executions, + fn ($execution) => !$execution->isEmpty() + )); + } else { + $executionMessage = Execution::fromArray($payload); + $executions = [$executionMessage->execution]; + } + + if (empty($executions)) { + throw new Exception($isBatch ? 'Missing executions' : 'Missing execution'); } Span::add('project.id', $executionMessage->project->getId()); - Span::add('function.id', $execution->getAttribute('resourceId', '')); - Span::add('execution.id', $execution->getId()); - Span::add('deployment.id', $execution->getAttribute('deploymentId', '')); - Span::add('resource.type', $execution->getAttribute('resourceType', '')); - $dbForProject->upsertDocument('executions', $execution); + if ($isBatch) { + Span::add('executions.count', \count($executions)); + $dbForProject->upsertDocuments('executions', $executions, self::UPSERT_BATCH_SIZE); + } else { + $execution = $executions[0]; + Span::add('function.id', $execution->getAttribute('resourceId', '')); + Span::add('execution.id', $execution->getId()); + Span::add('deployment.id', $execution->getAttribute('deploymentId', '')); + Span::add('resource.type', $execution->getAttribute('resourceType', '')); + $dbForProject->upsertDocument('executions', $execution); + } } } From c7c17862fd3a2cde2d7cf4d0d09c704ed04e0acd Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Wed, 17 Jun 2026 15:26:35 +0400 Subject: [PATCH 16/31] Revert "fix: remove unused build cache capture" This reverts commit 4a9e9e050895ab4025c67a2d99ba1ee5a811ee3c. --- src/Appwrite/Platform/Modules/Functions/Workers/Builds.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php b/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php index 3c8219cdf5..d01d82e2e7 100644 --- a/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php +++ b/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php @@ -704,7 +704,7 @@ class Builds extends Action $span = Span::current(); Co::join([ - Co\go(function () use ($executor, &$response, $project, $deployment, $source, $resource, $runtime, $vars, $command, $cpus, $memory, $timeout, &$err, $version, $span) { + Co\go(function () use ($executor, &$response, $project, $deployment, $source, $resource, $runtime, $vars, $command, $cacheKey, $cpus, $memory, $timeout, &$err, $version, $span) { try { if ($version === 'v2') { $command = 'tar -zxf /tmp/code.tar.gz -C /usr/code && cd /usr/local/src/ && ./build.sh'; From 8cf7846733ffed5f47ae015f260497436c5f90af Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Wed, 17 Jun 2026 15:26:35 +0400 Subject: [PATCH 17/31] Revert "fix: disable build cache" This reverts commit 7d785e7963eee062036c5cbdadea1d729088fc9b. --- src/Appwrite/Platform/Modules/Functions/Workers/Builds.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php b/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php index d01d82e2e7..2550db36e2 100644 --- a/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php +++ b/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php @@ -732,8 +732,7 @@ class Builds extends Action variables: $vars, command: $command, outputDirectory: $outputDirectory ?? '', - // temporarily disable build cache - // cacheKey: $cacheKey + cacheKey: $cacheKey ); } catch (ExecutorTimeout $error) { From edd633de6e5e2455df520f8cc12b5e39f2f072c5 Mon Sep 17 00:00:00 2001 From: Chirag Aggarwal Date: Thu, 18 Jun 2026 12:03:28 +0530 Subject: [PATCH 18/31] Fix legacy database SDK deprecation metadata (#12615) --- .../Databases/Collections/Attributes/Longtext/Create.php | 5 +++++ .../Databases/Collections/Attributes/Longtext/Update.php | 5 +++++ .../Databases/Collections/Attributes/Mediumtext/Create.php | 5 +++++ .../Databases/Collections/Attributes/Mediumtext/Update.php | 5 +++++ .../Http/Databases/Collections/Attributes/Text/Create.php | 5 +++++ .../Http/Databases/Collections/Attributes/Text/Update.php | 5 +++++ .../Databases/Collections/Attributes/Varchar/Create.php | 5 +++++ .../Databases/Collections/Attributes/Varchar/Update.php | 5 +++++ .../Databases/Http/Databases/Transactions/Create.php | 7 ++++++- .../Databases/Http/Databases/Transactions/Delete.php | 7 ++++++- .../Modules/Databases/Http/Databases/Transactions/Get.php | 7 ++++++- .../Http/Databases/Transactions/Operations/Create.php | 7 ++++++- .../Databases/Http/Databases/Transactions/Update.php | 7 ++++++- .../Databases/Http/Databases/Transactions/XList.php | 7 ++++++- 14 files changed, 76 insertions(+), 6 deletions(-) diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Longtext/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Longtext/Create.php index 90591b43fb..6dd7492ce9 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Longtext/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Longtext/Create.php @@ -7,6 +7,7 @@ use Appwrite\Event\Publisher\Database as DatabasePublisher; use Appwrite\Extend\Exception; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Attributes\Action; use Appwrite\SDK\AuthType; +use Appwrite\SDK\Deprecated; use Appwrite\SDK\Method; use Appwrite\SDK\Response as SDKResponse; use Appwrite\Utopia\Response as UtopiaResponse; @@ -57,6 +58,10 @@ class Create extends Action model: $this->getResponseModel() ) ], + deprecated: new Deprecated( + since: '1.8.0', + replaceWith: 'tablesDB.createLongtextColumn', + ), )) ->param('databaseId', '', new UID(), 'Database ID.') ->param('collectionId', '', new UID(), 'Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection).') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Longtext/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Longtext/Update.php index 26e3f0ef8f..6af0578891 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Longtext/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Longtext/Update.php @@ -6,6 +6,7 @@ use Appwrite\Event\Event; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Attributes\Action; use Appwrite\SDK\AuthType; use Appwrite\SDK\ContentType; +use Appwrite\SDK\Deprecated; use Appwrite\SDK\Method; use Appwrite\SDK\Response as SDKResponse; use Appwrite\Utopia\Response as UtopiaResponse; @@ -55,6 +56,10 @@ class Update extends Action ) ], contentType: ContentType::JSON, + deprecated: new Deprecated( + since: '1.8.0', + replaceWith: 'tablesDB.updateLongtextColumn', + ), )) ->param('databaseId', '', new UID(), 'Database ID.') ->param('collectionId', '', new UID(), 'Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection).') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Mediumtext/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Mediumtext/Create.php index 0f7b386fd5..5e49243481 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Mediumtext/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Mediumtext/Create.php @@ -7,6 +7,7 @@ use Appwrite\Event\Publisher\Database as DatabasePublisher; use Appwrite\Extend\Exception; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Attributes\Action; use Appwrite\SDK\AuthType; +use Appwrite\SDK\Deprecated; use Appwrite\SDK\Method; use Appwrite\SDK\Response as SDKResponse; use Appwrite\Utopia\Response as UtopiaResponse; @@ -57,6 +58,10 @@ class Create extends Action model: $this->getResponseModel() ) ], + deprecated: new Deprecated( + since: '1.8.0', + replaceWith: 'tablesDB.createMediumtextColumn', + ), )) ->param('databaseId', '', new UID(), 'Database ID.') ->param('collectionId', '', new UID(), 'Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection).') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Mediumtext/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Mediumtext/Update.php index 45feb7aa9a..1672131123 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Mediumtext/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Mediumtext/Update.php @@ -6,6 +6,7 @@ use Appwrite\Event\Event; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Attributes\Action; use Appwrite\SDK\AuthType; use Appwrite\SDK\ContentType; +use Appwrite\SDK\Deprecated; use Appwrite\SDK\Method; use Appwrite\SDK\Response as SDKResponse; use Appwrite\Utopia\Response as UtopiaResponse; @@ -55,6 +56,10 @@ class Update extends Action ) ], contentType: ContentType::JSON, + deprecated: new Deprecated( + since: '1.8.0', + replaceWith: 'tablesDB.updateMediumtextColumn', + ), )) ->param('databaseId', '', new UID(), 'Database ID.') ->param('collectionId', '', new UID(), 'Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection).') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Text/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Text/Create.php index 79968d0feb..8943c05339 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Text/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Text/Create.php @@ -7,6 +7,7 @@ use Appwrite\Event\Publisher\Database as DatabasePublisher; use Appwrite\Extend\Exception; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Attributes\Action; use Appwrite\SDK\AuthType; +use Appwrite\SDK\Deprecated; use Appwrite\SDK\Method; use Appwrite\SDK\Response as SDKResponse; use Appwrite\Utopia\Response as UtopiaResponse; @@ -57,6 +58,10 @@ class Create extends Action model: $this->getResponseModel() ) ], + deprecated: new Deprecated( + since: '1.8.0', + replaceWith: 'tablesDB.createTextColumn', + ), )) ->param('databaseId', '', new UID(), 'Database ID.') ->param('collectionId', '', new UID(), 'Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection).') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Text/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Text/Update.php index ec9b2979f7..f86e47f36d 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Text/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Text/Update.php @@ -6,6 +6,7 @@ use Appwrite\Event\Event; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Attributes\Action; use Appwrite\SDK\AuthType; use Appwrite\SDK\ContentType; +use Appwrite\SDK\Deprecated; use Appwrite\SDK\Method; use Appwrite\SDK\Response as SDKResponse; use Appwrite\Utopia\Response as UtopiaResponse; @@ -55,6 +56,10 @@ class Update extends Action ) ], contentType: ContentType::JSON, + deprecated: new Deprecated( + since: '1.8.0', + replaceWith: 'tablesDB.updateTextColumn', + ), )) ->param('databaseId', '', new UID(), 'Database ID.') ->param('collectionId', '', new UID(), 'Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection).') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Varchar/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Varchar/Create.php index 89690de4e9..e45b3fed28 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Varchar/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Varchar/Create.php @@ -7,6 +7,7 @@ use Appwrite\Event\Publisher\Database as DatabasePublisher; use Appwrite\Extend\Exception; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Attributes\Action; use Appwrite\SDK\AuthType; +use Appwrite\SDK\Deprecated; use Appwrite\SDK\Method; use Appwrite\SDK\Response as SDKResponse; use Appwrite\Utopia\Response as UtopiaResponse; @@ -59,6 +60,10 @@ class Create extends Action model: $this->getResponseModel() ) ], + deprecated: new Deprecated( + since: '1.8.0', + replaceWith: 'tablesDB.createVarcharColumn', + ), )) ->param('databaseId', '', new UID(), 'Database ID.') ->param('collectionId', '', new UID(), 'Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection).') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Varchar/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Varchar/Update.php index 0ce20abd2d..1aacd92fd5 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Varchar/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Varchar/Update.php @@ -6,6 +6,7 @@ use Appwrite\Event\Event; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Attributes\Action; use Appwrite\SDK\AuthType; use Appwrite\SDK\ContentType; +use Appwrite\SDK\Deprecated; use Appwrite\SDK\Method; use Appwrite\SDK\Response as SDKResponse; use Appwrite\Utopia\Response as UtopiaResponse; @@ -57,6 +58,10 @@ class Update extends Action ) ], contentType: ContentType::JSON, + deprecated: new Deprecated( + since: '1.8.0', + replaceWith: 'tablesDB.updateVarcharColumn', + ), )) ->param('databaseId', '', new UID(), 'Database ID.') ->param('collectionId', '', new UID(), 'Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection).') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Transactions/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Transactions/Create.php index f2b351fa6a..1e0c7af49b 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Transactions/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Transactions/Create.php @@ -4,6 +4,7 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases\Transactions; use Appwrite\SDK\AuthType; use Appwrite\SDK\ContentType; +use Appwrite\SDK\Deprecated; use Appwrite\SDK\Method; use Appwrite\SDK\Response as SDKResponse; use Appwrite\Utopia\Response as UtopiaResponse; @@ -49,7 +50,11 @@ class Create extends Action model: UtopiaResponse::MODEL_TRANSACTION, ) ], - contentType: ContentType::JSON + contentType: ContentType::JSON, + deprecated: new Deprecated( + since: '1.8.0', + replaceWith: 'tablesDB.createTransaction', + ) )) ->param('ttl', APP_DATABASE_TXN_TTL_DEFAULT, new Range(min: APP_DATABASE_TXN_TTL_MIN, max: APP_DATABASE_TXN_TTL_MAX), 'Seconds before the transaction expires.', true) ->inject('response') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Transactions/Delete.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Transactions/Delete.php index 072cb21bbc..9130929162 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Transactions/Delete.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Transactions/Delete.php @@ -7,6 +7,7 @@ use Appwrite\Event\Publisher\Delete as DeletePublisher; use Appwrite\Extend\Exception; use Appwrite\SDK\AuthType; use Appwrite\SDK\ContentType; +use Appwrite\SDK\Deprecated; use Appwrite\SDK\Method; use Appwrite\SDK\Response as SDKResponse; use Appwrite\Utopia\Response as UtopiaResponse; @@ -48,7 +49,11 @@ class Delete extends Action model: UtopiaResponse::MODEL_NONE, ) ], - contentType: ContentType::NONE + contentType: ContentType::NONE, + deprecated: new Deprecated( + since: '1.8.0', + replaceWith: 'tablesDB.deleteTransaction', + ) )) ->param('transactionId', '', fn (Database $dbForProject) => new UID($dbForProject->getAdapter()->getMaxUIDLength()), 'Transaction ID.', false, ['dbForProject']) ->inject('response') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Transactions/Get.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Transactions/Get.php index af0f7cdc10..dc20349e7c 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Transactions/Get.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Transactions/Get.php @@ -5,6 +5,7 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases\Transactions; use Appwrite\Extend\Exception; use Appwrite\SDK\AuthType; use Appwrite\SDK\ContentType; +use Appwrite\SDK\Deprecated; use Appwrite\SDK\Method; use Appwrite\SDK\Response as SDKResponse; use Appwrite\Utopia\Response as UtopiaResponse; @@ -45,7 +46,11 @@ class Get extends Action model: UtopiaResponse::MODEL_TRANSACTION, ) ], - contentType: ContentType::JSON + contentType: ContentType::JSON, + deprecated: new Deprecated( + since: '1.8.0', + replaceWith: 'tablesDB.getTransaction', + ) )) ->param('transactionId', '', fn (Database $dbForProject) => new UID($dbForProject->getAdapter()->getMaxUIDLength()), 'Transaction ID.', false, ['dbForProject']) ->inject('response') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Transactions/Operations/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Transactions/Operations/Create.php index 8e085a9481..4b9cf20b9c 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Transactions/Operations/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Transactions/Operations/Create.php @@ -7,6 +7,7 @@ use Appwrite\Extend\Exception; use Appwrite\Platform\Modules\Databases\Http\Databases\Transactions\Action; use Appwrite\SDK\AuthType; use Appwrite\SDK\ContentType; +use Appwrite\SDK\Deprecated; use Appwrite\SDK\Method; use Appwrite\SDK\Response as SDKResponse; use Appwrite\Utopia\Database\Documents\User; @@ -56,7 +57,11 @@ class Create extends Action model: UtopiaResponse::MODEL_TRANSACTION, ) ], - contentType: ContentType::JSON + contentType: ContentType::JSON, + deprecated: new Deprecated( + since: '1.8.0', + replaceWith: 'tablesDB.createOperations', + ) )) ->param('transactionId', '', fn (Database $dbForProject) => new UID($dbForProject->getAdapter()->getMaxUIDLength()), 'Transaction ID.', false, ['dbForProject']) ->param('operations', [], new ArrayList(new Operation(type: 'legacy')), 'Array of staged operations.', true) diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Transactions/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Transactions/Update.php index de057ae15e..a757f0079e 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Transactions/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Transactions/Update.php @@ -12,6 +12,7 @@ use Appwrite\Extend\Exception; use Appwrite\Functions\EventProcessor; use Appwrite\SDK\AuthType; use Appwrite\SDK\ContentType; +use Appwrite\SDK\Deprecated; use Appwrite\SDK\Method; use Appwrite\SDK\Response as SDKResponse; use Appwrite\Usage\Context; @@ -65,7 +66,11 @@ class Update extends Action model: UtopiaResponse::MODEL_TRANSACTION, ) ], - contentType: ContentType::JSON + contentType: ContentType::JSON, + deprecated: new Deprecated( + since: '1.8.0', + replaceWith: 'tablesDB.updateTransaction', + ) )) ->param('transactionId', '', fn (Database $dbForProject) => new UID($dbForProject->getAdapter()->getMaxUIDLength()), 'Transaction ID.', false, ['dbForProject']) ->param('commit', false, new Boolean(), 'Commit transaction?', true) diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Transactions/XList.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Transactions/XList.php index b10972ad64..22a7da97aa 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Transactions/XList.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Transactions/XList.php @@ -5,6 +5,7 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases\Transactions; use Appwrite\Extend\Exception; use Appwrite\SDK\AuthType; use Appwrite\SDK\ContentType; +use Appwrite\SDK\Deprecated; use Appwrite\SDK\Method; use Appwrite\SDK\Response as SDKResponse; use Appwrite\Utopia\Database\Validator\Queries\Transactions; @@ -48,7 +49,11 @@ class XList extends Action model: UtopiaResponse::MODEL_TRANSACTION_LIST, ) ], - contentType: ContentType::JSON + contentType: ContentType::JSON, + deprecated: new Deprecated( + since: '1.8.0', + replaceWith: 'tablesDB.listTransactions', + ) )) ->param('queries', [], new Transactions(), 'Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries).', true) ->inject('response') From 84d4b566e29de6d533d0e22f857b87ca03c9babd Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Fri, 19 Jun 2026 18:33:58 +1200 Subject: [PATCH 19/31] fix: address pdoproxy review comments --- app/init/registers.php | 35 +++++++------- composer.json | 8 ++-- composer.lock | 74 +++++++++++++++--------------- tests/unit/Utopia/ResponseTest.php | 52 +++++++++++++++++++++ 4 files changed, 109 insertions(+), 60 deletions(-) diff --git a/app/init/registers.php b/app/init/registers.php index e7ede8b025..43ae64bc53 100644 --- a/app/init/registers.php +++ b/app/init/registers.php @@ -6,7 +6,6 @@ use Appwrite\Hooks\Hooks; use Appwrite\PubSub\Adapter\Redis as PubSub; use Appwrite\URL\URL as AppwriteURL; use MaxMind\Db\Reader; -use Swoole\Database\PDOProxy; use Utopia\Cache\Adapter\Redis as RedisCache; use Utopia\Config\Config; use Utopia\Console; @@ -291,15 +290,14 @@ $register->set('pools', function () { $resource = match ($dsnScheme) { 'mysql', 'mariadb' => function () use ($dsnHost, $dsnPort, $dsnUser, $dsnPass, $dsnDatabase) { - return new PDOProxy(function () use ($dsnHost, $dsnPort, $dsnUser, $dsnPass, $dsnDatabase) { - return new PDO("mysql:host={$dsnHost};port={$dsnPort};dbname={$dsnDatabase};charset=utf8mb4", $dsnUser, $dsnPass, [ - \PDO::ATTR_TIMEOUT => 3, // Seconds - \PDO::ATTR_PERSISTENT => false, - \PDO::ATTR_DEFAULT_FETCH_MODE => \PDO::FETCH_ASSOC, - \PDO::ATTR_EMULATE_PREPARES => true, - \PDO::ATTR_STRINGIFY_FETCHES => true - ]); - }); + return new PDO("mysql:host={$dsnHost};port={$dsnPort};dbname={$dsnDatabase};charset=utf8mb4", $dsnUser, $dsnPass, [ + \PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION, + \PDO::ATTR_TIMEOUT => 3, // Seconds + \PDO::ATTR_PERSISTENT => false, + \PDO::ATTR_DEFAULT_FETCH_MODE => \PDO::FETCH_ASSOC, + \PDO::ATTR_EMULATE_PREPARES => true, + \PDO::ATTR_STRINGIFY_FETCHES => true + ]); }, 'mongodb' => function () use ($dsnHost, $dsnPort, $dsnUser, $dsnPass, $dsnDatabase) { try { @@ -312,15 +310,14 @@ $register->set('pools', function () { } }, 'postgresql' => function () use ($dsnHost, $dsnPort, $dsnUser, $dsnPass, $dsnDatabase) { - return new PDOProxy(function () use ($dsnHost, $dsnPort, $dsnUser, $dsnPass, $dsnDatabase) { - return new PDO("pgsql:host={$dsnHost};port={$dsnPort};dbname={$dsnDatabase};connect_timeout=3", $dsnUser, $dsnPass, array( - \PDO::ATTR_TIMEOUT => 3, // Seconds - \PDO::ATTR_PERSISTENT => false, - \PDO::ATTR_DEFAULT_FETCH_MODE => \PDO::FETCH_ASSOC, - \PDO::ATTR_EMULATE_PREPARES => true, - \PDO::ATTR_STRINGIFY_FETCHES => true - )); - }); + return new PDO("pgsql:host={$dsnHost};port={$dsnPort};dbname={$dsnDatabase};connect_timeout=3", $dsnUser, $dsnPass, array( + \PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION, + \PDO::ATTR_TIMEOUT => 3, // Seconds + \PDO::ATTR_PERSISTENT => false, + \PDO::ATTR_DEFAULT_FETCH_MODE => \PDO::FETCH_ASSOC, + \PDO::ATTR_EMULATE_PREPARES => true, + \PDO::ATTR_STRINGIFY_FETCHES => true + )); }, default => function () use ($dsnHost, $dsnPort, $dsnPass) { $redis = new \Redis(); diff --git a/composer.json b/composer.json index f6e2a35066..5d75f38d4b 100644 --- a/composer.json +++ b/composer.json @@ -53,17 +53,17 @@ "ext-sockets": "*", "appwrite/php-runtimes": "0.20.*", "appwrite/php-clamav": "2.0.*", - "utopia-php/abuse": "1.3.*", + "utopia-php/abuse": "1.4.*", "utopia-php/agents": "2.*", "utopia-php/analytics": "0.15.*", - "utopia-php/audit": "^2.4", + "utopia-php/audit": "2.5.*", "utopia-php/auth": "0.5.*", "utopia-php/cache": "^3.0", "utopia-php/cli": "^0.24", "utopia-php/compression": "0.1.*", "utopia-php/config": "1.*", "utopia-php/console": "0.1.*", - "utopia-php/database": "5.*", + "utopia-php/database": "6.0.*", "utopia-php/detector": "0.2.*", "utopia-php/domains": "^2.2", "utopia-php/emails": "0.7.*", @@ -77,7 +77,7 @@ "utopia-php/lock": "0.2.*", "utopia-php/logger": "0.8.*", "utopia-php/messaging": "^1.1", - "utopia-php/migration": "1.*", + "utopia-php/migration": "1.14.*", "utopia-php/platform": "^1.0@RC", "utopia-php/pools": "1.*", "utopia-php/span": "3.0.*", diff --git a/composer.lock b/composer.lock index 484402325d..a43b5016da 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "2dfcf2f234c0ef563a0ee4b47534ddc5", + "content-hash": "264c11d2628eeebe5722497eca10e576", "packages": [ { "name": "adhocore/jwt", @@ -69,16 +69,16 @@ }, { "name": "appwrite/appwrite", - "version": "24.2.0", + "version": "26.1.0", "source": { "type": "git", "url": "https://github.com/appwrite/sdk-for-php.git", - "reference": "d3217b6524b9d174ab91fb7ffc555c68bfa1da97" + "reference": "533865f24f306cf6ac6f1737965553a5c54672e0" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/appwrite/sdk-for-php/zipball/d3217b6524b9d174ab91fb7ffc555c68bfa1da97", - "reference": "d3217b6524b9d174ab91fb7ffc555c68bfa1da97", + "url": "https://api.github.com/repos/appwrite/sdk-for-php/zipball/533865f24f306cf6ac6f1737965553a5c54672e0", + "reference": "533865f24f306cf6ac6f1737965553a5c54672e0", "shasum": "" }, "require": { @@ -88,7 +88,7 @@ }, "require-dev": { "mockery/mockery": "1.6.12", - "phpunit/phpunit": "^10" + "phpunit/phpunit": "^12" }, "type": "library", "autoload": { @@ -104,10 +104,10 @@ "support": { "email": "team@appwrite.io", "issues": "https://github.com/appwrite/sdk-for-php/issues", - "source": "https://github.com/appwrite/sdk-for-php/tree/24.2.0", + "source": "https://github.com/appwrite/sdk-for-php/tree/26.1.0", "url": "https://appwrite.io/support" }, - "time": "2026-05-21T18:56:51+00:00" + "time": "2026-06-19T08:16:32+00:00" }, { "name": "appwrite/php-clamav", @@ -3118,25 +3118,25 @@ }, { "name": "utopia-php/abuse", - "version": "1.3.1", + "version": "1.4.1", "source": { "type": "git", "url": "https://github.com/utopia-php/abuse.git", - "reference": "00e59c89a1ac5f4ad771695e5dbee020b3c7ac44" + "reference": "8f5df0274869cf9022eea7d8030ca1a0d458b3b2" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/abuse/zipball/00e59c89a1ac5f4ad771695e5dbee020b3c7ac44", - "reference": "00e59c89a1ac5f4ad771695e5dbee020b3c7ac44", + "url": "https://api.github.com/repos/utopia-php/abuse/zipball/8f5df0274869cf9022eea7d8030ca1a0d458b3b2", + "reference": "8f5df0274869cf9022eea7d8030ca1a0d458b3b2", "shasum": "" }, "require": { - "appwrite/appwrite": "24.*", + "appwrite/appwrite": "^26.0", "ext-curl": "*", "ext-pdo": "*", "ext-redis": "*", "php": ">=8.2", - "utopia-php/database": "5.*" + "utopia-php/database": "^6.0.0" }, "require-dev": { "laravel/pint": "1.*", @@ -3164,9 +3164,9 @@ ], "support": { "issues": "https://github.com/utopia-php/abuse/issues", - "source": "https://github.com/utopia-php/abuse/tree/1.3.1" + "source": "https://github.com/utopia-php/abuse/tree/1.4.1" }, - "time": "2026-06-03T07:30:05+00:00" + "time": "2026-06-18T11:18:52+00:00" }, { "name": "utopia-php/agents", @@ -3269,21 +3269,21 @@ }, { "name": "utopia-php/audit", - "version": "2.4.2", + "version": "2.5.0", "source": { "type": "git", "url": "https://github.com/utopia-php/audit.git", - "reference": "6f15caaac5455c98cec06e02fe8da3af9477ff38" + "reference": "d9e9bb50f2150e0a7ccbe24668ff7230e7cb7a20" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/audit/zipball/6f15caaac5455c98cec06e02fe8da3af9477ff38", - "reference": "6f15caaac5455c98cec06e02fe8da3af9477ff38", + "url": "https://api.github.com/repos/utopia-php/audit/zipball/d9e9bb50f2150e0a7ccbe24668ff7230e7cb7a20", + "reference": "d9e9bb50f2150e0a7ccbe24668ff7230e7cb7a20", "shasum": "" }, "require": { "php": ">=8.4", - "utopia-php/database": "5.*", + "utopia-php/database": "^6.0.0", "utopia-php/fetch": "^1.1", "utopia-php/query": "0.1.*", "utopia-php/validators": "0.2.*" @@ -3313,9 +3313,9 @@ ], "support": { "issues": "https://github.com/utopia-php/audit/issues", - "source": "https://github.com/utopia-php/audit/tree/2.4.2" + "source": "https://github.com/utopia-php/audit/tree/2.5.0" }, - "time": "2026-06-03T03:42:22+00:00" + "time": "2026-06-18T11:19:26+00:00" }, { "name": "utopia-php/auth", @@ -3682,16 +3682,16 @@ }, { "name": "utopia-php/database", - "version": "5.9.2", + "version": "6.0.0", "source": { "type": "git", "url": "https://github.com/utopia-php/database.git", - "reference": "698952455dd645ff41057621c90a4cea977fb1bf" + "reference": "fff9f0effbd40359ff925741ff9424856d8b4fde" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/database/zipball/698952455dd645ff41057621c90a4cea977fb1bf", - "reference": "698952455dd645ff41057621c90a4cea977fb1bf", + "url": "https://api.github.com/repos/utopia-php/database/zipball/fff9f0effbd40359ff925741ff9424856d8b4fde", + "reference": "fff9f0effbd40359ff925741ff9424856d8b4fde", "shasum": "" }, "require": { @@ -3736,9 +3736,9 @@ ], "support": { "issues": "https://github.com/utopia-php/database/issues", - "source": "https://github.com/utopia-php/database/tree/5.9.2" + "source": "https://github.com/utopia-php/database/tree/6.0.0" }, - "time": "2026-06-12T08:33:14+00:00" + "time": "2026-06-18T10:37:40+00:00" }, { "name": "utopia-php/detector", @@ -4406,25 +4406,25 @@ }, { "name": "utopia-php/migration", - "version": "1.13.2", + "version": "1.14.0", "source": { "type": "git", "url": "https://github.com/utopia-php/migration.git", - "reference": "50526e121efcf73e11309446f194623a431d7e32" + "reference": "f70dba326f1499d1ff4dd18b218b26a858aff1dd" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/migration/zipball/50526e121efcf73e11309446f194623a431d7e32", - "reference": "50526e121efcf73e11309446f194623a431d7e32", + "url": "https://api.github.com/repos/utopia-php/migration/zipball/f70dba326f1499d1ff4dd18b218b26a858aff1dd", + "reference": "f70dba326f1499d1ff4dd18b218b26a858aff1dd", "shasum": "" }, "require": { - "appwrite/appwrite": "24.*", + "appwrite/appwrite": "^26.0", "ext-curl": "*", "ext-openssl": "*", "halaxa/json-machine": "^1.2", "php": ">=8.2", - "utopia-php/database": "5.*", + "utopia-php/database": "^6.0.0", "utopia-php/dsn": "0.2.*", "utopia-php/storage": "2.*" }, @@ -4455,9 +4455,9 @@ ], "support": { "issues": "https://github.com/utopia-php/migration/issues", - "source": "https://github.com/utopia-php/migration/tree/1.13.2" + "source": "https://github.com/utopia-php/migration/tree/1.14.0" }, - "time": "2026-06-04T05:09:07+00:00" + "time": "2026-06-18T11:19:06+00:00" }, { "name": "utopia-php/mongo", diff --git a/tests/unit/Utopia/ResponseTest.php b/tests/unit/Utopia/ResponseTest.php index 80c59ee2f8..e00809ce26 100644 --- a/tests/unit/Utopia/ResponseTest.php +++ b/tests/unit/Utopia/ResponseTest.php @@ -4,7 +4,9 @@ declare(strict_types=1); namespace Tests\Unit\Utopia; +use Appwrite\Models\Project as GeneratedProject; use Appwrite\Utopia\Response; +use Appwrite\Utopia\Response\Model\Project as ProjectModel; use Exception; use PHPUnit\Framework\TestCase; use ReflectionProperty; @@ -110,6 +112,56 @@ final class ResponseTest extends TestCase ]), 'single'); } + public function testProjectResponseCanHydrateGeneratedSdkProjectWithoutOAuth2Fields(): void + { + $this->response->setModel(new ProjectModel()); + + $project = $this->response->output(new Document([ + '$id' => 'project', + '$createdAt' => '2026-06-19T00:00:00.000+00:00', + '$updatedAt' => '2026-06-19T00:00:00.000+00:00', + 'name' => 'Project', + 'teamId' => 'team', + 'region' => 'default', + ]), Response::MODEL_PROJECT); + + $generated = GeneratedProject::from($project); + + foreach ([ + 'oAuth2ServerEnabled', + 'oAuth2ServerAuthorizationUrl', + 'oAuth2ServerScopes', + 'oAuth2ServerAuthorizationDetailsTypes', + 'oAuth2ServerAccessTokenDuration', + 'oAuth2ServerRefreshTokenDuration', + 'oAuth2ServerPublicAccessTokenDuration', + 'oAuth2ServerPublicRefreshTokenDuration', + 'oAuth2ServerConfidentialPkce', + 'oAuth2ServerVerificationUrl', + 'oAuth2ServerUserCodeLength', + 'oAuth2ServerUserCodeFormat', + 'oAuth2ServerDeviceCodeDuration', + 'oAuth2ServerDiscoveryUrl', + ] as $key) { + $this->assertArrayNotHasKey($key, $project); + } + + $this->assertNull($generated->oAuth2ServerEnabled); + $this->assertNull($generated->oAuth2ServerAuthorizationUrl); + $this->assertNull($generated->oAuth2ServerScopes); + $this->assertNull($generated->oAuth2ServerAuthorizationDetailsTypes); + $this->assertNull($generated->oAuth2ServerAccessTokenDuration); + $this->assertNull($generated->oAuth2ServerRefreshTokenDuration); + $this->assertNull($generated->oAuth2ServerPublicAccessTokenDuration); + $this->assertNull($generated->oAuth2ServerPublicRefreshTokenDuration); + $this->assertNull($generated->oAuth2ServerConfidentialPkce); + $this->assertNull($generated->oAuth2ServerVerificationUrl); + $this->assertNull($generated->oAuth2ServerUserCodeLength); + $this->assertNull($generated->oAuth2ServerUserCodeFormat); + $this->assertNull($generated->oAuth2ServerDeviceCodeDuration); + $this->assertNull($generated->oAuth2ServerDiscoveryUrl); + } + public function testResponseModelLists(): void { $output = $this->response->output(new Document([ From e09d0b0ac8cbccbba71e21f63b6ff430650625b7 Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Fri, 19 Jun 2026 13:43:45 +0400 Subject: [PATCH 20/31] fix: bump executor to 0.25.1 --- app/views/install/compose.phtml | 2 +- docker-compose.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/install/compose.phtml b/app/views/install/compose.phtml index d71ccff0b4..abda3a650c 100644 --- a/app/views/install/compose.phtml +++ b/app/views/install/compose.phtml @@ -988,7 +988,7 @@ $hostPath = rtrim($this->getParam('hostPath', ''), '/'); <<: *x-logging restart: unless-stopped stop_signal: SIGINT - image: openruntimes/executor:0.24.1 + image: openruntimes/executor:0.25.1 networks: - appwrite - runtimes diff --git a/docker-compose.yml b/docker-compose.yml index d4b2aacd03..4341698653 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1249,7 +1249,7 @@ services: hostname: exc1 <<: *x-logging stop_signal: SIGINT - image: openruntimes/executor:0.24.1 + image: openruntimes/executor:0.25.1 restart: unless-stopped networks: - appwrite From 0cf472259712c8c458ae5f05cc72aa7ee0345592 Mon Sep 17 00:00:00 2001 From: Chirag Aggarwal Date: Fri, 19 Jun 2026 18:11:25 +0530 Subject: [PATCH 21/31] Handle missing resource token collection (#12625) --- app/init/resources/request.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/init/resources/request.php b/app/init/resources/request.php index 982cd13088..958f1a211a 100644 --- a/app/init/resources/request.php +++ b/app/init/resources/request.php @@ -1108,7 +1108,11 @@ return function (Container $context): void { return new Document([]); } - $token = $authorization->skip(fn () => $dbForProject->getDocument('resourceTokens', $tokenId)); + try { + $token = $authorization->skip(fn () => $dbForProject->getDocument('resourceTokens', $tokenId)); + } catch (\Utopia\Database\Exception\NotFound) { + return new Document([]); + } if ($token->isEmpty()) { return new Document([]); From 283bd1c9992b3a06263679a6d5a1d2af4773af0e Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Sat, 20 Jun 2026 14:04:32 +1200 Subject: [PATCH 22/31] fix(databases): 404 (not 500) for a wrong-type database id on product-DB APIs Product-DB routes (tablesdb/documentsdb/vectorsdb) resolved a database by id with only an isEmpty() check, so a database of the wrong type (e.g. a documentsdb id on the tablesdb path) proceeded to a type-mismatched backend op that surfaced as an opaque 500 instead of a clean 404. Centralise the per-path "allowed database types" in one source (Action::getAllowedDatabaseTypes), used by BOTH the list filter (getDatabaseTypeQueryFilters) and the by-id guard (isDatabaseTypeMismatch), so the two cannot diverge. TablesDB keeps legacy compatibility (mirrors listTablesDatabases); documentsdb/vectorsdb are scoped to their own type; the legacy /v1/databases API is not type-guarded. Every database carries a non-null type (set on create, backfilled to 'legacy' by migration V23), so the filter is a plain Query::equal and the redundant TablesDB list-filter override is removed. Apply the guard at every database-resolution site in the module, and make the remaining handlers type-aware so they can use it: re-base Databases Get/Update/Delete and the Databases/TablesDB log lists onto the type-aware base, and re-base the Collections Attributes/Indexes Action bases and Usage/Get onto it as well (with covariant setHttpPath signatures). Co-Authored-By: Claude Opus 4.8 --- .../Databases/Http/Databases/Action.php | 35 ++++++ .../Collections/Attributes/Action.php | 14 +-- .../Collections/Attributes/Delete.php | 2 +- .../Databases/Collections/Attributes/Get.php | 2 +- .../Attributes/Relationship/Create.php | 2 +- .../Collections/Attributes/XList.php | 2 +- .../Http/Databases/Collections/Create.php | 2 +- .../Http/Databases/Collections/Delete.php | 2 +- .../Documents/Attribute/Decrement.php | 2 +- .../Documents/Attribute/Increment.php | 2 +- .../Collections/Documents/Bulk/Delete.php | 2 +- .../Collections/Documents/Bulk/Update.php | 2 +- .../Collections/Documents/Bulk/Upsert.php | 2 +- .../Collections/Documents/Create.php | 2 +- .../Collections/Documents/Delete.php | 2 +- .../Databases/Collections/Documents/Get.php | 2 +- .../Collections/Documents/Logs/XList.php | 2 +- .../Collections/Documents/Update.php | 2 +- .../Collections/Documents/Upsert.php | 2 +- .../Databases/Collections/Documents/XList.php | 2 +- .../Http/Databases/Collections/Get.php | 2 +- .../Databases/Collections/Indexes/Action.php | 10 +- .../Databases/Collections/Indexes/Create.php | 2 +- .../Databases/Collections/Indexes/Delete.php | 2 +- .../Databases/Collections/Indexes/Get.php | 2 +- .../Databases/Collections/Indexes/XList.php | 2 +- .../Http/Databases/Collections/Logs/XList.php | 2 +- .../Http/Databases/Collections/Update.php | 2 +- .../Http/Databases/Collections/XList.php | 2 +- .../Databases/Http/Databases/Delete.php | 3 +- .../Modules/Databases/Http/Databases/Get.php | 3 +- .../Databases/Http/Databases/Logs/XList.php | 4 +- .../Transactions/Operations/Create.php | 2 +- .../Databases/Http/Databases/Update.php | 3 +- .../Databases/Http/Databases/Usage/Get.php | 8 +- .../Databases/Http/Databases/XList.php | 2 +- .../Databases/Http/TablesDB/Logs/XList.php | 4 +- .../Modules/Databases/Http/TablesDB/XList.php | 11 -- .../Http/VectorsDB/Collections/Create.php | 2 +- .../Http/VectorsDB/Collections/Update.php | 2 +- .../Databases/DatabaseTypeMismatchTest.php | 102 ++++++++++++++++++ 41 files changed, 192 insertions(+), 65 deletions(-) create mode 100644 tests/unit/Platform/Modules/Databases/DatabaseTypeMismatchTest.php diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Action.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Action.php index 7893a70753..9ea4f11ccb 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Action.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Action.php @@ -21,6 +21,41 @@ class Action extends AppwriteAction return $this->context; } + /** + * Database types this path may operate on. Single source of truth shared by + * the list filter ({@see getDatabaseTypeQueryFilters()}) and the by-id guard + * ({@see isDatabaseTypeMismatch()}) so they cannot diverge. + * + * TablesDB is the compatibility successor to the legacy databases API, so it + * also serves legacy-typed databases; the other product APIs are scoped to + * their own type. Every database carries a non-null `type` (set on create + * and backfilled to 'legacy' by migration V23), so null is not represented. + * + * @return string[] + */ + protected function getAllowedDatabaseTypes(): array + { + return match ($this->getDatabaseType()) { + DATABASE_TYPE_TABLESDB => [DATABASE_TYPE_TABLESDB, DATABASE_TYPE_LEGACY], + default => [$this->getDatabaseType()], + }; + } + + /** + * A database resolved by id on a product-DB path must be one of the path's + * allowed types; otherwise it is treated as not-found rather than proceeding + * to a type-mismatched backend operation that surfaces as an opaque 500. The + * legacy /v1/databases API is intentionally not type-guarded. + */ + protected function isDatabaseTypeMismatch(Document $database): bool + { + if ($this->getDatabaseType() === DATABASE_TYPE_LEGACY) { + return false; + } + + return !in_array($database->getAttribute('type', ''), $this->getAllowedDatabaseTypes(), true); + } + public function setHttpPath(string $path): self { if (\str_contains($path, '/tablesdb')) { diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Action.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Action.php index a07a4be561..292c613a5b 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Action.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Action.php @@ -6,6 +6,7 @@ use Appwrite\Event\Event; use Appwrite\Event\Message\Database as DatabaseMessage; use Appwrite\Event\Publisher\Database as DatabasePublisher; use Appwrite\Extend\Exception; +use Appwrite\Platform\Modules\Databases\Http\Databases\Action as DatabasesAction; use Appwrite\Utopia\Response; use Appwrite\Utopia\Response as UtopiaResponse; use Throwable; @@ -21,10 +22,9 @@ use Utopia\Database\Helpers\ID; use Utopia\Database\Validator\Authorization; use Utopia\Database\Validator\Structure; use Utopia\Http\Adapter\Swoole\Response as SwooleResponse; -use Utopia\Platform\Action as UtopiaAction; use Utopia\Validator\Range; -abstract class Action extends UtopiaAction +abstract class Action extends DatabasesAction { /** * @var string The current context (either 'column' or 'attribute') @@ -36,12 +36,14 @@ abstract class Action extends UtopiaAction */ abstract protected function getResponseModel(): string|array; - public function setHttpPath(string $path): UtopiaAction + public function setHttpPath(string $path): DatabasesAction { if (\str_contains($path, '/tablesdb')) { $this->context = COLUMNS; } - return parent::setHttpPath($path); + parent::setHttpPath($path); + + return $this; } /** @@ -333,7 +335,7 @@ abstract class Action extends UtopiaAction $db = $authorization->skip(fn () => $dbForProject->getDocument('databases', $databaseId)); - if ($db->isEmpty()) { + if ($db->isEmpty() || $this->isDatabaseTypeMismatch($db)) { throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]); } @@ -495,7 +497,7 @@ abstract class Action extends UtopiaAction { $db = $authorization->skip(fn () => $dbForProject->getDocument('databases', $databaseId)); - if ($db->isEmpty()) { + if ($db->isEmpty() || $this->isDatabaseTypeMismatch($db)) { throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]); } diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Delete.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Delete.php index ff1636ae60..2808a14088 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Delete.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Delete.php @@ -76,7 +76,7 @@ class Delete extends Action public function action(string $databaseId, string $collectionId, string $key, UtopiaResponse $response, Database $dbForProject, DatabasePublisher $publisherForDatabase, Event $queueForEvents, Authorization $authorization): void { $db = $authorization->skip(fn () => $dbForProject->getDocument('databases', $databaseId)); - if ($db->isEmpty()) { + if ($db->isEmpty() || $this->isDatabaseTypeMismatch($db)) { throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]); } diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Get.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Get.php index 3b9d665d70..4fc251fe51 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Get.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Get.php @@ -75,7 +75,7 @@ class Get extends Action public function action(string $databaseId, string $collectionId, string $key, UtopiaResponse $response, Database $dbForProject, Authorization $authorization): void { $database = $authorization->skip(fn () => $dbForProject->getDocument('databases', $databaseId)); - if ($database->isEmpty()) { + if ($database->isEmpty() || $this->isDatabaseTypeMismatch($database)) { throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]); } diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Relationship/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Relationship/Create.php index f94a60b9de..c62b89a633 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Relationship/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Relationship/Create.php @@ -99,7 +99,7 @@ class Create extends Action $twoWayKey ??= $collectionId; $database = $authorization->skip(fn () => $dbForProject->getDocument('databases', $databaseId)); - if ($database->isEmpty()) { + if ($database->isEmpty() || $this->isDatabaseTypeMismatch($database)) { throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]); } diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/XList.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/XList.php index 5813690802..430117188f 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/XList.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/XList.php @@ -71,7 +71,7 @@ class XList extends Action public function action(string $databaseId, string $collectionId, array $queries, bool $includeTotal, UtopiaResponse $response, Database $dbForProject, Authorization $authorization): void { $database = $authorization->skip(fn () => $dbForProject->getDocument('databases', $databaseId)); - if ($database->isEmpty()) { + if ($database->isEmpty() || $this->isDatabaseTypeMismatch($database)) { throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]); } diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Create.php index b2e783bccd..35a6692b88 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Create.php @@ -94,7 +94,7 @@ class Create extends Action { $database = $authorization->skip(fn () => $dbForProject->getDocument('databases', $databaseId)); - if ($database->isEmpty()) { + if ($database->isEmpty() || $this->isDatabaseTypeMismatch($database)) { throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]); } diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Delete.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Delete.php index 87171fb2fe..532ad23c67 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Delete.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Delete.php @@ -73,7 +73,7 @@ class Delete extends Action public function action(string $databaseId, string $collectionId, UtopiaResponse $response, Database $dbForProject, callable $getDatabasesDB, DatabasePublisher $publisherForDatabase, Event $queueForEvents, Authorization $authorization): void { $database = $authorization->skip(fn () => $dbForProject->getDocument('databases', $databaseId)); - if ($database->isEmpty()) { + if ($database->isEmpty() || $this->isDatabaseTypeMismatch($database)) { throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]); } diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Attribute/Decrement.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Attribute/Decrement.php index 9319cffc57..48c1802038 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Attribute/Decrement.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Attribute/Decrement.php @@ -97,7 +97,7 @@ class Decrement extends Action $isPrivilegedUser = $user->isPrivileged($authorization->getRoles()); $database = $authorization->skip(fn () => $dbForProject->getDocument('databases', $databaseId)); - if ($database->isEmpty()) { + if ($database->isEmpty() || $this->isDatabaseTypeMismatch($database)) { throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]); } diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Attribute/Increment.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Attribute/Increment.php index ba74545342..4d4ecc6777 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Attribute/Increment.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Attribute/Increment.php @@ -97,7 +97,7 @@ class Increment extends Action $isPrivilegedUser = $user->isPrivileged($authorization->getRoles()); $database = $authorization->skip(fn () => $dbForProject->getDocument('databases', $databaseId)); - if ($database->isEmpty()) { + if ($database->isEmpty() || $this->isDatabaseTypeMismatch($database)) { throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]); } diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Bulk/Delete.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Bulk/Delete.php index 2dc3100046..0959acf27c 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Bulk/Delete.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Bulk/Delete.php @@ -91,7 +91,7 @@ class Delete extends Action public function action(string $databaseId, string $collectionId, array $queries, ?string $transactionId, UtopiaResponse $response, Database $dbForProject, callable $getDatabasesDB, Context $usage, Event $queueForEvents, Event $queueForRealtime, FunctionPublisher $publisherForFunctions, Event $queueForWebhooks, array $plan, EventProcessor $eventProcessor): void { $database = $dbForProject->getDocument('databases', $databaseId); - if ($database->isEmpty()) { + if ($database->isEmpty() || $this->isDatabaseTypeMismatch($database)) { throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]); } diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Bulk/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Bulk/Update.php index 393590d1e6..bc09c477d8 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Bulk/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Bulk/Update.php @@ -103,7 +103,7 @@ class Update extends Action } $database = $dbForProject->getDocument('databases', $databaseId); - if ($database->isEmpty()) { + if ($database->isEmpty() || $this->isDatabaseTypeMismatch($database)) { throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]); } diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Bulk/Upsert.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Bulk/Upsert.php index d69298919b..231a2b3a4d 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Bulk/Upsert.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Bulk/Upsert.php @@ -93,7 +93,7 @@ class Upsert extends Action public function action(string $databaseId, string $collectionId, array $documents, ?string $transactionId, UtopiaResponse $response, Database $dbForProject, callable $getDatabasesDB, Context $usage, Event $queueForEvents, Event $queueForRealtime, FunctionPublisher $publisherForFunctions, Event $queueForWebhooks, array $plan, EventProcessor $eventProcessor): void { $database = $dbForProject->getDocument('databases', $databaseId); - if ($database->isEmpty()) { + if ($database->isEmpty() || $this->isDatabaseTypeMismatch($database)) { throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]); } diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Create.php index 2e861dfcce..676ff46a91 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Create.php @@ -209,7 +209,7 @@ class Create extends Action } $database = $authorization->skip(fn () => $dbForProject->getDocument('databases', $databaseId)); - if ($database->isEmpty() || (!$database->getAttribute('enabled', false) && !$isAPIKey && !$isPrivilegedUser)) { + if ($database->isEmpty() || $this->isDatabaseTypeMismatch($database) || (!$database->getAttribute('enabled', false) && !$isAPIKey && !$isPrivilegedUser)) { throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]); } diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Delete.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Delete.php index e0863b8ac7..55be2373a6 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Delete.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Delete.php @@ -110,7 +110,7 @@ class Delete extends Action $isAPIKey = $user->isKey($authorization->getRoles()); $isPrivilegedUser = $user->isPrivileged($authorization->getRoles()); - if ($database->isEmpty() || (!$database->getAttribute('enabled', false) && !$isAPIKey && !$isPrivilegedUser)) { + if ($database->isEmpty() || $this->isDatabaseTypeMismatch($database) || (!$database->getAttribute('enabled', false) && !$isAPIKey && !$isPrivilegedUser)) { throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]); } diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Get.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Get.php index c40e70d667..1c51e38e2e 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Get.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Get.php @@ -82,7 +82,7 @@ class Get extends Action $isPrivilegedUser = $user->isPrivileged($authorization->getRoles()); $database = $authorization->skip(fn () => $dbForProject->getDocument('databases', $databaseId)); - if ($database->isEmpty() || (!$database->getAttribute('enabled', false) && !$isAPIKey && !$isPrivilegedUser)) { + if ($database->isEmpty() || $this->isDatabaseTypeMismatch($database) || (!$database->getAttribute('enabled', false) && !$isAPIKey && !$isPrivilegedUser)) { throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]); } diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Logs/XList.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Logs/XList.php index 8aaac5fcb4..976a76bba7 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Logs/XList.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Logs/XList.php @@ -81,7 +81,7 @@ class XList extends Action public function action(string $databaseId, string $collectionId, string $documentId, array $queries, UtopiaResponse $response, Database $dbForProject, callable $getDatabasesDB, Locale $locale, Reader $geodb, Authorization $authorization, Audit $audit): void { $database = $authorization->skip(fn () => $dbForProject->getDocument('databases', $databaseId)); - if ($database->isEmpty()) { + if ($database->isEmpty() || $this->isDatabaseTypeMismatch($database)) { throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]); } diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Update.php index 4a675615da..7c80a578ff 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Update.php @@ -106,7 +106,7 @@ class Update extends Action $isAPIKey = $user->isKey($authorization->getRoles()); $isPrivilegedUser = $user->isPrivileged($authorization->getRoles()); - if ($database->isEmpty() || (!$database->getAttribute('enabled', false) && !$isAPIKey && !$isPrivilegedUser)) { + if ($database->isEmpty() || $this->isDatabaseTypeMismatch($database) || (!$database->getAttribute('enabled', false) && !$isAPIKey && !$isPrivilegedUser)) { throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]); } diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Upsert.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Upsert.php index ae940456f0..73fcf35b7b 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Upsert.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Upsert.php @@ -112,7 +112,7 @@ class Upsert extends Action $isPrivilegedUser = $user->isPrivileged($authorization->getRoles()); $database = $authorization->skip(fn () => $dbForProject->getDocument('databases', $databaseId)); - if ($database->isEmpty() || (!$database->getAttribute('enabled', false) && !$isAPIKey && !$isPrivilegedUser)) { + if ($database->isEmpty() || $this->isDatabaseTypeMismatch($database) || (!$database->getAttribute('enabled', false) && !$isAPIKey && !$isPrivilegedUser)) { throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]); } diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/XList.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/XList.php index afde3d0baa..fd1d5b53d4 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/XList.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/XList.php @@ -92,7 +92,7 @@ class XList extends Action $isPrivilegedUser = $user->isPrivileged($authorization->getRoles()); $database = $authorization->skip(fn () => $dbForProject->getDocument('databases', $databaseId)); - if ($database->isEmpty() || (!$database->getAttribute('enabled', false) && !$isAPIKey && !$isPrivilegedUser)) { + if ($database->isEmpty() || $this->isDatabaseTypeMismatch($database) || (!$database->getAttribute('enabled', false) && !$isAPIKey && !$isPrivilegedUser)) { throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]); } diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Get.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Get.php index 61b9d515f4..43364413db 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Get.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Get.php @@ -65,7 +65,7 @@ class Get extends Action { $database = $authorization->skip(fn () => $dbForProject->getDocument('databases', $databaseId)); - if ($database->isEmpty()) { + if ($database->isEmpty() || $this->isDatabaseTypeMismatch($database)) { throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]); } diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/Action.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/Action.php index 251e493cb6..4dad2429cc 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/Action.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/Action.php @@ -3,9 +3,9 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Indexes; use Appwrite\Extend\Exception; -use Utopia\Platform\Action as UtopiaAction; +use Appwrite\Platform\Modules\Databases\Http\Databases\Action as DatabasesAction; -abstract class Action extends UtopiaAction +abstract class Action extends DatabasesAction { /** * The current API context (either 'columnIndex' or 'index'). @@ -17,12 +17,14 @@ abstract class Action extends UtopiaAction */ abstract protected function getResponseModel(): string; - public function setHttpPath(string $path): UtopiaAction + public function setHttpPath(string $path): DatabasesAction { if (\str_contains($path, '/tablesdb')) { $this->context = COLUMN_INDEX; } - return parent::setHttpPath($path); + parent::setHttpPath($path); + + return $this; } /** diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/Create.php index 4e989621f1..2a2fffcc07 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/Create.php @@ -90,7 +90,7 @@ class Create extends Action { $db = $authorization->skip(fn () => $dbForProject->getDocument('databases', $databaseId)); - if ($db->isEmpty()) { + if ($db->isEmpty() || $this->isDatabaseTypeMismatch($db)) { throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]); } diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/Delete.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/Delete.php index 82cada6e0d..f88f833764 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/Delete.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/Delete.php @@ -80,7 +80,7 @@ class Delete extends Action { $db = $authorization->skip(fn () => $dbForProject->getDocument('databases', $databaseId)); - if ($db->isEmpty()) { + if ($db->isEmpty() || $this->isDatabaseTypeMismatch($db)) { throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]); } $collection = $dbForProject->getDocument('database_' . $db->getSequence(), $collectionId); diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/Get.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/Get.php index 0ab022f777..763fd86f7b 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/Get.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/Get.php @@ -67,7 +67,7 @@ class Get extends Action { $database = $authorization->skip(fn () => $dbForProject->getDocument('databases', $databaseId)); - if ($database->isEmpty()) { + if ($database->isEmpty() || $this->isDatabaseTypeMismatch($database)) { throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]); } $collection = $dbForProject->getDocument('database_' . $database->getSequence(), $collectionId); diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/XList.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/XList.php index a4f65d0fcc..c4d70c5fb6 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/XList.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/XList.php @@ -75,7 +75,7 @@ class XList extends Action /** @var Document $database */ $database = $authorization->skip(fn () => $dbForProject->getDocument('databases', $databaseId)); - if ($database->isEmpty()) { + if ($database->isEmpty() || $this->isDatabaseTypeMismatch($database)) { throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]); } diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Logs/XList.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Logs/XList.php index cc082532f9..f2b4e1b4fa 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Logs/XList.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Logs/XList.php @@ -80,7 +80,7 @@ class XList extends Action { $database = $authorization->skip(fn () => $dbForProject->getDocument('databases', $databaseId)); - if ($database->isEmpty()) { + if ($database->isEmpty() || $this->isDatabaseTypeMismatch($database)) { throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]); } diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Update.php index 800df6d044..6ba8b67bd4 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Update.php @@ -80,7 +80,7 @@ class Update extends Action public function action(string $databaseId, string $collectionId, ?string $name, ?array $permissions, bool $documentSecurity, bool $enabled, bool $purge, UtopiaResponse $response, Database $dbForProject, callable $getDatabasesDB, Event $queueForEvents, Authorization $authorization): void { $database = $authorization->skip(fn () => $dbForProject->getDocument('databases', $databaseId)); - if ($database->isEmpty()) { + if ($database->isEmpty() || $this->isDatabaseTypeMismatch($database)) { throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]); } diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/XList.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/XList.php index f2f2947016..5d1ccbd45f 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/XList.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/XList.php @@ -75,7 +75,7 @@ class XList extends Action { $database = $authorization->skip(fn () => $dbForProject->getDocument('databases', $databaseId)); - if ($database->isEmpty()) { + if ($database->isEmpty() || $this->isDatabaseTypeMismatch($database)) { throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]); } diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Delete.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Delete.php index 058c48d68f..6394e2667e 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Delete.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Delete.php @@ -15,7 +15,6 @@ use Appwrite\Utopia\Response as UtopiaResponse; use Utopia\Database\Database; use Utopia\Database\Validator\UID; use Utopia\Http\Adapter\Swoole\Response as SwooleResponse; -use Utopia\Platform\Action; class Delete extends Action { @@ -68,7 +67,7 @@ class Delete extends Action { $database = $dbForProject->getDocument('databases', $databaseId); - if ($database->isEmpty()) { + if ($database->isEmpty() || $this->isDatabaseTypeMismatch($database)) { throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]); } diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Get.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Get.php index 90561364ab..5ee8e2f5e3 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Get.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Get.php @@ -12,7 +12,6 @@ use Appwrite\Utopia\Response as UtopiaResponse; use Utopia\Database\Database; use Utopia\Database\Validator\UID; use Utopia\Http\Adapter\Swoole\Response as SwooleResponse; -use Utopia\Platform\Action; class Get extends Action { @@ -60,7 +59,7 @@ class Get extends Action { $database = $dbForProject->getDocument('databases', $databaseId); - if ($database->isEmpty()) { + if ($database->isEmpty() || $this->isDatabaseTypeMismatch($database)) { throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]); } diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Logs/XList.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Logs/XList.php index a13c6c4903..1474e602e3 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Logs/XList.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Logs/XList.php @@ -4,6 +4,7 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases\Logs; use Appwrite\Detector\Detector; use Appwrite\Extend\Exception; +use Appwrite\Platform\Modules\Databases\Http\Databases\Action; use Appwrite\SDK\AuthType; use Appwrite\SDK\ContentType; use Appwrite\SDK\Deprecated; @@ -23,7 +24,6 @@ use Utopia\Database\Validator\Query\Offset; use Utopia\Database\Validator\UID; use Utopia\Http\Adapter\Swoole\Response as SwooleResponse; use Utopia\Locale\Locale; -use Utopia\Platform\Action; class XList extends Action { @@ -75,7 +75,7 @@ class XList extends Action { $database = $dbForProject->getDocument('databases', $databaseId); - if ($database->isEmpty()) { + if ($database->isEmpty() || $this->isDatabaseTypeMismatch($database)) { throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]); } diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Transactions/Operations/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Transactions/Operations/Create.php index 4b9cf20b9c..3aca66cd6d 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Transactions/Operations/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Transactions/Operations/Create.php @@ -122,7 +122,7 @@ class Create extends Action } $database = $databases[$operation['databaseId']] ??= $authorization->skip(fn () => $dbForProject->getDocument('databases', $operation['databaseId'])); - if ($database->isEmpty() || (!$database->getAttribute('enabled', false) && !$isAPIKey && !$isPrivilegedUser)) { + if ($database->isEmpty() || $this->isDatabaseTypeMismatch($database) || (!$database->getAttribute('enabled', false) && !$isAPIKey && !$isPrivilegedUser)) { throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$operation['databaseId']]); } diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Update.php index c5d55c1b1b..c681d0b3f3 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Update.php @@ -13,7 +13,6 @@ use Appwrite\Utopia\Response as UtopiaResponse; use Utopia\Database\Database; use Utopia\Database\Validator\UID; use Utopia\Http\Adapter\Swoole\Response as SwooleResponse; -use Utopia\Platform\Action; use Utopia\Validator\Boolean; use Utopia\Validator\Text; @@ -69,7 +68,7 @@ class Update extends Action { $database = $dbForProject->getDocument('databases', $databaseId); - if ($database->isEmpty()) { + if ($database->isEmpty() || $this->isDatabaseTypeMismatch($database)) { throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]); } diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Usage/Get.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Usage/Get.php index 39e57a0aee..ee65cbd7ff 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Usage/Get.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Usage/Get.php @@ -3,7 +3,7 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases\Usage; use Appwrite\Extend\Exception; -use Appwrite\Platform\Action; +use Appwrite\Platform\Modules\Databases\Http\Databases\Action as DatabasesAction; use Appwrite\SDK\AuthType; use Appwrite\SDK\ContentType; use Appwrite\SDK\Deprecated; @@ -20,7 +20,7 @@ use Utopia\Http\Adapter\Swoole\Response as SwooleResponse; use Utopia\Platform\Enum; use Utopia\Validator\WhiteList; -class Get extends Action +class Get extends DatabasesAction { public static function getName(): string { @@ -29,7 +29,7 @@ class Get extends Action protected $databaseType = DATABASE_TYPE_LEGACY; - public function setHttpPath(string $path): Action + public function setHttpPath(string $path): DatabasesAction { $this->databaseType = match (true) { str_contains($path, '/documentsdb') => DATABASE_TYPE_DOCUMENTSDB, @@ -114,7 +114,7 @@ class Get extends Action { $database = $dbForProject->getDocument('databases', $databaseId); - if ($database->isEmpty()) { + if ($database->isEmpty() || $this->isDatabaseTypeMismatch($database)) { throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]); } diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/XList.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/XList.php index 21dbc83edc..840672114c 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/XList.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/XList.php @@ -29,7 +29,7 @@ class XList extends Action protected function getDatabaseTypeQueryFilters(): array { - return [Query::equal('type', [$this->getDatabaseType()])]; + return [Query::equal('type', $this->getAllowedDatabaseTypes())]; } public function __construct() diff --git a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Logs/XList.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Logs/XList.php index ccb421b36d..0df38fbf4b 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Logs/XList.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Logs/XList.php @@ -4,6 +4,7 @@ namespace Appwrite\Platform\Modules\Databases\Http\TablesDB\Logs; use Appwrite\Detector\Detector; use Appwrite\Extend\Exception; +use Appwrite\Platform\Modules\Databases\Http\Databases\Action; use Appwrite\SDK\AuthType; use Appwrite\SDK\ContentType; use Appwrite\SDK\Method; @@ -22,7 +23,6 @@ use Utopia\Database\Validator\Query\Offset; use Utopia\Database\Validator\UID; use Utopia\Http\Adapter\Swoole\Response as SwooleResponse; use Utopia\Locale\Locale; -use Utopia\Platform\Action; class XList extends Action { @@ -70,7 +70,7 @@ class XList extends Action { $database = $dbForProject->getDocument('databases', $databaseId); - if ($database->isEmpty()) { + if ($database->isEmpty() || $this->isDatabaseTypeMismatch($database)) { throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]); } diff --git a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/XList.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/XList.php index 8dc0f6521a..80a9bd3686 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/XList.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/XList.php @@ -9,7 +9,6 @@ use Appwrite\SDK\Method; use Appwrite\SDK\Response as SDKResponse; use Appwrite\Utopia\Database\Validator\Queries\Databases; use Appwrite\Utopia\Response as UtopiaResponse; -use Utopia\Database\Query; use Utopia\Http\Adapter\Swoole\Response as SwooleResponse; use Utopia\Validator\Boolean; use Utopia\Validator\Text; @@ -21,16 +20,6 @@ class XList extends DatabaseXList return 'listTablesDatabases'; } - protected function getDatabaseTypeQueryFilters(): array - { - return [ - Query::or([ - Query::equal('type', [DATABASE_TYPE_TABLESDB, DATABASE_TYPE_LEGACY]), - Query::isNull('type'), - ]), - ]; - } - public function __construct() { $this diff --git a/src/Appwrite/Platform/Modules/Databases/Http/VectorsDB/Collections/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/VectorsDB/Collections/Create.php index 3b346bb7c0..49de7f7cc5 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/VectorsDB/Collections/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/VectorsDB/Collections/Create.php @@ -85,7 +85,7 @@ class Create extends CollectionAction { $database = $authorization->skip(fn () => $dbForProject->getDocument('databases', $databaseId)); - if ($database->isEmpty()) { + if ($database->isEmpty() || $this->isDatabaseTypeMismatch($database)) { throw new Exception(Exception::DATABASE_NOT_FOUND); } diff --git a/src/Appwrite/Platform/Modules/Databases/Http/VectorsDB/Collections/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/VectorsDB/Collections/Update.php index f8ba767e7e..12b680496a 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/VectorsDB/Collections/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/VectorsDB/Collections/Update.php @@ -76,7 +76,7 @@ class Update extends CollectionAction public function action(string $databaseId, string $collectionId, ?string $name, ?int $dimensions, ?array $permissions, bool $documentSecurity, ?bool $enabled, UtopiaResponse $response, Database $dbForProject, callable $getDatabasesDB, Event $queueForEvents, Authorization $authorization): void { $database = $authorization->skip(fn () => $dbForProject->getDocument('databases', $databaseId)); - if ($database->isEmpty()) { + if ($database->isEmpty() || $this->isDatabaseTypeMismatch($database)) { throw new Exception(Exception::DATABASE_NOT_FOUND); } diff --git a/tests/unit/Platform/Modules/Databases/DatabaseTypeMismatchTest.php b/tests/unit/Platform/Modules/Databases/DatabaseTypeMismatchTest.php new file mode 100644 index 0000000000..68da1db3fa --- /dev/null +++ b/tests/unit/Platform/Modules/Databases/DatabaseTypeMismatchTest.php @@ -0,0 +1,102 @@ +isDatabaseTypeMismatch($database); + } + + /** @return string[] */ + public function exposeAllowedTypes(): array + { + return $this->getAllowedDatabaseTypes(); + } + }; + $action->setHttpPath('/v1/tablesdb/:databaseId/tables'); + + // TablesDB is the compatibility successor to the legacy databases API: + // the allowed set must equal what listTablesDatabases advertises. + $this->assertSame([DATABASE_TYPE_TABLESDB, DATABASE_TYPE_LEGACY], $action->exposeAllowedTypes()); + + $this->assertFalse($action->exposeMismatch(new Document(['type' => DATABASE_TYPE_TABLESDB]))); + $this->assertFalse($action->exposeMismatch(new Document(['type' => DATABASE_TYPE_LEGACY]))); + $this->assertTrue($action->exposeMismatch(new Document(['type' => DATABASE_TYPE_DOCUMENTSDB]))); + $this->assertTrue($action->exposeMismatch(new Document(['type' => DATABASE_TYPE_VECTORSDB]))); + // Databases always carry a non-null type (V23 backfilled old rows to + // legacy); an unexpected empty type is excluded by both the list and guard. + $this->assertTrue($action->exposeMismatch(new Document([]))); + } + + public function testDocumentsAndVectorsPathsScopeStrictlyToTheirOwnType(): void + { + $documents = new class () extends Action { + public static function getName(): string + { + return 'testDocumentsdbTypeGuard'; + } + + public function exposeMismatch(Document $database): bool + { + return $this->isDatabaseTypeMismatch($database); + } + }; + $documents->setHttpPath('/v1/documentsdb/:databaseId/collections'); + $this->assertFalse($documents->exposeMismatch(new Document(['type' => DATABASE_TYPE_DOCUMENTSDB]))); + $this->assertTrue($documents->exposeMismatch(new Document(['type' => DATABASE_TYPE_VECTORSDB]))); + $this->assertTrue($documents->exposeMismatch(new Document(['type' => DATABASE_TYPE_LEGACY]))); + $this->assertTrue($documents->exposeMismatch(new Document([]))); + + $vectors = new class () extends Action { + public static function getName(): string + { + return 'testVectorsdbTypeGuard'; + } + + public function exposeMismatch(Document $database): bool + { + return $this->isDatabaseTypeMismatch($database); + } + }; + $vectors->setHttpPath('/v1/vectorsdb/:databaseId/collections'); + $this->assertFalse($vectors->exposeMismatch(new Document(['type' => DATABASE_TYPE_VECTORSDB]))); + $this->assertTrue($vectors->exposeMismatch(new Document(['type' => DATABASE_TYPE_DOCUMENTSDB]))); + $this->assertTrue($vectors->exposeMismatch(new Document(['type' => DATABASE_TYPE_LEGACY]))); + } + + public function testLegacyDatabasesPathIsNeverTypeGuarded(): void + { + $legacy = new class () extends Action { + public static function getName(): string + { + return 'testLegacyTypeGuard'; + } + + public function exposeMismatch(Document $database): bool + { + return $this->isDatabaseTypeMismatch($database); + } + }; + $legacy->setHttpPath('/v1/databases/:databaseId/collections'); + $this->assertFalse($legacy->exposeMismatch(new Document(['type' => DATABASE_TYPE_LEGACY]))); + $this->assertFalse($legacy->exposeMismatch(new Document([]))); + $this->assertFalse($legacy->exposeMismatch(new Document(['type' => DATABASE_TYPE_TABLESDB]))); + $this->assertFalse($legacy->exposeMismatch(new Document(['type' => DATABASE_TYPE_DOCUMENTSDB]))); + } +} From cffdb38f41e3c5fded34f8ea3557800a0054f2a6 Mon Sep 17 00:00:00 2001 From: Chirag Aggarwal Date: Sat, 20 Jun 2026 19:26:30 +0530 Subject: [PATCH 23/31] Fix local installer dev flow (#12627) --- app/http.php | 12 +-- app/views/install/compose.phtml | 3 +- .../Installer/Http/Installer/Install.php | 9 +- .../Installer/Http/Installer/Reset.php | 27 ++++-- src/Appwrite/Platform/Installer/Server.php | 5 +- .../Modules/Storage/Http/Buckets/Create.php | 4 +- src/Appwrite/Platform/Tasks/Install.php | 94 ++++++++++++++----- 7 files changed, 115 insertions(+), 39 deletions(-) diff --git a/app/http.php b/app/http.php index 94bc5d01ac..6a1d7250be 100644 --- a/app/http.php +++ b/app/http.php @@ -270,8 +270,8 @@ function createDatabase(Container $resources, string $resourceKey, string $dbNam '$id' => ID::custom($index['$id']), 'type' => $index['type'], 'attributes' => $index['attributes'], - 'lengths' => $index['lengths'], - 'orders' => $index['orders'], + 'lengths' => $index['lengths'] ?? [], + 'orders' => $index['orders'] ?? [], ]), $collection['indexes']); $database->createCollection($key, $attributes, $indexes); @@ -353,8 +353,8 @@ $http->on(Constant::EVENT_START, function ($http) use ($payloadSize, $totalWorke '$id' => ID::custom($index['$id']), 'type' => $index['type'], 'attributes' => $index['attributes'], - 'lengths' => $index['lengths'], - 'orders' => $index['orders'], + 'lengths' => $index['lengths'] ?? [], + 'orders' => $index['orders'] ?? [], ]), $files['indexes']); $dbForPlatform->createCollection('bucket_' . $bucket->getSequence(), $attributes, $indexes); @@ -399,8 +399,8 @@ $http->on(Constant::EVENT_START, function ($http) use ($payloadSize, $totalWorke '$id' => ID::custom($index['$id']), 'type' => $index['type'], 'attributes' => $index['attributes'], - 'lengths' => $index['lengths'], - 'orders' => $index['orders'], + 'lengths' => $index['lengths'] ?? [], + 'orders' => $index['orders'] ?? [], ]), $files['indexes']); $authorization->skip(fn () => $dbForPlatform->createCollection('bucket_' . $bucket->getSequence(), $attributes, $indexes)); diff --git a/app/views/install/compose.phtml b/app/views/install/compose.phtml index abda3a650c..d04baa5e11 100644 --- a/app/views/install/compose.phtml +++ b/app/views/install/compose.phtml @@ -12,6 +12,7 @@ $version = $this->getParam('version', ''); $organization = $this->getParam('organization', ''); $image = $this->getParam('image', ''); $enableAssistant = $this->getParam('enableAssistant', false); +$executorImages = $this->getParam('executorImages', ''); $dbService = $this->getParam('database', 'mongodb'); $allowedDbServices = ['mariadb', 'mongodb']; if (!\in_array($dbService, $allowedDbServices, true)) { @@ -991,7 +992,6 @@ $hostPath = rtrim($this->getParam('hostPath', ''), '/'); image: openruntimes/executor:0.25.1 networks: - appwrite - - runtimes volumes: - /var/run/docker.sock:/var/run/docker.sock - appwrite-builds:/storage/builds:rw @@ -1003,6 +1003,7 @@ $hostPath = rtrim($this->getParam('hostPath', ''), '/'); environment: - OPR_EXECUTOR_CONNECTION_STORAGE=local://localhost - OPR_EXECUTOR_CONNECTION_BUILD_CACHE_STORAGE= + - OPR_EXECUTOR_IMAGES= - OPR_EXECUTOR_INACTIVE_TRESHOLD=$_APP_COMPUTE_INACTIVE_THRESHOLD - OPR_EXECUTOR_MAINTENANCE_INTERVAL=$_APP_COMPUTE_MAINTENANCE_INTERVAL - OPR_EXECUTOR_NETWORK=$_APP_COMPUTE_RUNTIMES_NETWORK diff --git a/src/Appwrite/Platform/Installer/Http/Installer/Install.php b/src/Appwrite/Platform/Installer/Http/Installer/Install.php index a3368a75b1..7cf81b5eb8 100644 --- a/src/Appwrite/Platform/Installer/Http/Installer/Install.php +++ b/src/Appwrite/Platform/Installer/Http/Installer/Install.php @@ -42,7 +42,14 @@ class Install extends Action ->param('accountPassword', '', new Password(allowEmpty: true), 'Account password', true) ->param('database', '', new WhiteList(['mongodb', 'mariadb', 'postgresql']), 'Database adapter', true) ->param('installId', '', new Text(64, 0), 'Installation ID', true) - ->param('retryStep', null, new Nullable(new WhiteList([Server::STEP_DOCKER_COMPOSE, Server::STEP_ENV_VARS, Server::STEP_DOCKER_CONTAINERS], true)), 'Retry from step', true) + ->param('retryStep', null, new Nullable(new WhiteList([ + Server::STEP_CONFIG_FILES, + Server::STEP_DOCKER_COMPOSE, + Server::STEP_ENV_VARS, + Server::STEP_DOCKER_CONTAINERS, + Server::STEP_ACCOUNT_SETUP, + Server::STEP_MIGRATION, + ], true)), 'Retry from step', true) ->param('migrate', false, new \Utopia\Validator\Boolean(true), 'Run database migration after upgrade', true) ->inject('request') ->inject('response') diff --git a/src/Appwrite/Platform/Installer/Http/Installer/Reset.php b/src/Appwrite/Platform/Installer/Http/Installer/Reset.php index 8e5b877473..0bd319019d 100644 --- a/src/Appwrite/Platform/Installer/Http/Installer/Reset.php +++ b/src/Appwrite/Platform/Installer/Http/Installer/Reset.php @@ -69,17 +69,33 @@ class Reset extends Action $isLocal = $config->isLocal(); $composeFileName = $isLocal ? 'docker-compose.web-installer.yml' : 'docker-compose.yml'; $envFileName = $isLocal ? '.env.web-installer' : '.env'; - $path = $isLocal ? '/usr/src/code' : '/usr/src/code/appwrite'; + $path = $isLocal ? $config->getHostPath() : '/usr/src/code/appwrite'; + + if ($path === null || $path === '') { + return 'Missing host path for local installer reset'; + } $composeFile = $path . '/' . $composeFileName; + $envFile = $path . '/' . $envFileName; if (file_exists($composeFile)) { - $command = array_map(escapeshellarg(...), [ + $command = [ 'docker', 'compose', - '-f', $composeFile, + ]; + if (file_exists($envFile)) { + $command[] = '--env-file'; + $command[] = $envFile; + } + $command = array_map(escapeshellarg(...), [ + ...$command, + '-f', + $composeFile, ...($isLocal ? ['--project-name', 'appwrite'] : []), - '--project-directory', $path, - 'down', '-v', '--remove-orphans', + '--project-directory', + $path, + 'down', + '-v', + '--remove-orphans', ]); $output = []; @@ -92,7 +108,6 @@ class Reset extends Action @unlink($composeFile); } - $envFile = $path . '/' . $envFileName; if (file_exists($envFile)) { @unlink($envFile); } diff --git a/src/Appwrite/Platform/Installer/Server.php b/src/Appwrite/Platform/Installer/Server.php index 26d82adf24..b86db4d93d 100644 --- a/src/Appwrite/Platform/Installer/Server.php +++ b/src/Appwrite/Platform/Installer/Server.php @@ -114,7 +114,6 @@ class Server } if (isset($opts['docker'])) { - $this->printInstallerUrl($host, $port); $this->startDockerInstaller($opts); } @@ -365,9 +364,13 @@ class Server '-i', '--rm', '--name', $container, + '--label', 'com.docker.compose.project=appwrite-installer', + '--label', 'com.docker.compose.service=appwrite-installer', + '--add-host', 'host.docker.internal:host-gateway', '-p', "127.0.0.1:$port:" . self::INSTALLER_WEB_PORT, '--volume', '/var/run/docker.sock:/var/run/docker.sock', '--volume', "$volumePath:/usr/src/code:rw", + '--volume', "$volumePath:$volumePath:rw", ]; $args[] = '-e'; $args[] = 'APPWRITE_INSTALLER_CONFIG=' . $configJson; diff --git a/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Create.php b/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Create.php index ebe06d0ccf..8f288c45d1 100644 --- a/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Create.php +++ b/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Create.php @@ -129,8 +129,8 @@ class Create extends Action '$id' => $index['$id'], 'type' => $index['type'], 'attributes' => $index['attributes'], - 'lengths' => $index['lengths'], - 'orders' => $index['orders'], + 'lengths' => $index['lengths'] ?? [], + 'orders' => $index['orders'] ?? [], ]); } diff --git a/src/Appwrite/Platform/Tasks/Install.php b/src/Appwrite/Platform/Tasks/Install.php index 3e11a4060c..75f3c5bf18 100644 --- a/src/Appwrite/Platform/Tasks/Install.php +++ b/src/Appwrite/Platform/Tasks/Install.php @@ -538,6 +538,19 @@ class Install extends Action $assistantKey = (string) ($input['_APP_ASSISTANT_OPENAI_API_KEY'] ?? ''); $enableAssistant = trim($assistantKey) !== ''; + $enabledRuntimes = \array_unique(\array_filter(\array_map( + 'trim', + \explode(',', ($input['_APP_FUNCTIONS_RUNTIMES'] ?? '') . ',' . ($input['_APP_SITES_RUNTIMES'] ?? '')) + ))); + $runtimes = Config::getParam('runtimes', []); + $runtimeImages = []; + foreach ($enabledRuntimes as $runtime) { + $imageName = $runtimes[$runtime]['image'] ?? ''; + if ($imageName !== '') { + $runtimeImages[] = $imageName; + } + } + $executorImages = \implode(',', \array_unique($runtimeImages)); $templateForCompose ->setParam('httpPort', $httpPort) @@ -547,17 +560,24 @@ class Install extends Action ->setParam('image', $image) ->setParam('database', $database) ->setParam('hostPath', $this->hostPath) - ->setParam('enableAssistant', $enableAssistant); + ->setParam('enableAssistant', $enableAssistant) + ->setParam('executorImages', $executorImages); $templateForEnv->setParam('vars', $input); $steps = [ InstallerServer::STEP_DOCKER_COMPOSE, InstallerServer::STEP_ENV_VARS, - InstallerServer::STEP_DOCKER_CONTAINERS + InstallerServer::STEP_DOCKER_CONTAINERS, + InstallerServer::STEP_ACCOUNT_SETUP, + InstallerServer::STEP_MIGRATION, ]; $startIndex = 0; + $resumeFromStep = match ($resumeFromStep) { + InstallerServer::STEP_CONFIG_FILES => InstallerServer::STEP_DOCKER_COMPOSE, + default => $resumeFromStep, + }; if ($resumeFromStep !== null) { $resumeIndex = array_search($resumeFromStep, $steps, true); if ($resumeIndex !== false) { @@ -597,37 +617,43 @@ class Install extends Action $this->updateProgress($progress, InstallerServer::STEP_CONFIG_FILES, InstallerServer::STATUS_COMPLETED, $messages); } - if ($database === 'mongodb' && !$useExistingConfig) { + if ($database === 'mongodb' && !$useExistingConfig && $startIndex <= 1) { $this->copyMongoEntrypointIfNeeded(); } if (!$noStart) { - $currentStep = InstallerServer::STEP_DOCKER_CONTAINERS; - $this->updateProgress($progress, InstallerServer::STEP_DOCKER_CONTAINERS, InstallerServer::STATUS_IN_PROGRESS, $messages); - $this->runDockerCompose($input, $isLocalInstall, $useExistingConfig, $isCLI, $progress, $isUpgrade); + $shouldStartContainers = $startIndex <= 2; + if ($shouldStartContainers) { + $currentStep = InstallerServer::STEP_DOCKER_CONTAINERS; + $this->updateProgress($progress, InstallerServer::STEP_DOCKER_CONTAINERS, InstallerServer::STATUS_IN_PROGRESS, $messages); + $this->runDockerCompose($input, $isLocalInstall, $useExistingConfig, $isCLI, $progress, $isUpgrade); - if (!$isUpgrade) { - $this->updateProgress($progress, InstallerServer::STEP_DOCKER_CONTAINERS, InstallerServer::STATUS_COMPLETED, $messages); - $this->updateProgress($progress, InstallerServer::STEP_ACCOUNT_SETUP, InstallerServer::STATUS_IN_PROGRESS, messageOverride: 'Creating Appwrite account...'); + if (!$isUpgrade) { + $this->updateProgress($progress, InstallerServer::STEP_DOCKER_CONTAINERS, InstallerServer::STATUS_COMPLETED, $messages); + $this->updateProgress($progress, InstallerServer::STEP_ACCOUNT_SETUP, InstallerServer::STATUS_IN_PROGRESS, messageOverride: 'Creating Appwrite account...'); + } } - if (!$isLocalInstall) { + if (!$isLocalInstall || file_exists('/.dockerenv') || file_exists('/run/.containerenv')) { $this->connectInstallerToAppwriteNetwork(); } $domain = $input['_APP_DOMAIN'] ?? 'localhost'; $healthStep = $isUpgrade ? InstallerServer::STEP_DOCKER_CONTAINERS : InstallerServer::STEP_ACCOUNT_SETUP; + if ($isUpgrade && $startIndex >= 4) { + $healthStep = InstallerServer::STEP_MIGRATION; + } if (!$isUpgrade) { $currentStep = InstallerServer::STEP_ACCOUNT_SETUP; } $apiUrl = $this->waitForApiReady($domain, $httpPort, $isLocalInstall, $progress, $healthStep); - if ($isUpgrade) { + if ($isUpgrade && $shouldStartContainers) { $this->updateProgress($progress, InstallerServer::STEP_DOCKER_CONTAINERS, InstallerServer::STATUS_COMPLETED, $messages); } - if (!$isUpgrade) { + if (!$isUpgrade && $startIndex <= 3) { $this->createInitialAdminAccount($account, $progress, $apiUrl, $domain); } @@ -762,13 +788,30 @@ class Install extends Action // Allow the SSE chunk to flush before the blocking exec usleep(100_000); - // Static command — no user input involved - $command = $isLocalInstall - ? 'docker compose exec appwrite migrate 2>&1' - : 'docker exec appwrite migrate 2>&1'; + if ($isLocalInstall) { + $composePath = $this->hostPath !== '' ? $this->hostPath : $this->path; + $command = [ + 'docker', + 'compose', + '--env-file', + $composePath . '/' . $this->getEnvFileName(), + '-f', + $composePath . '/' . $this->getComposeFileName(), + '--project-name', + 'appwrite', + '--project-directory', + $composePath, + 'exec', + 'appwrite', + 'migrate', + ]; + } else { + $command = ['docker', 'exec', 'appwrite', 'migrate']; + } + $commandLine = implode(' ', array_map(escapeshellarg(...), $command)); $output = []; - \exec($command, $output, $exit); + \exec($commandLine . ' 2>&1', $output, $exit); if ($exit !== 0) { $message = trim(implode("\n", $output)); @@ -856,9 +899,9 @@ class Install extends Action * the runtime context and returns whichever responds first. * * Candidates (in order of preference): - * - Docker internal DNS (http://appwrite) — only if on the appwrite network - * - host.docker.internal:{port} — reaches host-published ports from inside a container + * - Docker internal DNS (http://appwrite) — preferred when on the appwrite network * - localhost:{port} — works when running directly on the host (local dev) + * - host.docker.internal:{port} — non-local fallback for host-published ports */ private function waitForApiReady(string $domain, string $httpPort, bool $isLocalInstall, ?callable $progress, string $step = InstallerServer::STEP_ACCOUNT_SETUP): string { @@ -872,6 +915,7 @@ class Install extends Action if ($isLocalInstall) { $candidates = [ + self::APPWRITE_API_URL . $healthPath, 'http://localhost:' . $httpPort . $healthPath, ]; } else { @@ -1081,12 +1125,18 @@ class Install extends Action Console::log("Running \"docker compose up -d --remove-orphans --renew-anon-volumes\""); } - $composeFileName = $this->getComposeFileName(); - $composeFile = $this->path . '/' . $composeFileName; + $composePath = $this->path; + if ($isLocalInstall && $this->hostPath !== '') { + $composePath = $this->hostPath; + } + $composeFile = $composePath . '/' . $this->getComposeFileName(); + $envFile = $composePath . '/' . $this->getEnvFileName(); $command = [ 'docker', 'compose', + '--env-file', + $envFile, '-f', $composeFile, ]; @@ -1097,7 +1147,7 @@ class Install extends Action } $command[] = '--project-directory'; - $command[] = $this->path; + $command[] = $composePath; $command[] = 'up'; $command[] = '-d'; $command[] = '--remove-orphans'; From 2120f2f41e1b996996602a089dc7dd8e0af479a3 Mon Sep 17 00:00:00 2001 From: Chirag Aggarwal Date: Sat, 20 Jun 2026 20:53:26 +0530 Subject: [PATCH 24/31] Improve CI image handoff and merged-run behavior (#12629) --- .github/workflows/ci.yml | 169 ++++++++++++++------------------------- 1 file changed, 62 insertions(+), 107 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c2bd7ea4a7..488d635828 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,13 +1,12 @@ name: CI concurrency: - group: ci-${{ github.ref }} - cancel-in-progress: true + group: ci-${{ github.event_name == 'pull_request' && github.ref || github.run_id }} + cancel-in-progress: ${{ github.event_name == 'pull_request' }} env: COMPOSE_FILE: docker-compose.yml IMAGE: appwrite-dev - REGISTRY_IMAGE: ghcr.io/${{ github.repository }}/appwrite-dev K6_VERSION: '0.53.0' on: @@ -239,36 +238,36 @@ jobs: uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 with: script: | - const runner4 = `runs-on=${context.runId}/runner=4cpu-linux-x64/volume=120g/spot=false/extras=otel`; - const runner8 = `runs-on=${context.runId}/runner=8cpu-linux-x64/volume=120g/spot=false/extras=otel`; + const runner4 = `runs-on=${context.runId}/runner=4cpu-linux-x64/volume=120g/spot=false/extras=otel+ecr-cache`; + const runner8 = `runs-on=${context.runId}/runner=8cpu-linux-x64/volume=120g/spot=false/extras=otel+ecr-cache`; const services = [ - { name: 'Account', runner: runner4, functional: true, processes: null, timeout: 20 }, - { name: 'Avatars', runner: runner4, functional: true, processes: null, timeout: 20 }, - { name: 'Console', runner: runner4, functional: true, processes: null, timeout: 20 }, - { name: 'Databases', runner: runner8, functional: false, processes: 3, timeout: 30 }, - { name: 'TablesDB', runner: runner8, functional: false, processes: 3, timeout: 30 }, - { name: 'Functions', runner: runner4, functional: false, processes: null, timeout: 20 }, - { name: 'FunctionsSchedule', runner: runner4, functional: true, processes: null, timeout: 20 }, - { name: 'GraphQL', runner: runner4, functional: false, processes: null, timeout: 20 }, - { name: 'Health', runner: runner4, functional: true, processes: null, timeout: 20 }, - { name: 'Advisor', runner: runner4, functional: true, processes: null, timeout: 20 }, - { name: 'Locale', runner: runner4, functional: true, processes: null, timeout: 20 }, - { name: 'Projects', runner: runner4, functional: true, processes: null, timeout: 20 }, - { name: 'Realtime', runner: runner4, functional: false, processes: null, timeout: 20 }, - { name: 'Sites', runner: runner4, functional: true, processes: null, timeout: 20 }, - { name: 'Proxy', runner: runner4, functional: true, processes: null, timeout: 20 }, - { name: 'Storage', runner: runner4, functional: true, processes: null, timeout: 20 }, - { name: 'Tokens', runner: runner4, functional: true, processes: null, timeout: 20 }, - { name: 'Teams', runner: runner4, functional: true, processes: null, timeout: 20 }, - { name: 'Users', runner: runner4, functional: true, processes: null, timeout: 20 }, - { name: 'ProjectWebhooks', runner: runner4, functional: false, processes: null, timeout: 20 }, - { name: 'Webhooks', runner: runner4, functional: true, processes: null, timeout: 20 }, - { name: 'VCS', runner: runner4, functional: true, processes: null, timeout: 20 }, - { name: 'Messaging', runner: runner4, functional: true, processes: null, timeout: 20 }, - { name: 'Migrations', runner: runner4, functional: true, processes: 1, timeout: 20 }, - { name: 'Project', runner: runner4, functional: true, processes: null, timeout: 20 }, - { name: 'Presences', runner: runner4, functional: true, processes: null, timeout: 20 }, + { name: 'Account', runner: runner4, functional: true, processes: null, timeout: 15 }, + { name: 'Avatars', runner: runner4, functional: true, processes: null, timeout: 15 }, + { name: 'Console', runner: runner4, functional: true, processes: null, timeout: 15 }, + { name: 'Databases', runner: runner8, functional: false, processes: 3, timeout: 15 }, + { name: 'TablesDB', runner: runner8, functional: false, processes: 3, timeout: 15 }, + { name: 'Functions', runner: runner4, functional: false, processes: null, timeout: 15 }, + { name: 'FunctionsSchedule', runner: runner4, functional: true, processes: null, timeout: 15 }, + { name: 'GraphQL', runner: runner4, functional: false, processes: null, timeout: 15 }, + { name: 'Health', runner: runner4, functional: true, processes: null, timeout: 15 }, + { name: 'Advisor', runner: runner4, functional: true, processes: null, timeout: 15 }, + { name: 'Locale', runner: runner4, functional: true, processes: null, timeout: 15 }, + { name: 'Projects', runner: runner4, functional: true, processes: null, timeout: 15 }, + { name: 'Realtime', runner: runner4, functional: false, processes: null, timeout: 15 }, + { name: 'Sites', runner: runner4, functional: true, processes: null, timeout: 15 }, + { name: 'Proxy', runner: runner4, functional: true, processes: null, timeout: 15 }, + { name: 'Storage', runner: runner4, functional: true, processes: null, timeout: 15 }, + { name: 'Tokens', runner: runner4, functional: true, processes: null, timeout: 15 }, + { name: 'Teams', runner: runner4, functional: true, processes: null, timeout: 15 }, + { name: 'Users', runner: runner4, functional: true, processes: null, timeout: 15 }, + { name: 'ProjectWebhooks', runner: runner4, functional: false, processes: null, timeout: 15 }, + { name: 'Webhooks', runner: runner4, functional: true, processes: null, timeout: 15 }, + { name: 'VCS', runner: runner4, functional: true, processes: null, timeout: 15 }, + { name: 'Messaging', runner: runner4, functional: true, processes: null, timeout: 15 }, + { name: 'Migrations', runner: runner4, functional: true, processes: 1, timeout: 15 }, + { name: 'Project', runner: runner4, functional: true, processes: null, timeout: 15 }, + { name: 'Presences', runner: runner4, functional: true, processes: null, timeout: 15 }, ]; core.setOutput('services', JSON.stringify(services)); @@ -303,7 +302,7 @@ jobs: build: name: Build - runs-on: ubuntu-latest + runs-on: runs-on=${{ github.run_id }}/runner=4cpu-linux-x64/volume=120g/spot=false/extras=otel+s3-cache+ecr-cache steps: - name: Checkout repository uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 @@ -316,13 +315,6 @@ jobs: username: ${{ vars.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - - name: Login to GHCR - uses: docker/login-action@4907a6ddec9925e35a0a9e82d7399ccc52663121 # v4.1.0 - with: - registry: ghcr.io - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - name: Set up Docker Buildx uses: docker/setup-buildx-action@4d04d5d9486b7bd6fa91e7baf45bbb4f8b9deedd # v4.0.0 @@ -331,9 +323,9 @@ jobs: with: context: . push: true - tags: ${{ env.REGISTRY_IMAGE }}:${{ github.sha }} - cache-from: type=gha - cache-to: type=gha,mode=max + tags: ${{ env.RUNS_ON_ECR_CACHE }}:${{ env.IMAGE }}-${{ github.sha }} + cache-from: type=s3,blobs_prefix=cache/${{ github.repository }}/,manifests_prefix=cache/${{ github.repository }}/,region=${{ env.RUNS_ON_AWS_REGION }},bucket=${{ env.RUNS_ON_S3_BUCKET_CACHE }} + cache-to: type=s3,blobs_prefix=cache/${{ github.repository }}/,manifests_prefix=cache/${{ github.repository }}/,region=${{ env.RUNS_ON_AWS_REGION }},bucket=${{ env.RUNS_ON_S3_BUCKET_CACHE }},mode=max target: development build-args: | DEBUG=false @@ -342,7 +334,7 @@ jobs: unit: name: Tests / Unit - runs-on: ubuntu-latest + runs-on: runs-on=${{ github.run_id }}/runner=4cpu-linux-x64/volume=120g/spot=false/extras=otel+ecr-cache needs: build permissions: contents: read @@ -358,17 +350,10 @@ jobs: username: ${{ vars.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - - name: Login to GHCR - uses: docker/login-action@4907a6ddec9925e35a0a9e82d7399ccc52663121 # v4.1.0 - with: - registry: ghcr.io - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - name: Pull Docker Image run: | - docker pull ${{ env.REGISTRY_IMAGE }}:${{ github.sha }} - docker tag ${{ env.REGISTRY_IMAGE }}:${{ github.sha }} ${{ env.IMAGE }} + docker pull ${{ env.RUNS_ON_ECR_CACHE }}:${{ env.IMAGE }}-${{ github.sha }} + docker tag ${{ env.RUNS_ON_ECR_CACHE }}:${{ env.IMAGE }}-${{ github.sha }} ${{ env.IMAGE }} - name: Load and Start Appwrite timeout-minutes: 5 @@ -380,9 +365,10 @@ jobs: run: docker compose exec -T appwrite vars - name: Run Unit Tests + timeout-minutes: 15 uses: itznotabug/php-retry@d6bef45a8bff490babfb613e33b00d133e4062f0 # v3 with: - max_attempts: 2 + max_attempts: ${{ github.event_name == 'pull_request' && 2 || 1 }} retry_wait_seconds: 60 timeout_minutes: 15 job_id: ${{ job.check_run_id }} @@ -395,7 +381,7 @@ jobs: e2e_general: name: Tests / E2E / General - runs-on: ubuntu-latest + runs-on: runs-on=${{ github.run_id }}/runner=4cpu-linux-x64/volume=120g/spot=false/extras=otel+ecr-cache needs: build permissions: contents: read @@ -411,17 +397,10 @@ jobs: username: ${{ vars.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - - name: Login to GHCR - uses: docker/login-action@4907a6ddec9925e35a0a9e82d7399ccc52663121 # v4.1.0 - with: - registry: ghcr.io - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - name: Pull Docker Image run: | - docker pull ${{ env.REGISTRY_IMAGE }}:${{ github.sha }} - docker tag ${{ env.REGISTRY_IMAGE }}:${{ github.sha }} ${{ env.IMAGE }} + docker pull ${{ env.RUNS_ON_ECR_CACHE }}:${{ env.IMAGE }}-${{ github.sha }} + docker tag ${{ env.RUNS_ON_ECR_CACHE }}:${{ env.IMAGE }}-${{ github.sha }} ${{ env.IMAGE }} - name: Load and Start Appwrite timeout-minutes: 5 @@ -438,9 +417,10 @@ jobs: done - name: Run General Tests + timeout-minutes: 15 uses: itznotabug/php-retry@d6bef45a8bff490babfb613e33b00d133e4062f0 # v3 with: - max_attempts: 2 + max_attempts: ${{ github.event_name == 'pull_request' && 2 || 1 }} retry_wait_seconds: 60 timeout_minutes: 15 job_id: ${{ job.check_run_id }} @@ -502,17 +482,10 @@ jobs: username: ${{ vars.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - - name: Login to GHCR - uses: docker/login-action@4907a6ddec9925e35a0a9e82d7399ccc52663121 # v4.1.0 - with: - registry: ghcr.io - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - name: Pull Docker Image run: | - docker pull ${{ env.REGISTRY_IMAGE }}:${{ github.sha }} - docker tag ${{ env.REGISTRY_IMAGE }}:${{ github.sha }} ${{ env.IMAGE }} + docker pull ${{ env.RUNS_ON_ECR_CACHE }}:${{ env.IMAGE }}-${{ github.sha }} + docker tag ${{ env.RUNS_ON_ECR_CACHE }}:${{ env.IMAGE }}-${{ github.sha }} ${{ env.IMAGE }} - name: Load and Start Appwrite timeout-minutes: 5 @@ -534,9 +507,10 @@ jobs: done - name: Run tests + timeout-minutes: 15 uses: itznotabug/php-retry@d6bef45a8bff490babfb613e33b00d133e4062f0 # v3 with: - max_attempts: 2 + max_attempts: ${{ github.event_name == 'pull_request' && 2 || 1 }} retry_wait_seconds: 60 timeout_minutes: ${{ matrix.service.timeout }} job_id: ${{ job.check_run_id }} @@ -569,7 +543,7 @@ jobs: e2e_abuse: name: Tests / E2E / Abuse (${{ matrix.mode }}) - runs-on: ubuntu-latest + runs-on: runs-on=${{ github.run_id }}/runner=4cpu-linux-x64/volume=120g/spot=false/extras=otel+ecr-cache needs: [build, matrix] permissions: contents: read @@ -591,17 +565,10 @@ jobs: username: ${{ vars.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - - name: Login to GHCR - uses: docker/login-action@4907a6ddec9925e35a0a9e82d7399ccc52663121 # v4.1.0 - with: - registry: ghcr.io - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - name: Pull Docker Image run: | - docker pull ${{ env.REGISTRY_IMAGE }}:${{ github.sha }} - docker tag ${{ env.REGISTRY_IMAGE }}:${{ github.sha }} ${{ env.IMAGE }} + docker pull ${{ env.RUNS_ON_ECR_CACHE }}:${{ env.IMAGE }}-${{ github.sha }} + docker tag ${{ env.RUNS_ON_ECR_CACHE }}:${{ env.IMAGE }}-${{ github.sha }} ${{ env.IMAGE }} - name: Load and Start Appwrite timeout-minutes: 5 @@ -615,9 +582,10 @@ jobs: docker compose up -d --quiet-pull --wait - name: Run tests + timeout-minutes: 15 uses: itznotabug/php-retry@d6bef45a8bff490babfb613e33b00d133e4062f0 # v3 with: - max_attempts: 2 + max_attempts: ${{ github.event_name == 'pull_request' && 2 || 1 }} retry_wait_seconds: 60 timeout_minutes: 15 job_id: ${{ job.check_run_id }} @@ -636,7 +604,7 @@ jobs: e2e_screenshots: name: Tests / E2E / Screenshots (${{ matrix.mode }}) - runs-on: ubuntu-latest + runs-on: runs-on=${{ github.run_id }}/runner=4cpu-linux-x64/volume=120g/spot=false/extras=otel+ecr-cache needs: [build, matrix] permissions: contents: read @@ -656,17 +624,10 @@ jobs: username: ${{ vars.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - - name: Login to GHCR - uses: docker/login-action@4907a6ddec9925e35a0a9e82d7399ccc52663121 # v4.1.0 - with: - registry: ghcr.io - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - name: Pull Docker Image run: | - docker pull ${{ env.REGISTRY_IMAGE }}:${{ github.sha }} - docker tag ${{ env.REGISTRY_IMAGE }}:${{ github.sha }} ${{ env.IMAGE }} + docker pull ${{ env.RUNS_ON_ECR_CACHE }}:${{ env.IMAGE }}-${{ github.sha }} + docker tag ${{ env.RUNS_ON_ECR_CACHE }}:${{ env.IMAGE }}-${{ github.sha }} ${{ env.IMAGE }} - name: Load and Start Appwrite timeout-minutes: 5 @@ -687,9 +648,10 @@ jobs: done - name: Run tests + timeout-minutes: 15 uses: itznotabug/php-retry@d6bef45a8bff490babfb613e33b00d133e4062f0 # v3 with: - max_attempts: 2 + max_attempts: ${{ github.event_name == 'pull_request' && 2 || 1 }} retry_wait_seconds: 60 timeout_minutes: 15 job_id: ${{ job.check_run_id }} @@ -709,7 +671,7 @@ jobs: benchmark: name: Benchmark if: github.event_name == 'pull_request' || github.event_name == 'push' - runs-on: ubuntu-latest + runs-on: runs-on=${{ github.run_id }}/runner=4cpu-linux-x64/volume=120g/spot=false/extras=otel+ecr-cache needs: build permissions: actions: read @@ -729,18 +691,11 @@ jobs: username: ${{ vars.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - - name: Login to GHCR - uses: docker/login-action@4907a6ddec9925e35a0a9e82d7399ccc52663121 # v4.1.0 - with: - registry: ghcr.io - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - name: Pull Appwrite image run: | - docker pull ${{ env.REGISTRY_IMAGE }}:${{ github.sha }} - docker tag ${{ env.REGISTRY_IMAGE }}:${{ github.sha }} ${{ env.IMAGE }} - docker tag ${{ env.REGISTRY_IMAGE }}:${{ github.sha }} ${{ env.IMAGE }}:after + docker pull ${{ env.RUNS_ON_ECR_CACHE }}:${{ env.IMAGE }}-${{ github.sha }} + docker tag ${{ env.RUNS_ON_ECR_CACHE }}:${{ env.IMAGE }}-${{ github.sha }} ${{ env.IMAGE }} + docker tag ${{ env.RUNS_ON_ECR_CACHE }}:${{ env.IMAGE }}-${{ github.sha }} ${{ env.IMAGE }}:after - name: Setup k6 uses: grafana/setup-k6-action@db07bd9765aac508ef18982e52ab937fe633a065 # v1.2.1 From c2d84ee25e4eb04f6c11b27c26c489ffee35af5f Mon Sep 17 00:00:00 2001 From: loks0n <22452787+loks0n@users.noreply.github.com> Date: Sun, 21 Jun 2026 00:04:02 +0100 Subject: [PATCH 25/31] fix(audits): use span attributes instead of per-message Console logging The Audits worker logged on every message via Console (info/log/success/error), flooding worker logs in a hot path (thousands/s) with little signal. Replace with span telemetry on the batch flush: - drop "Aggregating audit logs" (logged per message, before the batch check) - on flush, add audits.projects and audits.count (events) to the span - on a per-project failure, add audits.error instead of Console::error Also fix a PHP 8.x deprecation: the project sequence was used directly as an array key, warning "Using null as an array offset is deprecated" when null. Cast to string (null -> "") to keep the prior coercion without the warning. Co-Authored-By: Claude Opus 4.8 (1M context) --- src/Appwrite/Platform/Workers/Audits.php | 26 +++++++++++++----------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/src/Appwrite/Platform/Workers/Audits.php b/src/Appwrite/Platform/Workers/Audits.php index e0f50756cb..6c45aa63f3 100644 --- a/src/Appwrite/Platform/Workers/Audits.php +++ b/src/Appwrite/Platform/Workers/Audits.php @@ -5,11 +5,11 @@ namespace Appwrite\Platform\Workers; use Appwrite\Event\Message\Audit; use Exception; use Throwable; -use Utopia\Console; use Utopia\Database\Document; use Utopia\Database\Exception\Structure; use Utopia\Platform\Action; use Utopia\Queue\Message; +use Utopia\Span\Span; use Utopia\System\System; class Audits extends Action @@ -63,8 +63,6 @@ class Audits extends Action $auditMessage = Audit::fromArray($payload); - Console::info('Aggregating audit logs'); - $event = $auditMessage->event; $auditPayload = ''; @@ -123,10 +121,11 @@ class Audits extends Action ]; } - if (isset($this->logs[$auditMessage->project->getSequence()])) { - $this->logs[$auditMessage->project->getSequence()]['logs'][] = $eventData; + $projectSequence = (string) $auditMessage->project->getSequence(); + if (isset($this->logs[$projectSequence])) { + $this->logs[$projectSequence]['logs'][] = $eventData; } else { - $this->logs[$auditMessage->project->getSequence()] = [ + $this->logs[$projectSequence] = [ 'project' => new Document([ '$id' => $auditMessage->project->getId(), '$sequence' => $auditMessage->project->getSequence(), @@ -148,22 +147,25 @@ class Audits extends Action return; } + $projects = 0; + $events = 0; foreach ($this->logs as $sequence => $projectLogs) { try { - Console::log('Processing Project "' . $sequence . '" batch with ' . count($projectLogs['logs']) . ' events'); - - $projectDocument = $projectLogs['project']; - $audit = $getAudit($projectDocument); + $audit = $getAudit($projectLogs['project']); $audit->logBatch($projectLogs['logs']); - Console::success('Audit logs processed successfully'); + $projects++; + $events += count($projectLogs['logs']); } catch (Throwable $e) { - Console::error('Error processing audit logs for Project "' . $sequence . '": ' . $e->getMessage()); + Span::add('audits.error', $e->getMessage()); } finally { unset($this->logs[$sequence]); } } + Span::add('audits.projects', $projects); + Span::add('audits.count', $events); + $this->lastTriggeredTime = time(); } } From 4ce89efe33e0ee8ba5b1522adbf171dfb8f90482 Mon Sep 17 00:00:00 2001 From: loks0n <22452787+loks0n@users.noreply.github.com> Date: Sun, 21 Jun 2026 17:27:27 +0100 Subject: [PATCH 26/31] fix(deletes): run execution-limit cleanup sequentially to avoid shared-connection crash deleteExecutionsByLimit() fanned the two resource types out with Swoole\Coroutine\batch(), but both coroutines share one $dbForProject (getProjectDB caches the Database/Pool per host). When one coroutine opens a delete transaction the Pool adapter pins that connection in a process-global field and routes the sibling coroutine's reads onto it, producing "2014 Cannot execute queries while other unbuffered queries are active" and crashing the worker. Process the resource types sequentially so only one transaction holds the connection at a time. Co-Authored-By: Claude Opus 4.8 (1M context) --- src/Appwrite/Platform/Workers/Deletes.php | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/Appwrite/Platform/Workers/Deletes.php b/src/Appwrite/Platform/Workers/Deletes.php index 9eda3dbd52..1ac808c682 100644 --- a/src/Appwrite/Platform/Workers/Deletes.php +++ b/src/Appwrite/Platform/Workers/Deletes.php @@ -1106,7 +1106,7 @@ class Deletes extends Action // fast path, no need to list anything! $delete($dbForProject, $resourceInternalId, $resourceType); } else { - $processResource = function (string $type) use ($dbForProject, $delete) { + foreach ([RESOURCE_TYPE_SITES, RESOURCE_TYPE_FUNCTIONS] as $type) { $this->listByGroup( collection: $type, queries: [Query::select(['$id', '$sequence'])], @@ -1115,13 +1115,7 @@ class Deletes extends Action $delete($dbForProject, $resource->getSequence(), $type); } ); - }; - - /* perform processing in parallel */ - batch([ - fn () => $processResource(RESOURCE_TYPE_SITES), - fn () => $processResource(RESOURCE_TYPE_FUNCTIONS), - ]); + } } } From 21b75e37785f2c9fb74e4199131041e4a199afef Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Mon, 22 Jun 2026 04:17:32 +0000 Subject: [PATCH 27/31] chore(deps): allow utopia-php/audit 2.6.* audit 2.6.0 carries the ClickHouse audit adapter tenant-leading sort key and LowCardinality schema change. CE/self-hosted uses the Database adapter, not ClickHouse, so this is purely a constraint widening with no functional change. utopia-php/database stays on 6.x. --- composer.json | 2 +- composer.lock | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/composer.json b/composer.json index 5d75f38d4b..bfd843c9a1 100644 --- a/composer.json +++ b/composer.json @@ -56,7 +56,7 @@ "utopia-php/abuse": "1.4.*", "utopia-php/agents": "2.*", "utopia-php/analytics": "0.15.*", - "utopia-php/audit": "2.5.*", + "utopia-php/audit": "2.6.*", "utopia-php/auth": "0.5.*", "utopia-php/cache": "^3.0", "utopia-php/cli": "^0.24", diff --git a/composer.lock b/composer.lock index a43b5016da..c999e053c7 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "264c11d2628eeebe5722497eca10e576", + "content-hash": "da448b447a61b122c0c454f2b7c86b0d", "packages": [ { "name": "adhocore/jwt", @@ -3269,16 +3269,16 @@ }, { "name": "utopia-php/audit", - "version": "2.5.0", + "version": "2.6.0", "source": { "type": "git", "url": "https://github.com/utopia-php/audit.git", - "reference": "d9e9bb50f2150e0a7ccbe24668ff7230e7cb7a20" + "reference": "f5bb07841e335e9ea7d4bd5860da1f580447014a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/audit/zipball/d9e9bb50f2150e0a7ccbe24668ff7230e7cb7a20", - "reference": "d9e9bb50f2150e0a7ccbe24668ff7230e7cb7a20", + "url": "https://api.github.com/repos/utopia-php/audit/zipball/f5bb07841e335e9ea7d4bd5860da1f580447014a", + "reference": "f5bb07841e335e9ea7d4bd5860da1f580447014a", "shasum": "" }, "require": { @@ -3313,9 +3313,9 @@ ], "support": { "issues": "https://github.com/utopia-php/audit/issues", - "source": "https://github.com/utopia-php/audit/tree/2.5.0" + "source": "https://github.com/utopia-php/audit/tree/2.6.0" }, - "time": "2026-06-18T11:19:26+00:00" + "time": "2026-06-22T03:33:28+00:00" }, { "name": "utopia-php/auth", From 3930df146c1ac1c5800cc59de1bb08103a921b1b Mon Sep 17 00:00:00 2001 From: Chirag Aggarwal Date: Mon, 22 Jun 2026 10:10:47 +0530 Subject: [PATCH 28/31] (test): report true per-test duration and de-duplicate variable build tests (#12637) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * (test): report true per-test duration and de-duplicate variable build tests The PHPUnit test reporter printed `durationSinceStart()` — wall-clock elapsed since the run began — and labeled it as per-test duration. That made the numbers climb monotonically across the run and flagged nearly every test past the 15s mark as "slow", even pure CRUD tests that finish in well under a second. Capture an elapsed-since-start stamp when each test is prepared and subtract it at finish, so the reported time and the "slow" warning are the test's own duration. Separately, the variable-in-build integration tests (testProjectVariableInFunction, testProjectVariableInSite) lived in the shared VariablesBase trait and therefore ran in both the console-client and custom-server suites — 4 real Docker/npm builds where 2 suffice. The contract is auth-side independent, so move them into VariablesCustomServerTest only and keep the cheap CRUD coverage shared. * (test): satisfy rector string-cast rule and document refactor pre-check Rector's StringCastAssertStringContainsStringRector requires (string) casts on the assertStringContains(Not) arguments in the moved build tests. Apply them, and add composer refactor / refactor:check to the AGENTS.md command table so the CI "Refactor" check is run before pushing. * fix: purge project cache after config updates * (test): stamp test start at PreparationStarted, not Prepared Prepared fires after setUp/fixtures run, so expensive e2e setup was excluded from the reported per-test duration and the slow-test warning. Listen on PreparationStarted (before preparation begins) instead, and rename the subscriber to match. * (ci): bump php-retry to node24 runtime commit itznotabug/php-retry#15 migrated the action runtime from the deprecated node20 to node24. The v3 tag has not been re-pointed yet, so pin the merged commit (d4500b9) directly to clear the "Node 20 is being deprecated" warning on the unit-test retry step. Updates all 5 pins. * (ci): combine PHP check jobs into a single Checks job * (test): use full-precision duration in per-test reporter durationSinceStart()->seconds() returns only the whole-second part, so the finish-minus-start delta dropped all sub-second time: a 10.9s→11.1s test reported 1000ms instead of ~200ms, and most sub-second tests reported 0ms. Use Duration::asFloat() (seconds + nanoseconds) for both the start stamp and the finish elapsed, and format output as rounded integer ms / 2-decimal seconds. * fix: remove project cache purge calls --- .github/workflows/ci.yml | 144 +++-------- AGENTS.md | 2 + tests/e2e/Services/Project/VariablesBase.php | 242 ----------------- .../Project/VariablesCustomServerTest.php | 243 ++++++++++++++++++ tests/extensions/TestFinishedSubscriber.php | 14 +- tests/extensions/TestHook.php | 1 + .../TestPreparationStartedSubscriber.php | 26 ++ 7 files changed, 321 insertions(+), 351 deletions(-) create mode 100644 tests/extensions/TestPreparationStartedSubscriber.php diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 488d635828..159782dfbb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -91,111 +91,13 @@ jobs: sarif_file: 'trivy-fs-results.sarif' category: 'trivy-source' - composer: - name: Checks / Composer + checks: + name: Checks runs-on: ubuntu-latest steps: - name: Checkout repository uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 - - name: Setup PHP - uses: shivammathur/setup-php@accd6127cb78bee3e8082180cb391013d204ef9f # 2.37.0 - with: - php-version: '8.3' - tools: composer:v2 - coverage: none - - - name: Validate - run: composer validate - - - name: Install dependencies - run: composer install --prefer-dist --no-progress --ignore-platform-reqs - - - name: Audit - env: - COMPOSER_NO_AUDIT: 0 - run: composer audit - - format: - name: Checks / Format - runs-on: ubuntu-latest - steps: - - name: Checkout repository - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 - with: - fetch-depth: 2 - - - run: git checkout HEAD^2 - if: github.event_name == 'pull_request' - - - name: Setup PHP - uses: shivammathur/setup-php@accd6127cb78bee3e8082180cb391013d204ef9f # 2.37.0 - with: - php-version: '8.3' - tools: composer:v2 - coverage: none - - - name: Install dependencies - run: composer install --prefer-dist --no-progress --ignore-platform-reqs - - - name: Run Linter - run: composer lint - - refactor: - name: Checks / Refactor - runs-on: ubuntu-latest - steps: - - name: Checkout repository - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 - - - name: Setup PHP - uses: shivammathur/setup-php@accd6127cb78bee3e8082180cb391013d204ef9f # 2.37.0 - with: - php-version: '8.3' - tools: composer:v2 - coverage: none - - - name: Install dependencies - run: composer install --prefer-dist --no-progress --ignore-platform-reqs - - - name: Run Rector - run: composer refactor:check - - analyze: - name: Checks / Analyze - runs-on: ubuntu-latest - steps: - - name: Check out the repo - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 - - - name: Setup PHP - uses: shivammathur/setup-php@accd6127cb78bee3e8082180cb391013d204ef9f # 2.37.0 - with: - php-version: '8.3' - tools: composer:v2 - coverage: none - - - name: Install dependencies - run: composer install --prefer-dist --no-progress --ignore-platform-reqs - - - name: Cache PHPStan result cache - uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5 - with: - path: .phpstan-cache - key: phpstan-${{ github.sha }} - restore-keys: | - phpstan- - - - name: Run PHPStan - run: composer analyze -- --no-progress - - specs: - name: Checks / Specs - runs-on: ubuntu-latest - steps: - - name: Check out the repo - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 - - name: Setup PHP uses: shivammathur/setup-php@accd6127cb78bee3e8082180cb391013d204ef9f # 2.37.0 with: @@ -204,10 +106,42 @@ jobs: tools: composer:v2 coverage: none + - name: Validate composer.json + run: composer validate + - name: Install dependencies + id: install run: composer install --prefer-dist --no-progress --ignore-platform-reqs + - name: Cache PHPStan result cache + if: ${{ !cancelled() && steps.install.outcome == 'success' }} + uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5 + with: + path: .phpstan-cache + key: phpstan-${{ github.sha }} + restore-keys: | + phpstan- + + - name: Audit dependencies + if: ${{ !cancelled() && steps.install.outcome == 'success' }} + env: + COMPOSER_NO_AUDIT: 0 + run: composer audit + + - name: Run Linter + if: ${{ !cancelled() && steps.install.outcome == 'success' }} + run: composer lint + + - name: Run Rector + if: ${{ !cancelled() && steps.install.outcome == 'success' }} + run: composer refactor:check + + - name: Run PHPStan + if: ${{ !cancelled() && steps.install.outcome == 'success' }} + run: composer analyze -- --no-progress + - name: Generate specs + if: ${{ !cancelled() && steps.install.outcome == 'success' }} run: _APP_STORAGE_LIMIT=5368709120 php app/cli.php specs --version=latest --git=no locale: @@ -366,7 +300,7 @@ jobs: - name: Run Unit Tests timeout-minutes: 15 - uses: itznotabug/php-retry@d6bef45a8bff490babfb613e33b00d133e4062f0 # v3 + uses: itznotabug/php-retry@d4500b9db3258e2cc8857427980f28e1611eb79c # v3 with: max_attempts: ${{ github.event_name == 'pull_request' && 2 || 1 }} retry_wait_seconds: 60 @@ -418,7 +352,7 @@ jobs: - name: Run General Tests timeout-minutes: 15 - uses: itznotabug/php-retry@d6bef45a8bff490babfb613e33b00d133e4062f0 # v3 + uses: itznotabug/php-retry@d4500b9db3258e2cc8857427980f28e1611eb79c # v3 with: max_attempts: ${{ github.event_name == 'pull_request' && 2 || 1 }} retry_wait_seconds: 60 @@ -508,7 +442,7 @@ jobs: - name: Run tests timeout-minutes: 15 - uses: itznotabug/php-retry@d6bef45a8bff490babfb613e33b00d133e4062f0 # v3 + uses: itznotabug/php-retry@d4500b9db3258e2cc8857427980f28e1611eb79c # v3 with: max_attempts: ${{ github.event_name == 'pull_request' && 2 || 1 }} retry_wait_seconds: 60 @@ -583,7 +517,7 @@ jobs: - name: Run tests timeout-minutes: 15 - uses: itznotabug/php-retry@d6bef45a8bff490babfb613e33b00d133e4062f0 # v3 + uses: itznotabug/php-retry@d4500b9db3258e2cc8857427980f28e1611eb79c # v3 with: max_attempts: ${{ github.event_name == 'pull_request' && 2 || 1 }} retry_wait_seconds: 60 @@ -649,7 +583,7 @@ jobs: - name: Run tests timeout-minutes: 15 - uses: itznotabug/php-retry@d6bef45a8bff490babfb613e33b00d133e4062f0 # v3 + uses: itznotabug/php-retry@d4500b9db3258e2cc8857427980f28e1611eb79c # v3 with: max_attempts: ${{ github.event_name == 'pull_request' && 2 || 1 }} retry_wait_seconds: 60 diff --git a/AGENTS.md b/AGENTS.md index edaeff9ea5..2a73d6d90e 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -15,6 +15,8 @@ Self-hosted Backend-as-a-Service platform. Hybrid monolithic-microservice archit | `composer lint ` | Check formatting of a file | | `composer analyze` | Static analysis (PHPStan level 3) | | `composer check` | Same as `analyze` | +| `composer refactor:check` | Rector dry-run over `tests/` (CI "Refactor" check) | +| `composer refactor` | Apply Rector fixes | ## Stack diff --git a/tests/e2e/Services/Project/VariablesBase.php b/tests/e2e/Services/Project/VariablesBase.php index b1f8ed61b9..c6cf4115f2 100644 --- a/tests/e2e/Services/Project/VariablesBase.php +++ b/tests/e2e/Services/Project/VariablesBase.php @@ -3,7 +3,6 @@ namespace Tests\E2E\Services\Project; use Appwrite\Tests\Async; -use Appwrite\Tests\Async\Exceptions\Critical; use CURLFile; use Tests\E2E\Client; use Utopia\Console; @@ -11,7 +10,6 @@ use Utopia\Database\Document; use Utopia\Database\Helpers\ID; use Utopia\Database\Query; use Utopia\Database\Validator\Datetime as DatetimeValidator; -use Utopia\System\System; trait VariablesBase { @@ -738,246 +736,6 @@ trait VariablesBase $this->assertSame('variable_not_found', $delete['body']['type']); } - // Integration tests - - /** - * Test that project variables are available in function build and runtime. - */ - public function testProjectVariableInFunction(): void - { - $projectId = $this->getProject()['$id']; - $apiKey = $this->getProject()['apiKey']; - - // 1. Create a project variable - $variable = $this->createVariable( - ID::unique(), - 'GLOBAL_VARIABLE', - 'Project Variable Value', - false - ); - - $this->assertSame(201, $variable['headers']['status-code']); - $variableId = $variable['body']['$id']; - - // 2. Create a function with build commands that echo the variable - $function = $this->client->call(Client::METHOD_POST, '/functions', [ - 'content-type' => 'application/json', - 'x-appwrite-project' => $projectId, - 'x-appwrite-key' => $apiKey, - ], [ - 'functionId' => ID::unique(), - 'name' => 'Project Variable Test', - 'runtime' => 'node-22', - 'entrypoint' => 'index.js', - 'execute' => ['any'], - 'timeout' => 15, - 'commands' => 'echo $GLOBAL_VARIABLE', - ]); - - $this->assertSame(201, $function['headers']['status-code']); - $functionId = $function['body']['$id']; - - // 3. Deploy the function (basic function reads GLOBAL_VARIABLE from env) - $deployment = $this->client->call(Client::METHOD_POST, '/functions/' . $functionId . '/deployments', [ - 'content-type' => 'multipart/form-data', - 'x-appwrite-project' => $projectId, - 'x-appwrite-key' => $apiKey, - ], [ - 'code' => $this->packageCode('functions', 'basic'), - 'activate' => true, - ]); - - $this->assertSame(202, $deployment['headers']['status-code']); - $deploymentId = $deployment['body']['$id'] ?? ''; - - // 4. Wait for deployment to be ready and activated - $this->assertEventually(function () use ($projectId, $apiKey, $functionId, $deploymentId) { - $deployment = $this->client->call(Client::METHOD_GET, '/functions/' . $functionId . '/deployments/' . $deploymentId, [ - 'content-type' => 'application/json', - 'x-appwrite-project' => $projectId, - 'x-appwrite-key' => $apiKey, - ]); - - $status = $deployment['body']['status'] ?? ''; - if ($status === 'failed') { - throw new Critical('Deployment build failed: ' . ($deployment['body']['buildLogs'] ?? 'no logs')); - } - - $this->assertSame('ready', $status, 'Deployment status is not ready'); - }, 120000, 500); - - $this->assertEventually(function () use ($projectId, $apiKey, $functionId, $deploymentId) { - $function = $this->client->call(Client::METHOD_GET, '/functions/' . $functionId, [ - 'content-type' => 'application/json', - 'x-appwrite-project' => $projectId, - 'x-appwrite-key' => $apiKey, - ]); - $this->assertSame($deploymentId, $function['body']['deploymentId'] ?? ''); - }, 120000, 500); - - // 5. Verify the project variable was available during build - $deployment = $this->client->call(Client::METHOD_GET, '/functions/' . $functionId . '/deployments/' . $deploymentId, [ - 'content-type' => 'application/json', - 'x-appwrite-project' => $projectId, - 'x-appwrite-key' => $apiKey, - ]); - $this->assertSame(200, $deployment['headers']['status-code']); - $this->assertStringContainsString('Project Variable Value', $deployment['body']['buildLogs']); - - // 6. Execute the function and verify the project variable is in runtime output - $execution = $this->client->call(Client::METHOD_POST, '/functions/' . $functionId . '/executions', array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $projectId, - ], $this->getHeaders()), [ - 'async' => false, - ]); - - $this->assertSame(201, $execution['headers']['status-code']); - $this->assertSame('completed', $execution['body']['status']); - $this->assertSame(200, $execution['body']['responseStatusCode']); - $output = json_decode($execution['body']['responseBody'], true); - $this->assertSame('Project Variable Value', $output['GLOBAL_VARIABLE']); - - // Cleanup - $this->client->call(Client::METHOD_DELETE, '/functions/' . $functionId, [ - 'content-type' => 'application/json', - 'x-appwrite-project' => $projectId, - 'x-appwrite-key' => $apiKey, - ]); - $this->deleteVariable($variableId); - } - - /** - * Test that project variables are available in site build and SSR runtime. - */ - public function testProjectVariableInSite(): void - { - $projectId = $this->getProject()['$id']; - $apiKey = $this->getProject()['apiKey']; - - // 1. Create a project variable - $variable = $this->createVariable( - ID::unique(), - 'name', - 'ProjectVarTest', - ); - - $this->assertSame(201, $variable['headers']['status-code']); - $variableId = $variable['body']['$id']; - - // 2. Create a site - $site = $this->client->call(Client::METHOD_POST, '/sites', [ - 'content-type' => 'application/json', - 'x-appwrite-project' => $projectId, - 'x-appwrite-key' => $apiKey, - ], [ - 'siteId' => ID::unique(), - 'name' => 'Project Variable Astro Site', - 'framework' => 'astro', - 'adapter' => 'ssr', - 'buildRuntime' => 'node-22', - 'outputDirectory' => './dist', - 'buildCommand' => 'echo $name && npm run build', - 'installCommand' => 'npm ci', - 'fallbackFile' => '', - ]); - - $this->assertSame(201, $site['headers']['status-code']); - $siteId = $site['body']['$id']; - - // 3. Setup domain for proxy access - $sitesDomain = \explode(',', System::getEnv('_APP_DOMAIN_SITES', ''))[0]; - $rule = $this->client->call(Client::METHOD_POST, '/proxy/rules/site', array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $projectId, - ], $this->getHeaders()), [ - 'domain' => ID::unique() . '.' . $sitesDomain, - 'siteId' => $siteId, - ]); - - $this->assertSame(201, $rule['headers']['status-code']); - - // 4. Deploy the site (astro site reads import.meta.env.name) - $deployment = $this->client->call(Client::METHOD_POST, '/sites/' . $siteId . '/deployments', [ - 'content-type' => 'multipart/form-data', - 'x-appwrite-project' => $projectId, - 'x-appwrite-key' => $apiKey, - ], [ - 'code' => $this->packageCode('sites', 'astro'), - 'activate' => 'true', - ]); - - $this->assertSame(202, $deployment['headers']['status-code']); - $deploymentId = $deployment['body']['$id'] ?? ''; - - // 5. Wait for deployment to be ready and activated - $this->assertEventually(function () use ($projectId, $apiKey, $siteId, $deploymentId) { - $deployment = $this->client->call(Client::METHOD_GET, '/sites/' . $siteId . '/deployments/' . $deploymentId, [ - 'content-type' => 'application/json', - 'x-appwrite-project' => $projectId, - 'x-appwrite-key' => $apiKey, - ]); - - $status = $deployment['body']['status'] ?? ''; - if ($status === 'failed') { - throw new Critical('Site deployment failed: ' . json_encode($deployment['body'], JSON_PRETTY_PRINT)); - } - - $this->assertSame('ready', $status, 'Deployment status is not ready'); - }, 120000, 500); - - $this->assertEventually(function () use ($projectId, $apiKey, $siteId, $deploymentId) { - $site = $this->client->call(Client::METHOD_GET, '/sites/' . $siteId, [ - 'content-type' => 'application/json', - 'x-appwrite-project' => $projectId, - 'x-appwrite-key' => $apiKey, - ]); - $this->assertSame($deploymentId, $site['body']['deploymentId'] ?? ''); - }, 120000, 500); - - // 6. Verify the project variable was available during build - $deployment = $this->client->call(Client::METHOD_GET, '/sites/' . $siteId . '/deployments/' . $deploymentId, [ - 'content-type' => 'application/json', - 'x-appwrite-project' => $projectId, - 'x-appwrite-key' => $apiKey, - ]); - $this->assertSame(200, $deployment['headers']['status-code']); - $this->assertStringContainsString('ProjectVarTest', $deployment['body']['buildLogs']); - - // 7. Get the domain and access the site - $rules = $this->client->call(Client::METHOD_GET, '/proxy/rules', array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $projectId, - ], $this->getHeaders()), [ - 'queries' => [ - Query::equal('deploymentResourceId', [$siteId])->toString(), - Query::equal('trigger', ['manual'])->toString(), - Query::equal('type', ['deployment'])->toString(), - ], - ]); - - $this->assertSame(200, $rules['headers']['status-code']); - $this->assertGreaterThanOrEqual(1, \count($rules['body']['rules'])); - $domain = $rules['body']['rules'][0]['domain']; - - $proxyClient = new Client(); - $proxyClient->setEndpoint('http://' . $domain); - - $response = $proxyClient->call(Client::METHOD_GET, '/'); - - $this->assertSame(200, $response['headers']['status-code']); - $this->assertStringContainsString('Env variable is ProjectVarTest', $response['body']); - $this->assertStringNotContainsString('Variable not found', $response['body']); - - // Cleanup - $this->client->call(Client::METHOD_DELETE, '/sites/' . $siteId, [ - 'content-type' => 'application/json', - 'x-appwrite-project' => $projectId, - 'x-appwrite-key' => $apiKey, - ]); - $this->deleteVariable($variableId); - } - // Helpers protected function createVariable(string $variableId, ?string $key, ?string $value, ?bool $secret = null, bool $authenticated = true): mixed diff --git a/tests/e2e/Services/Project/VariablesCustomServerTest.php b/tests/e2e/Services/Project/VariablesCustomServerTest.php index f4af7069cb..6c710fecf2 100644 --- a/tests/e2e/Services/Project/VariablesCustomServerTest.php +++ b/tests/e2e/Services/Project/VariablesCustomServerTest.php @@ -4,13 +4,256 @@ declare(strict_types=1); namespace Tests\E2E\Services\Project; +use Appwrite\Tests\Async\Exceptions\Critical; +use Tests\E2E\Client; use Tests\E2E\Scopes\ProjectCustom; use Tests\E2E\Scopes\Scope; use Tests\E2E\Scopes\SideServer; +use Utopia\Database\Helpers\ID; +use Utopia\Database\Query; +use Utopia\System\System; final class VariablesCustomServerTest extends Scope { use VariablesBase; use ProjectCustom; use SideServer; + + /** + * Test that project variables are available in function build and runtime. + */ + public function testProjectVariableInFunction(): void + { + $projectId = $this->getProject()['$id']; + $apiKey = $this->getProject()['apiKey']; + + // 1. Create a project variable + $variable = $this->createVariable( + ID::unique(), + 'GLOBAL_VARIABLE', + 'Project Variable Value', + false + ); + + $this->assertSame(201, $variable['headers']['status-code']); + $variableId = $variable['body']['$id']; + + // 2. Create a function with build commands that echo the variable + $function = $this->client->call(Client::METHOD_POST, '/functions', [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $projectId, + 'x-appwrite-key' => $apiKey, + ], [ + 'functionId' => ID::unique(), + 'name' => 'Project Variable Test', + 'runtime' => 'node-22', + 'entrypoint' => 'index.js', + 'execute' => ['any'], + 'timeout' => 15, + 'commands' => 'echo $GLOBAL_VARIABLE', + ]); + + $this->assertSame(201, $function['headers']['status-code']); + $functionId = $function['body']['$id']; + + // 3. Deploy the function (basic function reads GLOBAL_VARIABLE from env) + $deployment = $this->client->call(Client::METHOD_POST, '/functions/' . $functionId . '/deployments', [ + 'content-type' => 'multipart/form-data', + 'x-appwrite-project' => $projectId, + 'x-appwrite-key' => $apiKey, + ], [ + 'code' => $this->packageCode('functions', 'basic'), + 'activate' => true, + ]); + + $this->assertSame(202, $deployment['headers']['status-code']); + $deploymentId = $deployment['body']['$id'] ?? ''; + + // 4. Wait for deployment to be ready and activated + $this->assertEventually(function () use ($projectId, $apiKey, $functionId, $deploymentId) { + $deployment = $this->client->call(Client::METHOD_GET, '/functions/' . $functionId . '/deployments/' . $deploymentId, [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $projectId, + 'x-appwrite-key' => $apiKey, + ]); + + $status = $deployment['body']['status'] ?? ''; + if ($status === 'failed') { + throw new Critical('Deployment build failed: ' . ($deployment['body']['buildLogs'] ?? 'no logs')); + } + + $this->assertSame('ready', $status, 'Deployment status is not ready'); + }, 120000, 500); + + $this->assertEventually(function () use ($projectId, $apiKey, $functionId, $deploymentId) { + $function = $this->client->call(Client::METHOD_GET, '/functions/' . $functionId, [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $projectId, + 'x-appwrite-key' => $apiKey, + ]); + $this->assertSame($deploymentId, $function['body']['deploymentId'] ?? ''); + }, 120000, 500); + + // 5. Verify the project variable was available during build + $deployment = $this->client->call(Client::METHOD_GET, '/functions/' . $functionId . '/deployments/' . $deploymentId, [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $projectId, + 'x-appwrite-key' => $apiKey, + ]); + $this->assertSame(200, $deployment['headers']['status-code']); + $this->assertStringContainsString('Project Variable Value', (string) $deployment['body']['buildLogs']); + + // 6. Execute the function and verify the project variable is in runtime output + $execution = $this->client->call(Client::METHOD_POST, '/functions/' . $functionId . '/executions', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $projectId, + ], $this->getHeaders()), [ + 'async' => false, + ]); + + $this->assertSame(201, $execution['headers']['status-code']); + $this->assertSame('completed', $execution['body']['status']); + $this->assertSame(200, $execution['body']['responseStatusCode']); + $output = json_decode($execution['body']['responseBody'], true); + $this->assertSame('Project Variable Value', $output['GLOBAL_VARIABLE']); + + // Cleanup + $this->client->call(Client::METHOD_DELETE, '/functions/' . $functionId, [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $projectId, + 'x-appwrite-key' => $apiKey, + ]); + $this->deleteVariable($variableId); + } + + /** + * Test that project variables are available in site build and SSR runtime. + */ + public function testProjectVariableInSite(): void + { + $projectId = $this->getProject()['$id']; + $apiKey = $this->getProject()['apiKey']; + + // 1. Create a project variable + $variable = $this->createVariable( + ID::unique(), + 'name', + 'ProjectVarTest', + ); + + $this->assertSame(201, $variable['headers']['status-code']); + $variableId = $variable['body']['$id']; + + // 2. Create a site + $site = $this->client->call(Client::METHOD_POST, '/sites', [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $projectId, + 'x-appwrite-key' => $apiKey, + ], [ + 'siteId' => ID::unique(), + 'name' => 'Project Variable Astro Site', + 'framework' => 'astro', + 'adapter' => 'ssr', + 'buildRuntime' => 'node-22', + 'outputDirectory' => './dist', + 'buildCommand' => 'echo $name && npm run build', + 'installCommand' => 'npm ci', + 'fallbackFile' => '', + ]); + + $this->assertSame(201, $site['headers']['status-code']); + $siteId = $site['body']['$id']; + + // 3. Setup domain for proxy access + $sitesDomain = \explode(',', System::getEnv('_APP_DOMAIN_SITES', ''))[0]; + $rule = $this->client->call(Client::METHOD_POST, '/proxy/rules/site', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $projectId, + ], $this->getHeaders()), [ + 'domain' => ID::unique() . '.' . $sitesDomain, + 'siteId' => $siteId, + ]); + + $this->assertSame(201, $rule['headers']['status-code']); + + // 4. Deploy the site (astro site reads import.meta.env.name) + $deployment = $this->client->call(Client::METHOD_POST, '/sites/' . $siteId . '/deployments', [ + 'content-type' => 'multipart/form-data', + 'x-appwrite-project' => $projectId, + 'x-appwrite-key' => $apiKey, + ], [ + 'code' => $this->packageCode('sites', 'astro'), + 'activate' => 'true', + ]); + + $this->assertSame(202, $deployment['headers']['status-code']); + $deploymentId = $deployment['body']['$id'] ?? ''; + + // 5. Wait for deployment to be ready and activated + $this->assertEventually(function () use ($projectId, $apiKey, $siteId, $deploymentId) { + $deployment = $this->client->call(Client::METHOD_GET, '/sites/' . $siteId . '/deployments/' . $deploymentId, [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $projectId, + 'x-appwrite-key' => $apiKey, + ]); + + $status = $deployment['body']['status'] ?? ''; + if ($status === 'failed') { + throw new Critical('Site deployment failed: ' . json_encode($deployment['body'], JSON_PRETTY_PRINT)); + } + + $this->assertSame('ready', $status, 'Deployment status is not ready'); + }, 120000, 500); + + $this->assertEventually(function () use ($projectId, $apiKey, $siteId, $deploymentId) { + $site = $this->client->call(Client::METHOD_GET, '/sites/' . $siteId, [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $projectId, + 'x-appwrite-key' => $apiKey, + ]); + $this->assertSame($deploymentId, $site['body']['deploymentId'] ?? ''); + }, 120000, 500); + + // 6. Verify the project variable was available during build + $deployment = $this->client->call(Client::METHOD_GET, '/sites/' . $siteId . '/deployments/' . $deploymentId, [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $projectId, + 'x-appwrite-key' => $apiKey, + ]); + $this->assertSame(200, $deployment['headers']['status-code']); + $this->assertStringContainsString('ProjectVarTest', (string) $deployment['body']['buildLogs']); + + // 7. Get the domain and access the site + $rules = $this->client->call(Client::METHOD_GET, '/proxy/rules', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $projectId, + ], $this->getHeaders()), [ + 'queries' => [ + Query::equal('deploymentResourceId', [$siteId])->toString(), + Query::equal('trigger', ['manual'])->toString(), + Query::equal('type', ['deployment'])->toString(), + ], + ]); + + $this->assertSame(200, $rules['headers']['status-code']); + $this->assertGreaterThanOrEqual(1, \count($rules['body']['rules'])); + $domain = $rules['body']['rules'][0]['domain']; + + $proxyClient = new Client(); + $proxyClient->setEndpoint('http://' . $domain); + + $response = $proxyClient->call(Client::METHOD_GET, '/'); + + $this->assertSame(200, $response['headers']['status-code']); + $this->assertStringContainsString('Env variable is ProjectVarTest', (string) $response['body']); + $this->assertStringNotContainsString('Variable not found', (string) $response['body']); + + // Cleanup + $this->client->call(Client::METHOD_DELETE, '/sites/' . $siteId, [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $projectId, + 'x-appwrite-key' => $apiKey, + ]); + $this->deleteVariable($variableId); + } } diff --git a/tests/extensions/TestFinishedSubscriber.php b/tests/extensions/TestFinishedSubscriber.php index e07a9b67ed..fd58ad1f88 100644 --- a/tests/extensions/TestFinishedSubscriber.php +++ b/tests/extensions/TestFinishedSubscriber.php @@ -15,16 +15,22 @@ class TestFinishedSubscriber implements FinishedSubscriber public function notify(Finished $event): void { $test = $event->test()->name(); - $time = $event->telemetryInfo()->durationSinceStart()->seconds(); + $testId = $event->test()->id(); + + $elapsed = $event->telemetryInfo()->durationSinceStart()->asFloat(); + $start = TestPreparationStartedSubscriber::$startSeconds[$testId] ?? null; + $time = $start === null ? $elapsed : $elapsed - $start; + + unset(TestPreparationStartedSubscriber::$startSeconds[$testId]); printf( - "%s ended in %s milliseconds\n", + "%s ended in %d milliseconds\n", $test, - $time * 1000 + (int) round($time * 1000) ); if ($time > $this->maxSecondsAllowed) { - fwrite(STDOUT, sprintf("\e[31mThe %s test is slow, it took %s seconds!\n\e[0m", $test, $time)); + fwrite(STDOUT, sprintf("\e[31mThe %s test is slow, it took %.2f seconds!\n\e[0m", $test, $time)); } } } diff --git a/tests/extensions/TestHook.php b/tests/extensions/TestHook.php index 6ac1ec4afe..00cdfda33c 100644 --- a/tests/extensions/TestHook.php +++ b/tests/extensions/TestHook.php @@ -13,6 +13,7 @@ class TestHook implements Extension public function bootstrap(Configuration $configuration, Facade $facade, ParameterCollection $parameters): void { + $facade->registerSubscriber(new TestPreparationStartedSubscriber()); $facade->registerSubscriber(new TestFinishedSubscriber(self::MAX_SECONDS_ALLOWED)); $facade->registerSubscriber(new RetrySubscriber()); } diff --git a/tests/extensions/TestPreparationStartedSubscriber.php b/tests/extensions/TestPreparationStartedSubscriber.php new file mode 100644 index 0000000000..3bb59e52a8 --- /dev/null +++ b/tests/extensions/TestPreparationStartedSubscriber.php @@ -0,0 +1,26 @@ + + */ + public static array $startSeconds = []; + + public function notify(PreparationStarted $event): void + { + self::$startSeconds[$event->test()->id()] = $event->telemetryInfo()->durationSinceStart()->asFloat(); + } +} From 9b2b0def15c040972d7c55bcd51b99cd23777dbb Mon Sep 17 00:00:00 2001 From: Chirag Aggarwal Date: Mon, 22 Jun 2026 11:22:23 +0530 Subject: [PATCH 29/31] Bump utopia auth to 0.6 (#12642) --- composer.json | 2 +- composer.lock | 20 +++++++------------- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/composer.json b/composer.json index bfd843c9a1..f952d94d89 100644 --- a/composer.json +++ b/composer.json @@ -57,7 +57,7 @@ "utopia-php/agents": "2.*", "utopia-php/analytics": "0.15.*", "utopia-php/audit": "2.6.*", - "utopia-php/auth": "0.5.*", + "utopia-php/auth": "^0.6", "utopia-php/cache": "^3.0", "utopia-php/cli": "^0.24", "utopia-php/compression": "0.1.*", diff --git a/composer.lock b/composer.lock index c999e053c7..969d2985ee 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "da448b447a61b122c0c454f2b7c86b0d", + "content-hash": "bf0c07c029c54b225566c1a731fccae0", "packages": [ { "name": "adhocore/jwt", @@ -3319,16 +3319,16 @@ }, { "name": "utopia-php/auth", - "version": "0.5.1", + "version": "0.6.1", "source": { "type": "git", "url": "https://github.com/utopia-php/auth.git", - "reference": "9245a6342ed94f00425aef6963a32b8af9b0dc9d" + "reference": "8323a51314f6988c62926117ed642588ca8e8c4a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/auth/zipball/9245a6342ed94f00425aef6963a32b8af9b0dc9d", - "reference": "9245a6342ed94f00425aef6963a32b8af9b0dc9d", + "url": "https://api.github.com/repos/utopia-php/auth/zipball/8323a51314f6988c62926117ed642588ca8e8c4a", + "reference": "8323a51314f6988c62926117ed642588ca8e8c4a", "shasum": "" }, "require": { @@ -3338,12 +3338,6 @@ "ext-sodium": "*", "php": ">=8.0" }, - "require-dev": { - "laravel/pint": "1.2.*", - "phpstan/phpstan": "1.9.x-dev", - "phpunit/phpunit": "^9.3", - "vimeo/psalm": "4.0.1" - }, "type": "library", "autoload": { "psr-4": { @@ -3369,9 +3363,9 @@ ], "support": { "issues": "https://github.com/utopia-php/auth/issues", - "source": "https://github.com/utopia-php/auth/tree/0.5.1" + "source": "https://github.com/utopia-php/auth/tree/0.6.1" }, - "time": "2026-05-30T12:21:17+00:00" + "time": "2026-06-20T09:45:06+00:00" }, { "name": "utopia-php/cache", From 62cf3f303b7b59520e77799647743c84f6500a9e Mon Sep 17 00:00:00 2001 From: Chirag Aggarwal Date: Mon, 22 Jun 2026 14:26:45 +0530 Subject: [PATCH 30/31] Fix project OAuth provider sparse update (#12646) --- app/controllers/api/projects.php | 34 ++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/app/controllers/api/projects.php b/app/controllers/api/projects.php index 8ab30fac99..a39ce3c4bd 100644 --- a/app/controllers/api/projects.php +++ b/app/controllers/api/projects.php @@ -38,27 +38,31 @@ Http::patch('/v1/projects/:projectId/oauth2') ->inject('dbForPlatform') ->action(function (string $projectId, string $provider, ?string $appId, ?string $secret, ?bool $enabled, Response $response, Database $dbForPlatform) { - $project = $dbForPlatform->getDocument('projects', $projectId); + $project = $dbForPlatform->withTransaction(function () use ($dbForPlatform, $projectId, $provider, $appId, $secret, $enabled) { + $project = $dbForPlatform->getDocument('projects', $projectId, forUpdate: true); - if ($project->isEmpty()) { - throw new Exception(Exception::PROJECT_NOT_FOUND); - } + if ($project->isEmpty()) { + throw new Exception(Exception::PROJECT_NOT_FOUND); + } - $providers = $project->getAttribute('oAuthProviders', []); + $providers = $project->getAttribute('oAuthProviders', []); - if ($appId !== null) { - $providers[$provider . 'Appid'] = $appId; - } + if ($appId !== null) { + $providers[$provider . 'Appid'] = $appId; + } - if ($secret !== null) { - $providers[$provider . 'Secret'] = $secret; - } + if ($secret !== null) { + $providers[$provider . 'Secret'] = $secret; + } - if ($enabled !== null) { - $providers[$provider . 'Enabled'] = $enabled; - } + if ($enabled !== null) { + $providers[$provider . 'Enabled'] = $enabled; + } - $project = $dbForPlatform->updateDocument('projects', $project->getId(), $project->setAttribute('oAuthProviders', $providers)); + return $dbForPlatform->updateDocument('projects', $project->getId(), new Document([ + 'oAuthProviders' => $providers, + ])); + }); $response->dynamic($project, Response::MODEL_PROJECT); }); From 90a5575cb9e5838c34858c4fd7f6dd7e859dc565 Mon Sep 17 00:00:00 2001 From: Chirag Aggarwal Date: Mon, 22 Jun 2026 14:41:57 +0530 Subject: [PATCH 31/31] Update php-retry action to v4 (#12647) --- .github/workflows/ci.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 159782dfbb..5c734df8e9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -300,7 +300,7 @@ jobs: - name: Run Unit Tests timeout-minutes: 15 - uses: itznotabug/php-retry@d4500b9db3258e2cc8857427980f28e1611eb79c # v3 + uses: itznotabug/php-retry@60547503cb2126eddaa082d0999e99cfca2b3856 # v4 with: max_attempts: ${{ github.event_name == 'pull_request' && 2 || 1 }} retry_wait_seconds: 60 @@ -352,7 +352,7 @@ jobs: - name: Run General Tests timeout-minutes: 15 - uses: itznotabug/php-retry@d4500b9db3258e2cc8857427980f28e1611eb79c # v3 + uses: itznotabug/php-retry@60547503cb2126eddaa082d0999e99cfca2b3856 # v4 with: max_attempts: ${{ github.event_name == 'pull_request' && 2 || 1 }} retry_wait_seconds: 60 @@ -442,7 +442,7 @@ jobs: - name: Run tests timeout-minutes: 15 - uses: itznotabug/php-retry@d4500b9db3258e2cc8857427980f28e1611eb79c # v3 + uses: itznotabug/php-retry@60547503cb2126eddaa082d0999e99cfca2b3856 # v4 with: max_attempts: ${{ github.event_name == 'pull_request' && 2 || 1 }} retry_wait_seconds: 60 @@ -517,7 +517,7 @@ jobs: - name: Run tests timeout-minutes: 15 - uses: itznotabug/php-retry@d4500b9db3258e2cc8857427980f28e1611eb79c # v3 + uses: itznotabug/php-retry@60547503cb2126eddaa082d0999e99cfca2b3856 # v4 with: max_attempts: ${{ github.event_name == 'pull_request' && 2 || 1 }} retry_wait_seconds: 60 @@ -583,7 +583,7 @@ jobs: - name: Run tests timeout-minutes: 15 - uses: itznotabug/php-retry@d4500b9db3258e2cc8857427980f28e1611eb79c # v3 + uses: itznotabug/php-retry@60547503cb2126eddaa082d0999e99cfca2b3856 # v4 with: max_attempts: ${{ github.event_name == 'pull_request' && 2 || 1 }} retry_wait_seconds: 60