Moves carry follows over; first DMs to Lemmy 0.19 and Mbin go as ChatMessage
Two owner decisions of 2026-10-05, both recorded in ROADMAP: - After a verified Move the personas following the old account follow the new one, in the same lists, and a mute or block of the old account carries over, as Mastodon does it. - A direct message to one account on a server whose NodeInfo names Lemmy before 1.0 or Mbin goes as a ChatMessage, the one place PrivaPub decides by a server's software (invariant 17). G-0008 is closed. Mbin addresses its private messages to the recipient's profile page, so a Create addressed to a persona's /@name now reaches the persona. Checked live: moves 8/8, Lemmy 0.19 30/30, Mbin 26/26 with messages both ways. The software theory runs alone, since every test's peer shares 127.0.0.1. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LsXgEaXee4GCU1hwYgPJXw
This commit is contained in:
1 parent
f3e8cce2ed
commit
7b0377c85f
19 files changed
+309
-63
No files matched your search
@@ -0,0 +1,75 @@
|
||||
using MongoDB.Entities;
|
||||
|
||||
using PrivaPub.ClientModels.Post;
|
||||
using PrivaPub.Models.Post;
|
||||
using PrivaPub.Tests.Support;
|
||||
|
||||
using System.Text.Json.Nodes;
|
||||
|
||||
namespace PrivaPub.Tests.Federation
|
||||
{
|
||||
// alone in its collection: every test's peer is 127.0.0.1, and the server row it writes decides for whoever writes there
|
||||
[Trait("Category", "Integration")]
|
||||
[Xunit.Collection(nameof(Exclusive))]
|
||||
public sealed class ChatMessageSoftwareTests : IAsyncLifetime
|
||||
{
|
||||
Harness _harness;
|
||||
|
||||
public async ValueTask InitializeAsync()
|
||||
{
|
||||
Assert.SkipUnless(MongoFixture.Enabled, MongoFixture.Skip);
|
||||
_harness = await Harness.Start();
|
||||
}
|
||||
|
||||
public async ValueTask DisposeAsync()
|
||||
{
|
||||
if (_harness != default)
|
||||
await _harness.DisposeAsync();
|
||||
}
|
||||
|
||||
static string NewId(RemoteActor actor, string kind) => $"{new Uri(actor.Id).GetLeftPart(UriPartial.Authority)}/{kind}/{Guid.NewGuid():N}";
|
||||
|
||||
// the one decision taken by a server's software (owner decision 2026-10-05): Lemmy before 1.0 and Mbin get a
|
||||
// ChatMessage even from a persona answering a Note; Lemmy 1.0 a Note
|
||||
[Theory]
|
||||
[InlineData("lemmy", "0.19.20", "ChatMessage")]
|
||||
[InlineData("mbin", "1.10.1", "ChatMessage")]
|
||||
[InlineData("lemmy", "1.0.0-beta.2", "Note")]
|
||||
public async Task A_direct_message_to_lemmy_before_1_0_or_mbin_is_a_chat_message(string software, string version, string sent)
|
||||
{
|
||||
var token = TestContext.Current.CancellationToken;
|
||||
var (_, alice) = await _harness.Persona("alice");
|
||||
var sender = new RemoteActor(_harness.Peer, "pm");
|
||||
var host = new Uri(sender.Id).Host;
|
||||
await DB.Default.DeleteAsync<PrivaPub.Models.Jobs.RemoteInstance>(i => i.Host == host);
|
||||
await DB.Default.SaveAsync(new PrivaPub.Models.Jobs.RemoteInstance { Host = host, Software = software, SoftwareVersion = version }, token);
|
||||
try
|
||||
{
|
||||
var id = NewId(sender, "messages");
|
||||
await _harness.Deliver(sender, "/human-centipede", new JsonObject
|
||||
{
|
||||
["id"] = NewId(sender, "activities/create"), ["type"] = "Create", ["actor"] = sender.Id, ["to"] = new JsonArray(alice.Uri),
|
||||
["object"] = new JsonObject
|
||||
{
|
||||
["id"] = id, ["type"] = "Note", ["attributedTo"] = sender.Id, ["to"] = new JsonArray(alice.Uri),
|
||||
["content"] = "<p>psst</p>", ["published"] = DateTime.UtcNow.ToString("O")
|
||||
}
|
||||
});
|
||||
var message = await DB.Default.Find<Post>().Match(p => p.ObjectURI == id).ExecuteSingleAsync(token);
|
||||
|
||||
var answer = await _harness.Statuses.Publish(alice, new PrivaPub.Domain.Statuses.StatusDraft
|
||||
{
|
||||
Text = "psst back", Visibility = PostVisibility.Direct, ConversationId = message.ConversationId
|
||||
}, token);
|
||||
|
||||
Assert.True(answer.Ok, answer.Error);
|
||||
var create = (await _harness.Outgoing(sender.Id + "/inbox")).Last(a => a["type"]!.GetValue<string>() == "Create");
|
||||
Assert.Equal(sent, create["object"]!["type"]!.GetValue<string>());
|
||||
}
|
||||
finally
|
||||
{
|
||||
await DB.Default.DeleteAsync<PrivaPub.Models.Jobs.RemoteInstance>(i => i.Host == host);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ using MongoDB.Entities;
|
||||
|
||||
using PrivaPub.ClientModels.Post;
|
||||
using PrivaPub.Federation.Objects;
|
||||
using PrivaPub.Models.Group;
|
||||
using PrivaPub.Models.Post;
|
||||
using PrivaPub.Tests.Support;
|
||||
|
||||
@@ -106,6 +107,32 @@ namespace PrivaPub.Tests.Federation
|
||||
Assert.NotNull(message.ConversationId);
|
||||
}
|
||||
|
||||
// Mbin addresses its private messages to the recipient's profile page (its `url`), not to the actor
|
||||
[Fact]
|
||||
public async Task A_chat_message_addressed_to_a_personas_profile_page_reaches_the_persona()
|
||||
{
|
||||
var token = TestContext.Current.CancellationToken;
|
||||
var (_, alice) = await _harness.Persona("alice");
|
||||
var mbin = new RemoteActor(_harness.Peer, "mbuser");
|
||||
var messageId = NewId(mbin, "f/object");
|
||||
|
||||
await _harness.Deliver(mbin, "/human-centipede", new JsonObject
|
||||
{
|
||||
["id"] = NewId(mbin, "f/object"), ["type"] = "Create", ["actor"] = mbin.Id, ["to"] = new JsonArray(alice.HtmlUrl), ["cc"] = new JsonArray(),
|
||||
["object"] = new JsonObject
|
||||
{
|
||||
["id"] = messageId, ["type"] = "ChatMessage", ["attributedTo"] = mbin.Id, ["to"] = new JsonArray(alice.HtmlUrl), ["cc"] = new JsonArray(),
|
||||
["content"] = "<p>an answer</p>", ["mediaType"] = "text/html", ["published"] = DateTime.UtcNow.ToString("O")
|
||||
}
|
||||
});
|
||||
|
||||
var message = await DB.Default.Find<Post>().Match(p => p.ObjectURI == messageId).ExecuteFirstAsync(token);
|
||||
Assert.NotNull(message);
|
||||
Assert.Equal(PostVisibility.Direct, message.Visibility);
|
||||
var conversation = await DB.Default.Find<DmGroup>().OneAsync(message.ConversationId, token);
|
||||
Assert.Equal(new[] { alice.Id, mbin.Id }.Order(StringComparer.Ordinal), conversation.Members.Select(m => m.AvatarId).Order(StringComparer.Ordinal));
|
||||
}
|
||||
|
||||
// Lemmy 0.19 and Mbin take a private message only as a ChatMessage: someone who writes to us that way is answered in
|
||||
// kind, anyone else with a Note
|
||||
[Fact]
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using MongoDB.Entities;
|
||||
|
||||
using PrivaPub.Api.Mastodon.Mappers;
|
||||
using PrivaPub.Models.Social;
|
||||
using PrivaPub.Models.User;
|
||||
using PrivaPub.Tests.Support;
|
||||
|
||||
@@ -49,13 +50,23 @@ namespace PrivaPub.Tests.Federation
|
||||
static Task<ForeignAvatar> Stored(RemoteActor actor) =>
|
||||
DB.Default.Find<ForeignAvatar>().Match(a => a.ActorURI == actor.Id).ExecuteFirstAsync(TestContext.Current.CancellationToken);
|
||||
|
||||
// as Mastodon does it (owner decision 2026-10-05): the follow moves to the new account, in the same lists, and a mute
|
||||
// or a block of the old account carries over
|
||||
[Fact]
|
||||
public async Task A_move_the_new_account_confirms_shows_the_old_account_moved_there()
|
||||
public async Task A_move_the_new_account_confirms_moves_the_personas_follows_lists_mutes_and_blocks()
|
||||
{
|
||||
var token = TestContext.Current.CancellationToken;
|
||||
var (_, alice) = await _harness.Persona("alice");
|
||||
var (_, bob) = await _harness.Persona("bob");
|
||||
var old = new RemoteActor(_harness.Peer, "old");
|
||||
await _harness.Remote.GetActor(old.Id, refresh: true, token);
|
||||
await Follows(alice.Id, old);
|
||||
var oldAccount = await Stored(old);
|
||||
var list = new PersonaList { AvatarId = alice.Id, Title = "friends" };
|
||||
await DB.Default.SaveAsync(list, token);
|
||||
await DB.Default.SaveAsync(new PersonaListMember { ListId = list.ID, AvatarId = alice.Id, AccountId = oldAccount.ID }, token);
|
||||
await _harness.Relationships.Mute(alice, old.Id, oldAccount.ID, hideNotifications: true, duration: default, token);
|
||||
await _harness.Relationships.Block(bob, old.Id, oldAccount.ID, token);
|
||||
var target = Target("new", aliasOf: old);
|
||||
|
||||
await Move(old, old, target);
|
||||
@@ -65,6 +76,14 @@ namespace PrivaPub.Tests.Federation
|
||||
var account = await new MastodonMapper(_harness.Db, _harness.Local).Account(stored.ID, token);
|
||||
Assert.Equal(target.Name, account.Moved?.Username);
|
||||
Assert.Contains(_harness.Ledger.Of("in"), e => e.Activity == "Move" && e.Reason == "moved");
|
||||
var newAccount = await Stored(target);
|
||||
Assert.True(await DB.Default.Find<Following>().Match(f => f.AvatarId == alice.Id && f.TargetActorURI == target.Id).ExecuteAnyAsync(token));
|
||||
Assert.False(await DB.Default.Find<Following>().Match(f => f.AvatarId == alice.Id && f.TargetActorURI == old.Id).ExecuteAnyAsync(token));
|
||||
Assert.Contains(await _harness.Outgoing(target.Id + "/inbox"), a => a["type"]!.GetValue<string>() == "Follow");
|
||||
Assert.Contains(await _harness.Outgoing(old.Id + "/inbox"), a => a["type"]!.GetValue<string>() == "Undo");
|
||||
Assert.True(await DB.Default.Find<PersonaListMember>().Match(m => m.ListId == list.ID && m.AccountId == newAccount.ID).ExecuteAnyAsync(token));
|
||||
Assert.True(await DB.Default.Find<Mute>().Match(m => m.AvatarId == alice.Id && m.TargetActorURI == target.Id).ExecuteAnyAsync(token));
|
||||
Assert.True(await DB.Default.Find<Block>().Match(b => b.AvatarId == bob.Id && b.TargetActorURI == target.Id).ExecuteAnyAsync(token));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
||||
Reference in new issue
Block a user