From 5ff7e2af24971d502f4b6e3b017877cd8481165f Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 26 Feb 2026 12:31:05 +0000 Subject: [PATCH] fix: revert regions.php, add mock PATCH route for project region in tests Co-authored-by: abnegate <5857008+abnegate@users.noreply.github.com> --- app/config/regions.php | 6 ---- app/controllers/mock.php | 34 ++++++++++++++++++++ tests/e2e/Services/Realtime/RealtimeBase.php | 21 ++++++------ 3 files changed, 46 insertions(+), 15 deletions(-) diff --git a/app/config/regions.php b/app/config/regions.php index ddc78b7873..05e04930fe 100644 --- a/app/config/regions.php +++ b/app/config/regions.php @@ -7,10 +7,4 @@ return [ 'disabled' => false, 'default' => true, ], - 'fra' => [ - '$id' => 'fra', - 'name' => 'Frankfurt', - 'disabled' => false, - 'default' => false, - ], ]; diff --git a/app/controllers/mock.php b/app/controllers/mock.php index 712d4b7742..aafa84aff4 100644 --- a/app/controllers/mock.php +++ b/app/controllers/mock.php @@ -279,6 +279,40 @@ Http::get('/v1/mock/github/callback') ]); }); +Http::patch('/v1/mock/projects/{projectId}/region') + ->desc('Update project region (development/testing only)') + ->groups(['mock']) + ->label('scope', 'public') + ->label('docs', false) + ->label('mock', true) + ->param('projectId', '', new UID(), 'Project ID.') + ->param('region', '', new Text(64), 'Region value to set on the project document.') + ->inject('response') + ->inject('dbForPlatform') + ->action(function (string $projectId, string $region, Response $response, Database $dbForPlatform) { + $isDevelopment = System::getEnv('_APP_ENV', 'development') === 'development'; + + if (!$isDevelopment) { + throw new Exception(Exception::GENERAL_NOT_IMPLEMENTED); + } + + $project = $dbForPlatform->getDocument('projects', $projectId); + + if ($project->isEmpty()) { + throw new Exception(Exception::PROJECT_NOT_FOUND); + } + + $dbForPlatform->updateDocument( + 'projects', + $project->getId(), + $project->setAttribute('region', $region) + ); + + $dbForPlatform->purgeCachedDocument('projects', $project->getId()); + + $response->json(['projectId' => $project->getId(), 'region' => $region]); + }); + Http::shutdown() ->groups(['mock']) ->inject('utopia') diff --git a/tests/e2e/Services/Realtime/RealtimeBase.php b/tests/e2e/Services/Realtime/RealtimeBase.php index 9686d0a1b9..efb53ddea3 100644 --- a/tests/e2e/Services/Realtime/RealtimeBase.php +++ b/tests/e2e/Services/Realtime/RealtimeBase.php @@ -4,7 +4,6 @@ namespace Tests\E2E\Services\Realtime; use Tests\E2E\Client; use Utopia\Database\Helpers\ID; -use Utopia\System\System; use WebSocket\Client as WebSocketClient; use WebSocket\ConnectionException; @@ -156,12 +155,6 @@ trait RealtimeBase public function testConnectionFailureRegionMismatch(): void { - $serverRegion = System::getEnv('_APP_REGION', 'default'); - - if ($serverRegion === 'fra') { - $this->markTestSkipped('Test requires server region to not be "fra"'); - } - // Create a team for the mismatched-region project $team = $this->client->call(Client::METHOD_POST, '/teams', [ 'origin' => 'http://localhost', @@ -176,7 +169,7 @@ trait RealtimeBase $this->assertEquals(201, $team['headers']['status-code']); $teamId = $team['body']['$id']; - // Create a project in the 'fra' region (which won't match the server's region) + // Create a project with the default (matching) region $project = $this->client->call(Client::METHOD_POST, '/projects', [ 'origin' => 'http://localhost', 'content-type' => 'application/json', @@ -184,7 +177,6 @@ trait RealtimeBase 'x-appwrite-project' => 'console', ], [ 'projectId' => ID::unique(), - 'region' => 'fra', 'name' => 'Region Mismatch Project', 'teamId' => $teamId, ]); @@ -192,6 +184,17 @@ trait RealtimeBase $this->assertEquals(201, $project['headers']['status-code']); $projectId = $project['body']['$id']; + // Force a mismatched region directly in the DB via the mock endpoint (bypasses API validation) + $response = $this->client->call(Client::METHOD_PATCH, '/mock/projects/' . $projectId . '/region', [ + 'origin' => 'http://localhost', + 'content-type' => 'application/json', + 'x-appwrite-project' => $projectId, + ], [ + 'region' => 'mismatched-region', + ]); + + $this->assertEquals(200, $response['headers']['status-code']); + /** * Test for FAILURE * A project in a different region should be rejected with an access forbidden error.