Repository navigation
chore: absorb cdn into packages/cdn - #13923
Conversation
add CDN provider integrations
Replace Fetch with Utopia Client
…/utopia-php/cdn into agent/cloudflare-cache-tag-purge
Add Cloudflare cache tag purging
Prevent proxy cache key fan-out
Cache\Adapter\Proxy hard-codes one deployment's routing into the library: an app domain, a set of network domains, and a list of adapters for everything else. Any consumer whose split is not exactly that cannot use it, and a consumer whose split is that has encoded its topology in a dependency it does not control. #4 has since established that it cannot route key purges at all, since keys are scoped to a service or zone, and told consumers to select the adapter themselves before constructing Cache. That is the same conclusion for every operation, not only keys. Nothing uses it. Its only references were its own test and the README. Certificates\Provider\Proxy is untouched; this removes the cache adapter only. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Remove the Proxy cache adapter
purgeDomain() ran purge_all on Fastly and never sent the domain: the argument was validated and discarded, so two different domains produced byte-identical requests. On a service fronting many domains that evicts all of them, and Fastly documents purge_all as taking up to two minutes, spiking origin traffic, and being incompatible with soft purge -- so a caller asking for a soft purge of one domain got a hard purge of everything. Fastly has no purge-by-host operation; its API offers URL, surrogate key and whole-service purges and nothing else. A domain is therefore the surrogate key the origin attaches, and the adapter has to know how those keys are named, so domainKeyPrefix is required rather than optional. There is no configuration in which purgeDomain() means purge_all. Cloudflare needed no such fix -- it purges a hostname natively -- but it was missing a zone purge entirely. Cache\Adapter now declares purgeZone() alongside the other three, so both providers offer the same set and Cache exposes it. Naming is aligned across adapters: purgeZone() for the widest purge either provider has, and PATHS_PER_PURGE / KEYS_PER_PURGE for the per-request ceilings, provider-specific numbers behind identical names. purgeKeys() on Fastly uses the batch endpoint: keys in the request body, up to 256 per request rather than one request each. A body also means no percent-encoding, which would purge a key the origin never attached. tests/Cdn/Cache/AdapterTest.php asserts the contract itself, so a provider growing a purge the others lack, or spelling one differently, fails there rather than in a caller that assumed they behaved alike. Requests are byte-identical to main for Cloudflare's three operations and Fastly's path purge, headers included. Refs Fastly purging API and purging concepts, Cloudflare purge cache docs. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Audit of what the diff actually claims, against the code and the provider documentation. - Fastly::PATHS_PER_PURGE was read by nothing but a test. A URL purge takes one URL, so there is no ceiling to name; only Cloudflare batches paths. - Cloudflare's batch constants claimed the provider's pages disagree about the ceiling. They do about hostnames and prefixes, not about the URLs and tags this adapter batches: those are documented at 100 per request, 500 on Enterprise for URLs. 30 is a conservative default and, more to the point, the number this adapter already sent -- the constants name existing behaviour rather than change it. - purgeZone() said the purge is disruptive to origin "for both providers". Fastly documents that; for Cloudflare it was my inference. Replaced with the consequence that holds either way. - The README still advertised three purge modes while listing four. - The Fastly note omitted zone purges from the operations that need a service ID. - Dropped a "now" that dated a comment to this change rather than describing the code, and restored the empty-paths guard so both adapters read alike. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Fix Fastly domain purge, and make both cache adapters consistent
Provider selection lived in every consumer: read the env, decide which of
Fastly and Cloudflare applies, build one Cache per provider, call a
different purge method on each. That logic is the same everywhere and is
wrong in the same way everywhere, so it moves here.
Cache\Adapter\Balancer takes a utopia-php/balancer Balancer and purges
through every option its filters leave standing, attempting each
independently and aggregating failures into Exception\Purge, so one
provider outage cannot silently skip the rest. No option matching the
filters raises Exception\Configuration rather than passing quietly.
Extend\CdnOption wraps a balancer Option with typed accessors, so a filter
reads getProvider()/isEdge() instead of getState('provider'), and carries
the provider names as constants rather than a separate enum class.
purgeZone() is implemented too, since #6 put it on the interface: it fans
out like the others, which makes it the widest purge available here, and
only the filters keep it away from the options they exclude. AdapterTest
now covers this adapter as well, so a composite that lagged the interface
would fail there rather than silently stop forwarding an operation.
Requires utopia-php/balancer 0.4.1 for getFilteredOptions(): run() returns
one option and $filters is private, while a purge has to reach every
provider that may hold a response for the domain.
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Add balancer cache adapter with typed CDN options
The adapter required the response envelope to be present and carry success: true, so any 2xx whose body a gateway rewrote, a proxy dropped, or a test double never sent was reported as a failed purge. Cloudflare signals failures with a non-2xx status; the envelope's verdict is kept as an override, so an explicit success: false inside a 2xx still fails, but the envelope's absence no longer does. Co-Authored-By: Claude Fable 5 <[email protected]>
Treat the status line as Cloudflare's primary purge signal
Add managed Fastly certificate provider
Fix Fastly domain reassignment renewal check
`Domain::validate()` rejected any domain that was not already lowercase. DNS labels are case-insensitive (RFC 4343), so case carries no meaning and folding it is the correct handling — rejecting it turns a cosmetic difference into a hard failure on data that already exists. This surfaced on Appwrite Cloud's deletes worker, where deleting a rule whose stored domain had mixed case threw `InvalidArgumentException` and aborted the job, orphaning the certificate row it was about to remove. `Proxy` compounded it. Every public method called `select()`, which validated into a *local* variable and discarded the result, so the raw domain still reached the provider. Normalization now happens once at each entry point and the canonical value flows to both the `appDomain` comparison and the provider call. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
fix(certificates): normalize domain case instead of rejecting it
chore(cdn): absorb utopia-php/cdn
chore: stop committing package lock files
chore(cdn,messaging): upgrade HTTP client to ^0.4
…izations fix(cdn): report blocked Fastly domain validation instead of pending
fix(cdn): retry a failed Fastly TLS subscription with force
refactor(storage, domains, cdn, fastly): use client 0.5's names
# Conflicts: # composer.lock
|
| $this->assertTrue(\defined($adapter . '::KEYS_PER_PURGE'), $adapter . ' must declare KEYS_PER_PURGE'); | ||
| } | ||
|
|
||
| $this->assertSame(256, Fastly::KEYS_PER_PURGE); | ||
| $this->assertSame(30, Cloudflare::KEYS_PER_PURGE); | ||
| $this->assertSame(30, Cloudflare::PATHS_PER_PURGE); | ||
| } |
There was a problem hiding this comment.
Tests mirror batch configuration. These assertions pin the current batch constants, while the batching tests build their inputs and expected results from those same constants. A wrong limit could therefore leave the batching tests green. The repository requires tests of observable behavior, not assertions that mirror configuration. Please satisfy that requirement 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/cdn/tests/Cache/AdapterTest.php
Line: 52-58
Comment:
**Tests mirror batch configuration.** These assertions pin the current batch constants, while the batching tests build their inputs and expected results from those same constants. A wrong limit could therefore leave the batching tests green. The repository requires tests of observable behavior, not assertions that mirror configuration. Please satisfy that requirement 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!
| { | ||
| return (string) preg_replace_callback( | ||
| '/[^A-Za-z0-9\-._~\/%?=&:+]/u', | ||
| static fn (array $match): string => rawurlencode($match[0]), | ||
| $path, | ||
| ); |
There was a problem hiding this comment.
Path encoding adds regex.
encodePath() introduces a regular-expression pattern. The repository guide says not to add preg_* patterns; if no string function or existing validator works, the PR must explain why. Please satisfy that requirement before merging.
Context Used: AGENTS.md (source)
Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/cdn/src/Cache/Adapter/Fastly.php
Line: 108-113
Comment:
**Path encoding adds regex.** `encodePath()` introduces a regular-expression pattern. The repository guide says not to add `preg_*` patterns; if no string function or existing validator works, the PR must explain why. Please satisfy that requirement 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!
|
|
||
| ## System requirements | ||
|
|
||
| Utopia CDN requires PHP 8.1 or later. We recommend using the latest PHP version whenever possible. |
There was a problem hiding this comment.
PHP minimum is misstated. The README says PHP 8.1 or later is supported, but
packages/cdn/composer.json requires PHP 8.5 or later. Someone following these installation instructions on PHP 8.1–8.4 will be rejected by Composer.
| Utopia CDN requires PHP 8.1 or later. We recommend using the latest PHP version whenever possible. | |
| Utopia CDN requires PHP 8.5 or later. We recommend using the latest PHP version whenever possible. |
Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/cdn/README.md
Line: 246
Comment:
**PHP minimum is misstated.** The README says PHP 8.1 or later is supported, but `packages/cdn/composer.json` requires PHP 8.5 or later. Someone following these installation instructions on PHP 8.1–8.4 will be rejected by Composer.
```suggestion
Utopia CDN requires PHP 8.5 or later. We recommend using the latest PHP version whenever possible.
```
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.| Run the test suite: | ||
|
|
||
| ```bash | ||
| composer test | ||
| ``` | ||
|
|
||
| Run static analysis: | ||
|
|
||
| ```bash | ||
| composer analyse | ||
| ``` | ||
|
|
||
| Run formatting checks: | ||
|
|
||
| ```bash | ||
| composer lint |
There was a problem hiding this comment.
Documented QA commands fail. The standalone package defines neither
composer analyse nor composer lint, although the README tells users to run both. It also documents composer test without declaring PHPUnit as a development dependency. After a fresh standalone install, users cannot run the documented QA workflow.
Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/cdn/README.md
Line: 250-265
Comment:
**Documented QA commands fail.** The standalone package defines neither `composer analyse` nor `composer lint`, although the README tells users to run both. It also documents `composer test` without declaring PHPUnit as a development dependency. After a fresh standalone install, users cannot run the documented QA workflow.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.# Conflicts: # rfc/monorepo.md
✨ Benchmark resultsComparing
Per-scenario breakdown & investigation detailsMetrics below reflect the current branch (after). Δ P95 compares against the base.
Top API waits (after)
|
|
|
||
| public function testEveryAdapterOffersTheSameOperations(): void | ||
| { | ||
| $this->assertSame(self::OPERATIONS, get_class_methods(Adapter::class)); |
There was a problem hiding this comment.
Tests mirror method declarations. This test compares a hard-coded method list with the interface. The checks below also use reflection to verify that adapters and the facade declare those methods. These assertions mirror source structure instead of testing observable purge behavior, violating the repository requirement to test behavior rather than implementation. That requirement must be satisfied 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/cdn/tests/Cache/AdapterTest.php
Line: 25
Comment:
**Tests mirror method declarations.** This test compares a hard-coded method list with the interface. The checks below also use reflection to verify that adapters and the facade declare those methods. These assertions mirror source structure instead of testing observable purge behavior, violating the repository requirement to test behavior rather than implementation. That requirement must be satisfied 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!
# Conflicts: # composer.lock
Summary
Moves
utopia-php/cdnintopackages/cdnso Appwrite loads it directly. Wave 2 of #13828, following the playbook inrfc/monorepo.md. The mirror headd4bca957is the0.0.13release Appwrite already locks, so there is no version gap.Add 'packages/cdn/' from commit 'd4bca957…'utopia-php/cdnwith full historychore(cdn): mirror plumbingmirror.ymlpoints atappwrite/appwrite'smirror-redirect.yml; README banner points hererefactor: load cdn from packages/replace, droprequireline andvcsrepository entry, lock update, PHPStan baseline, RFC phase 8 lineStep A:
src/Cdn/*→src/. Identical to 0.0.13 apart from the move and Pint formatting (empty bodies,fn (); Rector changes nothingtests/Cdn/*→tests/, namespaceUtopia\Tests\Cdn→Utopia\Cdn\Tests. All tests use a fake PSR-18TestClient, so everything is unit tier and notests/E2E/is neededphpstan.neonsrcandtests, standalone, withphpstan-baseline.neonrector.php/phpunit.xmlbalancerNothing to hoist: the package requires
ext-curlandext-json(already in rootrequire) plusbalancerandclient(both inpackages/, covered byreplace).composer update --lock: 0 installs, 0 updates, 1 removal (utopia-php/cdn0.0.13)src, 42tests): offset access and concatenation onmixeddecoded API responses in the Fastly, Fastly TLS and Cloudflare providers and cache adapters;request()results not narrowed to their declared shapes; assertions on decoded request bodies in tests. Added to the RFC phase 8 listsrc/Appwrite/Platform/Workers/Certificates.php,src/Appwrite/Platform/Workers/Deletes.php,src/Appwrite/Certificates/LetsEncrypt.php,tests/unit/Workers/CertificatesDomainValidationTest.phpValidation
bin/monorepo validatebin/monorepo check cdnbin/monorepo test cdnvendor/bin/phpunit --testsuite packages --filter 'Utopia\\Cdn'Utopia\Cdn\Cacheresolves topackages/cdn/src/Cache.phpcomposer validate --no-check-publishutopia-php/platformexact-version warning)bin/monorepo split cdn --dry-run9f89e676, fast-forwards from mirror headd4bca957(+2 commits)git diff --checkMerge and follow-up
Warning
Merge with a merge commit, not a squash. A squash drops the
git-subtree-*annotation and the split is rejected by the mirror.The mirror already has the canonical
mainruleset (id21914382: no required approvals, split app4016286as the only always-bypass actor), soabsorbran with--skip-ruleset. There is no classic branch protection onmain.Splitpushes toutopia-php/cdnpackages/cdnfromutopia-php/monorepoutopia-php/cdnon Packagist (never published, hence thevcsentry)utopia-phpvendorfix(cdn): recover Fastly certificates and preserve DNS failure details), which editspackages/cdnthere and is not in 0.0.13utopia-php/cdnutopia-php/fastlyin the monorepo does not depend on cdn, so nothing else is affected.🤖 Generated with Claude Code