| 299 | } |
| 300 | |
| 301 | func TestHandleAction_CallsRecordActivity(t *testing.T) { |
| 302 | t.Parallel() |
| 303 | |
| 304 | logger := slogtest.Make(t, nil) |
| 305 | fake := &fakeDesktop{ |
| 306 | startCfg: agentdesktop.DisplayConfig{Width: 1920, Height: 1080}, |
| 307 | } |
| 308 | api := agentdesktop.NewAPI(logger, fake, nil) |
| 309 | defer api.Close() |
| 310 | |
| 311 | body := agentdesktop.DesktopAction{ |
| 312 | Action: "left_click", |
| 313 | Coordinate: &[2]int{100, 200}, |
| 314 | } |
| 315 | b, err := json.Marshal(body) |
| 316 | require.NoError(t, err) |
| 317 | |
| 318 | rr := httptest.NewRecorder() |
| 319 | req := httptest.NewRequest(http.MethodPost, "/action", bytes.NewReader(b)) |
| 320 | req.Header.Set("Content-Type", "application/json") |
| 321 | |
| 322 | handler := api.Routes() |
| 323 | handler.ServeHTTP(rr, req) |
| 324 | require.Equal(t, http.StatusOK, rr.Code) |
| 325 | |
| 326 | fake.recMu.Lock() |
| 327 | count := fake.activityCount |
| 328 | fake.recMu.Unlock() |
| 329 | assert.Equal(t, 1, count, "handleAction should call RecordActivity exactly once") |
| 330 | } |
| 331 | |
| 332 | func TestHandleAction_Screenshot(t *testing.T) { |
| 333 | t.Parallel() |