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

Function TestInjectDiffMap

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

Source from the content-addressed store, hash-verified

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