fix: regression where topic moves during Announce(Create(Note)) stopped working, added test for #14040, fix broken AP test helper mock

This commit is contained in:
Julian Lam
2026-03-26 12:04:40 -04:00
parent 781ed3447b
commit 4d3211caba
5 changed files with 70 additions and 17 deletions

View File

@@ -55,12 +55,13 @@ Helpers.mocks.group = (override = {}) => {
type: 'Group',
...override,
});
const { hostname } = new URL(id);
activitypub._cache.set(`0;${id}`, actor);
activitypub.helpers._webfingerCache.set(`${actor.preferredUsername}@example.org`, {
activitypub.helpers._webfingerCache.set(`${actor.preferredUsername}@${hostname}`, {
actorUri: id,
username: id,
hostname: 'example.org',
hostname,
});
return { id, actor };

View File

@@ -183,20 +183,72 @@ describe('Inbox', () => {
});
describe('(Create)', () => {
it('should create a new topic in a remote category if addressed', async () => {
const { id: remoteCid } = helpers.mocks.group();
const { id, note } = helpers.mocks.note({
audience: [remoteCid],
describe('newly-discovered topic', () => {
before(async function () {
const { id: remoteCid } = helpers.mocks.group();
const { id, note } = helpers.mocks.note({
audience: [remoteCid],
});
this.id = id;
this.remoteCid = remoteCid;
let { activity } = helpers.mocks.create(note);
({ activity } = helpers.mocks.announce({ actor: remoteCid, object: activity }));
await activitypub.inbox.announce({ body: activity });
});
let { activity } = helpers.mocks.create(note);
({ activity } = helpers.mocks.announce({ actor: remoteCid, object: activity }));
await activitypub.inbox.announce({ body: activity });
it('should create a new topic in a remote category if addressed', async function () {
assert(await posts.exists(this.id));
assert(await posts.exists(id));
const cid = await posts.getCidByPid(this.id);
assert.strictEqual(cid, this.remoteCid);
});
});
const cid = await posts.getCidByPid(id);
assert.strictEqual(cid, remoteCid);
describe.only('known topic in cid -1 (author domain != announcer domain)', async () => {
/**
* This happens if follower receives object from microblog user before the community announces it.
* It's probably more likely to occur because the Create(Note) is a single hop whereas the reflected
* Announce(Create(Note)) takes two hops.
*
* If the author and announcer domain are the same, the object should already be correctly classified.
*/
before(async function () {
const { id: remoteCid } = helpers.mocks.group({
id: `https://example.social/${utils.generateUUID()}`,
});
await activitypub.actors.assertGroup([remoteCid]);
const uid = await user.create({ username: utils.generateUUID().slice(0, 10) });
this.uid = uid;
this.remoteCid = remoteCid;
});
it('should create a topic in cid -1', async function () {
const { id, note } = helpers.mocks.note({
to: [activitypub._constants.publicAddress, this.remoteCid],
});
const { activity } = helpers.mocks.create(note);
await activitypub.inbox.create({ uid: this.uid, body: activity });
this.id = id;
this.note = note;
this.activity = activity;
const cid = await posts.getCidByPid(this.id);
assert.strictEqual(cid, -1);
});
it('should handle the Announce(Create) from the remote category', async function () {
const { activity } = helpers.mocks.announce({ actor: this.remoteCid, object: this.activity });
await activitypub.inbox.announce({ uid: this.uid, body: activity });
});
it('should be categorized in the remote category', async function () {
const cid = await posts.getCidByPid(this.id);
assert.strictEqual(cid, this.remoteCid);
});
});
});