惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

人人都是产品经理
人人都是产品经理
有赞技术团队
有赞技术团队
WordPress大学
WordPress大学
月光博客
月光博客
T
Tailwind CSS Blog
阮一峰的网络日志
阮一峰的网络日志
小众软件
小众软件
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Last Week in AI
Last Week in AI
大猫的无限游戏
大猫的无限游戏
S
SegmentFault 最新的问题
罗磊的独立博客
Jina AI
Jina AI
酷 壳 – CoolShell
酷 壳 – CoolShell
宝玉的分享
宝玉的分享
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
博客园 - 三生石上(FineUI控件)
量子位
雷峰网
雷峰网
Apple Machine Learning Research
Apple Machine Learning Research
美团技术团队
博客园 - 聂微东
V
V2EX

Recent Commits to openclaw:main

test: merge chat side-result checks · openclaw/openclaw@ddd2c2a test: merge cron history checks · openclaw/openclaw@f7eb746 test: merge responsive navigation shell checks · openclaw/openclaw@c2e4b47 docs(changelog): add codex oauth fixes · openclaw/openclaw@628e6cd test: merge navigation routing cases · openclaw/openclaw@5d8cecb Tests: mock channel registry bundled fallback · openclaw/openclaw@2b08233 Secrets: avoid broad web search discovery for single plugin config · openclaw/openclaw@a464f59 test: merge config view browser checks · openclaw/openclaw@20cf511 fix(status): align oauth health with runtime · openclaw/openclaw@eed7116 feat: add macOS screen snapshots for monitor preview (#67954) thanks … · openclaw/openclaw@f377db1 fix: report shared auth scopes in hello-ok (#67810) thanks @BunsDev · openclaw/openclaw@0b6c39b Auto-reply: avoid eager bundled route fallback · openclaw/openclaw@3ea1bf4 Tests: narrow session binding contract setup · openclaw/openclaw@54e4e16 fix(macOS): enable undo/redo in webchat composer text input (#34962) · openclaw/openclaw@00951dc Tests: speed up channel setup promotion · openclaw/openclaw@82b529a Docs: refresh agent instructions · openclaw/openclaw@5775fe2 fix(auth): serialize OAuth refresh across agents to fix #26322 (#67876) · openclaw/openclaw@8e79080 test: allow ollama public surface boundary test · openclaw/openclaw@7d4f1a6 Docs: add test performance guardrails · openclaw/openclaw@89706d3 Tests: restore context-engine usage proof · openclaw/openclaw@e4c4f95 Tests: slim context engine runtime coverage · openclaw/openclaw@74c198f ci: retry failed custom checkouts · openclaw/openclaw@0ee5baf test: trim duplicate provider auth onboarding cases · openclaw/openclaw@1ffc02e matrix: fix sessions_spawn --thread subagent session spawning (#67643) · openclaw/openclaw@1ce2596 test: reduce auth choice fixture churn · openclaw/openclaw@857b9cd test: mock health status config boundaries · openclaw/openclaw@9d5ab4a test: mock onboard config io boundary · openclaw/openclaw@299694d test: mock legacy state plugin boundaries · openclaw/openclaw@2713089 test: mock channel install boundaries · openclaw/openclaw@b945248 test: mock doctor preview channel boundaries · openclaw/openclaw@b1a3ad4
fix(tools): treat no-op writes and edits as terminal tool...
zw-xysk · 2026-06-27 · via Recent Commits to openclaw:main

@@ -11,7 +11,7 @@ import {

1111

createRebindableDirectoryAlias,

1212

withRealpathSymlinkRebindRace,

1313

} from "../test-utils/symlink-rebind-race.js";

14-

import { applyPatch } from "./apply-patch.js";

14+

import { applyPatch, createApplyPatchTool } from "./apply-patch.js";

1515

import type { SandboxFsBridge } from "./sandbox/fs-bridge.js";

16161717

async function withTempDir<T>(fn: (dir: string) => Promise<T>) {

@@ -43,15 +43,16 @@ function createMemoryPatchSandbox(initialFiles: Record<string, string> = {}) {

4343

const files = new Map<string, string>(

4444

Object.entries(initialFiles).map(([filePath, contents]) => [`/sandbox/${filePath}`, contents]),

4545

);

46+

const writeFile = vi.fn(async ({ filePath, data }) => {

47+

files.set(filePath, Buffer.isBuffer(data) ? data.toString("utf8") : data);

48+

});

4649

const bridge: SandboxFsBridge = {

4750

resolvePath: ({ filePath }) => ({

4851

relativePath: filePath,

4952

containerPath: `/sandbox/${filePath}`,

5053

}),

5154

readFile: async ({ filePath }) => Buffer.from(files.get(filePath) ?? "", "utf8"),

52-

writeFile: async ({ filePath, data }) => {

53-

files.set(filePath, Buffer.isBuffer(data) ? data.toString("utf8") : data);

54-

},

55+

writeFile,

5556

remove: async ({ filePath }) => {

5657

files.delete(filePath);

5758

},

@@ -72,6 +73,8 @@ function createMemoryPatchSandbox(initialFiles: Record<string, string> = {}) {

7273

};

7374

return {

7475

files,

76+

bridge,

77+

writeFile,

7578

options: {

7679

cwd: "/local/workspace",

7780

sandbox: {

@@ -155,6 +158,85 @@ describe("applyPatch", () => {

155158

expect(result.summary.modified).toEqual(["source.txt"]);

156159

});

157160161+

it("returns a terminal no-op without rewriting unchanged update hunks", async () => {

162+

const memory = createMemoryPatchSandbox({

163+

"source.txt": "foo\nbar\n",

164+

});

165+

const patch = `*** Begin Patch

166+

*** Update File: source.txt

167+

@@

168+

foo

169+

-bar

170+

+bar

171+

*** End Patch`;

172+173+

const result = await applyPatch(patch, memory.options);

174+175+

expect(result.noOp).toBe(true);

176+

expect(result.text).toBe("No changes made to source.txt.");

177+

expect(result.summary).toEqual({ added: [], modified: [], deleted: [] });

178+

expect(memory.files.get("/sandbox/source.txt")).toBe("foo\nbar\n");

179+

expect(memory.writeFile.mock.calls).toHaveLength(0);

180+181+

const tool = createApplyPatchTool(memory.options);

182+

const toolResult = await tool.execute("call-no-op", { input: patch }, undefined);

183+

expect(toolResult.terminate).toBe(true);

184+

});

185+186+

it("preserves line endings and EOF state for no-op update hunks", async () => {

187+

const patch = `*** Begin Patch

188+

*** Update File: source.txt

189+

@@

190+

foo

191+

-bar

192+

+bar

193+

*** End Patch`;

194+

for (const initial of ["foo\r\nbar\r\n", "foo\nbar"]) {

195+

const memory = createMemoryPatchSandbox({ "source.txt": initial });

196+197+

const result = await applyPatch(patch, memory.options);

198+199+

expect(result.noOp).toBe(true);

200+

expect(memory.files.get("/sandbox/source.txt")).toBe(initial);

201+

expect(memory.writeFile.mock.calls).toHaveLength(0);

202+

}

203+

});

204+205+

it("applies a real deletion of the sole blank line", async () => {

206+

const memory = createMemoryPatchSandbox({ "source.txt": "\n" });

207+

const patch = `*** Begin Patch

208+

*** Update File: source.txt

209+

@@

210+

-

211+

*** End Patch`;

212+213+

const result = await applyPatch(patch, memory.options);

214+215+

expect(result.noOp).toBeUndefined();

216+

expect(memory.files.get("/sandbox/source.txt")).toBe("");

217+

expect(memory.writeFile.mock.calls).toHaveLength(1);

218+

});

219+220+

it("preserves formatting for same-path move no-op hunks", async () => {

221+

const patch = `*** Begin Patch

222+

*** Update File: source.txt

223+

*** Move to: ./source.txt

224+

@@

225+

foo

226+

-bar

227+

+bar

228+

*** End Patch`;

229+

for (const initial of ["foo\r\nbar\r\n", "foo\nbar"]) {

230+

const memory = createMemoryPatchSandbox({ "source.txt": initial });

231+232+

const result = await applyPatch(patch, memory.options);

233+234+

expect(result.noOp).toBe(true);

235+

expect(memory.files.get("/sandbox/source.txt")).toBe(initial);

236+

expect(memory.writeFile.mock.calls).toHaveLength(0);

237+

}

238+

});

239+158240

it("applies context-only insertions at the requested context", async () => {

159241

const memory = createMemoryPatchSandbox({

160242

"source.txt": "alpha\nanchor\nomega\n",