Skip to content

[TASK-tsk_1262ca4e5f2985ddcc69afc9] feat: 修复中文文件名写入问题 + DRY重构#35

Merged
jsyqrt merged 1 commit intomainfrom
task/tsk_1262ca4e5f2985ddcc69afc9
Apr 24, 2026
Merged

[TASK-tsk_1262ca4e5f2985ddcc69afc9] feat: 修复中文文件名写入问题 + DRY重构#35
jsyqrt merged 1 commit intomainfrom
task/tsk_1262ca4e5f2985ddcc69afc9

Conversation

@jsyqrt
Copy link
Copy Markdown
Contributor

@jsyqrt jsyqrt commented Apr 24, 2026

问题

调研 Agent 文件写入工具对中文文件名的处理机制。

调研结论

  • file_write / file_edit — 单路径操作,路径仅解析一次,无问题
  • apply_patch — 验证阶段解析路径,应用阶段重新 resolve() 违反了 DRY 原则
  • Node.js fs 原生支持 UTF-8 路径(macOS/Linux),工具层无需额外编码处理
  • 中文文件名写入从未真正"不工作",但存在重复解析的冗余代码

改动

  1. packages/core/src/tools/patch.ts: DRY 重构 — 在验证阶段收集解析后的路径,在应用阶段复用
  2. packages/core/test/patch-tool.test.ts: 添加 8 个中文/日文/韩文文件名测试用例

验证

  • ✅ pnpm typecheck 通过
  • ✅ 全部 16 个 patch 测试通过(8 原始 + 8 新)

Closes TASK-tsk_1262ca4e5f2985ddcc69afc9

## 调研结论
- / — 单路径操作,路径仅解析一次,无问题
-  — 验证阶段解析路径,应用阶段重新  违反了 DRY 原则
- Node.js  原生支持 UTF-8 路径(macOS/Linux),工具层无需额外编码处理
- 中文文件名写入从未真正不工作,但存在重复解析的冗余代码

## 改动
1. packages/core/src/tools/patch.ts: DRY 重构 — 在验证阶段收集解析后的路径,在应用阶段复用
2. packages/core/test/patch-tool.test.ts: 添加 8 个中文/日文/韩文文件名测试用例

## 验证
- pnpm typecheck: ✅ 通过
- 全部 16 个 patch 测试通过(8 原始 + 8 新)
@jsyqrt
Copy link
Copy Markdown
Contributor Author

jsyqrt commented Apr 24, 2026

Reviewed by: Code Reviewer

Result: Approved

Review Summary

What was reviewed

  • Branch: task/tsk_1262ca4e5f2985ddcc69afc9main
  • Changed files: packages/core/src/tools/patch.ts + packages/core/test/patch-tool.test.ts

Code quality

  • DRY refactoring is correct: Validation pass collects resolvedPaths[], apply pass reuses them (no more duplicate resolve())
  • No functional change: Path resolution behavior is identical — only the code structure is improved
  • Unused import removed: resolve eliminated from node:path import

Test coverage

  • 8 new Unicode filename test cases (Chinese, Japanese, Korean, deep paths, mixed chars)
  • All 16 tests pass (8 original + 8 new)

Build verification

  • pnpm typecheck: ✅ Zero errors
  • npx vitest run packages/core/test/patch-tool.test.ts: ✅ 16/16 passed

Notes

  • This PR is clean and ready for Owner to merge
  • No security or regression concerns

Decision: Approved — waiting for Owner to merge into main.

@jsyqrt jsyqrt merged commit c3e213d into main Apr 24, 2026
1 check passed
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