Skip to content

fix(2d): fix typo in SpriteAtlas.getSprites warning message#3032

Open
cptbtptpbcptdtptp wants to merge 4 commits into
dev/2.0from
fix/sprite-atlas-warning
Open

fix(2d): fix typo in SpriteAtlas.getSprites warning message#3032
cptbtptpbcptdtptp wants to merge 4 commits into
dev/2.0from
fix/sprite-atlas-warning

Conversation

@cptbtptpbcptdtptp

@cptbtptpbcptdtptp cptbtptpbcptdtptp commented Jun 13, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Fix typo in SpriteAtlas.getSprites warning: "not exit" → "no sprite named X in the atlas"
  • Aligns with the already-correct message in getSprite

Test plan

  • Trivial string change, no functional impact

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Improved the “sprite not found” warning to be more informative, including the requested sprite name and clearer mention of the atlas.
  • Tests
    • Added Vitest coverage for sprite lookup behavior in the atlas, validating successful single/multiple retrieval and expected console warnings when sprites are missing.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jun 13, 2026

Copy link
Copy Markdown

Review Change Stack

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: 82c439e1-069a-4a6d-a834-fb2191eff853

📥 Commits

Reviewing files that changed from the base of the PR and between f88214c and 256e3cf.

📒 Files selected for processing (1)
  • tests/src/core/SpriteAtlas.test.ts

Walkthrough

The SpriteAtlas.getSprites method's warning message for missing sprites is updated to dynamically include the requested sprite name and refer to "the atlas." A comprehensive test suite validates both sprite lookup methods and the updated warning behavior.

Changes

Sprite Lookup and Warning

Layer / File(s) Summary
Sprite not found warning message
packages/core/src/2d/atlas/SpriteAtlas.ts
The console warning emitted when no sprites match the requested name is updated to dynamically include the sprite name and reference "the atlas," improving diagnostic clarity.
SpriteAtlas test coverage
tests/src/core/SpriteAtlas.test.ts
New test suite using WebGLEngine with an in-memory canvas validates getSprite and getSprites behaviors, asserting correct return values and console.warn calls for existing and missing sprite names.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 A sprite once lost, now speaks its name,
With atlas warnings clear and plain,
Tests validate the sprite's refrain—
No more confusion in the game! ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: fixing a typo in the SpriteAtlas.getSprites warning message, which aligns with the primary modification shown in the raw summary.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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 docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/sprite-atlas-warning

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.

@codecov

codecov Bot commented Jun 13, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 79.17%. Comparing base (5d74c1d) to head (2ca4126).

Additional details and impacted files
@@           Coverage Diff            @@
##           dev/2.0    #3032   +/-   ##
========================================
  Coverage    79.17%   79.17%           
========================================
  Files          914      914           
  Lines       101666   101666           
  Branches     11209    11213    +4     
========================================
+ Hits         80489    80499   +10     
+ Misses       20990    20980   -10     
  Partials       187      187           
Flag Coverage Δ
unittests 79.17% <100.00%> (+<0.01%) ⬆️

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.

GuoLei1990

This comment was marked as outdated.

@GuoLei1990 GuoLei1990 marked this pull request as draft June 15, 2026 02:50
@cptbtptpbcptdtptp cptbtptpbcptdtptp marked this pull request as ready for review June 16, 2026 04:01
… messages

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

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

Inline comments:
In `@tests/src/core/SpriteAtlas.test.ts`:
- Around line 22-29: The warnSpy.mockRestore() call at the end of both test
cases (lines 22-29 and 53-62) only executes on the success path, so if any
assertion fails before reaching it, the spy cleanup is skipped and leaks into
later tests. Wrap the test logic in a try-finally block in both locations so
that warnSpy.mockRestore() is guaranteed to execute regardless of whether
assertions pass or fail. This ensures the spy is properly cleaned up even when
test assertions fail.
- Around line 5-8: The WebGLEngine instance created via WebGLEngine.create is
never destroyed, causing WebGL resource leaks. Add an afterEach hook in the
SpriteAtlas describe block that calls the appropriate destroy or dispose method
on the engine variable to ensure proper cleanup after each test runs and prevent
cross-test instability.
🪄 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: acfa9c8e-c2ee-4dc8-8e26-871003f43f50

📥 Commits

Reviewing files that changed from the base of the PR and between 23068e5 and f88214c.

📒 Files selected for processing (1)
  • tests/src/core/SpriteAtlas.test.ts

Comment on lines +5 to +8
describe("SpriteAtlas", async () => {
const canvas = document.createElement("canvas");
const engine = await WebGLEngine.create({ canvas: canvas });

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

Add engine teardown to prevent test resource leaks.

WebGLEngine is created once but never destroyed. This can leak WebGL resources and cause cross-test instability in browser runs. Add explicit teardown.

Suggested fix
-import { describe, expect, it, vi } from "vitest";
+import { afterAll, beforeAll, describe, expect, it, vi } from "vitest";

-describe("SpriteAtlas", async () => {
-  const canvas = document.createElement("canvas");
-  const engine = await WebGLEngine.create({ canvas: canvas });
+describe("SpriteAtlas", () => {
+  let engine: WebGLEngine;
+
+  beforeAll(async () => {
+    const canvas = document.createElement("canvas");
+    engine = await WebGLEngine.create({ canvas });
+  });
+
+  afterAll(() => {
+    engine.destroy();
+  });
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
describe("SpriteAtlas", async () => {
const canvas = document.createElement("canvas");
const engine = await WebGLEngine.create({ canvas: canvas });
import { afterAll, beforeAll, describe, expect, it, vi } from "vitest";
describe("SpriteAtlas", () => {
let engine: WebGLEngine;
beforeAll(async () => {
const canvas = document.createElement("canvas");
engine = await WebGLEngine.create({ canvas });
});
afterAll(() => {
engine.destroy();
});
🤖 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 `@tests/src/core/SpriteAtlas.test.ts` around lines 5 - 8, The WebGLEngine
instance created via WebGLEngine.create is never destroyed, causing WebGL
resource leaks. Add an afterEach hook in the SpriteAtlas describe block that
calls the appropriate destroy or dispose method on the engine variable to ensure
proper cleanup after each test runs and prevent cross-test instability.

Comment thread tests/src/core/SpriteAtlas.test.ts
Prevents console.warn spy from leaking into subsequent tests when
an assertion fails.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
GuoLei1990

This comment was marked as outdated.

@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 256e3cf 与上轮我 review 所基于的 commit 相同,但上轮 P3 是基于早于本 commit 的快照写的——本 commit("use afterEach to restore mocks",提交于上轮 review 前 1m43s)恰好已实现该修复。复核当前代码全部到位:

  • typo 修复完整闭环 —— getSprites 未命中分支(SpriteAtlas.ts:48)与 getSpriteSpriteAtlas.ts:27)现在文案完全一致:"There is no sprite named " + name + " in the atlas.",PR 主旨已达成。
  • 上轮 P3 已修复(闭环) —— 测试改用顶层 afterEach(() => vi.restoreAllMocks()),并移除了每个 it 末尾的手动 warnSpy.mockRestore()。断言中途抛错也不会再让 console.warn mock 泄漏到后续测试。这正是上轮我建议的改法,CodeRabbit 的 "spy cleanup on assertion failure" 也由同一 commit 一并解决(其 inline comment 已标 "✅ Addressed in commit 256e3cf")。
  • codecov 绿 —— "All modified and coverable lines are covered"。

已关闭项不再重复:

  • typo / 文案一致性 —— 已修复。
  • engine teardown(CodeRabbit 建议加 engine.destroy() —— 上轮判定不采纳(跟随 tests/src/core/ 主流惯例,26 个测试文件仅 3 个 teardown),结论不变。
  • describe 顶层 await WebGLEngine.create_addSprite 同步登记、multi-match 反向收集契约 —— 上轮均已核对正确。

问题

无。上轮唯一的 P3 已在本 commit 修复,无新增问题。

简化建议

测试干净,覆盖到位,mock 清理已收口到 afterEach。LGTM,可以合并。

@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 2ca4126 是一个 merge commit(把 origin/dev/2.0 合进本分支),是相对上轮 256e3cf 的唯一新变更。本 PR 实际改动的两个文件 —— packages/core/src/2d/atlas/SpriteAtlas.tstests/src/core/SpriteAtlas.test.ts —— git diff 256e3cf..2ca4126 对这两个文件结果为,即与上轮我 review 时字节完全一致。merge 带入的全部是 dev/2.0 的无关变更(shader compiledShaders 清理、particle/gltf 测试、shader-compiler 测试、lockfile),不属于本 PR 的 authored diff,不在本次审查范围。

复核 PR HEAD 上的修复仍在位:

  • typo 修复闭环不变 —— getSprites 未命中分支(SpriteAtlas.ts:48)与 getSpriteSpriteAtlas.ts:27)文案完全一致:"There is no sprite named " + name + " in the atlas."
  • 测试无变化 —— afterEach(() => vi.restoreAllMocks()) 的 mock 清理收口、4 个命中/未命中分支用例均与上轮一致,依旧正确。
  • 无新评论 / 无新作者回复 —— 最后一次活动是我上轮 06:26:42Z 的 review;CodeRabbit 两条 finding(engine teardown / spy cleanup)状态不变(前者上轮判定不采纳并跟随项目惯例,后者已在 256e3cf 修复并被 CodeRabbit 标注 ✅)。

已关闭项不再重复:typo / 文案一致性、codecov 误报、engine teardown 惯例判定、spy cleanup(P3 已修复)、_addSprite 同步登记与 multi-match 反向收集契约 —— 结论均不变。

问题

无。本轮唯一变更是 merge dev/2.0,未触碰本 PR 的 authored 改动,无新增问题。

简化建议

merge 后 PR 仍只是一处字符串文案修复 + 配套测试,干净、覆盖到位。LGTM,可以合并。

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.

2 participants