Commit Graph

268 Commits

Author SHA1 Message Date
Chirag Aggarwal 5b6dd5f75a Merge pull request #11949 from appwrite/chore/phpstan-level-4 2026-04-22 11:17:21 +05:30
Jake Barnby 8a841a6971 fix: cast cached total to int in listDocuments/listRows
Redis stringifies scalars on save, so on a cache hit the `total` field
was served as a string. Flutter SDK (and any strictly-typed client) then
failed with `TypeError: "37": type 'String' is not a subtype of type 'int'`.
The cache-miss path returned an int from `count()`, which is why only
repeat requests with `ttl > 0` tripped the bug.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-22 16:14:30 +12:00
Chirag Aggarwal d2230f8fe7 chore: bump PHPStan to level 4 and fix all new errors
Raises `phpstan.neon` level from 3 to 4 and fixes the 549 new errors
that level 4 surfaces across 157 files. Fixes are root-cause — no
`@phpstan-ignore`, no `@var` casts, no baseline entries, no widened
types. A handful of latent bugs were fixed along the way:

- `app/controllers/general.php`: path-traversal guard was negating
  `\substr(...)` before the strict comparison (`!\substr(...) === $base`
  was always `false === $base`). Rewritten as `\substr(...) !== $base`.
- `src/Appwrite/Platform/Modules/Databases/Http/Databases/Logs/XList.php`
  and `.../TablesDB/Logs/XList.php`: were importing the raw Matomo
  `DeviceDetector` (whose `getDevice()` returns `?int`) but treating the
  result as an array with `deviceName/deviceBrand/deviceModel` keys.
  Swapped to `Appwrite\Detector\Detector`, matching the wrapper already
  used a few lines below for `$os`/`$client`.
- `src/Appwrite/Platform/Modules/Functions/Workers/Builds.php`: a match
  key was checking `$resourceKey === 'functions'` when `$resourceKey`
  is `'functionId'|'siteId'` — always false. Switched to the intended
  `$resource->getCollection() === 'functions'` check.
- `src/Appwrite/OpenSSL/OpenSSL.php`: `encrypt()` return type tightened
  to `string|false` to match `openssl_encrypt`; this lets callers'
  `=== false` error handling remain meaningful.
- `app/controllers/api/messaging.php`: removed a dead
  `array_key_exists('from', [])` branch in the Msg91 provider (empty
  array literal; branch was unreachable).

Large cleanup categories across the 549 fixes:
- Removed redundant `?? default` on array offsets and expressions that
  PHPStan now knows are non-nullable.
- Removed unreachable statements (mostly `return;` after `throw` or
  `markTestSkipped()`).
- Removed redundant `is_array`/`is_string`/`is_bool`/`instanceof` checks
  on already-narrowed types.
- Added `default =>` arms (or throwing arms) to non-exhaustive matches
  on `string`/`mixed` input.
- Removed dead `$document === false` branches where method return types
  were tightened to non-nullable `Document`.
- Removed unused properties (`$version` on Etsy/Zoom OAuth2, `$paths` on
  Installer State, `$source` on MigrationsWorker, `$account2` on two
  GraphQL auth tests), unused traits (`ApiVectorsDB`, `DatabaseFixture`),
  and an unused `cleanupStaleExecutions` task method.
- Replaced `assertTrue(true)` and redundant `assertIsArray`/`assertIsString`/
  `assertNotNull` assertions with `addToAssertionCount(1)` or
  `assertNotEmpty` where the runtime type was already known.
2026-04-19 17:31:20 +05:30
ArnabChatterjee20k 0cce480592 typo 2026-04-10 17:23:43 +05:30
ArnabChatterjee20k 96fe989f6d update composer dependencies and remove obsolete log classes 2026-04-10 17:15:31 +05:30
ArnabChatterjee20k d13dbae0fe added allowance of empty payload for documentsdb 2026-04-10 13:59:45 +05:30
Jake Barnby c5b8ed9cc1 feat(databases): cache list responses without requiring a select query 2026-04-08 23:02:34 +12:00
Jake Barnby 939092726c test(databases): add regression for purge=true list cache invalidation 2026-04-08 21:31:42 +12:00
ArnabChatterjee20k 3ff7cadcab updated project size 2026-03-27 18:39:26 +05:30
ArnabChatterjee20k 8ae07ac61f Merge remote-tracking branch 'origin/1.9.x' into revert-11585-revert-11402-sync-mongodb 2026-03-23 10:47:23 +05:30
ArnabChatterjee20k 9a70445395 Merge remote-tracking branch 'origin/1.9.x' into revert-11585-revert-11402-sync-mongodb 2026-03-20 11:29:37 +05:30
Jake Barnby c9d023991d (test): add e2e test for $sequence query type validation per adapter 2026-03-20 18:03:17 +13:00
Jake Barnby 47408f04dc fix: always cast $sequence to string for SDK type safety
Revert the is_int preservation — SDKs declare $sequence as string,
so the API must always return a string. Updated tests to match.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-20 17:24:21 +13:00
ArnabChatterjee20k c7907932e4 Revert "Revert "Documentsdb + vectordb (latest)"" 2026-03-19 20:30:42 +05:30
ArnabChatterjee20k 9917f95dfd Revert "Documentsdb + vectordb (latest)" 2026-03-19 19:18:27 +05:30
ArnabChatterjee20k feddd77066 fixed analyze 2026-03-19 17:02:27 +05:30
ArnabChatterjee20k d6bc9f120e Merge remote-tracking branch 'origin/1.8.x' into sync-mongodb 2026-03-09 15:50:48 +05:30
ArnabChatterjee20k 1705266779 remove debug logging from database creation process 2026-03-09 15:48:46 +05:30
Jake Barnby 91edf82060 fix: database index length assertion and email race in password recovery
- Remove specific index length number from testPatchAttribute assertion
  since the value differs between shared/non-shared table modes (767 vs
  768) and the console API returns the console project's value, not the
  user project's
- Use getLastEmailByAddress in testPasswordRecoveryUrlParams to avoid
  retrieving emails from parallel test classes sharing the same maildev

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-06 03:41:35 +13:00
ArnabChatterjee20k 8c3f11b3d5 updated tests 2026-03-02 12:25:40 +05:30
ArnabChatterjee20k abf497d509 Merge remote-tracking branch 'origin/1.8.x' into sync-mongodb 2026-02-27 17:19:31 +05:30
ArnabChatterjee20k a76a5cda38 Refactor code structure for improved readability and maintainability 2026-02-27 17:15:00 +05:30
Jake Barnby 1c85789a6e fix: scope cache tests to setup document IDs to avoid count mismatch
The testListDocumentsWithCache and testListDocumentsCacheBustedByAttributeChange
tests were failing because testCreateDocument (which runs earlier) adds 3 more
documents to the same movies collection, resulting in 6 docs instead of expected 3.
Additionally, the cache bust test was getting a cache 'hit' instead of 'miss' on
its first request due to sharing the same cache key as the previous test.

Fix by filtering all cache test queries to the 3 known setup document IDs, and
using distinct select/order queries in each test to avoid cache key collisions.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-26 20:34:46 +13:00
Jake Barnby b174a50b2a fix: address coderabbit review comments
- Fix indentation alignment in cache hit detection condition
- Add total count assertions for cached and non-cached responses in test

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-26 19:00:25 +13:00
Jake Barnby 3e0ee30428 Add tests for collection bust 2026-02-26 18:31:52 +13:00
Jake Barnby d49dea9790 Merge remote-tracking branch 'origin/1.8.x' into cached-documents-list
# Conflicts:
#	composer.lock
#	tests/e2e/Services/Databases/DatabasesBase.php
2026-02-26 17:02:33 +13:00
ArnabChatterjee20k 42f914f6aa fixed merge conflicts 2026-02-25 16:49:31 +05:30
ArnabChatterjee20k 905763e755 added tests 2026-02-25 16:08:40 +05:30
Jake Barnby a43e94990b Lint 2026-02-25 21:49:31 +13:00
Jake Barnby c91252d94c Switch types 2026-02-25 21:42:28 +13:00
Jake Barnby 3b3177722b fix: cache setup data before waiting to prevent 409 on retry
When setupAttributes() or setupIndexes() timed out during
waitForAllAttributes/waitForAllIndexes, the cache was never populated.
Subsequent test methods calling setup again would find empty cache,
reuse the same collection IDs (from collection cache), and attempt to
re-create existing attributes/indexes, resulting in 409 Conflict errors.

Fix: populate the static cache immediately after successful creation
(202 assertions), before the wait calls. This ensures retries skip
creation and go straight to waiting.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-24 20:06:20 +13:00
Jake Barnby bada1a7c05 Timing updates 2026-02-24 14:00:07 +13:00
Jake Barnby f2759cb65a fix: remove file caching, disable --functional for Databases/Functions/Realtime
Services that depend on shared static state between test methods
(Databases, Functions, Realtime) now run without --functional flag,
so test methods execute sequentially within each class while classes
still run in parallel. All other services keep --functional mode.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-21 03:44:28 +13:00
Jake Barnby 8d18a33072 fix: call ensureSharedProject() in all setup methods, not just setupDatabase
When setupAttributes/setupIndexes/etc hit the file cache, they return
immediately without calling setupDatabase(), so ensureSharedProject()
was never called. This left self::$project empty, causing getProject()
to create a new project that didn't match the cached database IDs (404s).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-21 03:11:50 +13:00
Jake Barnby a0b8437f08 fix: scope file caching to Database tests only, revert for non-Database tests
The previous file caching approach cached getRoot(), getUser(), getProject(),
and getConsoleVariables() globally. This caused all test methods in a class
to share the same project, breaking non-Database tests that expect isolated
state (Account 401s, Storage 500s, Users 404s, etc.).

Now file caching is only applied in Database/Transaction test setup chains:
- ensureSharedProject() in DatabasesBase, TransactionsBase, TransactionPermissionsBase
  creates and file-caches both the project AND user so all methods share
  consistent project + user state (needed for collection permissions)
- Non-Database tests (Account, Storage, Users, etc.) create their own
  isolated projects per-process as before

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-21 02:46:56 +13:00
Jake Barnby 3ea1e8e59f fix: add file-based cross-process caching for ParaTest --functional mode
With --functional mode, each test method runs in its own process so
static caches are empty. This causes every method to recreate projects,
databases, collections, attributes, and indexes - flooding the serial
database worker queue and causing attribute polling timeouts.

File-based caching with file locks ensures resources are created once
per test class, then shared across all method processes. This restores
--functional mode and dramatically reduces worker queue load.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-21 01:47:20 +13:00
Jake Barnby abdceb831a fix: resolve E2E test failures for screenshots, account logs, risky tests, and deployment timeouts
- Accept 404 alongside 200 for screenshot tests with custom headers/permissions (browser service CI limitation)
- Fix testGetAccountLogs to expect 1 log (session.create only, user.create audit not triggered for self-service)
- Move getSupportForOperators() check before any assertions in testOperators/testBulkOperators (PHPUnit 12 risky test fix)
- Increase deployment build/activation polling timeout from 240s to 360s

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-20 20:43:51 +13:00
Jake Barnby b7d503e8e9 fix: resolve MariaDB spatial attribute and index creation failures
- Replace findOne()->isEmpty() with count() > 0 in spatial check to avoid
  potential false positives when checking for existing data in empty collections
- Use waitForAllAttributes instead of waitForAttribute before spatial index
  creation to ensure the collection document cache is refreshed
- Add response assertions for attribute creation in testSpatialPolygonAttributes
  to fail fast instead of timing out for 15 minutes

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-20 18:53:50 +13:00
Jake Barnby f8e29c6b38 fix: prevent testTimeout from deleting shared database
testTimeout was using setupDatabase() to get the shared database, creating
a collection within it, then deleting the entire database at cleanup. This
destroyed the shared Movies/Actors/Books collections, causing testNotSearch
and other tests relying on the shared database to fail with 404.

Fix: only delete the test collection, not the shared database. Also add
waitForAttribute to prevent intermittent failures from attribute not being
available when inserting documents.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-19 02:37:06 +13:00
Jake Barnby fa972093f4 fix: front-load fulltext search infrastructure into cached setup chain
Move the Books collection, attributes, and fulltext index creation into
the shared setupCollection/setupAttributes/setupIndexes cache chain so
they are processed early when the worker queue is less loaded. This
eliminates testNotSearch creating redundant infrastructure from scratch
at test time when the queue is overwhelmed with 830+ parallel tests.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-18 23:26:03 +13:00
Jake Barnby dca375624c fix: add missing 202 assertions before schema polling waits
- Fix testSpatialDistanceInMeter: move assertEquals(202) BEFORE waitForIndex
  (was after, causing misleading 4-minute timeout on creation failure)
- Add 202 assertions to testSpatialAttributesMixedCollection attribute creation
- Add 202 assertion to testConcurrentTransactionConflicts attribute creation
- Add 202 assertion to fulltext search index creation
- Add 202 assertion to shared collection attribute creation

These ensure tests fail fast with clear errors if schema creation returns
an error, instead of pointlessly polling for 4 minutes.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-18 22:58:05 +13:00
Jake Barnby dd1a3d8222 fix: adjust testCreateIndexes index count for MongoDB maxIndexLength=1024
MongoDB's maxIndexLength (1024) allows the 512+512 index to succeed,
resulting in 5 indexes instead of 4. Use conditional count and
assertContains for position-independent key checks.

Verified: 830/830 Database tests pass locally on MongoDB with paratest.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-18 19:59:20 +13:00
Jake Barnby 93bc3871df fix: MongoDB test compatibility and enable JUnit XML for paratest retry
- testCreateIndexes: conditionally check index length based on adapter's maxIndexLength (MongoDB 1024 vs SQL 768)
- testConcurrentTransactionConflicts: accept both 409 and 500 since MongoDB adapter doesn't map write conflicts to ConflictException
- testEnforceCollectionPermissions: add error body to assertion for debugging
- Enable --log-junit for paratest in both project and shared mode CI jobs so itznotabug/php-retry@v3 can identify and selectively retry failing tests

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-18 19:09:01 +13:00
Jake Barnby d6d12d818c fix: use getContainerIdResponseKey() instead of hardcoded $collectionId in upsert test
TablesDB uses $tableId not $collectionId in data payloads.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-18 16:03:46 +13:00
Jake Barnby 442a8d86d6 fix: use getRecordResource() instead of hardcoded 'documents' in testUpsertDocument
TablesDB uses 'rows' not 'documents' for the list records response key.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-18 15:44:41 +13:00
Jake Barnby 84c40cea41 fix: resolve testCreateAttributes, testUpsertDocument, and SchemaPolling timeouts
- Fix testCreateAttributes: use $actorsAttr instead of undefined $actors variable,
  and use $this->getSchemaResource() instead of hardcoded 'attributes' for TablesDB compat
- Fix testUpsertDocument: add missing 'data' => $upsertData in PUT request body
- Increase SchemaPolling default timeout from 60s to 120s for CI stability with
  spatial attributes under parallel load

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-18 15:25:45 +13:00
Jake Barnby 9796c46975 fix: misplaced assertion in testUpdateAttributeEnum and reduce timeouts
- Move maxLength/assertStringContainsString from testUpdateAttributeEnum
  back to testPatchAttribute where $attribute is defined
- Fix remaining $data['moviesId'] -> $moviesId in testCreateAttributes
- Reduce WebSocket timeout from 30s to 15s for faster failure detection
- Reduce Realtime helper assertEventually from 30s to 15s

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-18 15:07:05 +13:00
Jake Barnby ae4e79518b fix: remaining testCreateAttributes undefined variable references
- Change $data['moviesId'] to $moviesId at integers2 attribute creation
- Change $data['actorsId'] to $actorsId at relationship assertion

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-18 14:59:25 +13:00
Jake Barnby 2c1919140f fix: resolve additional test failures from CI results
DatabasesBase:
- testCreateAttributes: use local $moviesId/$actorsId instead of $data['...']
- testValidateOperators: add missing setupOneToManyRelationship() call
- testSelectQueries: add missing setupOneToManyRelationship() call
- testUniqueIndexDuplicate: define missing $serverHeaders variable
- testListDocuments: change return type from array to void (no callers)

RealtimeConsoleClientTest:
- testAttributesCollectionsAPI: create database/collection before opening
  WebSocket to prevent their events from interfering with attribute events
- testAttributesTablesAPI: same restructuring for TablesDB variant

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-18 14:42:41 +13:00
Jake Barnby acad17f3b8 fix: resolve test failures and reduce excessive timeouts
- DatabasesBase: fix 5 merge corruption issues (missing integers2 attr,
  undefined vars, wrong assertion, wrong setup method)
- WebhooksBase: increase deployment build timeout from 10s to 120s
- RealtimeBase: reduce WebSocket timeout 120s→30s, fix deprecated nullable
- RealtimeConsoleClientTest: reduce assertEventually 120s→30s
- SchemaPolling: reduce all default timeouts 600s→60s
- SitesBase: reduce build timeout 300s→120s, activation 200s→60s

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-18 14:23:42 +13:00