diff --git a/pkg/aflow/action/crash/test.go b/pkg/aflow/action/crash/test.go index 5c7d831b5ed2..9879c9bd90dc 100644 --- a/pkg/aflow/action/crash/test.go +++ b/pkg/aflow/action/crash/test.go @@ -47,6 +47,10 @@ func testPatch(ctx *aflow.Context, args testArgs) (testResult, error) { if err != nil { return res, err } + if diff == "" { + res.TestError = "No patch to test." + return res, nil + } res.PatchDiff = diff if err := kernel.BuildKernel(args.KernelScratchSrc, args.KernelScratchSrc, args.KernelConfig, false); err != nil { diff --git a/pkg/aflow/flow/patching/patching.go b/pkg/aflow/flow/patching/patching.go index ea5780022fd2..e092839e33c1 100644 --- a/pkg/aflow/flow/patching/patching.go +++ b/pkg/aflow/flow/patching/patching.go @@ -130,14 +130,17 @@ The explanation of the root cause of the bug is: {{.BugExplanation}} {{if .TestError}} -Another developer tried to fix this bug, and come up with the following patch: -{{.PatchDiff}} - -and the following explanation: +Another developer tried to fix this bug, and come up with the following strategy for fixing: {{.PatchExplanation}} +{{/* A TestError without PatchDiff means the previous invocation did not generate any patch. */}} +{{if .PatchDiff}} +and the following patch: + +{{.PatchDiff}} + However, the patch testing failed with the following error: {{.TestError}} @@ -149,6 +152,9 @@ then create a new patch from scratch. Note: in both cases the source tree does not contain the patch yet (so if you want to create a new fixed patch, you need to recreate it in its entirety from scratch using the codeeditor tool). +{{else}} +If the strategy looks reasonable to you, proceed with patch generation. +{{end}} {{end}} ` diff --git a/pkg/aflow/template.go b/pkg/aflow/template.go index 7dd213517e9c..cf8417bb9852 100644 --- a/pkg/aflow/template.go +++ b/pkg/aflow/template.go @@ -94,6 +94,7 @@ func walkTemplate(n parse.Node, used map[string]bool, errp *error) { used[n.Ident[0]] = true case *parse.VariableNode: case *parse.TextNode: + case *parse.IdentifierNode: default: noteError(errp, "unhandled node type %T", n) } diff --git a/pkg/aflow/template_test.go b/pkg/aflow/template_test.go index 3b24d62f6048..2de13a2c14bf 100644 --- a/pkg/aflow/template_test.go +++ b/pkg/aflow/template_test.go @@ -64,6 +64,14 @@ func TestTemplate(t *testing.T) { }, err: "input foo is not provided", }, + { + template: `{{if and .foo .bar}} yes {{end}}`, + vars: map[string]reflect.Type{ + "foo": reflect.TypeFor[bool](), + "bar": reflect.TypeFor[int](), + }, + used: []string{"foo", "bar"}, + }, } for i, test := range tests { t.Run(fmt.Sprint(i), func(t *testing.T) { diff --git a/pkg/aflow/tool/codeeditor/codeeditor.go b/pkg/aflow/tool/codeeditor/codeeditor.go index 750dba5d8dd2..4ee3fe0d27df 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 } diff --git a/pkg/aflow/tool/codeeditor/codeeditor_test.go b/pkg/aflow/tool/codeeditor/codeeditor_test.go index 06a97d7afe0f..0b066e3b5a68 100644 --- a/pkg/aflow/tool/codeeditor/codeeditor_test.go +++ b/pkg/aflow/tool/codeeditor/codeeditor_test.go @@ -105,6 +105,25 @@ foo`) ) } +func TestCodeeditorNopEdit(t *testing.T) { + dir := writeTestFile(t, "src.c", ` +line0 +line1 +`) + aflow.TestTool(t, Tool, + state{ + KernelScratchSrc: dir, + }, + args{ + SourceFile: "src.c", + CurrentCode: " line0", + NewCode: "line0", + }, + struct{}{}, + `The edit does not change the code.`, + ) +} + func TestCodeeditorReplacement(t *testing.T) { type Test struct { curFile string