Skip to content

fix(core): guard world_lores as array when loading preset - #1028

Merged
dingyi222666 merged 1 commit into
v1-devfrom
fix/preset-load
Aug 28, 2026
Merged

dingyi222666 merged 1 commit into
v1-devfrom
fix/preset-load

Conversation

@dingyi222666

Copy link
Copy Markdown
Member

问题

在加载 preset 时,如果 YAML 中的 world_lores 字段不是数组(例如为 null 或空对象),调用 rawJson.world_lores.find(...) 会抛错,导致 preset 加载失败。

修复

在调用 find 前先检查 Array.isArray(rawJson.world_lores),非数组时跳过 world lore 解析。

变更

  • packages/core/src/llm-core/prompt/preset_prompt_parse.ts: 增加数组类型守卫

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@coderabbitai

coderabbitai Bot commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

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 Plus

Run ID: 19c057fe-0ae7-45d0-bc69-a92c9df1526b

📥 Commits

Reviewing files that changed from the base of the PR and between 69732ed and 0cfdc2f.

📒 Files selected for processing (1)
  • packages/core/src/llm-core/prompt/preset_prompt_parse.ts

Included review availability: Your plan provides up to 2 included reviews per hour; 1 remains after this review.


Walkthrough

loadYamlPreset 现在仅处理数组类型的 world_lores。对象或字符串等非数组真值会进入备用分支,并将 loreBooks 设为 undefined

Changes

预设提示词解析

Layer / File(s) Summary
world_lores 数组校验
packages/core/src/llm-core/prompt/preset_prompt_parse.ts
loadYamlPreset 在处理 world_lores 前增加 Array.isArray 校验,避免对非数组值调用 .find.filter

Estimated code review effort: 1 (Trivial) | ~5 minutes

Merge Risk: ⚪ Minimal · up to 0cfdc

The change prevents preset loading from failing when world_lores is not an array and otherwise preserves the existing parsing behavior; no actionable merge-blocking risk remains after normal checks and review.

Poem

小兔检查 world_lores
先确认数组再跳跃。
非数组值绕开陷阱,
loreBooks 安静归空,
解析路径更稳妥。

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 1 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed 标题准确概括了主要变更:在加载 preset 时确保 world_lores 为数组。标题简洁、具体,并与代码变更一致。
Description check ✅ Passed 描述明确说明了 world_lores 非数组时导致 preset 加载失败的问题,以及通过 Array.isArray 进行类型保护的修复。描述与变更内容相关。
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/preset-load

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.

@dingyi222666
dingyi222666 merged commit 2e12acf into v1-dev Aug 28, 2026
4 of 5 checks passed
@dingyi222666
dingyi222666 deleted the fix/preset-load branch August 28, 2026 16:55
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