Skip to content

refactor(enum): introduce EngineEventType enum. chore: clean compiledShaders. build: chmod compat for windows.#3034

Merged
cptbtptpbcptdtptp merged 8 commits into
galacean:dev/2.0from
luo2430:dev/2.0
Jun 15, 2026
Merged

refactor(enum): introduce EngineEventType enum. chore: clean compiledShaders. build: chmod compat for windows.#3034
cptbtptpbcptdtptp merged 8 commits into
galacean:dev/2.0from
luo2430:dev/2.0

Conversation

@luo2430

@luo2430 luo2430 commented Jun 14, 2026

Copy link
Copy Markdown

Please check if the PR fulfills these requirements

  • The commit message follows our guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)

  • Add EngineEventType enum for better type safety
  • Add autoResizeCanvas method to WebGLEngine with ResizeObserver support
  • Update HOW_TO_CONTRIBUTE.md to use pnpm commands and Node.js 15+
  • Remove compiled shader files from version control (now gitignored)
  • Add shx dev dependency for cross-platform chmod support(否则在windows端build时会因ERR_PNPM_RECURSIVE_RUN_FIRST_FAIL  @galacean/engine-shader-compiler@2.0.0-alpha.34 build: rollup -c rollup.config.js && chmod +x bundler/cli.js而失败。shx chmod在windows端不会有任何操作,仅用作兼容)

What is the current behavior? (You can also link to an open issue here)

赞!

What is the new behavior (if this is a feature change)?

很赞!!

Does this PR introduce a breaking change? (What changes might users need to make in their application due to this PR?)

没有

Other information:

感谢开源,愿尽微薄之力。

Summary by CodeRabbit

  • Refactor

    • Improved engine event handling with type-safe identifiers.
    • Optimized shader build process and test infrastructure configuration.
    • Reorganized shader paths and test fixture references.
  • Chores

    • Updated testing framework dependencies to version 3.2.6 for improved performance and stability.
    • Updated build tooling for better compatibility.

@coderabbitai

coderabbitai Bot commented Jun 14, 2026

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 53b81600-c2b8-49c4-accc-8e4e7515565e

📥 Commits

Reviewing files that changed from the base of the PR and between 8af7c50 and e712794.

📒 Files selected for processing (4)
  • tests/src/shader-compiler/Precompile.test.ts
  • tests/src/shader-compiler/PrecompileABTest.test.ts
  • tests/src/shader-compiler/PrecompileBenchmark.test.ts
  • tests/src/shader-compiler/ShaderCompiler.test.ts

Walkthrough

Introduces a typed EngineEventType enum replacing string literals for engine lifecycle dispatch calls (run, shutdown, devicelost, devicerestored) and re-exports it from the core package. Upgrades Vitest dependencies from 2.1.3 to 3.2.6, replaces vitest.workspace.ts with a root vitest.config.ts, updates Playwright browser config shape, normalizes test fixture paths in shader-compiler tests, and removes compiled shader artifacts from version control.

Changes

Engine Event Typing

Layer / File(s) Summary
EngineEventType enum definition and public export
packages/core/src/EngineEventType.ts, packages/core/src/index.ts
New EngineEventType enum with four string-valued members (Run, Shutdown, DeviceLost, DeviceRestored) is created and re-exported from the core package barrel.
Engine dispatch refactored to use EngineEventType
packages/core/src/Engine.ts
Engine.ts imports EngineEventType, removes the unused ShaderProgram import, and replaces all four string-literal dispatch calls with enum values at the run, shutdown, devicelost, and devicerestored sites.

Vitest Upgrade and Test Infrastructure Migration

Layer / File(s) Summary
Vitest dependency upgrades and root config consolidation
package.json, tests/package.json, vitest.config.ts, vitest.workspace.ts, tests/vitest.config.ts
vitest, @vitest/coverage-v8, and @vitest/browser are bumped from 2.1.3 to 3.2.6; vitest.workspace.ts is removed and replaced by a root vitest.config.ts with test.projects; tests/vitest.config.ts is refactored from providerOptions.launch.args to an instances-based Playwright browser configuration.
Shader compiler test fixture path migration
tests/src/shader-compiler/ShaderCompiler.test.ts, tests/src/shader-compiler/Precompile.test.ts, tests/src/shader-compiler/PrecompileABTest.test.ts, tests/src/shader-compiler/PrecompileBenchmark.test.ts
All four shader-compiler test files update readFile fixture paths from relative ./shaders/... to src/shader-compiler/shaders/... and src/shader-compiler/expected/...; ShaderCompiler.test.ts additionally switches from @vitest/browser/context server.commands.readFile to a local readFile helper.

Shader Artifact Removal and Build Script Fix

Layer / File(s) Summary
Compiled shaders excluded from VCS and build script cross-platform fix
packages/shader/.gitignore, packages/shader/compiledShaders/Pipeline/DepthOnly.shaderc, packages/shader-compiler/package.json
compiledShaders/ is added to .gitignore to stop tracking compiled shader assets; Pipeline/DepthOnly.shaderc is removed; the shader-compiler build script replaces chmod +x with a Node fs.chmodSync call for cross-platform compatibility.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Suggested labels

enhancement, shader

Suggested reviewers

  • zhuxudong
  • cptbtptpbcptdtptp

Poem

🐇 Hoppity hop, no more string "run"!
An enum now governs the engine's begun.
Old shader blobs? Gitignored away!
Test paths are tidy, all pointing astray—
To src/shader-compiler/shaders/ they say.
Vitest leaps forward to 3.2.6 with glee,
This bunny approves — as clean as can be! ✨

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title addresses three distinct changes: EngineEventType enum introduction, compiled shaders cleanup, and Windows chmod compatibility. However, it is overly terse with multiple concerns compressed using backticks and colons, making it difficult to identify the primary change at a glance. Simplify the title to highlight the primary change (likely the EngineEventType enum refactor) and either move secondary changes to the PR description or use separate, clearer phrasing that doesn't rely on cryptic abbreviations.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
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.

✏️ 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.

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

🤖 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 `@packages/rhi-webgl/src/WebGLEngine.ts`:
- Around line 35-40: The JSDoc comment for the method (starting at line 35)
incorrectly states that the method returns a cleanup function, but the actual
method returns void. Update the `@returns` documentation line in the JSDoc comment
to accurately reflect the void return type, removing the reference to a cleanup
function and instead describing that the method sets up automatic canvas
resizing with window resize event listeners.
- Around line 41-49: The autoResizeCanvas method creates a new ResizeObserver
each time it is called without checking if one already exists, causing multiple
observers to stack and remain active until shutdown. Additionally, the canvas
only updates its size after the first observer callback fires, leaving it with
stale dimensions initially. To fix this, store the observer as an instance
variable and disconnect any existing observer before creating a new one to
prevent stacking. Then call this.canvas.resizeByClientSize(pixelRatio)
immediately at the start of the method before setting up the observer to apply
an initial resize synchronously. This makes autoResizeCanvas idempotent and
ensures the canvas is properly sized from the moment the method is called.

In `@packages/shader/.gitignore`:
- Line 1: The .gitignore entry uses an absolute path
packages/shader/compiledShaders/ when it should use a relative path. Since the
.gitignore file is located at packages/shader/.gitignore, paths should be
relative to that location. Change the entry from
packages/shader/compiledShaders/ to simply compiledShaders/ so that git
correctly ignores the compiled shaders directory.
🪄 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: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 9cb4aca4-3359-42ad-80fe-c2d78c500a64

📥 Commits

Reviewing files that changed from the base of the PR and between de75496 and 0b72c30.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (31)
  • .github/HOW_TO_CONTRIBUTE.md
  • packages/core/src/Engine.ts
  • packages/core/src/EngineEventType.ts
  • packages/core/src/index.ts
  • packages/rhi-webgl/src/WebGLEngine.ts
  • packages/shader-compiler/package.json
  • packages/shader/.gitignore
  • packages/shader/compiledShaders/2D/Sprite.shaderc
  • packages/shader/compiledShaders/2D/SpriteMask.shaderc
  • packages/shader/compiledShaders/2D/Text.shaderc
  • packages/shader/compiledShaders/2D/UIDefault.shaderc
  • packages/shader/compiledShaders/BlinnPhong.shaderc
  • packages/shader/compiledShaders/Blit/Blit.shaderc
  • packages/shader/compiledShaders/Blit/BlitScreen.shaderc
  • packages/shader/compiledShaders/Effect/Particle.shaderc
  • packages/shader/compiledShaders/Effect/ParticleFeedback.shaderc
  • packages/shader/compiledShaders/Effect/Trail.shaderc
  • packages/shader/compiledShaders/Lighting/ScalableAmbientOcclusion.shaderc
  • packages/shader/compiledShaders/PBR.shaderc
  • packages/shader/compiledShaders/Pipeline/DepthOnly.shaderc
  • packages/shader/compiledShaders/Pipeline/ShadowCaster.shaderc
  • packages/shader/compiledShaders/PostProcess/Bloom.shaderc
  • packages/shader/compiledShaders/PostProcess/FinalAntiAliasing.shaderc
  • packages/shader/compiledShaders/PostProcess/FinalSRGB.shaderc
  • packages/shader/compiledShaders/PostProcess/Uber.shaderc
  • packages/shader/compiledShaders/Sky/BackgroundTexture.shaderc
  • packages/shader/compiledShaders/Sky/SkyProcedural.shaderc
  • packages/shader/compiledShaders/Sky/Skybox.shaderc
  • packages/shader/compiledShaders/Unlit.shaderc
  • packages/shader/compiledShaders/index.ts
  • packages/shader/tsconfig.json
💤 Files with no reviewable changes (23)
  • packages/shader/compiledShaders/BlinnPhong.shaderc
  • packages/shader/compiledShaders/Effect/Particle.shaderc
  • packages/shader/compiledShaders/Effect/ParticleFeedback.shaderc
  • packages/shader/compiledShaders/2D/Sprite.shaderc
  • packages/shader/compiledShaders/Pipeline/DepthOnly.shaderc
  • packages/shader/compiledShaders/Sky/Skybox.shaderc
  • packages/shader/compiledShaders/PostProcess/FinalSRGB.shaderc
  • packages/shader/compiledShaders/Effect/Trail.shaderc
  • packages/shader/compiledShaders/Pipeline/ShadowCaster.shaderc
  • packages/shader/compiledShaders/PostProcess/Bloom.shaderc
  • packages/shader/compiledShaders/Unlit.shaderc
  • packages/shader/compiledShaders/Blit/Blit.shaderc
  • packages/shader/compiledShaders/Sky/BackgroundTexture.shaderc
  • packages/shader/compiledShaders/PBR.shaderc
  • packages/shader/compiledShaders/2D/SpriteMask.shaderc
  • packages/shader/compiledShaders/PostProcess/Uber.shaderc
  • packages/shader/compiledShaders/2D/Text.shaderc
  • packages/shader/compiledShaders/Lighting/ScalableAmbientOcclusion.shaderc
  • packages/shader/compiledShaders/Blit/BlitScreen.shaderc
  • packages/shader/compiledShaders/index.ts
  • packages/shader/compiledShaders/Sky/SkyProcedural.shaderc
  • packages/shader/compiledShaders/PostProcess/FinalAntiAliasing.shaderc
  • packages/shader/compiledShaders/2D/UIDefault.shaderc

Comment thread packages/rhi-webgl/src/WebGLEngine.ts Outdated
Comment thread packages/rhi-webgl/src/WebGLEngine.ts Outdated
Comment on lines +41 to +49
autoResizeCanvas(pixelRatio: number = window.devicePixelRatio): void {
let observer: ResizeObserver | undefined = new ResizeObserver(() => {
this.canvas.resizeByClientSize(pixelRatio);
});
observer.observe(this.canvas._webCanvas);
this.on(EngineEventType.shutdown, () => {
observer?.disconnect();
observer = undefined;
});

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Make autoResizeCanvas idempotent and apply an initial resize immediately.

Repeated calls currently stack observers until shutdown, and size is only updated after the first observer callback. That can cause duplicate resize work and stale canvas sizing.

💡 Proposed fix
 export class WebGLEngine extends Engine {
+  private _resizeObserver?: ResizeObserver;
+
   /**
    * Automatically resize the canvas to fit the client size,
    * and keep listening to window resize events.
    * `@param` pixelRatio - The pixel ratio used for resizing, defaults to `window.devicePixelRatio`
    * `@returns` A cleanup function to remove the resize listener
    */
   autoResizeCanvas(pixelRatio: number = window.devicePixelRatio): void {
-    let observer: ResizeObserver | undefined = new ResizeObserver(() => {
+    this._resizeObserver?.disconnect();
+    this.canvas.resizeByClientSize(pixelRatio);
+
+    const observer = new ResizeObserver(() => {
       this.canvas.resizeByClientSize(pixelRatio);
     });
+    this._resizeObserver = observer;
     observer.observe(this.canvas._webCanvas);
-    this.on(EngineEventType.shutdown, () => {
-      observer?.disconnect();
-      observer = undefined;
+
+    this.once(EngineEventType.shutdown, () => {
+      if (this._resizeObserver === observer) {
+        this._resizeObserver.disconnect();
+        this._resizeObserver = undefined;
+      } else {
+        observer.disconnect();
+      }
     });
   }
 }
🤖 Prompt for 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.

In `@packages/rhi-webgl/src/WebGLEngine.ts` around lines 41 - 49, The
autoResizeCanvas method creates a new ResizeObserver each time it is called
without checking if one already exists, causing multiple observers to stack and
remain active until shutdown. Additionally, the canvas only updates its size
after the first observer callback fires, leaving it with stale dimensions
initially. To fix this, store the observer as an instance variable and
disconnect any existing observer before creating a new one to prevent stacking.
Then call this.canvas.resizeByClientSize(pixelRatio) immediately at the start of
the method before setting up the observer to apply an initial resize
synchronously. This makes autoResizeCanvas idempotent and ensures the canvas is
properly sized from the moment the method is called.

Comment thread packages/shader/.gitignore Outdated
@luo2430 luo2430 marked this pull request as draft June 14, 2026 14:14
@luo2430 luo2430 marked this pull request as ready for review June 14, 2026 14:19
GuoLei1990

This comment was marked as outdated.

GuoLei1990

This comment was marked as outdated.

@luo2430

luo2430 commented Jun 15, 2026

Copy link
Copy Markdown
Author

@GuoLei1990 好的,autoResizeCanvas和EngineEventType已经重写完了,等会会重新整理git提交。目前我Windows端vitest插件对vitest@2.1.3版本会报错,可能要升级vitest及其套件的版本,4的破坏性变更太多,在考虑3的可能性。另外现在怎么加入galacean的交流群呢?主页上的三个二维码的群都进不去。

GuoLei1990

This comment was marked as outdated.

@luo2430 luo2430 marked this pull request as draft June 15, 2026 05:24
@luo2430

luo2430 commented Jun 15, 2026

Copy link
Copy Markdown
Author

@GuoLei1990

重新提交了几个commit,将不同操作分开了。目前autoResizeCanvas写了这些内容,有些问题想请教。

  private _resizeObserver?: ResizeObserver;

  autoResizeCanvas(): void {
    const webCanvas = this.canvas._webCanvas;

    // OffscreenCanvas (Worker environment) does not support ResizeObserver
    if (typeof OffscreenCanvas !== "undefined" && webCanvas instanceof OffscreenCanvas) {
      return;
    }

    // Disconnect previous observer to avoid duplicate observation
    this._resizeObserver?.disconnect();

    this._resizeObserver = new ResizeObserver(() => {
      this.canvas.resizeByClientSize();
    });

    // Start observing the canvas element for size changes.
    // Note: ResizeObserver.observe() triggers the callback immediately,
    // ensuring canvas is resized to the correct dimensions right away.
    this._resizeObserver.observe(webCanvas);

    this.on(EngineEventType.Shutdown, () => {
      this._resizeObserver?.disconnect();
      this._resizeObserver = undefined;
    });
  }

我注意到这个判断有多次重复调用,是否有必要提取成一个函数呢?

image

另外,可以确定windows端vscode的vitest插件不兼容vitest@2.1.3

插件激活时报错

Unable to deserialize cloned data due to invalid or unsupported version.

测试运行时报错

TypeError: Cannot read properties of undefined (reading 'config')
 ❯ kn.shouldLog ../../.vscode/extensions/vitest.explorer-1.50.6/dist/workerLegacy.js:12:9999
 ❯ kn.onUserConsoleLog ../../.vscode/extensions/vitest.explorer-1.50.6/dist/workerLegacy.js:12:9302
 ❯ Receiver.receiverOnMessage node_modules/.pnpm/ws@8.18.0/node_modules/ws/lib/websocket.js:1220:20
TypeError: Cannot read properties of undefined (reading 'configOverride')
 ❯ get collecting ../../.vscode/extensions/vitest.explorer-1.50.6/dist/workerLegacy.js:12:8096
 ❯ ../../.vscode/extensions/vitest.explorer-1.50.6/dist/workerLegacy.js:12:11578
 ❯ kn.onCollected ../../.vscode/extensions/vitest.explorer-1.50.6/dist/workerLegacy.js:12:11539

vitest以及相关套件升级到主版本3可以正常运行,测试结果会有4个不通过,需要与你们的测试结果核实。

@GuoLei1990 GuoLei1990 marked this pull request as ready for review June 15, 2026 09:42
GuoLei1990

This comment was marked as outdated.

@luo2430 luo2430 changed the title feat(core): add EngineEventType enum, WebGLEngine.autoResizeCanvas method and more refactor(enum): introduce EngineEventType enum. chore: clean compiledShaders. build: chmod compat for windows. Jun 15, 2026
@luo2430

luo2430 commented Jun 15, 2026

Copy link
Copy Markdown
Author

@GuoLei1990 标题已改,我工作太零散了,老是忘😂

@GuoLei1990 GuoLei1990 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

总结

HEAD 推进到 7fd5df1(merge dup dev/2.0,GLTF 那两文件是上游 #3027 带进来的、不在本 PR 3-dot 净 diff 内,已核对忽略)。本轮唯一新增的 PR 自有 commit 是 8af7c50c test: upgrade vitest to 3.2.6——这是作者在评论里提的 Windows vitest 插件不兼容 2.1.3 的后续处理,把整套 vitest 从 2.1.3 升到 3.2.6

逐条核对上轮问题,全部仍关闭autoResizeCanvas 仍移出、EngineEventType 已 PascalCase、shader 产物清理 + node -e chmod 已 LGTM),标题已按建议改为 refactor(enum) + chore + build,"and more" 已去掉。vitest 升级本身迁移正确、内部一致,无 P0/P1。

vitest 3.2.6 升级核对(本轮新增改动)— 均验证 OK

  • 配置迁移是官方 vitest 3 路径,1:1 等价vitest.workspace.tsdefineWorkspace([...]))→ vitest.config.tsdefineConfig({ test: { projects: [...] }})),glob ["packages/*", "tests"] 原样保留;browser config name: "chromium"instances: [{ browser: "chromium", launch: {...} }](vitest 3 browser API 变更)。launch args 完全照搬,无行为变化。
  • 版本对齐一致:lockfile 内 vitest / @vitest/{browser,coverage-v8,expect,mocker,runner,snapshot,spy,utils} 全部锁到 3.2.6,无 major skew——vitest 对 @vitest/* 同版本要求很硬,混版会运行时崩,这点过了。@vitest/coverage-v8vitest 同步升(3.2.6),--coverage 走 v8 默认无显式 config block,与升级前一致。
  • readShaderTestFile.ts 路径包装器正确且完整。vitest 3 的 server.commands.readFile 解析基准从「测试文件相对」变成「test 项目根(tests/)相对」,故需重写:./shaders/xsrc/shader-compiler/shaders/x(相对 tests/✓)、../../../packages/...../packages/...(相对 tests/ → 仓库根 packages/✓)。已 grep 全部 ~80 处 readFile(...) 调用点,路径只有这两种前缀(含 ./expected/...,走 ./ 分支,目录存在),全覆盖;fallback return readBrowserFile(path) 当前无调用但作安全网无害。四个测试文件都换了新 wrapper、无残留死 import。

备忘(提一次,不阻塞)

  • scope 又扩了一项:上轮 PR 已收窄成 refactor + chore + build 三件事,本轮 vitest 升级是第四个正交改动,而且是体量最大的一个(661 行 lockfile + browser/workspace config 迁移 + 测试 path 适配)。它跟枚举/shader 清理没有依赖关系,本质是作者本地 Windows dev 环境(VSCode vitest 插件不兼容 2.1.3)的工程化诉求。vitest major 升级影响全仓所有测试运行方式,回滚粒度、CI 验证面都和本 PR 主体不同——更适合单独成一个 build(deps): upgrade vitest to 3 PR,便于独立过 CI、独立回滚。当前 PR 名为 refactor(enum)...,vitest 升级既不在标题也不在三个前缀覆盖范围内。提一次即可,是否拆由你定。
  • CI 未实际跑:本 PR 的 CI 处于 action_required(外部贡献者待批准,0s 未执行),vitest 3 迁移的「跑得通」无法靠 CI 自证。作者评论里提到「升 3 后有 4 个测试不通过,需与你们结果核实」——这 4 个 fail 是否已随本轮 commit 解决、还是仍存在,需要 maintainer 批准 CI 跑一遍确认。迁移代码本身是对的,但「实际全绿」这一步只能等 CI 放行。

回答作者提问

  • OffscreenCanvas 判断抽不抽函数:那段在 autoResizeCanvas 里,不在本 PR diff 内WebGLEngine.ts 已随 autoResizeCanvas 一并移出),等它单独成 PR 时再讨论。简短答:typeof OffscreenCanvas !== "undefined" && x instanceof OffscreenCanvas 这个 guard 如果只在 autoResizeCanvas 一处用,没必要抽;若多处复用再抽成 _isOffscreenCanvas(canvas) 私有 helper 即可。
  • 入群问题:不在代码审查范围,建议 PR 里直接 @ 维护者或走官网/Discord。

代码侧无问题,LGTM。vitest 升级若不拆出,合并前请确保 CI 跑通且那 4 个 fail 已澄清。

@GuoLei1990 GuoLei1990 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

总结

HEAD 推进到 e712794,自上轮 review(7fd5df1)后唯一新增的 PR 自有 commit 是 e71279475 test: use explicit shader fixture paths。这一 commit 删除了上轮我验证并称赞过的 readShaderTestFile.ts 路径包装器(-17 行 + 全部 import),改为在每个 test 文件顶部 const { readFile } = server.commands 直接解构,并把所有调用点的路径换成 vitest 3 项目根(tests/)下的显式真实路径。

逐条核对上轮已关闭问题,全部仍关闭(枚举已 PascalCase、shader 产物清理 + node -e chmod、vitest 3.2.6 迁移、标题已收敛为 refactor(enum) + chore + build),本轮新改动验证正确、机械等价、无新问题,无 P0/P1。

本轮新增改动核对(e71279475)— 均验证 OK

  • 路径转换与被删包装器一一等价。被删的 wrapper 做两件映射:./<x>src/shader-compiler/<x>../../../packages/../packages/。新 commit 把这两套映射的结果直接写到调用点。grep 全部 shader-compiler 测试,现存 readFile 路径前缀只有三种,全部与 wrapper 输出对齐:
    • src/shader-compiler/shaders/...(原 ./shaders/...)✓
    • src/shader-compiler/expected/...(原 ./expected/...)✓
    • ../packages/shader/src/Shaders/...(原 ../../../packages/shader/src/Shaders/...)✓
  • 无残留与无遗漏:repo 内已无任何 readShaderTestFile 引用(4 个测试文件的 import 全删、文件本身删除);已无任何未转换的裸 ./ / ../../../ readFile 调用(去掉 wrapper 后这类路径会解析错,已确认零残留)。ShaderValidate.ts 不经 readFile,不受影响。
  • 改动面纯粹:本 commit 只动那 5 个文件,全是路径字符串替换,无新增逻辑、无新增注释,无行为变化。
  • 顺带确认:tests/vitest.config.tsname: "chromium"instances:[...])、tests/package.json@vitest/browser 2.1.3→3.2.6)等仍是上轮 8af7c50c vitest 升级的一部分,自上轮未变,无需重审。

方向评判:删 wrapper 是净简化,方向正确

上轮我把这个 wrapper 评为「正确且完整」,但退一步从第一性原理看:这个包装器存在的唯一理由是「让调用方写一个与真实解析路径不同的路径」(caller 写 ./shaders/x,wrapper 偷偷改写成 src/shader-compiler/shaders/x),本质是一处小的路径语义双源——读代码要打开 wrapper 才知道 ./shaders/x 究竟读的是哪个文件。删掉它、让调用点写 server.commands.readFile 实际会用的路径,所见即所读,无指间接、删 17 行 shim,更贴 vitest 3 server.commands.readFile(按 test 项目根解析)的官方语义。

代价仅是路径略冗长(src/shader-compiler/shaders/x vs ./shaders/x)且重复在 ~80 处——但 fixtures 目录不会移动,真要移动一次 find-replace 即可。这是教科书式的 DRY-vs-显式取舍,对测试套件而言显式更优。所以上轮的「wrapper 很好」我收回半步:删它不是回退,是把我自己当时漏判的双源消掉了,方向对。

备忘(沿用上轮,提一次不重复)

  • vitest 3 升级仍是本 PR 第四个正交改动,scope 偏宽,更适合独立成 build(deps) PR;本轮的测试 path 适配是其直接附属(vitest 3 改了 readFile 解析基准才需要),归在一起合理。是否拆由 maintainer 定。
  • CI 仍需 maintainer 放行实跑:vitest 3 迁移 + path 适配的「实际全绿」只能靠 CI 自证;作者此前提到升 3 后有 4 个 fail 待核实,本轮 path 适配是否已让其归零,需 CI 跑一遍确认。迁移与本轮 path 改动代码本身是对的。

代码侧无问题,LGTM。

@codecov

codecov Bot commented Jun 15, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 78.99%. Comparing base (2419929) to head (e712794).
⚠️ Report is 1 commits behind head on dev/2.0.

Additional details and impacted files
@@             Coverage Diff             @@
##           dev/2.0    #3034      +/-   ##
===========================================
+ Coverage    77.49%   78.99%   +1.49%     
===========================================
  Files          914      914              
  Lines       101746   101631     -115     
  Branches     10431    11139     +708     
===========================================
+ Hits         78853    80279    +1426     
+ Misses       22710    21165    -1545     
- Partials       183      187       +4     
Flag Coverage Δ
unittests 78.99% <100.00%> (+1.49%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

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

@cptbtptpbcptdtptp cptbtptpbcptdtptp removed their assignment Jun 15, 2026

@cptbtptpbcptdtptp cptbtptpbcptdtptp left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

+1

@cptbtptpbcptdtptp cptbtptpbcptdtptp merged commit efcca09 into galacean:dev/2.0 Jun 15, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants