MCPcopy Create free account
hub / github.com/alibaba/open-code-review / TestInjectDiffMap

Function TestInjectDiffMap

internal/agent/coverage_test.go:112–146  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

110}
111
112func TestInjectDiffMap(t *testing.T) {
113 reg := tool.NewRegistry()
114 emptyDM := tool.NewDiffMap(nil)
115 frd := tool.NewFileReadDiff(emptyDM)
116 reg.Register(frd)
117
118 a := New(Args{
119 LLMClient: &fakeAgentClient{},
120 Tools: reg,
121 Template: template.Template{MaxTokens: 10000, MaxToolRequestTimes: 5, MainTask: template.LlmConversation{Messages: []template.ChatMessage{{Role: "user", Content: "t"}}}},
122 })
123 a.diffs = []model.Diff{
124 {NewPath: "main.go", OldPath: "main.go", Diff: "+new code"},
125 {NewPath: "/dev/null", OldPath: "deleted.go", Diff: "-deleted"},
126 }
127
128 a.injectDiffMap()
129
130 result, err := frd.Execute(context.Background(), map[string]any{
131 "path_array": []any{"main.go"},
132 })
133 if err != nil {
134 t.Fatal(err)
135 }
136 if !strings.Contains(result, "+new code") {
137 t.Errorf("DiffMap did not contain main.go diff, got: %q", result)
138 }
139
140 result2, _ := frd.Execute(context.Background(), map[string]any{
141 "path_array": []any{"deleted.go"},
142 })
143 if !strings.Contains(result2, "not found") {
144 t.Errorf("/dev/null path should not be in DiffMap, got: %q", result2)
145 }
146}
147
148func TestFilterDiffs(t *testing.T) {
149 a := New(Args{

Callers

nothing calls this directly

Calls 7

RegisterMethod · 0.95
NewRegistryFunction · 0.92
NewDiffMapFunction · 0.92
NewFileReadDiffFunction · 0.92
injectDiffMapMethod · 0.80
NewFunction · 0.70
ExecuteMethod · 0.65

Tested by

no test coverage detected