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

Function TestHandleWriteFile_Failure_NoPathStoreUpdate

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

Source from the content-addressed store, hash-verified

1195}
1196
1197func TestHandleWriteFile_Failure_NoPathStoreUpdate(t *testing.T) {
1198 t.Parallel()
1199
1200 pathStore := agentgit.NewPathStore()
1201 logger := slogtest.Make(t, nil)
1202 fs := afero.NewMemMapFs()
1203 api := agentfiles.NewAPI(logger, fs, pathStore)
1204
1205 chatID := uuid.New()
1206
1207 // Write to a relative path (should fail with 400).
1208 body := strings.NewReader("hello world")
1209 req := httptest.NewRequest(http.MethodPost, "/write-file?path=relative/path.txt", body)
1210 req.Header.Set(workspacesdk.CoderChatIDHeader, chatID.String())
1211
1212 rr := httptest.NewRecorder()
1213 r := chi.NewRouter()
1214 r.Post("/write-file", api.HandleWriteFile)
1215 agentchat.Middleware(r).ServeHTTP(rr, req)
1216
1217 require.Equal(t, http.StatusBadRequest, rr.Code)
1218
1219 // PathStore should NOT be updated on failure.
1220 paths := pathStore.GetPaths(chatID)
1221 require.Empty(t, paths)
1222}
1223
1224func TestHandleEditFiles_ChatHeaders_UpdatesPathStore(t *testing.T) {
1225 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
StringMethod · 0.45
ServeHTTPMethod · 0.45
EqualMethod · 0.45
EmptyMethod · 0.45

Tested by

no test coverage detected