From 8d4c0cccf76f0cd365c0a36db93bd7939a26dc3b Mon Sep 17 00:00:00 2001 From: omartelo Date: Sat, 17 Oct 2026 15:14:39 -0300 Subject: [PATCH] test(drop): run past a small search budget instead of writing 50,001 files --- internal/drop/drop.go | 6 ++++-- internal/drop/drop_test.go | 11 +++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/internal/drop/drop.go b/internal/drop/drop.go index 984967a3..43976859 100644 --- a/internal/drop/drop.go +++ b/internal/drop/drop.go @@ -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. diff --git a/internal/drop/drop_test.go b/internal/drop/drop_test.go index 7926bb77..365dd6cf 100644 --- a/internal/drop/drop_test.go +++ b/internal/drop/drop_test.go @@ -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 { @@ -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) @@ -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 {