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

Function TestInjectDiffMap

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

Source from the content-addressed store, hash-verified

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