Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@fengmk2
Copy link
Member

@fengmk2 fengmk2 commented Sep 28, 2025

only feature use on both Agent and Application should use EggApplicationCore

Summary by CodeRabbit

  • New Features

    • File watcher supports all-in-one-process mode with automatic selection and clearer debug logs.
  • Bug Fixes

    • Improved app readiness and shutdown by awaiting watcher readiness and adding timing waits.
  • Refactor

    • Standardized public typings to a consistent Application/Context surface; removed prior augmented core typings.
  • Tests

    • Stabilized tests with explicit readiness waits; two custom watcher tests temporarily skipped.
  • Chores

    • Updated lint-staged and oxlint; simplified CI matrix to fewer OS/Node combinations.

only feature use on both Agent and Application should use EggApplicationCore
@fengmk2 fengmk2 requested a review from Copilot September 28, 2025 16:33
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Sep 28, 2025

Caution

Review failed

The pull request is closed.

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

Walkthrough

Removes TypeScript module augmentations of @eggjs/core and migrates public typings from EggApplicationCore/EggContext to Application/Context across core, plugins, and tests. Refactors watcher boot to support all-in-one and cluster modes, adds debug logs, adjusts test timing, and bumps lint-staged and oxlint versions.

Changes

Cohort / File(s) Summary
Remove module augmentation
packages/egg/src/lib/application.ts, packages/egg/src/lib/egg.ts
Deletes module augmentations for @eggjs/core that previously extended EggCore (removes many added methods/properties and their public typings).
Type refactor: Application / Context replace EggApplicationCore / EggContext
packages/egg/src/lib/core/base_context_class.ts, packages/egg/src/lib/core/context_httpclient.ts, packages/egg/src/lib/types.ts, packages/egg/test/index.test-d.ts, packages/egg/test/lib/core/loader/load_plugin.test.ts, plugins/tracer/src/boot.ts, plugins/schedule/src/lib/load_schedule.ts
Changes public/member signatures and imports to use Application (and Context) instead of EggApplicationCore (and EggContext); updates tests and tightens some test typings (e.g., non-null jsonp config).
Watcher initialization refactor & logging
plugins/watcher/src/lib/boot.ts, plugins/watcher/src/lib/watcher.ts, plugins/watcher/test/fixtures/apps/watcher-type-default/app.js, plugins/watcher/test/watcher.test.ts
Introduces dual initialization paths (all-in-one vs cluster), assigns app.watcher, removes private #watcher field, updates readiness usage to app.watcher.ready(), adds debug logs, moves a fixture watch into app.ready, and skips two tests.
Boot loader test timing
packages/egg/test/lib/core/loader/load_boot.test.ts
Converts beforeAll hooks to async, adds timers/promises waits (scheduler.wait) to synchronise readiness/shutdown, and updates an import path to .ts.
Tests: remove EggApplicationCore usage
packages/egg/test/...
Removes or replaces EggApplicationCore type usage in tests and related imports; adjusts test assertions/type casts accordingly.
Dev tooling bumps
pnpm-workspace.yaml
Bumps lint-staged (^16.2.0 → ^16.2.3) and oxlint (^1.18.0 → ^1.19.0).
CI matrix reduction
.github/workflows/ci.yml
Simplifies test matrix by removing macOS and multi-version Node combinations; keeps ubuntu/windows with Node 22.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor Dev as Developer
  participant App as Application
  participant Boot as WatcherBoot
  participant Cluster as ClusterWrapper
  participant W as Watcher

  Dev->>App: start()
  App->>Boot: new WatcherBoot(app)
  Note right of Boot: decide init mode (debug logged)
  alt all-in-one-process
    Boot->>W: new Watcher(app.config)
    Boot-->>App: app.watcher = W
  else cluster mode
    Boot->>Cluster: clusterWrapper(Watcher).delegate('watch','subscribe')
    Cluster->>W: create(app.config)
    Boot-->>App: app.watcher = W
  end
  Boot->>W: await app.watcher.ready()
  App-->>Dev: ready()
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related issues

Possibly related PRs

Poem

I nibble types from core to app,
Two watcher paths — a tidy map.
Debug lights blink where shadows played,
Tests wait patient for the parade.
Dependencies fresh, I hop and clap. 🐇✨

Pre-merge checks and finishing touches

❌ Failed checks (1 inconclusive)
Check name Status Explanation Resolution
Title Check ❓ Inconclusive The pull request title indicates a refactor to prioritize “Application” but is ambiguous and does not clearly convey the primary change of replacing EggApplicationCore and core augmentations with the Application type in the public API surface. Please revise the title to more explicitly summarize the main change, for example “refactor: prefer Application type over EggApplicationCore in public API,” so it clearly communicates the intent.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.

📜 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 b1a7df1 and 02a2c12.

📒 Files selected for processing (1)
  • .github/workflows/ci.yml (1 hunks)

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.

@gemini-code-assist
Copy link

Summary of Changes

Hello @fengmk2, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request undertakes a significant type refactoring within the Egg.js framework. The primary objective is to enhance type accuracy and clarity by ensuring that application-specific features correctly reference the Application class, while the more general EggApplicationCore is reserved for functionalities that are truly common to both Agent and Application instances. This involves updating various type imports, declarations, and test assertions across the codebase to reflect this refined type hierarchy.

Highlights

  • Type Refactoring: The pull request refactors type definitions to prioritize the Application type over EggApplicationCore in contexts specific to the application instance. This aligns with the goal of using EggApplicationCore only for features shared by both Agent and Application.
  • Removed Global Type Declarations: The declare module '@eggjs/core' blocks in packages/egg/src/lib/application.ts and packages/egg/src/lib/egg.ts have been removed, indicating a consolidation or more precise definition of these types elsewhere.
  • Updated Type References: Numerous files across the egg package and its plugins (e.g., schedule, tracer, watcher) have been updated to import and use Application instead of EggApplicationCore for application-level type references, including constructor parameters and property declarations.
  • Improved Test Type Assertions: Test files, particularly packages/egg/test/index.test-d.ts and packages/egg/test/lib/core/loader/load_plugin.test.ts, have been updated to reflect the new type hierarchy, removing explicit type assertions (as unknown as EggApplicationCore) and directly using Application.
  • Refined Watcher Plugin Types: In the watcher plugin, the watcher property is now explicitly declared on both Application and Agent interfaces, providing more granular type definitions.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This refactoring changes the framework to use Application instead of EggApplicationCore as the primary type for plugins and components that only need application-level functionality. The change follows the principle that only features used by both Agent and Application should use EggApplicationCore.

Key changes:

  • Updated plugin type declarations to use Application and Agent interfaces separately instead of the generic EggApplicationCore
  • Modified constructor parameters and type imports across plugins and core components
  • Cleaned up test files to remove unnecessary type casting

Reviewed Changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
plugins/watcher/src/types.ts Split interface declaration from EggApplicationCore to separate Application and Agent interfaces
plugins/watcher/src/lib/boot.ts Changed constructor parameter type from EggApplicationCore to Application
plugins/tracer/src/boot.ts Updated constructor parameter type from EggApplicationCore to Application
plugins/schedule/src/lib/load_schedule.ts Updated context type import from EggContext to Context
packages/egg/test/lib/core/loader/load_plugin.test.ts Removed unnecessary type casting in multiple test cases
packages/egg/test/index.test-d.ts Updated type declarations and added null assertions for optional config properties
packages/egg/src/lib/types.ts Changed onClientError callback parameter type from EggApplicationCore to Application
packages/egg/src/lib/egg.ts Removed module declaration augmentation for @eggjs/core
packages/egg/src/lib/core/context_httpclient.ts Updated app property type from EggApplicationCore to Application
packages/egg/src/lib/core/base_context_class.ts Changed app property type from EggApplicationCore to Application
packages/egg/src/lib/application.ts Removed module declaration augmentation for @eggjs/core

Comment on lines 10 to 12
watcher: Watcher;
}

Copy link

Copilot AI Sep 28, 2025

Choose a reason for hiding this comment

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

The watcher property is duplicated across both Application and Agent interfaces. Consider if this plugin truly needs to be available on both, or if it should only be on one based on the refactoring goal to use Application first.

Suggested change
watcher: Watcher;
}
}

Copilot uses AI. Check for mistakes.
@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Sep 28, 2025

Deploying egg with  Cloudflare Pages  Cloudflare Pages

Latest commit: 02a2c12
Status:🚫  Build failed.

View logs

@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Sep 28, 2025

Deploying egg-v3 with  Cloudflare Pages  Cloudflare Pages

Latest commit: 02a2c12
Status:🚫  Build failed.

View logs

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request refactors the codebase to prefer using the more specific Application type over the general EggApplicationCore type. This is a good practice that improves type safety and code clarity. The changes are largely well-executed and align with this goal. However, I've identified a critical issue in the watcher plugin where this refactoring was applied incorrectly. The watcher is used in both Application and Agent contexts, so it should continue to use the common base type EggApplicationCore to function correctly in agent workers. My review includes a specific comment and suggestion to fix this.

Comment on lines 1 to 9
import type { ILifecycleBoot, Application } from 'egg';

import { Watcher } from './watcher.ts';

export class Boot implements ILifecycleBoot {
#app: EggApplicationCore;
#app: Application;
#watcher: Watcher;

constructor(appOrAgent: EggApplicationCore) {
constructor(appOrAgent: Application) {

Choose a reason for hiding this comment

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

critical

The types for appOrAgent and #app have been changed to Application. However, as the parameter name appOrAgent suggests and as confirmed by the changes in plugins/watcher/src/types.ts, this class is used for both Application and Agent workers. Agent is not a subtype of Application, so this change is incorrect and will break the watcher in agent workers.

The correct type should be EggApplicationCore, which is the common base class for both Application and Agent. This aligns with the pull request's goal: "only feature use on both Agent and Application should use EggApplicationCore".

Suggested change
import type { ILifecycleBoot, Application } from 'egg';
import { Watcher } from './watcher.ts';
export class Boot implements ILifecycleBoot {
#app: EggApplicationCore;
#app: Application;
#watcher: Watcher;
constructor(appOrAgent: EggApplicationCore) {
constructor(appOrAgent: Application) {
import type { ILifecycleBoot, EggApplicationCore } from 'egg';
import { Watcher } from './watcher.ts';
export class Boot implements ILifecycleBoot {
#app: EggApplicationCore;
#watcher: Watcher;
constructor(appOrAgent: EggApplicationCore) {

@codecov
Copy link

codecov bot commented Sep 28, 2025

Codecov Report

❌ Patch coverage is 90.90909% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 80.61%. Comparing base (b8cf606) to head (02a2c12).
⚠️ Report is 2 commits behind head on next.

Files with missing lines Patch % Lines
plugins/watcher/src/lib/watcher.ts 75.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             next    #5569      +/-   ##
==========================================
- Coverage   81.23%   80.61%   -0.62%     
==========================================
  Files         209      200       -9     
  Lines        5984     5850     -134     
  Branches      874      858      -16     
==========================================
- Hits         4861     4716     -145     
- Misses       1050     1059       +9     
- Partials       73       75       +2     

☔ 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.

Copy link
Contributor

@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: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b8cf606 and 61f598f.

📒 Files selected for processing (11)
  • packages/egg/src/lib/application.ts (0 hunks)
  • packages/egg/src/lib/core/base_context_class.ts (2 hunks)
  • packages/egg/src/lib/core/context_httpclient.ts (1 hunks)
  • packages/egg/src/lib/egg.ts (0 hunks)
  • packages/egg/src/lib/types.ts (2 hunks)
  • packages/egg/test/index.test-d.ts (3 hunks)
  • packages/egg/test/lib/core/loader/load_plugin.test.ts (16 hunks)
  • plugins/schedule/src/lib/load_schedule.ts (2 hunks)
  • plugins/tracer/src/boot.ts (1 hunks)
  • plugins/watcher/src/lib/boot.ts (1 hunks)
  • plugins/watcher/src/types.ts (1 hunks)
💤 Files with no reviewable changes (2)
  • packages/egg/src/lib/egg.ts
  • packages/egg/src/lib/application.ts
🧰 Additional context used
📓 Path-based instructions (8)
packages/**/src/**/*.{ts,tsx}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Use TypeScript for all source files in packages (no JavaScript source files)

Files:

  • packages/egg/src/lib/core/base_context_class.ts
  • packages/egg/src/lib/types.ts
  • packages/egg/src/lib/core/context_httpclient.ts
packages/egg/src/lib/core/**

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Implement core components (httpclient, logger, messenger) under packages/egg/src/lib/core/

Files:

  • packages/egg/src/lib/core/base_context_class.ts
  • packages/egg/src/lib/core/context_httpclient.ts
**/*.ts

📄 CodeRabbit inference engine (AGENTS.md)

**/*.ts: Prefer TypeScript and ESM: write sources and exports in .ts (ESM-first) rather than CommonJS
Use two-space indentation, trailing commas, and semicolons (Prettier/oxlint defaults)
Name files in lowercase with hyphens (e.g., loader-context.ts)
Name classes in PascalCase
Name functions and variables in camelCase
Re-export types thoughtfully to keep the public API stable

Files:

  • packages/egg/src/lib/core/base_context_class.ts
  • packages/egg/src/lib/types.ts
  • plugins/watcher/src/lib/boot.ts
  • plugins/schedule/src/lib/load_schedule.ts
  • plugins/tracer/src/boot.ts
  • packages/egg/src/lib/core/context_httpclient.ts
  • packages/egg/test/lib/core/loader/load_plugin.test.ts
  • plugins/watcher/src/types.ts
  • packages/egg/test/index.test-d.ts
plugins/**

📄 CodeRabbit inference engine (CLAUDE.md)

All Egg framework plugins must be located under the plugins/ directory and follow the standard plugin structure (src, test, package.json, tsdown.config.ts)

Files:

  • plugins/watcher/src/lib/boot.ts
  • plugins/schedule/src/lib/load_schedule.ts
  • plugins/tracer/src/boot.ts
  • plugins/watcher/src/types.ts
packages/**/test/**/*.test.ts

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

packages/**/test/**/*.test.ts: Name test files as test/**/*.test.ts and run them with Vitest
Use import { describe, it } from 'vitest' in tests
Use Node.js built-in assert module for test assertions

Files:

  • packages/egg/test/lib/core/loader/load_plugin.test.ts
**/test/**/*.test.ts

📄 CodeRabbit inference engine (AGENTS.md)

**/test/**/*.test.ts: Place test suites following Vitest discovery: /test//*.test.ts
Mirror the repository test pattern when adding new suites

Files:

  • packages/egg/test/lib/core/loader/load_plugin.test.ts
{packages,plugins,tools}/**/test/**/*.test.ts

📄 CodeRabbit inference engine (CLAUDE.md)

Test files should follow the naming pattern test/**/*.test.ts

Files:

  • packages/egg/test/lib/core/loader/load_plugin.test.ts
plugins/*/src/types.ts

📄 CodeRabbit inference engine (CLAUDE.md)

All plugins MUST define src/types.ts and use module augmentation to extend the 'egg' module

Files:

  • plugins/watcher/src/types.ts
🧠 Learnings (5)
📓 Common learnings
Learnt from: CR
PR: eggjs/egg#0
File: CLAUDE.md:0-0
Timestamp: 2025-09-28T08:01:03.941Z
Learning: Applies to plugins/*/src/types.ts : All plugins MUST define src/types.ts and use module augmentation to extend the 'egg' module
📚 Learning: 2025-09-28T08:01:03.941Z
Learnt from: CR
PR: eggjs/egg#0
File: CLAUDE.md:0-0
Timestamp: 2025-09-28T08:01:03.941Z
Learning: Applies to plugins/*/src/types.ts : All plugins MUST define src/types.ts and use module augmentation to extend the 'egg' module

Applied to files:

  • plugins/schedule/src/lib/load_schedule.ts
  • packages/egg/test/index.test-d.ts
📚 Learning: 2025-09-28T08:01:03.941Z
Learnt from: CR
PR: eggjs/egg#0
File: CLAUDE.md:0-0
Timestamp: 2025-09-28T08:01:03.941Z
Learning: Applies to {tools/egg-bin,packages/cookies}/test/**/*.test.ts : Only egg-bin and cookies use Mocha for tests

Applied to files:

  • packages/egg/test/lib/core/loader/load_plugin.test.ts
  • packages/egg/test/index.test-d.ts
📚 Learning: 2025-09-28T08:01:03.941Z
Learnt from: CR
PR: eggjs/egg#0
File: CLAUDE.md:0-0
Timestamp: 2025-09-28T08:01:03.941Z
Learning: Applies to {packages,plugins}/**/vitest.config.ts : All new packages MUST use Vitest and include a vitest.config.ts (except packages/cookies and tools/egg-bin which use Mocha)

Applied to files:

  • packages/egg/test/index.test-d.ts
📚 Learning: 2025-09-28T08:01:03.941Z
Learnt from: CR
PR: eggjs/egg#0
File: CLAUDE.md:0-0
Timestamp: 2025-09-28T08:01:03.941Z
Learning: Applies to plugins/*/package.json : Plugin package.json must expose TypeScript sources for dev and compiled JS for publish via exports and publishConfig.exports (., ./types, ./agent, ./app)

Applied to files:

  • packages/egg/test/index.test-d.ts
🧬 Code graph analysis (8)
packages/egg/src/lib/core/base_context_class.ts (2)
packages/egg/src/lib/application.ts (1)
  • Application (43-299)
packages/egg/src/index.ts (1)
  • Application (46-46)
packages/egg/src/lib/types.ts (2)
packages/egg/src/lib/application.ts (2)
  • socket (74-100)
  • Application (43-299)
packages/egg/src/lib/core/base_hook_class.ts (1)
  • app (23-26)
plugins/watcher/src/lib/boot.ts (2)
packages/egg/src/lib/application.ts (1)
  • Application (43-299)
plugins/watcher/src/lib/watcher.ts (1)
  • Watcher (26-137)
plugins/schedule/src/lib/load_schedule.ts (1)
packages/egg/src/lib/egg.ts (1)
  • Context (66-66)
plugins/tracer/src/boot.ts (1)
packages/egg/src/lib/application.ts (1)
  • Application (43-299)
packages/egg/src/lib/core/context_httpclient.ts (2)
packages/core/src/egg.ts (1)
  • Context (56-90)
packages/egg/src/lib/application.ts (1)
  • Application (43-299)
plugins/watcher/src/types.ts (2)
packages/egg/src/lib/application.ts (1)
  • Application (43-299)
plugins/watcher/src/lib/watcher.ts (1)
  • Watcher (26-137)
packages/egg/test/index.test-d.ts (1)
packages/egg/src/lib/application.ts (1)
  • Application (43-299)
⏰ 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). (19)
  • GitHub Check: Test (windows-latest, 24, tools)
  • GitHub Check: Test (windows-latest, 24, packages)
  • GitHub Check: Test (ubuntu-latest, 24, packages)
  • GitHub Check: Test (macos-latest, 24, tools)
  • GitHub Check: Test (windows-latest, 22, plugins)
  • GitHub Check: Test (windows-latest, 22, packages)
  • GitHub Check: Test (windows-latest, 22, tools)
  • GitHub Check: Test (macos-latest, 24, packages)
  • GitHub Check: Test (windows-latest, 24, plugins)
  • GitHub Check: Test (ubuntu-latest, 22, packages)
  • GitHub Check: Test (macos-latest, 22, plugins)
  • GitHub Check: Test (ubuntu-latest, 24, plugins)
  • GitHub Check: Test (ubuntu-latest, 22, plugins)
  • GitHub Check: Test egg-bin (windows-latest, 24)
  • GitHub Check: Test egg-bin (macos-latest, 22)
  • GitHub Check: Test egg-bin (ubuntu-latest, 24)
  • GitHub Check: Test egg-bin (ubuntu-latest, 22)
  • GitHub Check: Test egg-bin (windows-latest, 22)
  • GitHub Check: Test egg-bin (macos-latest, 24)
🔇 Additional comments (5)
plugins/schedule/src/lib/load_schedule.ts (1)

33-37: Context factory signature matches runtime usage.

Confirmed the schedule class factory still receives the concrete HTTP context emitted by the application, so annotating ctx as Context remains faithful to the runtime contract.

plugins/watcher/src/types.ts (1)

5-11: Watcher property now typed on the public Application surface.

The augmentation tracks the actual boot-time assignment, so consumers get proper type coverage for both app.watcher and agent.watcher.

packages/egg/src/lib/core/base_context_class.ts (1)

3-17: app field narrowed to Application.

This aligns the base context helpers with the concrete application subclass that’s actually injected at runtime; no behavioral change.

packages/egg/src/lib/core/context_httpclient.ts (1)

1-12: ContextHttpClient now bound to Application.

ctx.app always resolves to the worker Application, so tightening the type keeps the helper accurate without altering behavior.

plugins/tracer/src/boot.ts (1)

3-12: Tracer boot hook typed against Application.

The tracer boot instance only ever runs inside workers, so targeting the concrete Application class is the right level of specificity.

Copy link
Contributor

@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: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 61f598f and 65a8526.

📒 Files selected for processing (2)
  • plugins/mock/src/lib/app.ts (1 hunks)
  • plugins/watcher/src/lib/boot.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.ts

📄 CodeRabbit inference engine (AGENTS.md)

**/*.ts: Prefer TypeScript and ESM: write sources and exports in .ts (ESM-first) rather than CommonJS
Use two-space indentation, trailing commas, and semicolons (Prettier/oxlint defaults)
Name files in lowercase with hyphens (e.g., loader-context.ts)
Name classes in PascalCase
Name functions and variables in camelCase
Re-export types thoughtfully to keep the public API stable

Files:

  • plugins/watcher/src/lib/boot.ts
  • plugins/mock/src/lib/app.ts
plugins/**

📄 CodeRabbit inference engine (CLAUDE.md)

All Egg framework plugins must be located under the plugins/ directory and follow the standard plugin structure (src, test, package.json, tsdown.config.ts)

Files:

  • plugins/watcher/src/lib/boot.ts
  • plugins/mock/src/lib/app.ts
🧬 Code graph analysis (1)
plugins/watcher/src/lib/boot.ts (1)
plugins/watcher/src/lib/watcher.ts (1)
  • Watcher (26-137)
⏰ 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). (19)
  • GitHub Check: Test (ubuntu-latest, 24, packages)
  • GitHub Check: Test (ubuntu-latest, 24, tools)
  • GitHub Check: Test (macos-latest, 22, packages)
  • GitHub Check: Test (macos-latest, 24, plugins)
  • GitHub Check: Test (windows-latest, 22, plugins)
  • GitHub Check: Test (macos-latest, 22, plugins)
  • GitHub Check: Test (ubuntu-latest, 24, plugins)
  • GitHub Check: Test (ubuntu-latest, 22, packages)
  • GitHub Check: Test (windows-latest, 24, plugins)
  • GitHub Check: Test (windows-latest, 22, packages)
  • GitHub Check: Test egg-bin (windows-latest, 22)
  • GitHub Check: Test egg-bin (windows-latest, 24)
  • GitHub Check: Test egg-bin (ubuntu-latest, 24)
  • GitHub Check: Test egg-bin (ubuntu-latest, 22)
  • GitHub Check: Test egg-bin (macos-latest, 24)
  • GitHub Check: Test egg-bin (macos-latest, 22)
  • GitHub Check: typecheck
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: Cloudflare Pages: egg-v3
🔇 Additional comments (2)
plugins/watcher/src/lib/boot.ts (2)

10-14: Reverting to EggApplicationCore keeps agent compatibility.

Thanks for wiring the cluster wrapper while retaining the shared EggApplicationCore type—this keeps the agent boot path building cleanly yet still exposes the delegated watcher API on both sides.


18-18: didLoad now waits on the delegated watcher instance.

Pointing ready() at this.#app.watcher keeps the lifecycle intact after removing the private field—no functional gaps spotted.

Copy link
Contributor

@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: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 65a8526 and b1a7df1.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (6)
  • packages/egg/test/lib/core/loader/load_boot.test.ts (2 hunks)
  • plugins/watcher/src/lib/boot.ts (1 hunks)
  • plugins/watcher/src/lib/watcher.ts (3 hunks)
  • plugins/watcher/test/fixtures/apps/watcher-type-default/app.js (1 hunks)
  • plugins/watcher/test/watcher.test.ts (2 hunks)
  • pnpm-workspace.yaml (2 hunks)
✅ Files skipped from review due to trivial changes (1)
  • plugins/watcher/test/watcher.test.ts
🧰 Additional context used
📓 Path-based instructions (7)
**/*.ts

📄 CodeRabbit inference engine (AGENTS.md)

**/*.ts: Prefer TypeScript and ESM: write sources and exports in .ts (ESM-first) rather than CommonJS
Use two-space indentation, trailing commas, and semicolons (Prettier/oxlint defaults)
Name files in lowercase with hyphens (e.g., loader-context.ts)
Name classes in PascalCase
Name functions and variables in camelCase
Re-export types thoughtfully to keep the public API stable

Files:

  • plugins/watcher/src/lib/boot.ts
  • packages/egg/test/lib/core/loader/load_boot.test.ts
  • plugins/watcher/src/lib/watcher.ts
plugins/**

📄 CodeRabbit inference engine (CLAUDE.md)

All Egg framework plugins must be located under the plugins/ directory and follow the standard plugin structure (src, test, package.json, tsdown.config.ts)

Files:

  • plugins/watcher/src/lib/boot.ts
  • plugins/watcher/src/lib/watcher.ts
  • plugins/watcher/test/fixtures/apps/watcher-type-default/app.js
packages/**/test/**/*.test.ts

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

packages/**/test/**/*.test.ts: Name test files as test/**/*.test.ts and run them with Vitest
Use import { describe, it } from 'vitest' in tests
Use Node.js built-in assert module for test assertions

Files:

  • packages/egg/test/lib/core/loader/load_boot.test.ts
**/test/**/*.test.ts

📄 CodeRabbit inference engine (AGENTS.md)

**/test/**/*.test.ts: Place test suites following Vitest discovery: /test//*.test.ts
Mirror the repository test pattern when adding new suites

Files:

  • packages/egg/test/lib/core/loader/load_boot.test.ts
{packages,plugins,tools}/**/test/**/*.test.ts

📄 CodeRabbit inference engine (CLAUDE.md)

Test files should follow the naming pattern test/**/*.test.ts

Files:

  • packages/egg/test/lib/core/loader/load_boot.test.ts
**/test/fixtures/**

📄 CodeRabbit inference engine (AGENTS.md)

Put reusable test data under test/fixtures/

Files:

  • plugins/watcher/test/fixtures/apps/watcher-type-default/app.js
pnpm-workspace.yaml

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Define dependency versions via the catalog section in pnpm-workspace.yaml and reference them with "catalog:"

Files:

  • pnpm-workspace.yaml
🧠 Learnings (2)
📚 Learning: 2025-09-14T08:41:30.618Z
Learnt from: CR
PR: eggjs/egg#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-09-14T08:41:30.618Z
Learning: Applies to pnpm-workspace.yaml : Define dependency versions via the catalog section in pnpm-workspace.yaml and reference them with "catalog:"

Applied to files:

  • pnpm-workspace.yaml
📚 Learning: 2025-09-28T08:01:03.941Z
Learnt from: CR
PR: eggjs/egg#0
File: CLAUDE.md:0-0
Timestamp: 2025-09-28T08:01:03.941Z
Learning: Applies to {package.json,packages/**/package.json,plugins/**/package.json,tools/**/package.json} : Use pnpm catalog mode: external dependencies referenced as "catalog:" and internal workspace deps as "workspace:*"

Applied to files:

  • pnpm-workspace.yaml
🧬 Code graph analysis (2)
plugins/watcher/src/lib/boot.ts (1)
plugins/watcher/src/lib/watcher.ts (1)
  • Watcher (26-140)
packages/egg/test/lib/core/loader/load_boot.test.ts (1)
packages/egg/test/utils.ts (1)
  • MockApplication (24-24)
⏰ 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). (18)
  • GitHub Check: Socket Security: Pull Request Alerts
  • GitHub Check: Test (windows-latest, 24, plugins)
  • GitHub Check: Test (windows-latest, 24, tools)
  • GitHub Check: Test (ubuntu-latest, 24, plugins)
  • GitHub Check: Test (macos-latest, 22, packages)
  • GitHub Check: Test (ubuntu-latest, 22, packages)
  • GitHub Check: Test (ubuntu-latest, 22, plugins)
  • GitHub Check: Test (windows-latest, 24, packages)
  • GitHub Check: Test (ubuntu-latest, 24, packages)
  • GitHub Check: Test (windows-latest, 22, plugins)
  • GitHub Check: Test (windows-latest, 22, packages)
  • GitHub Check: Test (macos-latest, 24, plugins)
  • GitHub Check: Test egg-bin (windows-latest, 22)
  • GitHub Check: Test egg-bin (ubuntu-latest, 24)
  • GitHub Check: Test egg-bin (windows-latest, 24)
  • GitHub Check: Test egg-bin (ubuntu-latest, 22)
  • GitHub Check: typecheck
  • GitHub Check: Cloudflare Pages: egg-v3
🔇 Additional comments (11)
pnpm-workspace.yaml (1)

132-149: Dependency bumps clear the release-age guardrail.

lint-staged 16.2.3 landed on 2025‑09‑28 (~3 days ago) and oxlint 1.19.0 shipped on 2025‑09‑29 (~2 days ago), so both upgrades respect the 24‑hour minimumReleaseAge requirement while keeping the catalog in sync. Good to go.

(newreleases.io)

plugins/watcher/test/fixtures/apps/watcher-type-default/app.js (1)

2-5: LGTM! Correct timing for watcher initialization.

Deferring app.watcher.watch() to inside app.ready() ensures the watcher has completed its async _init() before watch paths are registered. This aligns with the dual initialization paths introduced in boot.ts, where the Watcher instance (whether direct or cluster-wrapped) must be ready before accepting watch calls.

plugins/watcher/src/lib/watcher.ts (3)

12-12: LGTM! Debug namespace aligned with project convention.

The namespace change from egg-watcher/lib/watcher to egg/watcher/lib/watcher aligns with the broader Egg project structure.


39-43: LGTM! Helpful initialization logging.

The debug logs trace watcherType initialization and gracefully handle the undefined case, improving observability for the dual initialization paths introduced in boot.ts.


70-70: LGTM! Watch operation tracing.

Logging the path being watched aids debugging of watcher registration across both all-in-one-process and cluster modes.

plugins/watcher/src/lib/boot.ts (4)

1-8: LGTM! Debug logging for initialization paths.

The debug namespace and logs help trace which initialization mode is selected, complementing the dual-path refactor.


25-29: LGTM! Event forwarding preserved.

The coreLogger event bindings correctly work with both the direct Watcher instance and cluster-wrapped instance, as both expose the same event interface.


31-34: LGTM! Readiness check uses app.watcher.

The change from this.#watcher.ready() to this.#app.watcher.ready() correctly references the watcher instance now attached to the app, working for both initialization modes.


14-24: Verify all-in-one-process watcher initialization
No direct evidence of Boot instantiation in app.ts/agent.ts, no tests covering mode === 'all-in-one-process', and no obvious listen() usage in Watcher. Please manually confirm:

  • Whether the FIXME on singleton Watcher vs. port binding is critical or can be postponed
  • That Boot isn’t instantiated twice (once in app and once in agent)
  • That Watcher in all-in-one-process mode does not bind network ports unexpectedly
packages/egg/test/lib/core/loader/load_boot.test.ts (2)

13-16: LGTM! Cleaner async/await pattern.

Converting beforeAll to async functions with explicit await improves readability compared to returning promises. This is a good refactor.

Also applies to: 51-54


7-7: Verify .ts import resolution

Run the specific test file to ensure the import from ../../../utils.ts resolves correctly and no import errors occur:

npm test -- packages/egg/test/lib/core/loader/load_boot.test.ts

Once confirmed, remove this comment.

});

it('should load app.js', async () => {
await scheduler.wait(100);
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion | 🟠 Major

🧩 Analysis chain

Investigate why the delay is necessary instead of relying on arbitrary timing.

Adding a 100ms delay before app.close() suggests a race condition where app.ready() resolves before all boot lifecycle events have fully completed. This approach has several concerns:

  • The delay is arbitrary and may be insufficient on slower systems or in CI environments
  • It doesn't address the root cause of why app.ready() doesn't guarantee readiness
  • Time-based delays make tests brittle and slower

Consider:

  1. Adding a comment explaining what specific asynchronous operation needs to complete
  2. Waiting for a specific event or condition instead of a fixed delay
  3. Investigating whether the boot lifecycle should ensure all operations complete before ready() resolves

Run the following script to check if there are any pending async operations after app.ready():

Also applies to: 57-57


🏁 Script executed:

#!/bin/bash
# Description: Search for setTimeout, setImmediate, or process.nextTick in boot-related code
# that might explain why additional delay is needed

rg -n -C3 'setTimeout|setImmediate|process\.nextTick' --type ts -g '**/boot*.ts' -g '**/loader*.ts'

# Look for the boot app fixtures to understand their lifecycle
fd -t f "app.ts|app.js" -p "boot-app"

Length of output: 95


🏁 Script executed:

#!/bin/bash
# Locate scheduler implementation files
fd -t f scheduler*.ts

# Display the first 200 lines of each scheduler definition
for f in $(fd -t f scheduler*.ts); do
  echo "==> $f <=="
  sed -n '1,200p' "$f"
done

# Show usage of scheduler in the load_boot test file
rg -n "scheduler" -C3 packages/egg/test/lib/core/loader/load_boot.test.ts

Length of output: 6726


🏁 Script executed:

#!/bin/bash
# Locate all utils.ts files
fd -t f utils.ts

# Display contents to find createApp and MockApplication definitions
for f in $(fd -t f utils.ts); do
  echo "==> $f <=="
  sed -n '1,200p' "$f"
done

Length of output: 26197


Replace fixed delay with app.ready()

  • Remove await scheduler.wait(100) and instead await app.ready() to deterministically wait for the boot lifecycle to complete.
  • Eliminate the now-unused scheduler import.
🤖 Prompt for AI Agents
In packages/egg/test/lib/core/loader/load_boot.test.ts around line 19, replace
the nondeterministic await scheduler.wait(100) with await app.ready() so the
test waits deterministically for the application's boot lifecycle to complete,
and remove the now-unused scheduler import from the top of the file; ensure any
references to scheduler are deleted so there are no unused variables or imports
left.

@socket-security
Copy link

Warning

Review the following alerts detected in dependencies.

According to your organization's Security Policy, it is recommended to resolve "Warn" alerts. Learn more about Socket for GitHub.

Action Severity Alert  (click "▶" to expand/collapse)
Warn High
[email protected] has Obfuscated code.

Confidence: 0.96

Location: Package overview

From: pnpm-lock.yamlnpm/[email protected]

ℹ Read more on: This package | This alert | What is obfuscated code?

Next steps: Take a moment to review the security alert above. Review the linked package source code to understand the potential risk. Ensure the package is not malicious before proceeding. If you're unsure how to proceed, reach out to your security team or ask the Socket team for help at [email protected].

Suggestion: Packages should not obfuscate their code. Consider not using packages with obfuscated code.

Mark the package as acceptable risk. To ignore this alert only in this pull request, reply with the comment @SocketSecurity ignore npm/[email protected]. You can also ignore all packages with @SocketSecurity ignore-all. To ignore an alert for all future pull requests, use Socket's Dashboard to change the triage state of this alert.

Warn High
[email protected] has Obfuscated code.

Confidence: 0.96

Location: Package overview

From: pnpm-lock.yamlnpm/[email protected]

ℹ Read more on: This package | This alert | What is obfuscated code?

Next steps: Take a moment to review the security alert above. Review the linked package source code to understand the potential risk. Ensure the package is not malicious before proceeding. If you're unsure how to proceed, reach out to your security team or ask the Socket team for help at [email protected].

Suggestion: Packages should not obfuscate their code. Consider not using packages with obfuscated code.

Mark the package as acceptable risk. To ignore this alert only in this pull request, reply with the comment @SocketSecurity ignore npm/[email protected]. You can also ignore all packages with @SocketSecurity ignore-all. To ignore an alert for all future pull requests, use Socket's Dashboard to change the triage state of this alert.

View full report

@fengmk2 fengmk2 merged commit deedf32 into next Oct 1, 2025
18 of 32 checks passed
@fengmk2 fengmk2 deleted the refactor-EggApplicationCore branch October 1, 2025 12:13
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