From d589da59f29f3eb8321e804519c58f793ce729e6 Mon Sep 17 00:00:00 2001 From: Maurice Date: Sun, 25 Oct 2026 23:47:00 +0100 Subject: [PATCH] fix(wanderer): find the author of an account whose one actor wanderer expands as an object PocketBase answers a back-relation with a single record as the object itself, not a list, so the user lookup failed as an answer TREK did not understand and every search with it. Closes #2799 --- server/src/nest/wanderer/wanderer.client.ts | 11 +++++++++-- server/tests/unit/nest/wanderer.client.test.ts | 10 ++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/server/src/nest/wanderer/wanderer.client.ts b/server/src/nest/wanderer/wanderer.client.ts index 3b81ef014..5c839bf42 100644 --- a/server/src/nest/wanderer/wanderer.client.ts +++ b/server/src/nest/wanderer/wanderer.client.ts @@ -55,11 +55,18 @@ const tokenListSchema = z.object({ totalItems: z.number().optional(), }); -/** A user record with the ActivityPub actors that stand for it; the local one authors the user's trails. */ +const actorSchema = z.object({ id: z.string(), is_local: z.boolean().nullish() }); + +/** + * A user record with the ActivityPub actors that stand for it; the local one + * authors the user's trails. PocketBase expands a back-relation as a single + * object when only one record can match and as a list otherwise, so an account + * with one actor answers with the object itself. + */ const userActorsSchema = z.object({ expand: z .object({ - activitypub_actors_via_user: z.array(z.object({ id: z.string(), is_local: z.boolean().nullish() })).nullish(), + activitypub_actors_via_user: z.union([z.array(actorSchema), actorSchema.transform((actor) => [actor])]).nullish(), }) .nullish(), }); diff --git a/server/tests/unit/nest/wanderer.client.test.ts b/server/tests/unit/nest/wanderer.client.test.ts index df067e0d7..ceab921a0 100644 --- a/server/tests/unit/nest/wanderer.client.test.ts +++ b/server/tests/unit/nest/wanderer.client.test.ts @@ -126,6 +126,16 @@ describe('WandererClient', () => { expect(searchBody(0).options.filter).toEqual(["author IN ['nspsn7zu7octact']"]); }); + it('RS-03b: an owner with one actor, which wanderer expands as an object rather than a list, is found', async () => { + answer({ + ...OWNER, + '/api/v1/user/gixauk8ukjpqabm': reply({ + expand: { activitypub_actors_via_user: { id: 'nspsn7zu7octact', is_local: true } }, + }), + }); + await expect(client.ownActors(CREDS)).resolves.toEqual(['nspsn7zu7octact']); + }); + it('RS-03: a token wanderer reads as anonymous is refused, however 200 the answer', async () => { answer({ '/api/v1/api-token': reply({ items: [], totalItems: 0 }) }); expect((await failure(() => client.check(CREDS))).code).toBe('unauthorized');