(t *testing.T)
| 1381 | } |
| 1382 | |
| 1383 | func TestE2E_ReEditedFileTriggersRescan(t *testing.T) { |
| 1384 | t.Parallel() |
| 1385 | |
| 1386 | ctx := testutil.Context(t, testutil.WaitLong) |
| 1387 | repoDir := initTestRepo(t) |
| 1388 | |
| 1389 | // Write initial dirty file. |
| 1390 | filePath := filepath.Join(repoDir, "edited.go") |
| 1391 | require.NoError(t, os.WriteFile(filePath, []byte("package v1\n"), 0o600)) |
| 1392 | |
| 1393 | ps := agentgit.NewPathStore() |
| 1394 | chatID := uuid.New() |
| 1395 | mClock := quartz.NewMock(t) |
| 1396 | |
| 1397 | // First AddPaths — registers the path and repo. |
| 1398 | ps.AddPaths([]uuid.UUID{chatID}, []string{filePath}) |
| 1399 | |
| 1400 | stream := dialGitWatchWithPathStore(t, ps, chatID, agentgit.WithClock(mClock)) |
| 1401 | ch := stream.Chan() |
| 1402 | |
| 1403 | // Receive the initial scan showing the dirty file. |
| 1404 | msg1 := recvMsg(ctx, t, ch) |
| 1405 | require.Equal(t, codersdk.WorkspaceAgentGitServerMessageTypeChanges, msg1.Type) |
| 1406 | require.NotEmpty(t, msg1.Repositories) |
| 1407 | require.Contains(t, msg1.Repositories[0].UnifiedDiff, "v1") |
| 1408 | |
| 1409 | // Modify the same file again — the repo is already watched, |
| 1410 | // so Subscribe returns false. The handler must still scan. |
| 1411 | require.NoError(t, os.WriteFile(filePath, []byte("package v2\n"), 0o600)) |
| 1412 | |
| 1413 | // Advance past the scan cooldown so the second scan fires |
| 1414 | // immediately. |
| 1415 | mClock.Advance(2 * time.Second).MustWait(context.Background()) |
| 1416 | |
| 1417 | // AddPaths with the same path — triggers PathStore notification. |
| 1418 | ps.AddPaths([]uuid.UUID{chatID}, []string{filePath}) |
| 1419 | |
| 1420 | // The handler should rescan and send an updated diff. |
| 1421 | msg2 := recvMsg(ctx, t, ch) |
| 1422 | require.Equal(t, codersdk.WorkspaceAgentGitServerMessageTypeChanges, msg2.Type) |
| 1423 | require.NotEmpty(t, msg2.Repositories) |
| 1424 | require.Contains(t, msg2.Repositories[0].UnifiedDiff, "v2") |
| 1425 | } |
| 1426 | |
| 1427 | func TestE2E_RepoDeletionEmitsRemoved(t *testing.T) { |
| 1428 | t.Parallel() |
nothing calls this directly
no test coverage detected