MCPcopy Create free account
hub / github.com/InferCore/InferCore / TestReplayExact_RAGSuccess

Function TestReplayExact_RAGSuccess

internal/replay/replay_test.go:152–218  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

150}
151
152func TestReplayExact_RAGSuccess(t *testing.T) {
153 dir := t.TempDir()
154 doc := filepath.Join(dir, "doc.txt")
155 if err := os.WriteFile(doc, []byte("replay rag chunk about InferCore routing.\n"), 0o644); err != nil {
156 t.Fatal(err)
157 }
158 cfg := replayTestConfig()
159 cfg.KnowledgeBases = []config.KnowledgeBaseConfig{
160 {Name: "kb1", Type: "file", Path: dir},
161 }
162 st := requests.NewMemoryStore()
163 req := types.AIRequest{
164 RequestType: types.RequestTypeRAG,
165 TenantID: "team-a",
166 TaskType: "chat",
167 Priority: "high",
168 Context: map[string]any{
169 "knowledge_base": "kb1",
170 "query": "routing",
171 },
172 Input: map[string]any{"text": "routing"},
173 Options: types.RequestOptions{Stream: false, MaxTokens: 64},
174 }
175 full, _ := json.Marshal(req)
176 snap := types.PolicySnapshot{
177 PrimaryBackend: "small-model",
178 PrimaryRouteReason: "test",
179 EstimatedCost: 1,
180 }
181 snapBytes, _ := json.Marshal(snap)
182 now := time.Now()
183 _ = st.CreateRequest(context.Background(), requests.RequestRow{
184 RequestID: "rid-exact-rag",
185 TraceID: "trace-rag",
186 TenantID: req.TenantID,
187 TaskType: req.TaskType,
188 Priority: req.Priority,
189 RequestType: types.RequestTypeRAG,
190 PipelineRef: types.DefaultPipelineRAG,
191 AIRequestJSON: full,
192 PolicySnapshot: snapBytes,
193 SelectedBackend: "small-model",
194 CreatedAt: now,
195 UpdatedAt: now,
196 })
197 ad := mock.New(cfg.Backends[0])
198 retAdapters := retrieval.FromConfig(cfg)
199 deps := NewDependenciesFromConfig(cfg, map[string]interfaces.BackendAdapter{
200 "small-model": ad,
201 }, retAdapters)
202 resp, err := Replay(context.Background(), cfg, st, "rid-exact-rag", ModeExact, deps)
203 if err != nil {
204 t.Fatalf("replay: %v", err)
205 }
206 if resp.Status != "success" {
207 t.Fatalf("status=%q", resp.Status)
208 }
209 if resp.RouteReason != "replay_exact" {

Callers

nothing calls this directly

Calls 7

NewMemoryStoreFunction · 0.92
NewFunction · 0.92
FromConfigFunction · 0.92
replayTestConfigFunction · 0.85
ReplayFunction · 0.85
CreateRequestMethod · 0.65

Tested by

no test coverage detected