(t *testing.T)
| 477 | } |
| 478 | |
| 479 | func TestScanDeletedRepoEmitsRemoved(t *testing.T) { |
| 480 | t.Parallel() |
| 481 | |
| 482 | repoDir := initTestRepo(t) |
| 483 | logger := slogtest.Make(t, nil) |
| 484 | |
| 485 | h := agentgit.NewHandler(logger) |
| 486 | |
| 487 | // Create a dirty file so the initial scan has something to track. |
| 488 | dirtyFile := filepath.Join(repoDir, "dirty.go") |
| 489 | require.NoError(t, os.WriteFile(dirtyFile, []byte("package dirty\n"), 0o600)) |
| 490 | |
| 491 | h.Subscribe([]string{dirtyFile}) |
| 492 | ctx := context.Background() |
| 493 | |
| 494 | // Initial scan — populates the snapshot with the dirty file. |
| 495 | msg1 := h.Scan(ctx) |
| 496 | require.NotNil(t, msg1) |
| 497 | require.Len(t, msg1.Repositories, 1) |
| 498 | require.False(t, msg1.Repositories[0].Removed) |
| 499 | |
| 500 | // Delete the entire repo directory. |
| 501 | require.NoError(t, os.RemoveAll(repoDir)) |
| 502 | |
| 503 | // Next scan should emit a removal entry. |
| 504 | msg2 := h.Scan(ctx) |
| 505 | require.NotNil(t, msg2) |
| 506 | require.Len(t, msg2.Repositories, 1) |
| 507 | |
| 508 | removed := msg2.Repositories[0] |
| 509 | require.True(t, removed.Removed, "repo should be marked as removed") |
| 510 | require.Equal(t, repoDir, removed.RepoRoot) |
| 511 | require.Empty(t, removed.Branch) |
| 512 | |
| 513 | // Removed repo should have an empty diff. |
| 514 | require.Empty(t, removed.UnifiedDiff) |
| 515 | |
| 516 | // Subsequent scan should return nil — the repo was evicted from |
| 517 | // the watch set. |
| 518 | msg3 := h.Scan(ctx) |
| 519 | require.Nil(t, msg3, "evicted repo should not appear in subsequent scans") |
| 520 | } |
| 521 | |
| 522 | func TestScanDeletedGitDirEmitsRemoved(t *testing.T) { |
| 523 | t.Parallel() |
nothing calls this directly
no test coverage detected