runEditFiles issues a single POST /edit-files call against api and decodes the success body into FileEditResponse. It requires a 200 response; tests for error paths should decode the error shape directly.
(t *testing.T, api *agentfiles.API, req workspacesdk.FileEditRequest)
| 1774 | // response; tests for error paths should decode the error shape |
| 1775 | // directly. |
| 1776 | func runEditFiles(t *testing.T, api *agentfiles.API, req workspacesdk.FileEditRequest) workspacesdk.FileEditResponse { |
| 1777 | t.Helper() |
| 1778 | |
| 1779 | ctx := testutil.Context(t, testutil.WaitShort) |
| 1780 | |
| 1781 | buf := bytes.NewBuffer(nil) |
| 1782 | enc := json.NewEncoder(buf) |
| 1783 | enc.SetEscapeHTML(false) |
| 1784 | require.NoError(t, enc.Encode(req)) |
| 1785 | |
| 1786 | w := httptest.NewRecorder() |
| 1787 | r := httptest.NewRequestWithContext(ctx, http.MethodPost, "/edit-files", buf) |
| 1788 | api.Routes().ServeHTTP(w, r) |
| 1789 | require.Equal(t, http.StatusOK, w.Code, "body: %s", w.Body.String()) |
| 1790 | |
| 1791 | var resp workspacesdk.FileEditResponse |
| 1792 | require.NoError(t, json.NewDecoder(w.Body).Decode(&resp)) |
| 1793 | return resp |
| 1794 | } |
| 1795 | |
| 1796 | // TestFuzzyReplace_EndingAndWhitespace exercises the line-endings |
| 1797 | // and per-position whitespace behavior of the fuzzy matcher in |
no test coverage detected