diff --git a/client/src/components/AtlasGlobe/globeMesh.edge.test.ts b/client/src/components/AtlasGlobe/globeMesh.edge.test.ts index fd4666445..c4e7322b5 100644 --- a/client/src/components/AtlasGlobe/globeMesh.edge.test.ts +++ b/client/src/components/AtlasGlobe/globeMesh.edge.test.ts @@ -167,20 +167,15 @@ describe('densify', () => { describe('buildLayer', () => { const layer = buildLayer(SHAPES, 'countries', 100, (n) => 10 + n); - it('FE-ATLAS2-PAINT-507: fills a polygon with its hole, both parts of a multipolygon, and skips slivers and empty features', () => { - const fid = Array.from(layer.fill.fid); - // The square with its hole first, then the two parts; the sliver and the empty feature add nothing. - // (How many vertices the cut adds along the edges is the builder's business, not this test's.) - const firstOther = fid.indexOf(11); - expect(firstOther).toBeGreaterThanOrEqual(8); - expect(fid.slice(0, firstOther).every((v) => v === 10)).toBe(true); - expect(fid.slice(firstOther).every((v) => v === 11)).toBe(true); - expect(fid.length - firstOther).toBeGreaterThanOrEqual(8); - expect(layer.fill.ll).toHaveLength(fid.length * 2); - expect(layer.fill.ref).toHaveLength(fid.length * 2); - expect(layer.fill.index.length % 3).toBe(0); - expect(Math.min(...layer.fill.index)).toBe(0); - expect(Math.max(...layer.fill.index)).toBe(fid.length - 1); + it('FE-ATLAS2-PAINT-507: draws fill for every nondegenerate polygon part', () => { + const { fid, index, ll, ref } = layer.fill; + // A degenerate ring can contribute vertices, but no fill triangle may reference them. + const drawnVertices = Array.from(new Set(index)); + expect(new Set(drawnVertices.map((vertex) => fid[vertex]))).toEqual(new Set([10, 11])); + expect(new Set(drawnVertices.map((vertex) => Math.round(ref[vertex * 2] / RAD)))).toEqual(new Set([5, 21, 31])); + expect(ll).toHaveLength(fid.length * 2); + expect(ref).toHaveLength(fid.length * 2); + expect(index.length % 3).toBe(0); }); it('FE-ATLAS2-PAINT-508: the hole stays empty and every vertex refers to the centre of its own outline', () => { diff --git a/server/src/nest/app.module.ts b/server/src/nest/app.module.ts index cda214fc9..fb2dc4297 100644 --- a/server/src/nest/app.module.ts +++ b/server/src/nest/app.module.ts @@ -96,6 +96,7 @@ import { RoutingRelayModule } from './routing-relay/routing-relay.module'; import { SchedulingModule } from './scheduling/scheduling.module'; import { SchoolHolidaysModule } from './school-holidays/school-holidays.module'; import { ServiceIdentityModule } from './service-identity/service-identity.module'; +import { SessionActivityModule } from './sessions/session-activity.module'; import { SessionsModule } from './sessions/sessions.module'; import { SettingsModule } from './settings/settings.module'; import { ShareModule } from './share/share.module'; @@ -130,6 +131,7 @@ import { APP_FILTER, APP_GUARD, APP_INTERCEPTOR, APP_PIPE } from '@nestjs/core'; RealtimeModule, RealtimeGatewayModule, JourneyAccessModule, + SessionActivityModule, SchedulingModule, McpModule.forRoot({ accessPolicy: trekMcpAccessPolicy, diff --git a/server/src/nest/realtime/realtime-gateway.module.ts b/server/src/nest/realtime/realtime-gateway.module.ts index 9b765a0a3..1b5eeee9b 100644 --- a/server/src/nest/realtime/realtime-gateway.module.ts +++ b/server/src/nest/realtime/realtime-gateway.module.ts @@ -4,7 +4,6 @@ import { Users } from '../../db/entities/Users.entity'; import { EphemeralTokenModule } from '../auth-core/ephemeral-token.module'; import { DatabaseLifecycleModule } from '../database/database-lifecycle.module'; import { DatabaseLifecycle } from '../database/database-lifecycle.service'; -import { SessionsModule } from '../sessions/sessions.module'; import { TripMembershipModule } from '../trip-membership/trip-membership.module'; import { RealtimeGateway } from './realtime.gateway'; import { closeSockets, processRooms, RoomRegistry, roomsSlot } from './ws-state'; @@ -36,7 +35,6 @@ import { Module, type OnModuleDestroy } from '@nestjs/common'; TripMembershipModule, EphemeralTokenModule, DatabaseLifecycleModule, - SessionsModule, MikroOrmModule.forFeature([Users, AppSettings, Trips]), ], // The room registry is the process-wide in-memory one; the constructor diff --git a/server/src/nest/realtime/realtime.gateway.ts b/server/src/nest/realtime/realtime.gateway.ts index 59f247525..351ad1b80 100644 --- a/server/src/nest/realtime/realtime.gateway.ts +++ b/server/src/nest/realtime/realtime.gateway.ts @@ -10,9 +10,9 @@ import { EphemeralTokenService } from '../auth-core/ephemeral-token.service'; import { SESSION_TOUCH_INTERVAL_MS } from '../auth-core/jwt-verify'; import { readAppSetting } from '../common/app-settings.registry'; import { toRowId } from '../common/row-id'; -import { SessionsService } from '../sessions/sessions.service'; import { TripAccessService } from '../trip-membership/trip-access.service'; import { JOURNEY_ACCESS, type JourneyAccess } from './journey-access.types'; +import { SESSION_ACTIVITY, type SessionActivity } from './session-activity.types'; import { announceBookPeers, bookPeers, @@ -88,7 +88,7 @@ export class RealtimeGateway implements OnGatewayInit, OnGatewayConnection, OnGa @InjectRepository(AppSettings) private readonly appSettings: AppSettingsRepository, // A tab in front keeps its session's last activity current (presence below), // written through the sessions domain that owns the table. - private readonly sessions: SessionsService, + @Inject(SESSION_ACTIVITY) private readonly sessionActivity: SessionActivity, // Room membership, behind its port. The container's provider, which // RealtimeGatewayModule also installs for the broadcast functions in // ws-state.ts; a hand-built gateway takes the installed one. @@ -236,7 +236,7 @@ export class RealtimeGateway implements OnGatewayInit, OnGatewayConnection, OnGa if (now - (this.touchedAt.get(socket) ?? 0) < SESSION_TOUCH_INTERVAL_MS) return; this.touchedAt.set(socket, now); try { - await this.sessions.touchLastSeen(session, dbNow(new Date(now))); + await this.sessionActivity.touchLastSeen(session, dbNow(new Date(now))); } catch (err) { // Bookkeeping for the user list only: a busy database must not cost the socket. logError(`ws presence touch failed: ${err instanceof Error ? err.message : String(err)}`); diff --git a/server/src/nest/realtime/session-activity.types.ts b/server/src/nest/realtime/session-activity.types.ts new file mode 100644 index 000000000..d788d9457 --- /dev/null +++ b/server/src/nest/realtime/session-activity.types.ts @@ -0,0 +1,6 @@ +export const SESSION_ACTIVITY = Symbol('SESSION_ACTIVITY'); + +/** Persists the activity reported by a visible WebSocket tab. */ +export interface SessionActivity { + touchLastSeen(sessionId: string, now: string): Promise; +} diff --git a/server/src/nest/sessions/session-activity.module.ts b/server/src/nest/sessions/session-activity.module.ts new file mode 100644 index 000000000..ba24ff418 --- /dev/null +++ b/server/src/nest/sessions/session-activity.module.ts @@ -0,0 +1,13 @@ +import { SESSION_ACTIVITY } from '../realtime/session-activity.types'; +import { SessionsModule } from './sessions.module'; +import { SessionsService } from './sessions.service'; +import { Global, Module } from '@nestjs/common'; + +/** Binds the gateway's activity port to the existing session service. */ +@Global() +@Module({ + imports: [SessionsModule], + providers: [{ provide: SESSION_ACTIVITY, useExisting: SessionsService }], + exports: [SESSION_ACTIVITY], +}) +export class SessionActivityModule {} diff --git a/server/tests/unit/nest/realtime.gateway.test.ts b/server/tests/unit/nest/realtime.gateway.test.ts index a0f063d3a..e70aef101 100644 --- a/server/tests/unit/nest/realtime.gateway.test.ts +++ b/server/tests/unit/nest/realtime.gateway.test.ts @@ -6,6 +6,7 @@ import type { EphemeralTokenService } from '../../../src/nest/auth-core/ephemera import type { JourneyDomainService } from '../../../src/nest/journey/journey-domain.service'; import { hostVersion } from '../../../src/nest/plugins/install/host-compat'; import { RealtimeGateway } from '../../../src/nest/realtime/realtime.gateway'; +import type { SessionActivity } from '../../../src/nest/realtime/session-activity.types'; import { bookPeers, broadcast, @@ -22,7 +23,6 @@ import { userOf, type TrekWebSocket, } from '../../../src/nest/realtime/ws-state'; -import type { SessionsService } from '../../../src/nest/sessions/sessions.service'; import { TripAccessService } from '../../../src/nest/trip-membership/trip-access.service'; import { emitPluginEvent } from '../../../src/plugin-event-sink'; import type { User } from '../../../src/types'; @@ -89,7 +89,7 @@ const appSettings = { } as unknown as AppSettingsRepository; const touchLastSeen = vi.fn(async (_session: string, _now: string) => undefined); -const sessions = { touchLastSeen } as unknown as SessionsService; +const sessions: SessionActivity = { touchLastSeen }; const consumeWithMeta = vi.fn(); const tokens = { consumeWithMeta } as unknown as EphemeralTokenService;