Skip to content

chore: absorb image into packages/image - #13867

Merged
loks0n merged 208 commits into
mainfrom
feat/absorb-image
Sep 23, 2026
Merged

loks0n merged 208 commits into
mainfrom
feat/absorb-image

Conversation

@loks0n

@loks0n loks0n commented Sep 23, 2026

Copy link
Copy Markdown
Member

Summary

This moves utopia-php/image into packages/image, so Appwrite loads it directly. It follows the playbook in rfc/monorepo.md and comes in three commits:

  1. Add 'packages/image/' from commit 'cab2779f…': subtree import from the mirror with full history. The mirror head is the 0.8.12 tag Appwrite already locks, and its tree matches packages/image in utopia-php/monorepo (d801d07), so the dependency graph doesn't change.
  2. chore(image): mirror plumbing: mirror.yml now points here, and the README banner is refreshed.
  3. refactor: load image from packages/:
    • Adds the root autoload and replace entries, drops the utopia-php/image require line, and removes the package from the lock.
    • Step A of the standard shape:
      • src/Image/Image.php moves up to src/.
      • tests/Image/ImageTest.php moves up to tests/, and its fixture paths change to match. The test declared Appwrite\Tests, which isn't this package's namespace, so it becomes Utopia\Image\Tests with a matching autoload-dev entry.
    • The existing phpstan.neon (level max, src + tests) passes as-is, with no baseline.
    • Pint formatting (braces_position) in the test file.

There's nothing to hoist, since the package requires only PHP, ext-imagick and ext-gd, which the Appwrite image already has. The 14 MB of test fixtures are kept out of the image by the existing packages/*/tests rule in .dockerignore. Appwrite uses the package in the Avatars module, Storage/.../Preview/Get.php and app/config/storage/resource_limits.php, and root PHPStan passes on all of them. The library code is byte-identical to 0.8.12, so preview output doesn't change and APP_CACHE_BUSTER stays as it is.

Validation

  • bin/monorepo validate: all packages valid
  • bin/monorepo check image: Pint and PHPStan level max pass
  • bin/monorepo test image: 61 tests / 373 assertions
  • vendor/bin/phpunit --testsuite packages --filter 'Utopia\\Image\\Tests': 61 tests pass under the root autoloader
  • bin/monorepo split image --dry-run: 3a5df569, which fast-forwards from the mirror head cab2779f
  • git diff --check

Merge and follow-up

Merge with a merge commit; squash and rebase are now disabled on this repository.

The utopia-php/image mirror already has the canonical main ruleset (id 19217880), with the split app as an always-bypass actor, so the absorb ran with --skip-ruleset.

After merge: confirm Split pushes to utopia-php/image. Then remove packages/image from utopia-php/monorepo. The mirror has no open PRs, and neither does the monorepo for image.

🤖 Generated with Claude Code

loks0n and others added 18 commits April 17, 2026 15:28
Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
…essionQuality

setImageCompressionQuality() is silently ignored by the libheif coder in
the Imagick PHP extension — quality had no effect and all output was
encoded at the default level regardless of the requested value.

The fix is to call setCompressionQuality() (object-level) after
setImageFormat(), which correctly passes quality through to libheif.
See: Imagick/imagick#711

Also updates the HEIC q100 expected file size in tests (8426 → 8490)
to reflect the minor encoding difference between native Imagick and
the old magick convert path at the same quality level.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
fix: use native Imagick for AVIF and HEIC output instead of magick convert
The `cwebp` shell fallback dates back to the initial 2021 commit, when
it guarded against Imagick builds without libwebp delegate support. The
`utopia-base` image now ships Imagick with webp support, so the Imagick
path succeeds and the catch block has effectively stopped firing.

Switch to the same native pattern used for jpg, png, gif, avif, and
heic: setImageCompressionQuality + setImageFormat('webp'), then let the
shared getImagesBlob/writeImages path handle output.

Add two tests: blob-return via output() (covers the empty-path branch)
and webp-input roundtrip (covers readImageBlob on webp source).

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
fix: use native Imagick for WebP output
Fix aspect ratio handling for gravity crops
GIF already coalesced before resize; animated WebP took the static path and scaled delta frames independently, causing blocky ghosting. Use the same coalesce/deconstruct path for any multi-frame image.

Co-authored-by: Cursor <[email protected]>
deconstructImages() can collapse identical pause frames into empty deltas that WebP encoding drops, zeroing playback delay. Keep coalesced frames and assert total delay is preserved.

Co-authored-by: Cursor <[email protected]>
…ethods

chore: enforce camelCase PHPUnit method names
chore: stop committing package lock files
…ages

Normalize recently absorbed packages
…056948'

git-subtree-dir: packages/image
git-subtree-mainline: 0853aff
git-subtree-split: cab2779
Co-Authored-By: Claude Opus 5.5 <[email protected]>
@loks0n loks0n added the absorb History-preserving package absorption; merge commit required label Sep 23, 2026
@loks0n loks0n self-assigned this Sep 23, 2026
@greptile-apps

greptile-apps Bot commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 4/5

The runtime absorption appears sound, but the explicit repository testing requirement must be satisfied before merging by replacing brittle encoder snapshots and adding observable transformation assertions.

Fix All in Claude CodeFindings

  1. P2 Brittle encoder snapshots ▶
  2. P2 Transformations remain untested ▶
Fix with agent prompt
### Issue 1
packages/image/tests/ImageTest.php:596-598
These fixed byte-size bounds and comparisons against checked-in reference artifacts test encoder-specific output rather than observable image behavior. Encoder output can vary across ImageMagick and codec versions even when the image is correct, so harmless dependency upgrades can fail CI. The AVIF and HEIC tests at lines 733–735 and 784–786 repeat this pattern. This violates the repository requirement to test observable behavior instead of mirroring implementation details or fixtures, and must be corrected before merging; assert properties such as decodability, format, dimensions, pixels, or a meaningful quality relationship instead.

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/image/tests/ImageTest.php:915-925
This border test invokes `setBorder()` but only verifies that a readable JPEG was produced, so it still passes if the border operation becomes a no-op. The opacity and border-radius tests at lines 951–988 have the same problem because they never inspect alpha values or corner pixels. This violates the repository requirement to test observable behavior and must be corrected before merging by asserting the transformed pixels or geometry.

---

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

Summary

This PR absorbs utopia-php/image into the monorepo without changing the imported library implementation.

  • Adds root production and test autoload mappings and replaces the external Composer package.
  • Imports the standalone package metadata, mirror workflow, image implementation, tests, and fixtures.
  • Preserves the locked 0.8.12 implementation byte-for-byte, but brings in brittle and behaviorally weak tests that violate the repository’s testing requirement.

Reviews (1) · Last reviewed commit: "refactor: load image from packages/"

Comment on lines +596 to +598
$this->assertGreaterThan(500, filesize($target));
$this->assertLessThan(2000, filesize($target));
$this->assertEquals(mime_content_type($target), mime_content_type($original));

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 Brittle encoder snapshots

These fixed byte-size bounds and comparisons against checked-in reference artifacts test encoder-specific output rather than observable image behavior. Encoder output can vary across ImageMagick and codec versions even when the image is correct, so harmless dependency upgrades can fail CI. The AVIF and HEIC tests at lines 733–735 and 784–786 repeat this pattern. This violates the repository requirement to test observable behavior instead of mirroring implementation details or fixtures, and must be corrected before merging; assert properties such as decodability, format, dimensions, pixels, or a meaningful quality relationship instead.

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/image/tests/ImageTest.php
Line: 596-598

Comment:
**Brittle encoder snapshots**

These fixed byte-size bounds and comparisons against checked-in reference artifacts test encoder-specific output rather than observable image behavior. Encoder output can vary across ImageMagick and codec versions even when the image is correct, so harmless dependency upgrades can fail CI. The AVIF and HEIC tests at lines 733–735 and 784–786 repeat this pattern. This violates the repository requirement to test observable behavior instead of mirroring implementation details or fixtures, and must be corrected before merging; assert properties such as decodability, format, dimensions, pixels, or a meaningful quality relationship instead.

**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 +915 to +925
$image->setBorder(5, '#ff0000');

$image->save($target, 'jpg', 100);

$this->assertIsReadable($target);
$this->assertEquals(mime_content_type($target), mime_content_type($original));
$this->assertFileExists($target);
$this->assertNotEmpty(file_get_contents($target));

$image = new \Imagick($target);
$this->assertSame('JPEG', $image->getImageFormat());

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 Transformations remain untested

This border test invokes setBorder() but only verifies that a readable JPEG was produced, so it still passes if the border operation becomes a no-op. The opacity and border-radius tests at lines 951–988 have the same problem because they never inspect alpha values or corner pixels. This violates the repository requirement to test observable behavior and must be corrected before merging by asserting the transformed pixels or geometry.

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/image/tests/ImageTest.php
Line: 915-925

Comment:
**Transformations remain untested**

This border test invokes `setBorder()` but only verifies that a readable JPEG was produced, so it still passes if the border operation becomes a no-op. The opacity and border-radius tests at lines 951–988 have the same problem because they never inspect alpha values or corner pixels. This violates the repository requirement to test observable behavior and must be corrected before merging by asserting the transformed pixels or geometry.

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

Fix in Claude Code Fix in Codex

@github-actions

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → feat/absorb-image (after).

Metric Before After Change
🚀 Requests/sec 192.61 195.4 ⚪ +1.4%
⏱️ Latency P50 89.1 ms 89.5 ms ⚪ +0.5%
⏱️ Latency P95 210.43 ms 203.34 ms ⚪ -3.4%
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.5 203.34 12,426 195.4 -7.08
Account 165.8 307.33 654 10.93 -91.18
TablesDB 87.22 167.52 6,758 109.34 +3.68
Storage 80.39 175.06 3,270 54.22 -4.73
Functions 121.21 235.17 1,744 29.45 -14.55

Top API waits (after)

API request Max wait (ms)
tablesdb.rows.get 468.29
account.prefs.update 451.04
account.name.update 430.21
functions.delete 379.86
storage.buckets.create 379.64

@loks0n
loks0n merged commit f70a10a into main Sep 23, 2026
62 of 65 checks passed
@loks0n

loks0n commented Sep 23, 2026

Copy link
Copy Markdown
Member Author

Split run pushed utopia-php/image main to 989c329, a fast-forward on cab2779, with a tree matching packages/image. Remaining: utopia-php/monorepo#342 retires the package there.

@loks0n

loks0n commented Sep 23, 2026

Copy link
Copy Markdown
Member Author

Retired from the monorepo in utopia-php/monorepo#342. Its Split run no longer includes image, and the mirror stays at 989c329. The migration is complete.

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.