Skip to content

armgit / TREK

Public Imported from GitHub
0

The most complete open-source travel planner: real-time collaboration, bookings, budgets, packing lists, journals, offline PWA, SSO and an AI-ready MCP server, with planet-wide place search and routing built in.

fix(wanderer): find the author of an account whose one actor wanderer expands as an object

Mauriced589da59f29f
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');