Skip to content

fix(mock): create HTTP server after app is ready - #6071

Merged
fengmk2 merged 2 commits into
mainfrom
codex/fix-mock-http-ready
Oct 7, 2026
Merged

fengmk2 merged 2 commits into
mainfrom
codex/fix-mock-http-ready

Conversation

@fengmk2

@fengmk2 fengmk2 commented Oct 7, 2026 •

Copy link
Copy Markdown
Member

@eggjs/mock creates the HTTP handler before asynchronous middleware loading finishes. When middleware composition copies the list, requests use an incomplete chain and return 404.

Create the server after app.ready() in both normal and parallel startup. The handler then includes all loaded middleware, and the server event still runs after readiness. Register the default error listener before startup so application errors remain handled.

Summary by CodeRabbit

  • Bug Fixes
    • Mock HTTP servers are now created after the application is ready, so requests made after startup receive the expected responses.
    • Startup errors are handled consistently, including when an application has a custom error listener.
    • Parallel mock applications now serve requests correctly after readiness.

Copilot AI balanced review requested due to automatic review settings October 7, 2026 07:34
@coderabbitai

coderabbitai Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: f235dfb3-11a2-4c9d-8862-a50a061be93b
📥 Commits

Reviewing files that changed from the base of the PR and between 34c94e1 and 5da22b5.

📒 Files selected for processing (4)
  • plugins/mock/src/lib/app.ts
  • plugins/mock/src/lib/parallel/app.ts
  • plugins/mock/test/app.test.ts
  • plugins/mock/test/fixtures/parallel-framework/index.js

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.


📝 Walkthrough

Walkthrough

Both mock application implementations now install an error handler when needed and wait for application readiness before creating the HTTP server. Tests cover requests after readiness and startup error handling.

Changes

Mock application startup

Layer / File(s) Summary
Wait for readiness before server creation
plugins/mock/src/lib/app.ts, plugins/mock/src/lib/parallel/app.ts, plugins/mock/src/lib/mock_http_server.ts
Both startup paths add the bound onerror handler only when no error listener exists, then await app.ready() before server creation. The server event remains after creation. The helper comment describes startup emission and cached-server access.
Exercise ready requests and startup errors
plugins/mock/test/fixtures/snapshot-framework/index.js, plugins/mock/test/fixtures/parallel-framework/index.js, plugins/mock/test/app.test.ts
Fixtures provide readiness-dependent responses, error collection, and a snapshot application subclass. Tests check requests through direct server and mock request paths, and verify startup errors with and without a custom error listener.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Merge Risk: ⚪ Minimal · up to 5da22

The mock server is created after the application is ready, and startup errors retain their expected handling. No identified issue blocks merging after normal checks.

🚥 Pre-merge checks | ✅ 4 | ❌ 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%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 6 files. 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 clearly summarizes the main change: creating the mock HTTP server after the application is ready.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Oct 7, 2026 •

Copy link
Copy Markdown

Deploying egg-v3 with  Cloudflare Pages  Cloudflare Pages

Latest commit: 5da22b5
Status: ✅  Deploy successful!
Preview URL: https://bddc1695.egg-v3.pages.dev
Branch Preview URL: https://codex-fix-mock-http-ready.egg-v3.pages.dev

View logs

Copilot AI 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.

Copilot review overview

🟢 Approval recommended

Both startup paths use the corrected ordering, with focused regression coverage and no identified blocking issues.

Review effort: Balanced
Findings: None

What changed in this PR

Fixes premature HTTP handler creation in @eggjs/mock, preventing incomplete middleware chains from returning unexpected 404 responses.

Changes:

  • Creates HTTP servers after application readiness in normal and parallel startup.
  • Preserves post-readiness server events and adds regression coverage.
File Description
plugins/​mock/​test/​fixtures/​snapshot-framework/​index.js Models middleware composition that captures the current list.
plugins/​mock/​test/​fixtures/​parallel-framework/​index.js Makes responses reflect readiness at handler creation.
plugins/​mock/​test/​app.test.ts Tests middleware composition and parallel server readiness.
plugins/​mock/​src/​lib/​parallel/​app.ts Defers parallel server creation until ready.
plugins/​mock/​src/​lib/​mock_http_server.ts Clarifies server-event ownership in comments only.
plugins/​mock/​src/​lib/​app.ts Defers normal server creation until ready.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@codecov

codecov Bot commented Oct 7, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 84.02%. Comparing base (e701300) to head (5da22b5).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6071      +/-   ##
==========================================
+ Coverage   83.61%   84.02%   +0.41%     
==========================================
  Files         731      731              
  Lines       22608    22612       +4     
  Branches     4554     4556       +2     
==========================================
+ Hits        18903    19000      +97     
+ Misses       3202     3121      -81     
+ Partials      503      491      -12     

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

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Oct 7, 2026 •

Copy link
Copy Markdown

Deploying egg with  Cloudflare Pages  Cloudflare Pages

Latest commit: 5da22b5
Status: ✅  Deploy successful!
Preview URL: https://237c3929.egg-cci.pages.dev
Branch Preview URL: https://codex-fix-mock-http-ready.egg-cci.pages.dev

View logs

Copilot AI balanced review requested due to automatic review settings October 7, 2026 07:47

Copilot AI 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.

Copilot review overview

🟢 Approval recommended

Both startup paths consistently address middleware timing with focused regression coverage and no identified blockers; tests were not executed.

Review effort: Balanced
Findings: None

@killagu killagu 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.

LGTM

@fengmk2
fengmk2 merged commit bc5bd00 into main Oct 7, 2026
40 checks passed
@fengmk2
fengmk2 deleted the codex/fix-mock-http-ready branch October 7, 2026 08:12
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.

3 participants