Skip to content

Conversation

@withinboredom
Copy link
Member

@withinboredom withinboredom commented Aug 3, 2025

Summary by CodeRabbit

  • Refactor
    • Improved internal handling of property operations for better clarity and maintainability.
    • Updated internal labels for processing steps.
    • Enhanced access control logic to unconditionally deny access when specified.
  • Tests
    • Added tests to verify property access signals and enforce access control with security exceptions.

Signed-off-by: Robert Landers <landers.robert@gmail.com>
@coderabbitai
Copy link

coderabbitai bot commented Aug 3, 2025

Walkthrough

The EntityHistory.php file was updated to remove an unused import, revise property access logic in the execute method to interact directly with the $state object for 'get' and 'set' operations, and rename a label from done to finalize. The AbstractHistory.php file was modified to deny access unconditionally when a DenyAnyOperation attribute has all its origin properties set to null. The test suite EntityHistoryTest.php was extended with three new tests verifying property signal handling, including access control enforcement via a DenyAnyOperation attribute. No changes were made to public interfaces.

Changes

Cohort / File(s) Change Summary
Property Access and Label Refactor
src/State/EntityHistory.php
Removed unused import, changed property access logic in execute to use direct state access, and renamed label from done to finalize.
Access Control Enhancement
src/State/AbstractHistory.php
Added unconditional deny access check when DenyAnyOperation has all origin fields null in checkAccessControl method.
EntityHistory Signal Handling Tests
tests/Unit/EntityHistoryTest.php
Added tests for property 'get' and 'set' signals returning TaskCompleted events and for security enforcement on restricted properties.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

A hop and a skip through the code today,
Labels renamed, old imports swept away.
Properties accessed in a simpler way—
The state now shines, clear as May.
Access locked tight when none may pass,
Tests ensure the rules will last! 🐇🔐✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 98717b2 and e19d251.

📒 Files selected for processing (1)
  • src/State/AbstractHistory.php (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: build-docker
  • GitHub Check: Unit Tests - PHP
🔇 Additional comments (1)
src/State/AbstractHistory.php (1)

157-159: LGTM! Good security enhancement.

The unconditional deny logic for DenyAnyOperation when all origin properties are null follows the principle of least privilege. This ensures that a DenyAnyOperation attribute without specific criteria acts as a blanket denial, which is the expected behavior.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/properties

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@codecov
Copy link

codecov bot commented Aug 3, 2025

Codecov Report

❌ Patch coverage is 83.33333% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 47.21%. Comparing base (7cba4cb) to head (e19d251).
⚠️ Report is 1 commits behind head on v2.

Files with missing lines Patch % Lines
src/State/AbstractHistory.php 50.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##                 v2     #157      +/-   ##
============================================
+ Coverage     46.85%   47.21%   +0.35%     
- Complexity     1313     1317       +4     
============================================
  Files           103      103              
  Lines          3677     3679       +2     
============================================
+ Hits           1723     1737      +14     
+ Misses         1954     1942      -12     

☔ View full report in Codecov by Sentry.
📢 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.

@github-actions
Copy link

github-actions bot commented Aug 3, 2025

Performance Metrics

test time (s) memory usage
perf 16.16 170
Fan out/in 60.06 8

Performance Metrics

test time (s) memory usage
perf 16.41 102
Fan out/in 60.05 8

Signed-off-by: Robert Landers <landers.robert@gmail.com>
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
tests/Unit/EntityHistoryTest.php (1)

245-263: Enhance the access control test coverage.

The security test correctly validates that restricted properties throw SecurityException, but could be improved:

  1. Import the attribute class instead of using fully qualified name:
+use Bottledcode\DurablePhp\State\Attributes\DenyAnyOperation;

-        #[Bottledcode\DurablePhp\State\Attributes\DenyAnyOperation(fromType: 'test')]
+        #[DenyAnyOperation(fromType: 'test')]
  1. Test both get and set operations to ensure comprehensive access control:
    // Try to access the restricted property
    $restrictedEvent = RaiseEvent::forOperation('$restrictedProperty::get', []);
    
+   // Test both get and set operations are restricted
    expect(fn() => processEvent($restrictedEvent, $history->applyRaiseEvent(...)))->toThrow(SecurityException::class);
+   
+   $restrictedSetEvent = RaiseEvent::forOperation('$restrictedProperty::set', ['new value']);
+   expect(fn() => processEvent($restrictedSetEvent, $history->applyRaiseEvent(...)))->toThrow(SecurityException::class);
  1. Consider testing the public property to demonstrate the access control is selective.
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4a9200b and 98717b2.

📒 Files selected for processing (1)
  • tests/Unit/EntityHistoryTest.php (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: Unit Tests - PHP
  • GitHub Check: build-docker
🔇 Additional comments (3)
tests/Unit/EntityHistoryTest.php (3)

27-27: LGTM! Necessary imports for new test functionality.

The SecurityException and TaskCompleted imports are appropriately added to support the new property signal tests.

Also applies to: 30-30


221-243: Comprehensive property set signal test.

The test thoroughly validates property setting functionality by checking both the state change ($history->getState()->testProperty) and the event result. The test structure and assertions are well-designed.


199-219: Nested getInnerEvent() calls correctly unwrap the event layers.

Verified that:

  • AwaitResult implements getInnerEvent() and returns the inner event passed in.
  • Wrapper classes (e.g. WithFrom, WithEntity, etc.) also implement getInnerEvent().
  • TaskCompleted does not implement getInnerEvent(), so a second call lands on its result.

No changes needed—the current assertions on lines 217–218 of tests/Unit/EntityHistoryTest.php accurately verify the unwrapped TaskCompleted event and its result.

Signed-off-by: Robert Landers <landers.robert@gmail.com>
@withinboredom withinboredom merged commit c3b3e7d into v2 Aug 3, 2025
6 checks passed
@withinboredom withinboredom deleted the fix/properties branch August 3, 2025 11:58
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.

2 participants