Skip to content
Open
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
58 changes: 53 additions & 5 deletions tools/check-duplicates-test.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,44 @@ def test_analyze_repository(self):
queue_file = ROOT / "docs" / "AUTHORING-QUEUE.json"
results = analyze_repository(queue_file)
self.assertGreater(results["published_count"], 0)
self.assertGreater(results["queue_count"], 0)
self.assertGreaterEqual(results["queue_count"], 0)
self.assertIsInstance(results["collisions"], list)

def test_filter_deferred_queue_items(self):
import tempfile
import json
test_queue = [
{
"name": "Strategy Pattern",
"slug": "strategy",
"path": "patterns/01-gof/new-strategy-attempt.md",
"status": "active",
},
{
"name": "Deferred Pattern",
"slug": "virtual-list",
"path": "patterns/13-frontend-ui/virtual-list-attempt.md",
"status": "deferred",
},
]
with tempfile.NamedTemporaryFile("w+", suffix=".json", delete=False) as f:
json.dump(test_queue, f)
temp_path = Path(f.name)
try:
results = analyze_repository(temp_path)
self.assertEqual(results["queue_count"], 1)
# Strategy matches published strategy.md
collisions = [
c for c in results["collisions"] if c.get("queue_name") == "Strategy Pattern"
]
self.assertGreater(len(collisions), 0)
deferred_collisions = [
c for c in results["collisions"] if c.get("queue_name") == "Deferred Pattern"
]
self.assertEqual(len(deferred_collisions), 0)
finally:
temp_path.unlink(missing_ok=True)

def test_historical_proposal_detection(self):
history = fetch_historical_proposals()
self.assertIsInstance(history, list)
Expand All @@ -103,17 +138,29 @@ def test_historical_proposal_detection(self):
self.assertIsInstance(results["collisions"], list)

def test_historical_proposal_collision_mock(self):
import tempfile
import json
fake_history = [
{
"path": "patterns/24-stream-processing/old-windowing-attempt.md",
"slug": "windowing",
}
]
test_queue = [
{
"name": "Windowing",
"slug": "windowing",
"path": "patterns/24-stream-processing/new-windowing-attempt.md",
"status": "active",
}
]
original_fetch = check_duplicates.fetch_historical_proposals
check_duplicates.fetch_historical_proposals = lambda: fake_history
with tempfile.NamedTemporaryFile("w+", suffix=".json", delete=False) as f:
json.dump(test_queue, f)
temp_path = Path(f.name)
try:
queue_file = ROOT / "docs" / "AUTHORING-QUEUE.json"
results = analyze_repository(queue_file)
results = analyze_repository(temp_path)
historical_collisions = [
c
for c in results["collisions"]
Expand All @@ -122,6 +169,7 @@ def test_historical_proposal_collision_mock(self):
self.assertGreater(len(historical_collisions), 0)
finally:
check_duplicates.fetch_historical_proposals = original_fetch
temp_path.unlink(missing_ok=True)

def test_collision_deduplication(self):
queue_file = ROOT / "docs" / "AUTHORING-QUEUE.json"
Expand All @@ -140,13 +188,13 @@ def test_main_check_and_strict_exit_codes(self):
sys, "argv", ["check-duplicates.py", "--check"]
):
code_check = check_duplicates.main()
self.assertEqual(code_check, 1)
self.assertEqual(code_check, 0)

with unittest.mock.patch.object(
sys, "argv", ["check-duplicates.py", "--strict"]
):
code_strict = check_duplicates.main()
self.assertEqual(code_strict, 1)
self.assertEqual(code_strict, 0)


if __name__ == "__main__":
Expand Down
3 changes: 2 additions & 1 deletion tools/check-duplicates.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,8 @@ def analyze_repository(queue_path: Path) -> dict:
queue = []
if queue_path.exists():
try:
queue = json.loads(queue_path.read_text(encoding="utf-8"))
raw_queue = json.loads(queue_path.read_text(encoding="utf-8"))
queue = [q for q in raw_queue if q.get("status") != "deferred"]
except Exception:
queue = []

Expand Down
Loading