MCPcopy
hub / github.com/MemPalace/mempalace / test_batch_size_boundary

Method test_batch_size_boundary

tests/test_sync.py:681–731  ·  view source on GitHub ↗

`_delete_in_batches` correctness at batch_size smaller than dataset.

(self, tmp_dir, palace_path)

Source from the content-addressed store, hash-verified

679 assert set(report.keys()) == expected
680
681 def test_batch_size_boundary(self, tmp_dir, palace_path):
682 """`_delete_in_batches` correctness at batch_size smaller than dataset."""
683 from mempalace.sync import sync_palace
684
685 repo_path = Path(tmp_dir) / "repo"
686 repo_path.mkdir(parents=True)
687 (repo_path / ".gitignore").write_text("ignored/\n")
688 (repo_path / "ignored").mkdir()
689 n = 5
690 for i in range(n):
691 (repo_path / "ignored" / f"f{i}.py").write_text(f"# {i}\n")
692
693 client = chromadb.PersistentClient(path=palace_path)
694 col = client.get_or_create_collection(
695 "mempalace_drawers", metadata={"hnsw:space": "cosine"}
696 )
697 col.add(
698 ids=[f"d_{i}" for i in range(n)],
699 documents=[f"x{i}" for i in range(n)],
700 embeddings=[[float(i + 1), 0.0, 0.0] for i in range(n)],
701 metadatas=[
702 {
703 "wing": "demo",
704 "room": "ignored",
705 "source_file": str(repo_path / "ignored" / f"f{i}.py"),
706 "chunk_index": 0,
707 "added_by": "miner",
708 "filed_at": "2026-05-09T00:00:00",
709 }
710 for i in range(n)
711 ],
712 )
713 del client
714
715 seen = []
716
717 def fake_wal(operation, params, result=None):
718 if operation == "sync_prune":
719 seen.append(result["removed_count"])
720
721 report = sync_palace(
722 palace_path=palace_path,
723 project_dirs=[str(repo_path)],
724 wing="demo",
725 dry_run=False,
726 batch_size=2,
727 wal_log=fake_wal,
728 )
729 assert report["removed_drawers"] == n
730 # 5 ids at batch_size=2 → chunks of 2,2,1 → 3 wal entries
731 assert seen == [2, 2, 1], f"unexpected chunk sizes: {seen}"
732
733 def test_apply_is_idempotent(self, synced_world):
734 """Round-3: a second apply on the same palace must be a no-op."""

Callers

nothing calls this directly

Calls 3

sync_palaceFunction · 0.90
addMethod · 0.45

Tested by

no test coverage detected