test(retention): cover the recipients pin in prune_objects and watermark activity

This commit is contained in:
Lain Soykaf 2026-09-23 08:26:24 +04:00
commit 5a4ada881f
No known key found for this signature in database
2 changed files with 32 additions and 6 deletions

View file

@ -200,21 +200,33 @@ defmodule Mix.Tasks.Pleroma.DatabaseTest do
refute Object.get_by_ap_id(old_remote_post2_id)
end
test "with the --keep-threads option it keeps old threads that mentioned a local user", %{
test "with the --keep-threads option it keeps old threads addressed to a local user", %{
old_insert_date: old_insert_date
} do
remote_user = insert(:user, local: false)
local_user = insert(:user)
{:ok, activity} = CommonAPI.post(remote_user, %{status: "hey @#{local_user.nickname}"})
{:ok, mention} = CommonAPI.post(remote_user, %{status: "hey @#{local_user.nickname}"})
activity
|> Ecto.Changeset.change(%{local: false, updated_at: old_insert_date})
|> Repo.update!()
{:ok, dm} =
CommonAPI.post(remote_user, %{
status: "psst @#{local_user.nickname}",
visibility: "direct"
})
# The pin must not depend on the notifications still being there
Pleroma.Notification.clear(local_user)
for activity <- [mention, dm] do
activity
|> Ecto.Changeset.change(%{local: false, updated_at: old_insert_date})
|> Repo.update!()
end
Mix.Tasks.Pleroma.Database.run(["prune_objects", "--keep-threads"])
assert Object.get_by_ap_id(activity.data["object"])
assert Object.get_by_ap_id(mention.data["object"])
assert Object.get_by_ap_id(dm.data["object"])
end
test "with the --keep-threads option it still keeps non-old threads even with no local interactions" do

View file

@ -265,6 +265,20 @@ defmodule Pleroma.RetentionTest do
assert Object.get_by_ap_id(post.data["object"])
end
test "keeps an old thread with a recent reply, even over the watermark", %{
old_date: old_date
} do
clear_config([:retention, :max_objects], 0)
remote_user = insert(:user, local: false)
{:ok, post} = CommonAPI.post(remote_user, %{status: "old but active"})
# Old id, so the walk reaches it, but active an hour ago
age(post, old_date, %{local: false, updated_at: NaiveDateTime.add(days_ago(0), -3_600)})
assert %{contexts: 0} = Retention.run()
assert Object.get_by_ap_id(post.data["object"])
end
test "does not evict anything below the watermark" do
clear_config([:retention, :max_objects], 100)
remote_user = insert(:user, local: false)