From 71ad32b1e95a1c1dfca8e6ca4a530b77afcc4974 Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Tue, 27 Jan 2026 08:57:52 +0100 Subject: pkg/aflow/flow/patching: harden against empty generated patches Make codeeditor error on nop changes that don't actually change the code. Make patch testing error on empty patch. Perhaps we need a notion of "mandatory" tools that must be called successfully at least once... not sure yet. --- pkg/aflow/tool/codeeditor/codeeditor.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'pkg/aflow/tool/codeeditor/codeeditor.go') diff --git a/pkg/aflow/tool/codeeditor/codeeditor.go b/pkg/aflow/tool/codeeditor/codeeditor.go index 750dba5d8..4ee3fe0d2 100644 --- a/pkg/aflow/tool/codeeditor/codeeditor.go +++ b/pkg/aflow/tool/codeeditor/codeeditor.go @@ -79,7 +79,11 @@ func codeeditor(ctx *aflow.Context, state state, args args) (struct{}, error) { return struct{}{}, aflow.BadCallError("CurrentCode snippet matched %v places,"+ " increase context in CurrentCode to avoid ambiguity", matches) } - err = osutil.WriteFile(file, slices.Concat(newLines...)) + newFileData := slices.Concat(newLines...) + if bytes.Equal(fileData, newFileData) { + return struct{}{}, aflow.BadCallError("The edit does not change the code.") + } + err = osutil.WriteFile(file, newFileData) return struct{}{}, err } @@ -97,7 +101,7 @@ func replace(lines, src, dst [][]byte, fuzzy bool) (newLines [][]byte, matches i si++ continue } - if len(l) == 0 { + if len(l) == 0 && li != i { li++ continue } -- cgit mrf-deployment