Repository navigation
chore: absorb client and span into packages/ - #13858
Conversation
Co-Authored-By: Claude Opus 4.6 <[email protected]>
Co-Authored-By: Claude Opus 4.6 <[email protected]>
feat: add Pretty exporter
Set level=error when setError() is called, level=info otherwise.
Explicit level via set('level', ...) is never overridden.
Co-Authored-By: Claude Opus 4.6 <[email protected]>
feat: auto-set level attribute on spans
feat(span): batch Sentry exports
…hing revert(span): remove buffered Sentry export
chore: stop committing package lock files
fix(client): reconnect stale TLS sockets before sending
fix(client): enforce Swoole TLS peer identity verification
fix(client): keep streamed and buffered Swoole requests on separate connections
refactor(client)!: move Client and the streaming interface under Utopia\Client
Point mirror.yml and the README banner at appwrite/appwrite so PRs and issues opened on the mirror are redirected here.
Point mirror.yml and the README banner at appwrite/appwrite so PRs and issues opened on the mirror are redirected here.
span and client require each other, so installing span on its own made Composer reject client's span constraint against the unversioned root. Linked runs already set COMPOSER_ROOT_VERSION for this; registry-mode installs in check and test now do the same.
Packages here are autoloaded by the root composer.json rather than installed, so a package's own autoload.files never ran. autoload now lists them in the root, which client's alias shim for its renamed classes needs.
A package's test run in this repository loads two Composer autoloaders, the root one PHPUnit starts from and the package's own, and both list compat.php, so the second class_alias warned and failed CompatTest's fresh-process case. Each alias is now registered only if the name is not already defined.
PHPStan 2.2.14 misreads $responseBody = $streaming ? '' : $client->body followed by an is_string guard as ruling out the streaming path, then reports the redirect-body replay as dead code. Assigning the body only when not streaming says the same thing in a form it follows, so the package passes level 10 without a baseline.
utopia-php/client 0.5.0 moved Utopia\Client and Utopia\Psr18\StreamingClientInterface under Utopia\Client. agents now requires ^0.5 and imports the new names instead of relying on the aliases.
Appwrite now autoloads Utopia\Client and Utopia\Span from packages/, loads client's alias shim through the root autoload files, and replaces both packages so the vendored copies are no longer installed. client moves from 0.4.4 to 0.5.0: its classes now live under Utopia\Client, and 0.4.5's Swoole fixes keep streamed and buffered requests on separate connections. span's mirror head matches 4.2.0 (a batching change landed and was reverted). Neither needs a third-party requirement hoisted. Appwrite's three call sites use Utopia\Client\Client, and span moves to ^0.5 and the new names. span's src/Span is flattened; both packages' phpstan.neon and rector.php stand alone, client at level 10 on src and tests as before. The vendored messaging, storage, domains, cdn, usage and sdk-for-php packages keep the old names through the shim.
|
| $this->fail($old . ' does not resolve'); | ||
| } | ||
|
|
||
| $this->assertSame(Client::class, new \ReflectionClass($old)->getName()); |
There was a problem hiding this comment.
These reflection assertions hard-code that compatibility uses aliases targeting these exact symbols. The type-declaration test below already verifies the observable requirement by passing the moved implementations through the old type declarations. The repository requires tests to cover observable behavior rather than mirror implementation details, so these identity checks must be removed before merging. The same issue occurs for the legacy interface assertion on line 32.
Context Used: Call out and harshly judge implementation-coupled tests. We don't mirror source code, configuration, or version pins in assertions. We test observable behavior; use linters for syntax and schema checks. (source)
Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/client/tests/CompatTest.php
Line: 22
Comment:
**Tests Depend On Aliases**
These reflection assertions hard-code that compatibility uses aliases targeting these exact symbols. The type-declaration test below already verifies the observable requirement by passing the moved implementations through the old type declarations. The repository requires tests to cover observable behavior rather than mirror implementation details, so these identity checks must be removed before merging. The same issue occurs for the legacy interface assertion on line 32.
**Context Used:** Call out and harshly judge implementation-coupled tests. We don't mirror source code, configuration, or version pins in assertions. We test observable behavior; use linters for syntax and schema checks. ([source](https://app.greptile.com/review/custom-context?memory=instruction-0))
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
There was a problem hiding this comment.
Pre-existing in the imported library (client at the 0.5.0 release, span at c935f78). An absorb PR relocates the package with its history. The only library changes here are the two scoped client commits described in the PR, so this is left for its own change against the package, now that it lives here.
There was a problem hiding this comment.
That’s fair. Since these assertions are pre-existing in client 0.5.0 and this PR only relocates the package (apart from the two scoped compatibility changes), removing them here would expand the absorb PR’s scope and alter imported package history. I’m withdrawing this comment; the identity checks can be addressed in a follow-up change against packages/client if desired.
| { | ||
| $exporter = new Sentry(dsn: 'https://[email protected]/123'); | ||
|
|
||
| $method = new \ReflectionMethod(Sentry::class, 'buildEnvelope'); |
There was a problem hiding this comment.
This test invokes the private buildEnvelope method through reflection instead of exercising Sentry export through its public contract. Line 57 similarly reads the private client property. The repository explicitly prohibits reflection-based tests of private members because routine internal refactors can break them without changing observable behavior. This requirement must be satisfied before merging.
Context Used: AGENTS.md (source)
Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/span/tests/Exporter/SentryTest.php
Line: 33
Comment:
**Tests Reach Private Internals**
This test invokes the private `buildEnvelope` method through reflection instead of exercising Sentry export through its public contract. Line 57 similarly reads the private `client` property. The repository explicitly prohibits reflection-based tests of private members because routine internal refactors can break them without changing observable behavior. This requirement must be satisfied before merging.
**Context Used:** AGENTS.md ([source](https://github.com/appwrite/appwrite/blob/main/AGENTS.md))
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.There was a problem hiding this comment.
Pre-existing in the imported library (client at the 0.5.0 release, span at c935f78). An absorb PR relocates the package with its history. The only library changes here are the two scoped client commits described in the PR, so this is left for its own change against the package, now that it lives here.
There was a problem hiding this comment.
That context is reasonable. Since SentryTest.php is imported from the existing span package and this PR only relocates it (apart from the scoped client changes), the reflection-based coverage is pre-existing and outside this absorb PR’s scope. I’m withdrawing this as a merge blocker; it can be addressed in a follow-up change against packages/span.
| throw $this->networkException($request, $message === '' ? 'Curl request failed.' : $message, $code); | ||
| } | ||
|
|
||
| if (!preg_match("/\r\n\r\n|\n\n|\r\r/", $headers)) { |
There was a problem hiding this comment.
Regular Expressions Violate Guidance
The imported client uses a regular expression to detect the HTTP header terminator. The same pattern appears in parseHeaderBlock on lines 525–537 and in the new test helpers at packages/client/tests/server.php:161 and packages/client/tests/Server/Http.php:137. Repository guidance explicitly requires string functions or an existing parser unless the PR explains why neither works, so these expressions must be replaced or justified before merging.
Context Used: AGENTS.md (source)
Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/client/src/Adapter/Curl/Client.php
Line: 234
Comment:
**Regular Expressions Violate Guidance**
The imported client uses a regular expression to detect the HTTP header terminator. The same pattern appears in `parseHeaderBlock` on lines 525–537 and in the new test helpers at `packages/client/tests/server.php:161` and `packages/client/tests/Server/Http.php:137`. Repository guidance explicitly requires string functions or an existing parser unless the PR explains why neither works, so these expressions must be replaced or justified before merging.
**Context Used:** AGENTS.md ([source](https://github.com/appwrite/appwrite/blob/main/AGENTS.md))
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
There was a problem hiding this comment.
Pre-existing in the imported library (client at the 0.5.0 release, span at c935f78). An absorb PR relocates the package with its history. The only library changes here are the two scoped client commits described in the PR, so this is left for its own change against the package, now that it lives here.
There was a problem hiding this comment.
That’s fair. Since these regexes are unchanged from the imported client 0.5.0 implementation and this PR’s client edits are limited to the scoped follow-up commits, they’re not actionable for this absorb/relocation change. I’ll withdraw this finding and leave the replacement or justification for a dedicated client change.
…d-span # Conflicts: # composer.lock
| public function testItDecoratesConfigurableAdapters(): void | ||
| { | ||
| $request = new Request\Factory()->createRequest('GET', 'https://example.com'); | ||
| $adapter = new RecordingAdapter(); | ||
| $client = new Client($adapter); | ||
| $configured = $client | ||
| ->withTimeout(5.5) | ||
| ->withConnectTimeout(1.25); | ||
|
|
||
| $response = $configured->sendRequest($request); | ||
|
|
||
| $this->assertSame('', $client->sendRequest($request)->getHeaderLine('X-Timeout')); | ||
| $this->assertSame('5.5', $response->getHeaderLine('X-Timeout')); | ||
| $this->assertSame('1.25', $response->getHeaderLine('X-Connect-Timeout')); |
There was a problem hiding this comment.
Tests Mirror Adapter Internals
These tests encode timeout settings into synthetic X-* response headers and then assert those headers. The TLS checks on lines 39–55 and the connection-reuse and redirect checks on lines 58–77 follow the same pattern. This mirrors how configuration is forwarded rather than testing observable client behavior: the tests can fail after a harmless adapter refactor, yet still pass when an adapter accepts an option but applies it incorrectly. The repository requires tests to verify observable behavior rather than implementation details, so this must be replaced with transport-level timeout, TLS, connection-reuse, and redirect coverage before merging.
Context Used: Call out and harshly judge implementation-coupled tests. We don't mirror source code, configuration, or version pins in assertions. We test observable behavior; use linters for syntax and schema checks. (source)
Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/client/tests/ClientTest.php
Line: 23-36
Comment:
**Tests Mirror Adapter Internals**
These tests encode timeout settings into synthetic `X-*` response headers and then assert those headers. The TLS checks on lines 39–55 and the connection-reuse and redirect checks on lines 58–77 follow the same pattern. This mirrors how configuration is forwarded rather than testing observable client behavior: the tests can fail after a harmless adapter refactor, yet still pass when an adapter accepts an option but applies it incorrectly. The repository requires tests to verify observable behavior rather than implementation details, so this must be replaced with transport-level timeout, TLS, connection-reuse, and redirect coverage before merging.
**Context Used:** Call out and harshly judge implementation-coupled tests. We don't mirror source code, configuration, or version pins in assertions. We test observable behavior; use linters for syntax and schema checks. ([source](https://app.greptile.com/review/custom-context?memory=instruction-0))
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
There was a problem hiding this comment.
Pre-existing in the imported library (client at the 0.5.0 release, span at c935f78). An absorb PR relocates the package with its history. The only library changes here are the two scoped client commits described in the PR, so this is left for its own change against the package, now that it lives here.
There was a problem hiding this comment.
That’s fair. Since these tests are carried over from the released client package and the absorb PR only changes the two scoped client commits, this is pre-existing library coverage rather than a regression introduced here. I’m withdrawing this finding; the transport-level coverage can be addressed in a follow-up change against packages/client.
✨ Benchmark resultsComparing
Per-scenario breakdown & investigation detailsMetrics below reflect the current branch (after). Δ P95 compares against the base.
Top API waits (after)
|
Summary
Move
utopia-php/clientandutopia-php/spanintopackages/so Appwrite loads them directly. This is step 4 of the messaging chain in #13828 (smtp→telemetry→pools→client+span→messaging). They require each other, so they move together.This replaces #13850. client's namespace rename shipped first as
client/0.5.0from utopia-php/monorepo#331. So here client already has the standardUtopia\Client\shape, andbin/monoreponeeds no special case for it.Commits after the two history-preserving imports and their
mirror plumbingcommits:fix(monorepo): claim a release line when installing a package in a cycle. span and client require each other, so installing span on its own made Composer reject client'sutopia-php/spanconstraint against the unversioned root. Linked runs already setCOMPOSER_ROOT_VERSIONfor this. Registry-mode installs incheckandtestnow do the same.feat(monorepo): load a package's autoload files through the root. Packages here are autoloaded by the root instead of being installed by Composer, so a package'sautoload.filesnever ran.bin/monorepo autoloadnow copies them into the rootautoload.files, which client's alias shim needs.fix(client): register each old-name alias only once. A package's test run here loads two Composer autoloaders, the root one PHPUnit starts from and the package's own, and both includecompat.php. The secondclass_aliaswarned, and CompatTest's fresh-process case failed. Each alias is now registered only if the name is not already defined.refactor(client): build the buffered body without a ternary. PHPStan 2.2.14, which Appwrite runs, misreads$responseBody = $streaming ? '' : $client->bodyfollowed by anis_stringguard. It concludes the streaming path is impossible, then flags the redirect-body replay as dead code. The old monorepo's 2.2.5 did not. Assigning the body only when not streaming behaves the same and passes level 10 without a baseline.refactor(agents): use client 0.5's names. agents requires^0.5and importsUtopia\Client\ClientandUtopia\Client\Psr18\StreamingClientInterface.refactor: load client and span from packages/.filesandreplaceentries. Both packages leaverequire, and the lock drops only them.Utopia\Client\Client. span moves to^0.5and the new names, and itssrc/Spanis flattened.phpstan.neonandrector.phpstand alone. client keeps level 10 onsrcandtests.The vendored
messaging,storage,domains,cdn,usageandopen-runtimes/sdk-for-phpstill use the old names through the shim. The RFC now lists removing the shim at client's next major, once they move.Validation
bin/monorepo validate: all packages validbin/monorepo check span client agents: Rector, Pint and PHPStan pass, with no baselinesbin/monorepo test span client agents: span 108 tests, client 188, agents 139 with 4 skipped. client's tests start their own loopback server.--testsuite packages: span 108, client 188 and agents 102 tests pass.Utopia\Client,Utopia\SpanorUtopia\Agents.composer dump-autoloadshows no PSR-4 warnings. The Docker composer stage tolerates thefilesentry beforepackages/is copied in.551263e, spanbfd35c8, agents2c887cc.Merge and follow-up
Merge with a merge commit, not squash, to keep both subtree annotations the split continues from. Both mirror rulesets let the split app bypass them, and neither mirror has open PRs.
After merge:
packages/clientandpackages/spanfromutopia-php/monorepoin one PR.Part of #13828.