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

Function TestInjectDiffMap

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

Source from the content-addressed store, hash-verified

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