-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
refactor: try to use Application first #5569
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
only feature use on both Agent and Application should use EggApplicationCore
|
Caution Review failedThe pull request is closed. Note Other AI code review bot(s) detectedCodeRabbit 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. WalkthroughRemoves 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
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()
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related issues
Possibly related PRs
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 inconclusive)
✅ Passed checks (2 passed)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
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. Comment |
Summary of ChangesHello @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 Highlights
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this 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
ApplicationandAgentinterfaces separately instead of the genericEggApplicationCore - 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 |
| watcher: Watcher; | ||
| } | ||
|
|
Copilot
AI
Sep 28, 2025
There was a problem hiding this comment.
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.
| watcher: Watcher; | |
| } | |
| } |
There was a problem hiding this 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.
plugins/watcher/src/lib/boot.ts
Outdated
| 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) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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".
| 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 Report❌ Patch coverage is
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. 🚀 New features to boost your workflow:
|
There was a problem hiding this 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
📒 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.tspackages/egg/src/lib/types.tspackages/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.tspackages/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.tspackages/egg/src/lib/types.tsplugins/watcher/src/lib/boot.tsplugins/schedule/src/lib/load_schedule.tsplugins/tracer/src/boot.tspackages/egg/src/lib/core/context_httpclient.tspackages/egg/test/lib/core/loader/load_plugin.test.tsplugins/watcher/src/types.tspackages/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.tsplugins/schedule/src/lib/load_schedule.tsplugins/tracer/src/boot.tsplugins/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.tspackages/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.tspackages/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
ctxasContextremains 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.watcherandagent.watcher.packages/egg/src/lib/core/base_context_class.ts (1)
3-17:appfield 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.appalways resolves to the workerApplication, 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
Applicationclass is the right level of specificity.
There was a problem hiding this 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
📒 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.tsplugins/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.tsplugins/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 toEggApplicationCorekeeps agent compatibility.Thanks for wiring the cluster wrapper while retaining the shared
EggApplicationCoretype—this keeps the agent boot path building cleanly yet still exposes the delegated watcher API on both sides.
18-18:didLoadnow waits on the delegated watcher instance.Pointing
ready()atthis.#app.watcherkeeps the lifecycle intact after removing the private field—no functional gaps spotted.
There was a problem hiding this 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
⛔ Files ignored due to path filters (1)
pnpm-lock.yamlis 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.tspackages/egg/test/lib/core/loader/load_boot.test.tsplugins/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.tsplugins/watcher/src/lib/watcher.tsplugins/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.
plugins/watcher/test/fixtures/apps/watcher-type-default/app.js (1)
2-5: LGTM! Correct timing for watcher initialization.Deferring
app.watcher.watch()to insideapp.ready()ensures the watcher has completed its async_init()before watch paths are registered. This aligns with the dual initialization paths introduced inboot.ts, where theWatcherinstance (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/watchertoegg/watcher/lib/watcheraligns 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()tothis.#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 coveringmode === 'all-in-one-process', and no obviouslisten()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
beforeAllto async functions with explicitawaitimproves readability compared to returning promises. This is a good refactor.Also applies to: 51-54
7-7: Verify.tsimport resolutionRun the specific test file to ensure the import from
../../../utils.tsresolves correctly and no import errors occur:npm test -- packages/egg/test/lib/core/loader/load_boot.test.tsOnce confirmed, remove this comment.
| }); | ||
|
|
||
| it('should load app.js', async () => { | ||
| await scheduler.wait(100); |
There was a problem hiding this comment.
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:
- Adding a comment explaining what specific asynchronous operation needs to complete
- Waiting for a specific event or condition instead of a fixed delay
- 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.tsLength 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"
doneLength of output: 26197
Replace fixed delay with app.ready()
- Remove
await scheduler.wait(100)and insteadawait app.ready()to deterministically wait for the boot lifecycle to complete. - Eliminate the now-unused
schedulerimport.
🤖 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.
|
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.
|
only feature use on both Agent and Application should use EggApplicationCore
Summary by CodeRabbit
New Features
Bug Fixes
Refactor
Tests
Chores