Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions internal/drop/drop.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,10 @@ const maxUpload = 32 << 20

// maxEntries bounds one searched tree, so a drop over a home directory or a
// vendored monorepo cannot stall the window. Past it the search gives up and
// the item falls through to the upload copy.
const maxEntries = 50_000
// the item falls through to the upload copy. Replaced in tests: proving the
// budget runs out takes one more file than it, and 50,001 files cost close to
// forty seconds a test on Windows.
var maxEntries = 50_000

// homeDir is os.UserHomeDir, replaced in tests: the search must never reach
// the machine's real home, on any OS.
Expand Down
11 changes: 11 additions & 0 deletions internal/drop/drop_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,15 @@ func homeAt(t *testing.T, home string) *Service {
return New(t.TempDir(), nil)
}

// smallBudget shrinks the search budget for one test, so running past it takes
// a handful of files rather than fifty thousand.
func smallBudget(t *testing.T) {
t.Helper()
previous := maxEntries
maxEntries = 16
t.Cleanup(func() { maxEntries = previous })
}

// writeFile creates path with size bytes and a known modification time,
// standing in for the file the user drags out of a file manager.
func writeFile(t *testing.T, path string, size int, mtime time.Time) Item {
Expand Down Expand Up @@ -123,6 +132,7 @@ func TestResolveRefusesTwins(t *testing.T) {
// is not a unique match, and answering with it hands the session the wrong file
// — the exact failure the whole rule exists to prevent.
func TestResolveRefusesTwinsSplitByTheBudget(t *testing.T) {
smallBudget(t)
root := t.TempDir()
mtime := time.Now().Add(-time.Hour).Truncate(time.Second)
item := writeFile(t, filepath.Join(root, "a", "app.ts"), 41, mtime)
Expand Down Expand Up @@ -221,6 +231,7 @@ func TestResolveMapsEveryItem(t *testing.T) {
// reported the directory sitting right beside it as missing. The noise here is
// one entry over the budget for exactly that reason.
func TestResolveFindsShallowSiblingBeforeNoise(t *testing.T) {
smallBudget(t)
root := t.TempDir()
noise := filepath.Join(root, ".cache", "pkg")
if err := os.MkdirAll(noise, 0o755); err != nil {
Expand Down
Loading