Skip to content

Add Been proof-of-existence to demos - #16

Merged
koriym merged 1 commit into
1.xfrom
add-been-proof
Apr 16, 2026
Merged

koriym merged 1 commit into
1.xfrom
add-been-proof

Conversation

@koriym

@koriym koriym commented Apr 16, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Inject Been into Final objects with meaningful domain events
  • Final objects assert their own causal chain via assert() — proof lives in production code, not test files
  • Add Been section to README (ja/en) linking to Semantic Logging

Demos with Been

  • contact-form: receipt↔email causal link
  • user-registration: email traced through chain (assert)
  • order-processing: all moments completed with confirmed status (assert)

Demos without Been (no meaningful context)

hello-world, blog-publishing, medical-triage, loan-application, insurance-claim

Test plan

  • contact-form: 11 tests pass
  • user-registration: 13 tests pass
  • order-processing: 66 tests pass
  • All other demos unaffected

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Documentation

    • Added comprehensive guide for proof-of-existence feature, explaining how domain events are recorded and verified across demos.
  • New Features

    • Enabled semantic logging to record and assert domain events in contact-form, order-processing, and user-registration demos.
    • Domain events now automatically captured during object initialization with runtime verification support.

@coderabbitai

coderabbitai Bot commented Apr 16, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Rate limit exceeded

@koriym has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 24 minutes and 41 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 24 minutes and 41 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: f5e36f21-4552-43f7-8db9-cd15ab4f84cd

📥 Commits

Reviewing files that changed from the base of the PR and between cc2b4b6 and 42e5e52.

📒 Files selected for processing (11)
  • README.ja.md
  • README.md
  • demos/contact-form/src/Context/ReceiptGeneratedContext.php
  • demos/contact-form/src/Final/ContactReceived.php
  • demos/medical-triage/src/Module/AppModule.php
  • demos/order-processing/src/Context/OrderFinalizedContext.php
  • demos/order-processing/src/Final/OrderConfirmed.php
  • demos/order-processing/src/Module/AppModule.php
  • demos/order-processing/tests/Final/OrderConfirmedTest.php
  • demos/user-registration/src/Context/UserCreatedContext.php
  • demos/user-registration/src/Final/UserRegistered.php
📝 Walkthrough

Walkthrough

This PR introduces the "Been" semantic logging pattern across multiple demo applications. New Context classes (ReceiptGeneratedContext, OrderFinalizedContext, UserCreatedContext) are added to capture domain events. Final classes inject Been, record events via with(), and assert causal chains. BeModule is installed in app configurations, and documentation is updated to explain the pattern.

Changes

Cohort / File(s) Summary
Documentation Updates
README.md, README.ja.md
Added new "Been — Proof of Existence" sections explaining the Been immutable carrier pattern, with mapping tables of demos to their proofs and reference links to semantic logging documentation.
Contact-Form Demo
demos/contact-form/src/Context/ReceiptGeneratedContext.php, demos/contact-form/src/Final/ContactReceived.php
Introduced ReceiptGeneratedContext class with TYPE and SCHEMA_URL constants. ContactReceived now injects Been, records ReceiptGeneratedContext via with(), and asserts the causal chain.
Order-Processing Demo
demos/order-processing/src/Context/OrderFinalizedContext.php, demos/order-processing/src/Final/OrderConfirmed.php, demos/order-processing/src/Module/AppModule.php, demos/order-processing/tests/Final/OrderConfirmedTest.php
Added OrderFinalizedContext class. OrderConfirmed now injects Been and records events. AppModule installs BeModule. Tests updated to verify recorded events and context types.
User-Registration Demo
demos/user-registration/src/Context/UserCreatedContext.php, demos/user-registration/src/Final/UserRegistered.php
Introduced UserCreatedContext class. UserRegistered now injects Been, records UserCreatedContext via with(), and asserts causal chain validity.
Medical-Triage Demo
demos/medical-triage/src/Module/AppModule.php
AppModule::configure() now installs BeModule with semantic logging identifier.

Sequence Diagram

sequenceDiagram
    participant Test as Test/Client
    participant Final as Final<br/>(e.g., ContactReceived)
    participant Been as Been<br/>(SemanticLogger)
    participant Context as Context<br/>(e.g., ReceiptGeneratedContext)

    Test->>Final: Construct with #[Inject] Been $been
    Final->>Been: Receive injected Been instance
    Final->>Context: Create new Context(data)
    Context-->>Final: Return Context instance
    Final->>Been: Record via with(context)
    Been-->>Final: Return Been with recorded event
    Final->>Final: Assert events[0] instanceof Context
    Final->>Final: Assert context properties match
    Test->>Final: Access $final->been->events
    Test->>Test: Verify causal chain proven
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 Behold the proof of what we've been,
Events recorded, causal chained—
From test to prod, the truth stays true,
Been carries proof in all we do. ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title 'Add Been proof-of-existence to demos' directly and accurately summarizes the main change: injecting Been into demo Final objects to provide proof-of-existence semantics and enabling causal chain assertions in production code.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch add-been-proof

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 and usage tips.

@coderabbitai coderabbitai Bot left a comment

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.

🧹 Nitpick comments (2)
demos/user-registration/src/Final/UserRegistered.php (1)

45-47: Make the proof check resilient to pre-existing events.

Reading $this->been->events[0] assumes the first event is the one just recorded. If the chain already has events, this can assert against the wrong element.

♻️ Suggested patch
-        $event = $this->been->events[0];
+        $events = $this->been->events;
+        $event = $events[array_key_last($events)] ?? null;
         assert($event instanceof UserCreatedContext);
         assert($event->email === $this->email, 'User must be created with the input email');
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@demos/user-registration/src/Final/UserRegistered.php` around lines 45 - 47,
The current check reads $this->been->events[0] which assumes the new
UserCreatedContext is the first event; make the proof resilient by locating the
actual UserCreatedContext that matches the test email instead of indexing [0].
In the test surrounding $this->been->events and assertions, search through
$this->been->events for an instance of UserCreatedContext with ->email ===
$this->email (or take the last event if you intend "most recent"), then assert
that such an event was found and that its email equals $this->email; update
references to $event accordingly so the assertion no longer depends on a fixed
index.
demos/contact-form/src/Final/ContactReceived.php (1)

42-44: Use a stable event selection for the assertion proof.

Indexing events[0] can validate the wrong event when the chain is already populated; prefer checking the last appended event.

♻️ Suggested patch
-        $event = $this->been->events[0];
+        $events = $this->been->events;
+        $event = $events[array_key_last($events)] ?? null;
         assert($event instanceof ReceiptGeneratedContext);
         assert($event->email === $this->normalizedEmail, 'Receipt must be for the normalized email');
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@demos/contact-form/src/Final/ContactReceived.php` around lines 42 - 44, The
assertion currently grabs $this->been->events[0] which can be wrong for
non-empty chains; instead select the last appended event (e.g. use
array_key_last($this->been->events) or count()-1) and assign it to $event, then
assert $event instanceof ReceiptGeneratedContext and $event->email ===
$this->normalizedEmail as before; update the code around the $event assignment
to use $this->been->events[array_key_last($this->been->events)] (or equivalent)
rather than events[0].
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@demos/contact-form/src/Final/ContactReceived.php`:
- Around line 42-44: The assertion currently grabs $this->been->events[0] which
can be wrong for non-empty chains; instead select the last appended event (e.g.
use array_key_last($this->been->events) or count()-1) and assign it to $event,
then assert $event instanceof ReceiptGeneratedContext and $event->email ===
$this->normalizedEmail as before; update the code around the $event assignment
to use $this->been->events[array_key_last($this->been->events)] (or equivalent)
rather than events[0].

In `@demos/user-registration/src/Final/UserRegistered.php`:
- Around line 45-47: The current check reads $this->been->events[0] which
assumes the new UserCreatedContext is the first event; make the proof resilient
by locating the actual UserCreatedContext that matches the test email instead of
indexing [0]. In the test surrounding $this->been->events and assertions, search
through $this->been->events for an instance of UserCreatedContext with ->email
=== $this->email (or take the last event if you intend "most recent"), then
assert that such an event was found and that its email equals $this->email;
update references to $event accordingly so the assertion no longer depends on a
fixed index.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 6ae710e9-4ac0-4f7c-841d-a9539f224909

📥 Commits

Reviewing files that changed from the base of the PR and between 273ccaa and cc2b4b6.

📒 Files selected for processing (11)
  • README.ja.md
  • README.md
  • demos/contact-form/src/Context/ReceiptGeneratedContext.php
  • demos/contact-form/src/Final/ContactReceived.php
  • demos/medical-triage/src/Module/AppModule.php
  • demos/order-processing/src/Context/OrderFinalizedContext.php
  • demos/order-processing/src/Final/OrderConfirmed.php
  • demos/order-processing/src/Module/AppModule.php
  • demos/order-processing/tests/Final/OrderConfirmedTest.php
  • demos/user-registration/src/Context/UserCreatedContext.php
  • demos/user-registration/src/Final/UserRegistered.php

Inject Been into Final objects that have meaningful domain events to
record. The Final asserts its own causal chain in production code,
moving proof from test files into the domain.

Demos with Been:
- contact-form: receipt↔email link
- user-registration: email causal chain (assert)
- order-processing: moment completion status (assert)

Demos without Been (no meaningful context to prove):
hello-world, blog-publishing, medical-triage, loan-application, insurance-claim

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@koriym
koriym merged commit ff9a858 into 1.x Apr 16, 2026
25 checks passed
@koriym
koriym deleted the add-been-proof branch April 16, 2026 16:42
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