feat: implement smart unfollow with resonance evaluation and close friends guard
This commit is contained in:
@@ -24,9 +24,13 @@ def unfollow_mock_dependencies():
|
||||
dopamine.wants_to_change_feed.return_value = False
|
||||
dopamine.boredom = 0.0
|
||||
|
||||
resonance = MagicMock()
|
||||
resonance.calculate_resonance.return_value = 0.2
|
||||
|
||||
cognitive_stack = {
|
||||
"telepathic": telepathic,
|
||||
"dopamine": dopamine,
|
||||
"resonance": resonance,
|
||||
}
|
||||
|
||||
return device, zero_engine, nav_graph, configs, session_state, cognitive_stack
|
||||
@@ -36,21 +40,29 @@ def test_unfollow_engine_basic_loop(unfollow_mock_dependencies):
|
||||
|
||||
telepathic = cognitive_stack["telepathic"]
|
||||
|
||||
# First node gives a "Following" button
|
||||
# 1. Finds profile row
|
||||
# 2. Finds following button on profile
|
||||
# 3. Finds confirm dialog
|
||||
telepathic._extract_semantic_nodes.side_effect = [
|
||||
[{"x": 100, "y": 200, "skip": False, "bounds": "..."}], # following button
|
||||
[{"x": 150, "y": 250, "skip": False}], # confirm dialog
|
||||
[{"semantic_string": "Profile Row", "x": 100, "y": 200, "skip": False, "bounds": "..."}],
|
||||
[{"semantic_string": "Following Button", "x": 150, "y": 250, "skip": False}],
|
||||
[{"semantic_string": "Unfollow Confirm", "x": 200, "y": 300, "skip": False}],
|
||||
[], # second iteration
|
||||
[]
|
||||
]
|
||||
|
||||
with patch("GramAddict.core.unfollow_engine._humanized_scroll_down") as mock_scroll, \
|
||||
patch("GramAddict.core.bot_flow.sleep"), \
|
||||
patch("GramAddict.core.bot_flow.random_sleep"), \
|
||||
patch("GramAddict.core.utils.random_sleep"), \
|
||||
patch("GramAddict.core.bot_flow._humanized_click") as mock_click:
|
||||
|
||||
device.dump_hierarchy.return_value = '<node text="Basic Bio"/>'
|
||||
|
||||
res = _run_zero_latency_unfollow_loop(device, zero_engine, nav_graph, configs, session_state, "FollowingList", cognitive_stack)
|
||||
|
||||
assert mock_click.call_count == 2 # Clicked following THEN clicked confirm
|
||||
# Clicked profile -> following button -> confirm
|
||||
assert mock_click.call_count == 3
|
||||
assert session_state.totalUnfollowed == 1
|
||||
assert res == "FEED_EXHAUSTED"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user