(t *testing.T)
| 1262 | } |
| 1263 | |
| 1264 | func 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 | |
| 1302 | func TestReadFileLines(t *testing.T) { |
| 1303 | t.Parallel() |
nothing calls this directly
no test coverage detected