83 lines
3.1 KiB
Python
83 lines
3.1 KiB
Python
"""Unit tests for scripts/auto-cherry-pick.py heuristics."""
|
|
|
|
from __future__ import annotations
|
|
|
|
|
|
def test_return_channels_skipped(cherry_pick, empty_manifest):
|
|
_, manifest = empty_manifest
|
|
manifest["channels"]["29wilson"] = {
|
|
"status": "partial",
|
|
"messages": {"x": {"action": "import"}},
|
|
}
|
|
cherry_pick.reset_all_picks(manifest)
|
|
entry = manifest["channels"]["29wilson"]
|
|
assert entry["status"] == "skip"
|
|
assert entry["messages"] == {}
|
|
|
|
|
|
def test_conversation_not_imported(cherry_pick):
|
|
assert cherry_pick.looks_conversational("should we go with option A?")
|
|
assert cherry_pick.looks_conversational("sounds good!")
|
|
assert not cherry_pick.text_is_factual("should we book for Tuesday?")
|
|
assert cherry_pick.text_is_factual("Call Dr. Smith at 416-555-1234")
|
|
|
|
|
|
def test_name_list_detected(cherry_pick):
|
|
text = "Baby girl names\n• Maya\n• Sarah\n• Leah\n• Naomi"
|
|
assert cherry_pick.is_name_list_message(text)
|
|
assert not cherry_pick.is_name_list_message("Zoey had fun at camp today")
|
|
|
|
|
|
def test_latest_draft_only_one_winner(cherry_pick, export):
|
|
msgs, files_map = cherry_pick.build_latest_draft_winners(export, "153niagara")
|
|
# Multiple draft versions of hot_plate → one message id wins
|
|
hot = [mid for mid in msgs if "153niagara" in mid]
|
|
assert len(hot) >= 1
|
|
for mid, fids in files_map.items():
|
|
assert mid in msgs
|
|
assert fids
|
|
|
|
|
|
def test_should_import_doc_not_chat(cherry_pick, export):
|
|
latest, _ = cherry_pick.build_latest_draft_winners(export, "153niagara")
|
|
picked_docs = 0
|
|
picked_chat = 0
|
|
for msg in export.iter_channel_messages("153niagara"):
|
|
if cherry_pick.should_import(msg, "153niagara", latest_draft_msgs=latest):
|
|
if msg.get("files"):
|
|
picked_docs += 1
|
|
elif (msg.get("text") or "").strip():
|
|
picked_chat += 1
|
|
assert picked_docs >= 1
|
|
# Data-only mode: far fewer bare-text picks than files
|
|
assert picked_chat <= picked_docs + 5
|
|
|
|
|
|
def test_wilson_not_in_auto_channels(cherry_pick):
|
|
assert "29wilson" not in cherry_pick.AUTO_CHANNELS
|
|
assert "520steeles" not in cherry_pick.AUTO_CHANNELS
|
|
assert cherry_pick.RETURN_CHANNELS >= {"29wilson", "520steeles"}
|
|
|
|
|
|
def test_dry_run_pick_count(cherry_pick, export, empty_manifest, tmp_path, monkeypatch):
|
|
_path, manifest = empty_manifest
|
|
monkeypatch.setattr(cherry_pick, "MANIFEST_PATH", tmp_path / "manifest.json")
|
|
monkeypatch.setattr(cherry_pick, "DEFAULT_EXPORT", export.paths.root)
|
|
|
|
import sys
|
|
|
|
sys.argv = ["auto-cherry-pick.py", "--dry-run"]
|
|
# Run pick logic inline
|
|
cherry_pick.reset_all_picks(manifest)
|
|
total = 0
|
|
for ch_name in sorted(cherry_pick.AUTO_CHANNELS):
|
|
if ch_name in cherry_pick.RETURN_CHANNELS:
|
|
continue
|
|
if not export.channel_folder(ch_name):
|
|
continue
|
|
latest, _ = cherry_pick.build_latest_draft_winners(export, ch_name)
|
|
for msg in export.iter_channel_messages(ch_name):
|
|
if cherry_pick.should_import(msg, ch_name, latest_draft_msgs=latest):
|
|
total += 1
|
|
assert 0 < total < 200 # mini fixture stays small
|