MCPcopy Index your code
hub / github.com/coder/coder / TestHandleEditFiles_Failure_NoPathStoreUpdate

Function TestHandleEditFiles_Failure_NoPathStoreUpdate

agent/agentfiles/files_test.go:1264–1300  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1262}
1263
1264func TestHandleEditFiles_Failure_NoPathStoreUpdate(t *testing.T) {
1265 t.Parallel()
1266
1267 pathStore := agentgit.NewPathStore()
1268 logger := slogtest.Make(t, nil)
1269 fs := afero.NewMemMapFs()
1270 api := agentfiles.NewAPI(logger, fs, pathStore)
1271
1272 chatID := uuid.New()
1273
1274 // Edit a non-existent file (should fail with 404).
1275 editReq := workspacesdk.FileEditRequest{
1276 Files: []workspacesdk.FileEdits{
1277 {
1278 Path: "/nonexistent/file.txt",
1279 Edits: []workspacesdk.FileEdit{
1280 {Search: "hello", Replace: "world"},
1281 },
1282 },
1283 },
1284 }
1285 body, _ := json.Marshal(editReq)
1286 req := httptest.NewRequest(http.MethodPost, "/edit-files", bytes.NewReader(body))
1287 req.Header.Set("Content-Type", "application/json")
1288 req.Header.Set(workspacesdk.CoderChatIDHeader, chatID.String())
1289
1290 rr := httptest.NewRecorder()
1291 r := chi.NewRouter()
1292 r.Post("/edit-files", api.HandleEditFiles)
1293 agentchat.Middleware(r).ServeHTTP(rr, req)
1294
1295 require.NotEqual(t, http.StatusOK, rr.Code)
1296
1297 // PathStore should NOT be updated on failure.
1298 paths := pathStore.GetPaths(chatID)
1299 require.Empty(t, paths)
1300}
1301
1302func TestReadFileLines(t *testing.T) {
1303 t.Parallel()

Callers

nothing calls this directly

Calls 10

GetPathsMethod · 0.95
NewPathStoreFunction · 0.92
NewAPIFunction · 0.92
MiddlewareFunction · 0.92
NewMethod · 0.65
SetMethod · 0.65
MarshalMethod · 0.45
StringMethod · 0.45
ServeHTTPMethod · 0.45
EmptyMethod · 0.45

Tested by

no test coverage detected