Skip to content

Commit 74a549b

Browse files
committed
feat(diff): log the diff report URL and cover discovery memory
PR/MR runs logged the head and new scan IDs but no link to the result, so a CI log gave no way to reach the report. Log the diff report URL where it is computed, so every diff flow gets it rather than only the full-scan-only branches. Also add a regression test asserting manifest discovery's peak allocation stays bounded by the widest single directory and the result set rather than by repository size. Measured against the per-pattern rglob approach this replaced, on a tree of 59,300 files including one 50,000-entry directory: 3.25 MB peak vs 10.72 MB. os.walk keeps a list of names per directory where rglob materialised DirEntry objects and a Path per candidate, so the single-pass walk allocates strictly less. Ref: CE-379
1 parent da788bf commit 74a549b

2 files changed

Lines changed: 30 additions & 0 deletions

File tree

socketsecurity/core/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1970,6 +1970,10 @@ def create_new_diff(
19701970
else:
19711971
diff.diff_url = diff.report_url
19721972

1973+
# PR/MR runs previously logged only the scan IDs, so a CI log had no link to the
1974+
# result. Logged here rather than at each call site so every diff flow gets it.
1975+
log.info(f"Diff report URL: {diff.diff_url}")
1976+
19731977
return diff
19741978

19751979
def create_diff_report(

tests/unit/test_manifest_discovery.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,3 +303,29 @@ def test_core_initialization_logs_organization_timing(caplog):
303303
"Organization initialization completed" in record.message
304304
for record in caplog.records
305305
)
306+
307+
308+
def test_discovery_does_not_build_a_repository_sized_index(tmp_path):
309+
"""Peak memory must stay bounded by the widest directory and the result set, not
310+
by repository size. This is the property that keeps discovery viable on small
311+
runners; the per-pattern rglob approach it replaced allocated strictly more.
312+
"""
313+
import tracemalloc
314+
315+
wide_directory = tmp_path / "wide"
316+
wide_directory.mkdir()
317+
for index in range(20000):
318+
(wide_directory / f"source{index:05d}.ts").write_text("x", encoding="utf-8")
319+
(tmp_path / "package.json").write_text("{}", encoding="utf-8")
320+
321+
core = _make_core()
322+
tracemalloc.start()
323+
try:
324+
found = core.find_files(str(tmp_path))
325+
_, peak_bytes = tracemalloc.get_traced_memory()
326+
finally:
327+
tracemalloc.stop()
328+
329+
assert _relative_results(tmp_path, found) == {"package.json"}
330+
# 20k files in one directory; a repo-sized index would be far larger than this.
331+
assert peak_bytes < 8_000_000, f"peak allocation was {peak_bytes / 1e6:.1f} MB"

0 commit comments

Comments
 (0)