fix: 修复剧变节点进度解析 (#2506) - #2510
Conversation
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthrough式舆防卫战改用单个数字字符解析剧变节点 OCR 进度,并据此更新最大节点索引和下一节点索引;同时补充测试仓分支准备及合并后分支清理的 PR 流程说明。 Changes剧变节点进度处理
PR 流程文档
Estimated code review effort: 3 (Moderate) | ~20 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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 |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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 `@src/zzz_od/application/shiyu_defense/shiyu_defense_app.py`:
- Around line 102-115: 在处理多个 OCR 数字的分支中,更新进度解析逻辑以校验 current 和 total 的合法性:要求
current 不大于 total,且 total 不小于 1;校验失败时不要写入
critical_max_node_idx,也不要判定完成,改为沿用现有的解析失败流程。保留合法进度的日志、配置更新和完成判定行为。
🪄 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: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: cd47bc1b-8d32-4c41-a965-2fba7f8bdb7f
📒 Files selected for processing (1)
src/zzz_od/application/shiyu_defense/shiyu_defense_app.py
| if len(digits) >= 2: | ||
| current = int(digits[0]) | ||
| total = int(digits[-1]) | ||
| log.info('剧变节点进度 %d/%d', current, total) | ||
| self.config.critical_max_node_idx = total | ||
| next_idx = current + 1 | ||
| if next_idx > total: | ||
| return self.round_success(ShiyuDefenseApp.STATUS_ALL_FINISHED) | ||
| elif len(digits) == 1: | ||
| # 只有一个数字,可能是 "5",说明已完成 | ||
| total = int(digits[0]) | ||
| log.info('剧变节点进度 已完成 %d', total) | ||
| self.config.critical_max_node_idx = total | ||
| return self.round_success(ShiyuDefenseApp.STATUS_ALL_FINISHED) |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
增加对 OCR 解析结果的基础合法性校验
提取首尾数字作为进度的方法在遇到极端的 OCR 误读(例如解析出 current > total)或未来游戏更新中节点数达到两位数(例如 "10/10" 会被拆分为 ['1', '0', '1', '0'],导致 current=1, total=0)时,会解析出错误的数值。这不仅会导致误判为全部完成,还会将错误的 total 值覆写到配置 critical_max_node_idx 中。
建议增加基础的数值合法性校验,若不合法则回退到解析失败的逻辑,以保护配置数据的完整性。
🛡️ 建议的修复
- if len(digits) >= 2:
- current = int(digits[0])
- total = int(digits[-1])
- log.info('剧变节点进度 %d/%d', current, total)
- self.config.critical_max_node_idx = total
- next_idx = current + 1
- if next_idx > total:
- return self.round_success(ShiyuDefenseApp.STATUS_ALL_FINISHED)
- elif len(digits) == 1:
- # 只有一个数字,可能是 "5",说明已完成
- total = int(digits[0])
- log.info('剧变节点进度 已完成 %d', total)
- self.config.critical_max_node_idx = total
- return self.round_success(ShiyuDefenseApp.STATUS_ALL_FINISHED)
+ if len(digits) >= 2:
+ current = int(digits[0])
+ total = int(digits[-1])
+ if current > total or total == 0:
+ log.info('OCR 进度解析结果异常 (current=%d, total=%d): %s', current, total, progress_text)
+ next_idx = 1
+ else:
+ log.info('剧变节点进度 %d/%d', current, total)
+ self.config.critical_max_node_idx = total
+ next_idx = current + 1
+ if next_idx > total:
+ return self.round_success(ShiyuDefenseApp.STATUS_ALL_FINISHED)
+ elif len(digits) == 1:
+ # 只有一个数字,可能是 "5",说明已完成
+ total = int(digits[0])
+ if total == 0:
+ log.info('OCR 进度解析结果异常 (total=0): %s', progress_text)
+ next_idx = 1
+ else:
+ log.info('剧变节点进度 已完成 %d', total)
+ self.config.critical_max_node_idx = total
+ return self.round_success(ShiyuDefenseApp.STATUS_ALL_FINISHED)📝 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.
| if len(digits) >= 2: | |
| current = int(digits[0]) | |
| total = int(digits[-1]) | |
| log.info('剧变节点进度 %d/%d', current, total) | |
| self.config.critical_max_node_idx = total | |
| next_idx = current + 1 | |
| if next_idx > total: | |
| return self.round_success(ShiyuDefenseApp.STATUS_ALL_FINISHED) | |
| elif len(digits) == 1: | |
| # 只有一个数字,可能是 "5",说明已完成 | |
| total = int(digits[0]) | |
| log.info('剧变节点进度 已完成 %d', total) | |
| self.config.critical_max_node_idx = total | |
| return self.round_success(ShiyuDefenseApp.STATUS_ALL_FINISHED) | |
| if len(digits) >= 2: | |
| current = int(digits[0]) | |
| total = int(digits[-1]) | |
| if current > total or total == 0: | |
| log.info('OCR 进度解析结果异常 (current=%d, total=%d): %s', current, total, progress_text) | |
| next_idx = 1 | |
| else: | |
| log.info('剧变节点进度 %d/%d', current, total) | |
| self.config.critical_max_node_idx = total | |
| next_idx = current + 1 | |
| if next_idx > total: | |
| return self.round_success(ShiyuDefenseApp.STATUS_ALL_FINISHED) | |
| elif len(digits) == 1: | |
| # 只有一个数字,可能是 "5",说明已完成 | |
| total = int(digits[0]) | |
| if total == 0: | |
| log.info('OCR 进度解析结果异常 (total=0): %s', progress_text) | |
| next_idx = 1 | |
| else: | |
| log.info('剧变节点进度 已完成 %d', total) | |
| self.config.critical_max_node_idx = total | |
| return self.round_success(ShiyuDefenseApp.STATUS_ALL_FINISHED) |
🧰 Tools
🪛 Ruff (0.15.21)
[warning] 111-111: Comment contains ambiguous , (FULLWIDTH COMMA). Did you mean , (COMMA)?
(RUF003)
[warning] 111-111: Comment contains ambiguous , (FULLWIDTH COMMA). Did you mean , (COMMA)?
(RUF003)
🤖 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 `@src/zzz_od/application/shiyu_defense/shiyu_defense_app.py` around lines 102 -
115, 在处理多个 OCR 数字的分支中,更新进度解析逻辑以校验 current 和 total 的合法性:要求 current 不大于 total,且
total 不小于 1;校验失败时不要写入
critical_max_node_idx,也不要判定完成,改为沿用现有的解析失败流程。保留合法进度的日志、配置更新和完成判定行为。
…e-node Co-Authored-By: Claude Code <noreply@anthropic.com> Co-Authored-By: glm-5.2 <noreply@bigmodel.cn>
…e-node Co-Authored-By: Claude Code <noreply@anthropic.com> Co-Authored-By: glm-5.2 <noreply@bigmodel.cn>
- pr-review + pr-finishing: PR 合并后提示删本地 + remote 分支(只提示,不主动) - pr-review: 审 PR 时无论有无配套测试仓 PR,都先本地建同名分支占位(防补测试忘记切分支 → 误 commit 测试仓 main,即 OneDragon-Anything#2348 的 4ca301d 教训) Co-Authored-By: Claude Code <noreply@anthropic.com>
* fix: 修复剧变节点进度解析 (#2506) * docs(skill): 补合并后删分支提示 + 测试仓分支占位方法论 - pr-review + pr-finishing: PR 合并后提示删本地 + remote 分支(只提示,不主动) - pr-review: 审 PR 时无论有无配套测试仓 PR,都先本地建同名分支占位(防补测试忘记切分支 → 误 commit 测试仓 main,即 #2348 的 4ca301d 教训) Co-Authored-By: Claude Code <noreply@anthropic.com> * docs(game): 式舆防卫战(选关)+ 快捷手册 建档 + 玩法 doc(对应 #2510 L4 建档) 战斗 app 首次建档(L4 导航触发):式舆防卫战选关主界面(前哨档案+节点01-05+剧变节点进度)+ 快捷手册(5 TAB 入口)+ 式舆防卫战玩法。截图归档测试仓 fix/issue-2506-defense-node 分支。 Co-Authored-By: Claude Code <noreply@anthropic.com> * docs(skill): onboard 方法论强化 + 防卫战 source_image 归档名(对应 #2510) - AGENTS.md 加「改/建 skill」节(触发 skill-guide + design.md + 写方法论,工具无关) - onboard skill:覆盖检查写方法论(去 mock_screen 等具体 API)+ source_image 归档后用 screens/<screen>/<state>.webp + 玩法 doc 触发 gameplay skill;design.md 同步 - convert_to_webp.py 加覆盖提醒 - 式舆防卫战 + 快捷手册 source_image 更新为归档 state 名完整路径 Co-Authored-By: Claude Code <noreply@anthropic.com> Co-Authored-By: glm-5.2 <noreply@bigmodel.cn> * docs(game): 画面 doc source_image 统一为测试仓相对路径(对应 #2510) 23 个旧 doc 的 source_image 从 .debug 临时名/英文 fixture 名/只 state 名统一为 screens/<screen>/<state>.webp(自描述可找);顺带修正 doc 名 ≠ 测试仓名(3D地图 map_3d_default→默认、仓库 storage_drive_disc_default→默认、战斗画面 _xxx.png→默认/精英、大世界 _xxx→普通 等)。待补的吼吼饼铺/委托助手不动。 Co-Authored-By: Claude Code <noreply@anthropic.com> Co-Authored-By: glm-5.2 <noreply@bigmodel.cn> * feat(backend): analyze_screen 返回 vision_hint 能力边界提示 Co-Authored-By: Claude Code <noreply@anthropic.com> Co-Authored-By: glm-5.2 <noreply@bigmodel.cn> * docs(skill): 处理 #2517 CodeRabbit review(周期/建模统一 + source_image 契约 + convert_to_webp 移 design + vision_hint docstring) Co-Authored-By: Claude Code <noreply@anthropic.com> Co-Authored-By: glm-5.2 <noreply@bigmodel.cn> * docs(review): screenshot_archive 加图流程补多子态标题 source_image 同步(#2517 CodeRabbit) Co-Authored-By: Claude Code <noreply@anthropic.com> Co-Authored-By: glm-5.2 <noreply@bigmodel.cn> --------- Co-authored-by: kawayiYokami <95584793+kawayiYokami@users.noreply.github.com> Co-authored-by: Claude Code <noreply@anthropic.com> Co-authored-by: glm-5.2 <noreply@bigmodel.cn>
修复内容
2/5连写为215时,按首尾数字解析为 2/5,不再误判全部完成。验证
uv run pytest zzz-od-test/test/zzz_od/application/shiyu_defense/test_choose_node_idx.pyuv run ruff check zzz-od-test/test/zzz_od/application/shiyu_defense/test_choose_node_idx.py关联测试 PR:OneDragon-Anything/zzz-od-test#18
Fixes #2506
Summary by CodeRabbit