(t *testing.T)
| 1425 | } |
| 1426 | |
| 1427 | func TestE2E_RepoDeletionEmitsRemoved(t *testing.T) { |
| 1428 | t.Parallel() |
| 1429 | |
| 1430 | ctx := testutil.Context(t, testutil.WaitLong) |
| 1431 | repoDir := initTestRepo(t) |
| 1432 | |
| 1433 | // Write a dirty file so the initial scan has something to track. |
| 1434 | require.NoError(t, os.WriteFile(filepath.Join(repoDir, "doomed.go"), []byte("package doomed\n"), 0o600)) |
| 1435 | |
| 1436 | ps := agentgit.NewPathStore() |
| 1437 | chatID := uuid.New() |
| 1438 | mClock := quartz.NewMock(t) |
| 1439 | |
| 1440 | // Pre-populate paths and connect. |
| 1441 | ps.AddPaths([]uuid.UUID{chatID}, []string{filepath.Join(repoDir, "doomed.go")}) |
| 1442 | |
| 1443 | stream := dialGitWatchWithPathStore(t, ps, chatID, agentgit.WithClock(mClock)) |
| 1444 | ch := stream.Chan() |
| 1445 | |
| 1446 | // Receive the initial changes message. |
| 1447 | msg1 := recvMsg(ctx, t, ch) |
| 1448 | require.Equal(t, codersdk.WorkspaceAgentGitServerMessageTypeChanges, msg1.Type) |
| 1449 | require.NotEmpty(t, msg1.Repositories) |
| 1450 | require.False(t, msg1.Repositories[0].Removed) |
| 1451 | |
| 1452 | // Delete the entire repo directory. |
| 1453 | require.NoError(t, os.RemoveAll(repoDir)) |
| 1454 | |
| 1455 | // Advance past the scan cooldown so the refresh fires |
| 1456 | // immediately. |
| 1457 | mClock.Advance(2 * time.Second).MustWait(context.Background()) |
| 1458 | |
| 1459 | // Send a refresh message to trigger a new scan. |
| 1460 | err := stream.Send(codersdk.WorkspaceAgentGitClientMessage{ |
| 1461 | Type: codersdk.WorkspaceAgentGitClientMessageTypeRefresh, |
| 1462 | }) |
| 1463 | require.NoError(t, err) |
| 1464 | |
| 1465 | // The next message should indicate the repo was removed. |
| 1466 | msg2 := recvMsg(ctx, t, ch) |
| 1467 | require.Equal(t, codersdk.WorkspaceAgentGitServerMessageTypeChanges, msg2.Type) |
| 1468 | require.NotEmpty(t, msg2.Repositories) |
| 1469 | |
| 1470 | foundRemoved := false |
| 1471 | for _, r := range msg2.Repositories { |
| 1472 | if r.RepoRoot == repoDir && r.Removed { |
| 1473 | foundRemoved = true |
| 1474 | } |
| 1475 | } |
| 1476 | require.True(t, foundRemoved, "expected repo %s to be marked as removed", repoDir) |
| 1477 | } |
| 1478 | |
| 1479 | // TestRunLoopExitsPromptlyOnCancel_DuringPoll pins that RunLoop |
| 1480 | // returns quickly when its context is cancelled while it is blocked |
nothing calls this directly
no test coverage detected