Skip to content

chore: absorb cdn into packages/cdn - #13923

Merged
ChiragAgg5k merged 56 commits into
mainfrom
chore/absorb-cdn
Sep 27, 2026
Merged

ChiragAgg5k merged 56 commits into
mainfrom
chore/absorb-cdn

Conversation

@ChiragAgg5k

Copy link
Copy Markdown
Member

Summary

Moves utopia-php/cdn into packages/cdn so Appwrite loads it directly. Wave 2 of #13828, following the playbook in rfc/monorepo.md. The mirror head d4bca957 is the 0.0.13 release Appwrite already locks, so there is no version gap.

Commit What
Add 'packages/cdn/' from commit 'd4bca957…' Subtree import from utopia-php/cdn with full history
chore(cdn): mirror plumbing mirror.yml points at appwrite/appwrite's mirror-redirect.yml; README banner points here
refactor: load cdn from packages/ Step A shape, root autoload and replace, drop require line and vcs repository entry, lock update, PHPStan baseline, RFC phase 8 line

Step A:

Change Detail
Source src/Cdn/* → src/. Identical to 0.0.13 apart from the move and Pint formatting (empty bodies, fn (); Rector changes nothing
Tests tests/Cdn/* → tests/, namespace Utopia\Tests\Cdn → Utopia\Cdn\Tests. All tests use a fake PSR-18 TestClient, so everything is unit tier and no tests/E2E/ is needed
phpstan.neon Level max (was 6) over src and tests, standalone, with phpstan-baseline.neon
rector.php / phpunit.xml Standalone, matching balancer

Nothing to hoist: the package requires ext-curl and ext-json (already in root require) plus balancer and client (both in packages/, covered by replace).

Item Result
Lock diff composer update --lock: 0 installs, 0 updates, 1 removal (utopia-php/cdn 0.0.13)
PHPStan baseline 92 findings (50 src, 42 tests): offset access and concatenation on mixed decoded 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 list
Appwrite consumers src/Appwrite/Platform/Workers/Certificates.php, src/Appwrite/Platform/Workers/Deletes.php, src/Appwrite/Certificates/LetsEncrypt.php, tests/unit/Workers/CertificatesDomainValidationTest.php

Validation

Check Result
bin/monorepo validate All packages valid
bin/monorepo check cdn Rector, Pint, PHPStan level max (with baseline) pass
bin/monorepo test cdn 91 tests, 226 assertions
vendor/bin/phpunit --testsuite packages --filter 'Utopia\\Cdn' All 91 cdn tests pass under the root autoloader
Utopia\Cdn\Cache resolves to packages/cdn/src/Cache.php
Root PHPStan on the four consumer files No errors
composer validate --no-check-publish Valid (only the existing utopia-php/platform exact-version warning)
bin/monorepo split cdn --dry-run 9f89e676, fast-forwards from mirror head d4bca957 (+2 commits)
git diff --check Clean

Merge 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 main ruleset (id 21914382: no required approvals, split app 4016286 as the only always-bypass actor), so absorb ran with --skip-ruleset. There is no classic branch protection on main.

After merge Owner
Confirm Split pushes to utopia-php/cdn Merger
Retire packages/cdn from utopia-php/monorepo Maintainers
Register utopia-php/cdn on Packagist (never published, hence the vcs entry) Someone with Packagist access for the utopia-php vendor
Port or close utopia-php/monorepo#222 (fix(cdn): recover Fastly certificates and preserve DNS failure details), which edits packages/cdn there and is not in 0.0.13 Maintainers
Mirror PRs/issues to triage None open on utopia-php/cdn

utopia-php/fastly in the monorepo does not depend on cdn, so nothing else is affected.

🤖 Generated with Claude Code

TorstenDittmann and others added 30 commits April 16, 2026 14:37
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]>
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
loks0n and others added 18 commits August 28, 2026 13:12
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
…1f0b'

git-subtree-dir: packages/cdn
git-subtree-mainline: ee19d6d
git-subtree-split: d4bca95
@ChiragAgg5k ChiragAgg5k added the absorb History-preserving package absorption; merge commit required label Sep 26, 2026
@greptile-apps

greptile-apps Bot commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 4/5

[High risk] Moves CDN package from external dependency to monorepo.

The PR is not ready to merge because the outstanding repository requirement against adding regex patterns remains unmet.

Fix All in Claude CodeFindings

  1. P2 Tests mirror batch configuration. ▶
  2. P2 Path encoding adds regex. ▶
  3. P2 PHP minimum is misstated. ▶
  4. P2 Documented QA commands fail. ▶
  5. P2 Tests mirror method declarations. ▶
Fix with agent prompt
### Issue 1
packages/cdn/tests/Cache/AdapterTest.php:52-58
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.

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!

### Issue 2
packages/cdn/src/Cache/Adapter/Fastly.php:108-113
`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.

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!

### Issue 3
packages/cdn/README.md:undefined-246
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.
```

### Issue 4
packages/cdn/README.md:250-265
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.

### Issue 5
packages/cdn/tests/Cache/AdapterTest.php:undefined-25
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.

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!

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Summary

The PR moves Utopia CDN into packages/cdn, loads it through the root autoloader, removes the external Composer dependency, and adds standalone package configuration and tests. The changes since the previous review do not alter the CDN files.

Reviews (3) · Last reviewed commit: "Merge remote-tracking branch 'origin/mai..."

Comment on lines +52 to +58
$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);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 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!

Fix in Claude Code Fix in Codex

Comment on lines +108 to +113
{
return (string) preg_replace_callback(
'/[^A-Za-z0-9\-._~\/%?=&:+]/u',
static fn (array $match): string => rawurlencode($match[0]),
$path,
);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 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!

Fix in Claude Code Fix in Codex

Comment thread packages/cdn/README.md

## System requirements

Utopia CDN requires PHP 8.1 or later. We recommend using the latest PHP version whenever possible.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 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.

Suggested change
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.

Fix in Claude Code Fix in Codex

Comment thread packages/cdn/README.md
Comment on lines +250 to +265
Run the test suite:

```bash
composer test
```

Run static analysis:

```bash
composer analyse
```

Run formatting checks:

```bash
composer lint

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 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.

Fix in Claude Code Fix in Codex

@github-actions

github-actions Bot commented Sep 26, 2026 •

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → chore/absorb-cdn (after).

Metric Before After Change
🚀 Requests/sec 162.3 190.24 🟢 +17.2%
⏱️ Latency P50 105.6 ms 89.7 ms 🟢 -15.1%
⏱️ Latency P95 255.59 ms 212.83 ms 🟢 -16.7%
Per-scenario breakdown & investigation details

Metrics below reflect the current branch (after). Δ P95 compares against the base.

Scenario P50 (ms) P95 (ms) Requests RPS Δ P95 (ms)
API total 89.7 212.83 12,255 190.24 -42.76
Account 181.7 367.59 645 10.67 -29.27
TablesDB 86.63 164.12 6,665 107.08 -30.75
Storage 80.74 172.43 3,225 52.93 -43.73
Functions 134.18 263.75 1,720 28.75 -43.89

Top API waits (after)

API request Max wait (ms)
account.name.update 602.98
account.prefs.update 488.74
functions.create 481.62
functions.variables.update 478
tablesdb.rows.create 415.16


public function testEveryAdapterOffersTheSameOperations(): void
{
$this->assertSame(self::OPERATIONS, get_class_methods(Adapter::class));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 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!

Fix in Claude Code Fix in Codex

@ChiragAgg5k
ChiragAgg5k merged commit bed11bc into main Sep 27, 2026
49 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

absorb History-preserving package absorption; merge commit required

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants