fix(detect): probe every out subdirectory under an entry budget, not the first 20

Review follow-up: a wide TS outDir keeping compiled files only under a
late-sorted module dir slipped past the 20-subdirectory cap. The level-two
probe now covers every subdirectory, bounded by total entries scanned.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JJbLfztSxm2tH5cJwBbe9q
(cherry picked from commit ff0a8f6d64)
This commit is contained in:
abhay-codes07 authored and safishamsi committed 2026-09-09 17:20:57 +01:00
1 parent ba9b3e3d6c
commit 34735fa762
2 files changed
+30 -1

No files matched your search

+11 -1
View File
@@ -933,11 +933,21 @@ def _has_build_output_markers(d: "Path") -> bool:
return True
if entry.is_dir():
subdirs.append(entry.path)
for sub in subdirs[:20]: # bounded: probe one more level, cheaply
# Probe one more level across EVERY subdirectory (a wide TS outDir may
# keep its compiled files only under later-sorted module dirs), bounded
# by total entries scanned rather than by subdirectory count so a
# pathological tree still costs O(1)-ish.
budget = 4000
for sub in subdirs:
if budget <= 0:
break
with os.scandir(sub) as it:
for entry in it:
budget -= 1
if entry.is_file() and entry.name.lower().endswith(_BUILD_OUTPUT_SUFFIXES):
return True
if budget <= 0:
break
except OSError:
pass
return False
+19
View File
@@ -81,6 +81,25 @@ def test_compiled_artifacts_one_level_down_prune_out(tmp_path, monkeypatch):
assert not any("out/lib" in f for f in files), files
def test_wide_out_dir_markers_beyond_twenty_subdirs_still_prune(tmp_path, monkeypatch):
"""A wide outDir whose compiled files sit only under a late-sorted
subdirectory is still recognized as build output."""
monkeypatch.chdir(tmp_path)
for i in range(30):
sub = tmp_path / f"out/mod{i:02d}"
sub.mkdir(parents=True)
(sub / "notes.txt").write_text("no artifacts here\n", encoding="utf-8")
late = tmp_path / "out/zz-final"
late.mkdir()
(late / "index.js.map").write_text("{}", encoding="utf-8")
(tmp_path / "src").mkdir()
(tmp_path / "src/index.ts").write_text("export const x = 1;\n", encoding="utf-8")
files = _scanned(tmp_path)
assert any("src/index.ts" in f for f in files), files
assert not any("/out/" in f for f in files), files
def test_other_skip_dirs_stay_unconditional(tmp_path, monkeypatch):
"""The gate is scoped to `out`: build/, dist/, target/ prune by name."""
monkeypatch.chdir(tmp_path)