fix(cli): avoid duplicate ACP write BOM - #5688
Conversation
|
@qwen-code /triage |
|
Thanks for the PR! Template looks good ✓ On direction: This fixes a real bug — the ACP adapter was unconditionally prepending a BOM character even when the content already had one, producing double BOMs. That's a clear correctness issue in the ACP file write path, and aligning with the local file system service's existing BOM handling makes sense. Fixes #5687 as expected. On approach: Minimal and focused — 4 lines changed in source, 110 lines of well-scoped tests. No scope creep, no drive-by refactors. The fix pattern ( Moving on to code review. 🔍 中文说明感谢贡献! 模板完整 ✓ 方向:修复了一个真实 bug — ACP adapter 在内容已带 BOM 时仍无条件追加 BOM,导致双 BOM。这是 ACP 文件写入路径的正确性问题,与本地 file system service 的 BOM 处理保持一致是合理的。如预期修复了 #5687。 方案:最小且聚焦 — 源码改 4 行,测试 110 行,范围清晰。没有范围蔓延或顺手重构。修复模式( 进入代码审查 🔍 — Qwen Code · qwen3.7-max |
Code ReviewIndependent proposal: Given "ACP adapter prepends BOM even when content already has one" — I'd add a guard to check if PR's approach: Matches exactly. The condition Reuse check: No new utility needed — No blockers found. The fix is correct, the tests cover all four paths (plain write, BOM requested with existing BOM, BOM requested without existing BOM, fallback when capability disabled), and the broader ACP test suite (502 tests across 18 files) passes cleanly. Test ResultsBefore / After (tmux)N/A — this is a non-user-visible internal fix in the ACP protocol's file write adapter. The bug (double BOM prepending) only manifests when an ACP client receives a 中文说明代码审查独立方案: 已知"ACP adapter 在内容已带 BOM 时仍追加 BOM"——我会加一个 guard 检查 PR 方案: 完全一致。条件 复用检查: 无需新工具 — 无阻塞问题。 修复正确,测试覆盖四条路径(普通写入、请求 BOM 且已有 BOM、请求 BOM 且无 BOM、capability 关闭时的 fallback),完整 ACP 测试套件(18 个文件 502 个测试)全部通过。 测试结果Before / After(tmux)N/A — 这是 ACP 协议文件写入 adapter 的内部修复,不影响 CLI 输出或 TUI 行为。Bug(双 BOM 追加)仅在 ACP client 收到 — Qwen Code · qwen3.7-max |
ReflectionThis is a clean, minimal bug fix that does exactly what it says. The double-BOM bug in the ACP write adapter is real — the old code unconditionally prepended My independent proposal (before reading the diff) was identical: add The tests are thorough without being excessive: four new cases covering all four code paths through the method. The broader ACP suite (502 tests) is green. Formatting is clean. Every line in the diff serves the stated goal. No drive-by refactors, no speculative additions, no scope creep. If I had to maintain this in six months, I'd thank the author for the focused change and clear test coverage. Approving. ✅ 中文说明反思这是一个干净、最小化的 bug 修复,完全如其所述。ACP 写入 adapter 的双 BOM bug 确实存在 — 旧代码在 我在阅读 diff 之前的独立方案完全相同:在条件中加入 测试充分而不过度:四个新用例覆盖方法的所有四条代码路径。完整 ACP 测试套件(502 个测试)全部通过。格式规范。 diff 中每一行都服务于既定目标。没有顺手重构、没有投机性添加、没有范围蔓延。如果六个月后要维护这段代码,我会感谢作者的聚焦改动和清晰的测试覆盖。 批准 ✅ — Qwen Code · qwen3.7-max |
qwen-code-ci-bot
left a comment
There was a problem hiding this comment.
LGTM, looks ready to ship. ✅
✅ Local verification report (maintainer)Built and tested this PR locally to confirm the fix before merge. Environment
Results
Mutation test (the key evidence). To confirm the new tests actually guard the regression rather than passing vacuously, I reverted - content: "Hello" // expected: one BOM
+ content: "Hello" // buggy main: two BOMsThe other 7 tests stayed green (they don't exercise the double-BOM path). This proves the new test pins the exact bug described in #5687. Correctness. The guard Minor / non-blocking notes
Verdict: LGTM. The fix is minimal, correct, mutation-verified, and consistent with the core reference. Safe to merge from my side. 🇨🇳 中文版✅ 本地验证报告(维护者)合并前在本地构建并测试了本 PR 以确认修复。 环境
结果
变异测试(关键证据)。 为确认新增测试是真的能挡住回归、而不是空过,我把 - content: "Hello" // 期望:一个 BOM
+ content: "Hello" // main 的 bug:两个 BOM其余 7 个测试保持绿色(它们不会走到双 BOM 这条路径)。这证明新测试精确锁定了 #5687 描述的那个 bug。 正确性。 次要 / 非阻塞说明
结论:LGTM。 修复最小化、正确、经变异测试验证,且与 core 参考实现一致。从我这边看可以安全合并。 |
What this PR does
Updates
AcpFileSystemService.writeTextFile()so ACP file writes preserve a UTF-8 BOM without duplicating it when the content already starts with the BOM marker.Adds write-path tests for ACP forwarding, BOM insertion, existing BOM preservation, and fallback behavior when the ACP write capability is disabled.
Why it's needed
Before this change, the ACP adapter prepended
\uFEFFwhenever_meta.bomwas true. If the content already started with\uFEFF, the adapter forwarded two BOM characters to the ACP client.The local file system service already avoids this duplication when writing UTF-8 BOM files. This change keeps the ACP adapter consistent with that behavior.
Reviewer Test Plan
How to verify
Call
AcpFileSystemService.writeTextFile()with_meta: { bom: true }and content that already starts with\uFEFF. Confirm the forwarded ACPwriteTextFilerequest contains exactly one leading BOM marker.Call it with
_meta: { bom: true }and content without a BOM marker. Confirm the forwarded content gains one leading BOM marker.Disable the ACP
writeTextFilecapability and confirm the fallback file system receives the original params unchanged.Evidence (Before & After)
Before:
_meta.bom: trueplus content starting with\uFEFFproduced forwarded content starting with two BOM markers.After:
npm test --workspace=packages/cli -- acp-integration/service/filesystem.test.tspasses with 8 tests, including existing-BOM preservation and missing-BOM insertion coverage.After:
npm test --workspace=packages/cli -- acp-integration/service acp-integration/acpAgent.test.tspasses with 2 test files and 141 tests. The run emits existing EventEmitter max-listener warnings from the ACP agent test harness but all tests pass.After:
npm run lint --workspace=packages/cli --if-presentpasses.After:
npx prettier --experimental-cli --check packages/cli/src/acp-integration/service/filesystem.ts packages/cli/src/acp-integration/service/filesystem.test.tspasses.After:
git diff --checkpasses.Tested on
Environment (optional)
Local macOS workspace with the repository npm dependencies installed.
Risk & Scope
_meta.bomis true; fallback and non-BOM writes are unchanged.Linked Issues
Fixes #5687
AI Assistance Disclosure
I used Codex to review the changes, sanity-check the implementation against existing patterns, and help spot potential edge cases.
中文说明
What this PR does
更新
AcpFileSystemService.writeTextFile(),让 ACP 文件写入在保留 UTF-8 BOM 时,如果内容已经以 BOM marker 开头,不再重复添加 BOM。新增 write path 测试,覆盖 ACP 转发、BOM 插入、已有 BOM 保留,以及 ACP write capability 关闭时的 fallback 行为。
Why it's needed
在这个改动之前,只要
_meta.bom为 true,ACP adapter 就会 prepend\uFEFF。如果内容本身已经以\uFEFF开头,adapter 会向 ACP client 转发两个 BOM 字符。本地 file system service 写 UTF-8 BOM 文件时已经避免了这种重复。本改动让 ACP adapter 与本地行为保持一致。
Reviewer Test Plan
How to verify
用
_meta: { bom: true }且内容已经以\uFEFF开头调用AcpFileSystemService.writeTextFile()。确认转发给 ACPwriteTextFile的请求只包含一个 leading BOM marker。用
_meta: { bom: true }且内容不带 BOM marker 调用它。确认转发内容会增加一个 leading BOM marker。关闭 ACP
writeTextFilecapability,确认 fallback file system 收到的 params 保持原样。Evidence (Before & After)
Before:
_meta.bom: true加上以\uFEFF开头的内容,会产生以两个 BOM marker 开头的转发内容。After:
npm test --workspace=packages/cli -- acp-integration/service/filesystem.test.ts通过,8 个测试覆盖已有 BOM 保留和缺失 BOM 插入。After:
npm test --workspace=packages/cli -- acp-integration/service acp-integration/acpAgent.test.ts通过,2 个测试文件共 141 个测试。运行中会出现 ACP agent 测试 harness 里已有的 EventEmitter max-listener warning,但所有测试通过。After:
npm run lint --workspace=packages/cli --if-present通过。After:
npx prettier --experimental-cli --check packages/cli/src/acp-integration/service/filesystem.ts packages/cli/src/acp-integration/service/filesystem.test.ts通过。After:
git diff --check通过。Tested on
Environment (optional)
本地 macOS 工作区,已安装仓库 npm 依赖。
Risk & Scope
_meta.bom为 true 时调整 ACP write adapter 的 BOM normalization;fallback 和非 BOM 写入不变。Linked Issues
Fixes #5687
AI Assistance Disclosure
我使用 Codex 来审查改动、对照现有模式做 sanity check,并帮助发现潜在边界情况。