Skip to content

Throw EmbedException when a _self-embedded resource returns no body#374

Merged
koriym merged 4 commits into
bearsunday:1.xfrom
koriym:self-embed-domain-exception
Jul 15, 2026
Merged

Throw EmbedException when a _self-embedded resource returns no body#374
koriym merged 4 commits into
bearsunday:1.xfrom
koriym:self-embed-domain-exception

Conversation

@koriym

@koriym koriym commented Jul 3, 2026

Copy link
Copy Markdown
Member

Summary

A resource embedded as _self has its body flattened into the parent by EmbedInterceptor::linkSelf, which reads $result->body. But #[CacheableResponse] / #[DonutCache] restore only the view on a cache hit, not the body. So a _self-embedded resource with those cache attributes breaks silently on the second (cache-hit) request:

  • dev: dies on assert(is_array($result->body)) with no explanation
  • prod: does an empty foreach(null) merge (a warning, then a blank body)

This PR replaces the assert with a domain exception whose message names the fix, turning a confusing failure into a fail-fast with actionable guidance:

"_self" embed of {uri} returned no body. #[CacheableResponse]/#[DonutCache] restore only the view on a cache hit, not the body; a resource embedded as "_self" must use #[Cacheable] (value cache).

Test

Added testSelfLinkNullBodyThrowsEmbedException. Independently verified that reverting the guard back to the old assert makes the test fail — confirming the test truly depends on the new behavior rather than passing incidentally. Full suite green: 404 tests, 704 assertions.

🤖 Generated with Claude Code

@coderabbitai

coderabbitai Bot commented Jul 3, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 26a711c7-16d2-4d2d-abd2-8315546bcffc

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented Jul 3, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (f708627) to head (0e0e0a0).

Additional details and impacted files
@@             Coverage Diff             @@
##                 1.x      #374   +/-   ##
===========================================
  Coverage     100.00%   100.00%           
- Complexity       687       688    +1     
===========================================
  Files             96        96           
  Lines           1722      1726    +4     
===========================================
+ Hits            1722      1726    +4     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@koriym
koriym force-pushed the self-embed-domain-exception branch from 87cc22d to 044b16a Compare July 3, 2026 19:57
koriym and others added 3 commits July 16, 2026 03:17
#[CacheableResponse]/#[DonutCache] restore only the view on a cache hit, not the body, so a resource embedded as _self (whose body linkSelf reads) breaks silently: dev dies on assert, prod does an empty foreach(null) merge. Replace the assert with a domain exception whose message names the fix (use #[Cacheable] value cache).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
The tests (HttpResourceObjectTest, HttpRequestCurlTest) use Koriym\PhpServer\PhpServer directly, but it was only pulled in indirectly via bear/devtools (^1.0). On --prefer-lowest that resolved to 1.0.0, which predates the PhpServer class, causing a 'Class not found' fatal. Require it directly at ^1.0.1 (the version that introduced PhpServer).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@koriym
koriym force-pushed the self-embed-domain-exception branch from 0f36c85 to 7ab16b7 Compare July 15, 2026 18:18
@koriym

koriym commented Jul 15, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 15, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@koriym
koriym merged commit 5ca7388 into bearsunday:1.x Jul 15, 2026
18 checks passed
@koriym
koriym deleted the self-embed-domain-exception branch July 15, 2026 18:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant