@inneranimalmedia/agentsam-sdk 1.8.0 → 1.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/DEVELOPMENT.md +1 -1
- package/docs/RELEASES.iam-mirror.md +20 -0
- package/docs/RELEASES.md +4 -1
- package/package.json +2 -2
- package/python/agentsam_sdk/cli.py +57 -7
- package/python/agentsam_sdk/data/d1_bloat.py +279 -99
- package/python/agentsam_sdk/repository/__init__.py +26 -0
- package/python/agentsam_sdk/repository/inspect.py +496 -0
- package/python/docs/gaps.md +1 -1
- package/python/tests/test_d1_bloat.py +60 -24
- package/python/tests/test_repository_inspect.py +84 -0
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"""Unit tests for agentsam_sdk.repository.inspect — call SDK directly (no subprocess)."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
import tempfile
|
|
5
|
+
import unittest
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
|
|
8
|
+
from agentsam_sdk.repository.inspect import (
|
|
9
|
+
build_report,
|
|
10
|
+
find_dupes,
|
|
11
|
+
summarize,
|
|
12
|
+
walk_repo,
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class TestRepositoryInspect(unittest.TestCase):
|
|
17
|
+
def test_walk_summarize_and_dupes_via_direct_import(self):
|
|
18
|
+
"""Proof of SDK reuse: import + call without shelling out to repo_inspect.py."""
|
|
19
|
+
with tempfile.TemporaryDirectory() as tmp:
|
|
20
|
+
root = Path(tmp)
|
|
21
|
+
(root / "src").mkdir()
|
|
22
|
+
(root / "src" / "a.txt").write_bytes(b"hello-dup")
|
|
23
|
+
(root / "copy").mkdir()
|
|
24
|
+
(root / "copy" / "b.txt").write_bytes(b"hello-dup") # identical content
|
|
25
|
+
(root / "src" / "unique.txt").write_bytes(b"only-once-content-xyz")
|
|
26
|
+
(root / "node_modules").mkdir()
|
|
27
|
+
(root / "node_modules" / "skip.js").write_bytes(b"x" * 5000)
|
|
28
|
+
|
|
29
|
+
errors: list[dict] = []
|
|
30
|
+
files = walk_repo(root, errors=errors)
|
|
31
|
+
paths = {f["path"] for f in files}
|
|
32
|
+
self.assertIn("src/a.txt", paths)
|
|
33
|
+
self.assertIn("copy/b.txt", paths)
|
|
34
|
+
self.assertIn("src/unique.txt", paths)
|
|
35
|
+
self.assertNotIn("node_modules/skip.js", paths)
|
|
36
|
+
|
|
37
|
+
rollup = summarize(files, recent_n=10, largest_n=10)
|
|
38
|
+
self.assertEqual(rollup["file_count"], 3)
|
|
39
|
+
self.assertGreater(rollup["total_bytes"], 0)
|
|
40
|
+
|
|
41
|
+
warnings: list[str] = []
|
|
42
|
+
dupes = find_dupes(files, repo_root=root, warnings=warnings)
|
|
43
|
+
self.assertEqual(len(dupes), 1)
|
|
44
|
+
group = dupes[0]
|
|
45
|
+
self.assertEqual(group["count"], 2)
|
|
46
|
+
self.assertEqual(group["size_bytes"], len(b"hello-dup"))
|
|
47
|
+
self.assertEqual(group["wasted_bytes"], len(b"hello-dup"))
|
|
48
|
+
self.assertEqual(set(group["paths"]), {"src/a.txt", "copy/b.txt"})
|
|
49
|
+
self.assertEqual(len(group["sha256"]), 64)
|
|
50
|
+
|
|
51
|
+
report = build_report(root, include_dupes=True, recent_n=5, largest_n=5)
|
|
52
|
+
self.assertIn("summary", report)
|
|
53
|
+
self.assertIn("recent", report)
|
|
54
|
+
self.assertIn("largest", report)
|
|
55
|
+
self.assertEqual(report["summary"]["duplicate_groups"], 1)
|
|
56
|
+
self.assertEqual(report["summary"]["duplicate_wasted_bytes"], len(b"hello-dup"))
|
|
57
|
+
self.assertEqual(len(report["duplicates"]), 1)
|
|
58
|
+
|
|
59
|
+
def test_find_dupes_skips_unreadable_without_crash(self):
|
|
60
|
+
with tempfile.TemporaryDirectory() as tmp:
|
|
61
|
+
root = Path(tmp)
|
|
62
|
+
(root / "ok.txt").write_bytes(b"same")
|
|
63
|
+
(root / "also.txt").write_bytes(b"same")
|
|
64
|
+
# Fabricate a row pointing at a missing path (same size) — hash should warn
|
|
65
|
+
files = walk_repo(root)
|
|
66
|
+
files.append(
|
|
67
|
+
{
|
|
68
|
+
"path": "missing-ghost.txt",
|
|
69
|
+
"top_dir": "(root)",
|
|
70
|
+
"ext": ".txt",
|
|
71
|
+
"size_bytes": len(b"same"),
|
|
72
|
+
"mtime_unix": 0,
|
|
73
|
+
}
|
|
74
|
+
)
|
|
75
|
+
warnings: list[str] = []
|
|
76
|
+
errors: list[dict] = []
|
|
77
|
+
dupes = find_dupes(files, repo_root=root, warnings=warnings, errors=errors)
|
|
78
|
+
self.assertTrue(any("missing-ghost" in w for w in warnings))
|
|
79
|
+
self.assertEqual(len(dupes), 1)
|
|
80
|
+
self.assertEqual(dupes[0]["count"], 2)
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
if __name__ == "__main__":
|
|
84
|
+
unittest.main()
|