From c848626caaf16e09acf9d0951138c2433fe925a2 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Sat, 31 Oct 2026 17:11:35 +0100 Subject: [PATCH] Estate: prettier, and tests that kill the surviving mutants Co-Authored-By: Claude Sonnet 5.5 --- src/app/features/estate/buildEstate.test.ts | 81 ++++++++++++++++++- src/app/features/estate/buildEstate.ts | 6 +- .../features/estate/joinEstateRoom.test.ts | 13 +++ src/app/features/estate/useEstate.ts | 6 +- src/app/pages/Router.tsx | 18 +---- src/app/pages/client/space/SpaceTombstone.tsx | 1 - src/types/matrix/accountData.ts | 1 - 7 files changed, 101 insertions(+), 25 deletions(-) diff --git a/src/app/features/estate/buildEstate.test.ts b/src/app/features/estate/buildEstate.test.ts index 0593e195..27964a7b 100644 --- a/src/app/features/estate/buildEstate.test.ts +++ b/src/app/features/estate/buildEstate.test.ts @@ -19,7 +19,11 @@ const room = (id: string, name: string, alias?: string): EstateHierarchyRoom => const hierarchy = [ space(ROOT, 'GameCult', ['!general:gamecult.org', PROJECTS]), room('!general:gamecult.org', 'General', '#general:gamecult.org'), - space(PROJECTS, 'Projects', ['!cultlib:gamecult.org', '!aeth:gamecult.org', '!misc:gamecult.org']), + space(PROJECTS, 'Projects', [ + '!cultlib:gamecult.org', + '!aeth:gamecult.org', + '!misc:gamecult.org', + ]), room('!cultlib:gamecult.org', 'CultLib', '#cultlib:gamecult.org'), room('!aeth:gamecult.org', 'Aetheria', '#Aetheria:gamecult.org'), room('!misc:gamecult.org', 'Misc', '#misc:gamecult.org'), @@ -43,7 +47,9 @@ const find = (tiers: ReturnType, roomId: string) => describe('buildEstate', () => { it('lists an invited project room as invited', () => { - const tiers = buildEstate(input({ membership: new Map([['!cultlib:gamecult.org', 'invite']]) })); + const tiers = buildEstate( + input({ membership: new Map([['!cultlib:gamecult.org', 'invite']]) }) + ); expect(find(tiers, '!cultlib:gamecult.org')?.state).toBe('invited'); }); @@ -84,7 +90,12 @@ describe('buildEstate', () => { it('sorts steward groups by display label', () => { const projects = buildEstate( - input({ mindLabels: new Map([['eureka', 'Zed'], ['void', 'Alpha']]) }) + input({ + mindLabels: new Map([ + ['eureka', 'Zed'], + ['void', 'Alpha'], + ]), + }) ).find((t) => t.id === PROJECTS)!; expect(projects.groups.map((g) => g.label)).toEqual(['Alpha', 'Zed']); }); @@ -116,11 +127,73 @@ describe('buildEstate', () => { membership: new Map([['!dm:gamecult.org', 'join']]), }) ); - expect(tiers.map((t) => t.label)).toEqual(['GameCult', 'Projects', 'Workshop', 'Direct Messages']); + expect(tiers.map((t) => t.label)).toEqual([ + 'GameCult', + 'Projects', + 'Workshop', + 'Direct Messages', + ]); expect(tiers[0].loose.map((r) => r.name)).toEqual(['General']); expect(tiers[3].loose[0]).toMatchObject({ roomId: '!dm:gamecult.org', parentId: null }); }); + it('takes join servers from the matching children_state entry', () => { + const tiers = buildEstate( + input({ + hierarchy: [ + { + ...space(ROOT, 'GameCult', ['!a:gamecult.org', '!b:gamecult.org']), + children_state: [ + { state_key: '!a:gamecult.org', content: { via: ['one.example'] } }, + { state_key: '!b:gamecult.org', content: { via: ['two.example'] } }, + ], + }, + room('!a:gamecult.org', 'A'), + room('!b:gamecult.org', 'B'), + ], + }) + ); + expect(find(tiers, '!a:gamecult.org')?.via).toEqual(['one.example']); + expect(find(tiers, '!b:gamecult.org')?.via).toEqual(['two.example']); + }); + + it('puts every room of one Mind in a single group', () => { + const tiers = buildEstate( + input({ stewardships: { eureka: ['CultLib', 'Aetheria'] } }) + ); + const projects = tiers.find((t) => t.id === PROJECTS)!; + expect(projects.groups).toHaveLength(1); + expect(projects.groups[0].rooms.map((r) => r.roomId)).toEqual([ + '!cultlib:gamecult.org', + '!aeth:gamecult.org', + ]); + }); + + it('sorts group labels without regard to case', () => { + const projects = buildEstate( + input({ mindLabels: new Map([['eureka', 'beta'], ['void', 'Alpha']]) }) + ).find((t) => t.id === PROJECTS)!; + expect(projects.groups.map((g) => g.label)).toEqual(['Alpha', 'beta']); + }); + + it('omits a tier whose Space returned no rooms and the Direct tier when there are no DMs', () => { + const tiers = buildEstate( + input({ + hierarchy: [ + space(ROOT, 'GameCult', ['!general:gamecult.org', PROJECTS]), + room('!general:gamecult.org', 'General'), + space(PROJECTS, 'Projects', ['!hidden:gamecult.org']), + ], + }) + ); + expect(tiers.map((t) => t.id)).toEqual([ROOT]); + }); + + it('puts direct messages in the final tier, off any Space', () => { + const tiers = buildEstate(input({ directRoomIds: ['!dm:gamecult.org'] })); + expect(tiers[tiers.length - 1]).toMatchObject({ id: 'direct', groups: [] }); + }); + it('is identical for identical inputs', () => { expect(buildEstate(input())).toEqual(buildEstate(input())); }); diff --git a/src/app/features/estate/buildEstate.ts b/src/app/features/estate/buildEstate.ts index 096ea9ad..9ca9048c 100644 --- a/src/app/features/estate/buildEstate.ts +++ b/src/app/features/estate/buildEstate.ts @@ -7,8 +7,6 @@ * a room it returns is never hidden by the client. */ -export const STEWARDSHIPS_EVENT_TYPE = 'org.gamecult.stewardships'; - export type EstateHierarchyRoom = { room_id: string; name?: string; @@ -77,7 +75,9 @@ export const stewardOfRoom = ( const local = canonicalAlias.replace(/^#/, '').split(':')[0].toLowerCase(); const mind = Object.keys(stewardships).find((m) => { const repos = stewardships[m]; - return Array.isArray(repos) && repos.some((r) => typeof r === 'string' && repoName(r) === local); + return ( + Array.isArray(repos) && repos.some((r) => typeof r === 'string' && repoName(r) === local) + ); }); return mind; }; diff --git a/src/app/features/estate/joinEstateRoom.test.ts b/src/app/features/estate/joinEstateRoom.test.ts index 8976f325..fae21e5b 100644 --- a/src/app/features/estate/joinEstateRoom.test.ts +++ b/src/app/features/estate/joinEstateRoom.test.ts @@ -48,6 +48,19 @@ describe('activateEstateRoom', () => { } ); + it('falls back to the error message, then to a generic one', async () => { + const named = recordingClient(vi.fn().mockRejectedValue(new Error('Boom'))); + expect(await activateEstateRoom(named.mx, room('joinable'))).toEqual({ + kind: 'refused', + message: 'Boom', + }); + const bare = recordingClient(vi.fn().mockRejectedValue({})); + expect(await activateEstateRoom(bare.mx, room('joinable'))).toEqual({ + kind: 'refused', + message: 'Could not join', + }); + }); + it('reports the server refusal and does not decide access itself', async () => { const refusal = Object.assign(new Error('M_FORBIDDEN'), { data: { error: 'You are not invited to this room.' }, diff --git a/src/app/features/estate/useEstate.ts b/src/app/features/estate/useEstate.ts index 6ffccd1e..99927ba8 100644 --- a/src/app/features/estate/useEstate.ts +++ b/src/app/features/estate/useEstate.ts @@ -15,7 +15,11 @@ import { buildEstate, EstateHierarchyRoom, EstateTier, Stewardships } from './bu const HIERARCHY_DEPTH = 10; -type AliasedRoom = { roomId: string; getCanonicalAlias(): string | null; getAltAliases(): string[] }; +type AliasedRoom = { + roomId: string; + getCanonicalAlias(): string | null; + getAltAliases(): string[]; +}; const findLoadedRoom = ( mx: ReturnType, diff --git a/src/app/pages/Router.tsx b/src/app/pages/Router.tsx index ae5eac70..159162dd 100644 --- a/src/app/pages/Router.tsx +++ b/src/app/pages/Router.tsx @@ -151,11 +151,7 @@ export const createRouter = (clientConfig: ClientConfig, screenSize: ScreenSize) - } - > + }> } @@ -176,11 +172,7 @@ export const createRouter = (clientConfig: ClientConfig, screenSize: ScreenSize) - } - > + }> } @@ -200,11 +192,7 @@ export const createRouter = (clientConfig: ClientConfig, screenSize: ScreenSize) path={SPACE_PATH} element={ - - } - > + }> diff --git a/src/app/pages/client/space/SpaceTombstone.tsx b/src/app/pages/client/space/SpaceTombstone.tsx index 3e2d13bd..16bcdf63 100644 --- a/src/app/pages/client/space/SpaceTombstone.tsx +++ b/src/app/pages/client/space/SpaceTombstone.tsx @@ -76,4 +76,3 @@ export function SpaceTombstone({ roomId, replacementRoomId }: SpaceTombstoneProp ); } - diff --git a/src/types/matrix/accountData.ts b/src/types/matrix/accountData.ts index 1f5f0608..36c1e21b 100644 --- a/src/types/matrix/accountData.ts +++ b/src/types/matrix/accountData.ts @@ -3,7 +3,6 @@ export enum AccountDataEvent { Direct = 'm.direct', IgnoredUserList = 'm.ignored_user_list', - ElementRecentEmoji = 'io.element.recent_emoji', PoniesUserEmotes = 'im.ponies.user_emotes',