Skip to content

Issue/504 load modules boot stage#505

Merged
armanist merged 6 commits into
quantum-php:masterfrom
armanist:issue/504-load-modules-boot-stage
May 6, 2026
Merged

Issue/504 load modules boot stage#505
armanist merged 6 commits into
quantum-php:masterfrom
armanist:issue/504-load-modules-boot-stage

Conversation

@armanist

@armanist armanist commented May 6, 2026

Copy link
Copy Markdown
Collaborator

Closes #504

Summary by CodeRabbit

  • Refactor

    • Module loading now integrated into the application boot pipeline.
    • Route initialization in console commands now uses lazy-loading for improved efficiency.
    • Simplified request context cleanup and lifecycle management in tests.
  • Bug Fixes

    • Improved request and response handling to preserve state in error scenarios.

@coderabbitai

coderabbitai Bot commented May 6, 2026

Copy link
Copy Markdown

Warning

Rate limit exceeded

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

To continue reviewing without waiting, purchase usage credits in the billing tab.

⌛ 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: 16eb9df8-fc05-4401-91bf-6846fef05ceb

📥 Commits

Reviewing files that changed from the base of the PR and between 866b4d4 and faef83d.

📒 Files selected for processing (5)
  • src/App/Stages/LoadModulesStage.php
  • tests/Unit/Console/Commands/OpenApiCommandTest.php
  • tests/Unit/Console/Commands/RouteListCommandTest.php
  • tests/Unit/Http/Helpers/HttpHelperTest.php
  • tests/Unit/Http/Traits/Request/HttpRequestHeaderTest.php
📝 Walkthrough

Walkthrough

The PR moves module loading from per-request execution in WebAppAdapter::start() to a new boot-phase LoadModulesStage, preventing repeated route collection registration during long-lived app instances. Request cleanup is simplified, and console commands now lazily initialize the route collection. Test lifecycle methods are streamlined.

Changes

Boot & Request Lifecycle Refactoring

Layer / File(s) Summary
New Boot Stage
src/App/Stages/LoadModulesStage.php
New LoadModulesStage loads modules via ModuleLoader, builds RouteCollection via RouteBuilder, and stores it in DI during boot phase.
Adapter Pipeline Wiring
src/App/Adapters/WebAppAdapter.php
LoadModulesStage is imported and inserted into the boot pipeline after InitDebuggerStage; direct loadModules() call is removed from start().
Request Cleanup Adjustment
src/App/Traits/WebAppTrait.php
cleanupRequestContext() resets matched route via setMatchedRoute(null) instead of flushing response; docblock exceptions are simplified from four types to RouteException|BaseException.
Console Command Updates
src/Console/Commands/OpenApiCommand.php, src/Console/Commands/RouteListCommand.php
Both commands now lazily check/initialize RouteCollection in DI; if absent, they build and register it; if present, they reuse it.
Test Lifecycle & Assertions
tests/Unit/App/Adapters/WebAppAdapterTest.php, tests/Unit/Http/Helpers/HttpHelperTest.php, tests/Unit/Http/RequestTest.php, tests/Unit/Http/Traits/Request/Http*Test.php, tests/Unit/Router/Helpers/RouteHelpersTest.php
Per-test setUp/tearDown lifecycle methods are removed across multiple test classes; WebAppAdapterTest assertions updated to verify preserved response content instead of cleared response; HttpHelperTest conditionally retrieves RouteCollection from DI instead of manually registering; RouteHelpersTest adds helper method and new tests validating RouteCollection state dependency.

Sequence Diagram

sequenceDiagram
    participant Boot as Boot Pipeline
    participant LMS as LoadModulesStage
    participant ML as ModuleLoader
    participant RB as RouteBuilder
    participant DI as DI Container
    participant Start as start() Handler
    participant Req as Request

    Note over Boot,Start: Before: Module Load Per-Request
    Boot->>Start: invoke start()
    activate Start
    Start->>ML: loadModules()
    activate ML
    ML->>DI: register routes
    deactivate ML
    Start->>Req: handle request
    deactivate Start

    Note over Boot,Start: After: Module Load At Boot
    Boot->>LMS: boot phase
    activate LMS
    LMS->>ML: load modules
    activate ML
    ML->>RB: pass module routes
    deactivate ML
    RB->>DI: build & register RouteCollection
    deactivate LMS
    Boot->>Start: start (per-request)
    activate Start
    Start->>Req: handle request (routes cached)
    deactivate Start
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • softberg/quantum-php-core#503: Modifies WebAppTrait::cleanupRequestContext() and related WebAppAdapterTest assertions, directly overlapping with this PR's request cleanup changes.
  • softberg/quantum-php-core#476: Refactors WebAppAdapter::start() middleware handling and boot pipeline flow, closely related to the adapter pipeline updates in this PR.
  • softberg/quantum-php-core#466: Modifies the same core files (WebAppAdapter, console commands) and shifts routing/module initialization semantics.

Suggested labels

enhancement, refactoring

Suggested reviewers

  • andrey-smaelov
  • live-soft

Poem

🐰 Modules boot but once, not every hop!
LoadStage loads them when the app does start,
Routes cached, no re-registration stops,
Requests dance swift with a cleaner heart.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 22.73% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly refers to the main change—introducing LoadModulesStage into the boot pipeline—which is the primary objective of this PR.
Linked Issues check ✅ Passed All core requirements from issue #504 are met: LoadModulesStage created, wired into boot pipeline, module loading removed from start(), request cleanup preserved without response flush.
Out of Scope Changes check ✅ Passed All changes align with issue #504 objectives. The test cleanup updates reflect the lifecycle changes and are directly scoped to implementing the boot stage refactoring.

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

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

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 866b4d490a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/App/Traits/WebAppTrait.php

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/App/Stages/LoadModulesStage.php`:
- Line 52: The unconditional registration Di::set(RouteCollection::class,
$collection) in LoadModulesStage risks dependencyAlreadyRegistered when a
RouteCollection is already bound; guard this by checking the container before
setting (e.g., use Di::has or equivalent to detect an existing RouteCollection)
and only call Di::set(RouteCollection::class, $collection) when none exists, or
catch and ignore dependencyAlreadyRegistered around the Di::set call so multiple
app instances can boot safely.

In `@tests/Unit/Http/Helpers/HttpHelperTest.php`:
- Around line 61-65: The test is mutating the DI-shared RouteCollection by
calling Di::get(RouteCollection::class) and then $routeCollection->add(...);
replace that with an isolated fresh instance: always instantiate a new
RouteCollection() for the route-finder setup instead of using Di::get or
Di::has, and call add() on that new instance so the test does not modify shared
DI state (look for usage of Di::get(RouteCollection::class),
Di::has(RouteCollection::class), the $routeCollection variable and the add()
call).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: f4286641-69ef-4713-961d-487d65e20060

📥 Commits

Reviewing files that changed from the base of the PR and between f296867 and 866b4d4.

📒 Files selected for processing (15)
  • src/App/Adapters/WebAppAdapter.php
  • src/App/Stages/LoadModulesStage.php
  • src/App/Traits/WebAppTrait.php
  • src/Console/Commands/OpenApiCommand.php
  • src/Console/Commands/RouteListCommand.php
  • tests/Unit/App/Adapters/WebAppAdapterTest.php
  • tests/Unit/Http/Helpers/HttpHelperTest.php
  • tests/Unit/Http/RequestTest.php
  • tests/Unit/Http/Traits/Request/HttpRequestBodyTest.php
  • tests/Unit/Http/Traits/Request/HttpRequestFileTest.php
  • tests/Unit/Http/Traits/Request/HttpRequestHeaderTest.php
  • tests/Unit/Http/Traits/Request/HttpRequestQueryTest.php
  • tests/Unit/Http/Traits/Request/HttpRequestRouteTest.php
  • tests/Unit/Http/Traits/Request/HttpRequestUrlTest.php
  • tests/Unit/Router/Helpers/RouteHelpersTest.php
💤 Files with no reviewable changes (6)
  • tests/Unit/Http/Traits/Request/HttpRequestBodyTest.php
  • tests/Unit/Http/Traits/Request/HttpRequestRouteTest.php
  • tests/Unit/Http/Traits/Request/HttpRequestFileTest.php
  • tests/Unit/Http/Traits/Request/HttpRequestUrlTest.php
  • tests/Unit/Http/Traits/Request/HttpRequestQueryTest.php
  • tests/Unit/Http/RequestTest.php

Comment thread src/App/Stages/LoadModulesStage.php Outdated
Comment thread tests/Unit/Http/Helpers/HttpHelperTest.php Outdated
@armanist armanist requested a review from andrey-smaelov May 6, 2026 12:36
@codecov

codecov Bot commented May 6, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 56.52174% with 10 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.70%. Comparing base (f296867) to head (faef83d).
⚠️ Report is 7 commits behind head on master.

Files with missing lines Patch % Lines
src/Console/Commands/OpenApiCommand.php 16.66% 5 Missing ⚠️
src/Console/Commands/RouteListCommand.php 28.57% 5 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master     #505      +/-   ##
============================================
- Coverage     90.87%   90.70%   -0.18%     
- Complexity     2927     2930       +3     
============================================
  Files           255      256       +1     
  Lines          7708     7711       +3     
============================================
- Hits           7005     6994      -11     
- Misses          703      717      +14     

☔ 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.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@armanist armanist added bug Something isn't working refactoring labels May 6, 2026
@armanist armanist added this to the 3.0.0 milestone May 6, 2026
@armanist armanist merged commit af7bdc5 into quantum-php:master May 6, 2026
5 of 7 checks passed
@armanist armanist deleted the issue/504-load-modules-boot-stage branch May 6, 2026 13:00
armanist added a commit to armanist/quantum-php-core that referenced this pull request May 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working refactoring

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Move Module Loading to Web Boot Stage and Keep start() Request-Only

2 participants