mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-06 10:44:23 +00:00
fix(ci): presence through the sessions domain, warm bags taken once, a slimmer planner page
Server lint: the realtime gateway injected the user_sessions repository, a table the sessions domain owns; it now asks SessionsService. The presence tests reuse the handshake's gateway instead of building one more by hand (test-new-service ratchet). Client tests: the packing bags kept per trip leaked from one test (and one list) into the next; bags read ahead are now taken once as the list's first state, and only while bag tracking is on. The planner hook hands the page planMapKept, tourMapKept and the tour stage's class, so page tests that mock the hook keep working and TripPlannerPage is back at its size baseline (1127); the B4A wiring test reads the new condition. Client lint: max-depth in src is down to 19, the baseline follows; the new websocket tests call onopen with ?. instead of a non-null assertion.
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
import { AppSettings } from '../../db/entities/AppSettings.entity';
|
||||
import { Trips } from '../../db/entities/Trips.entity';
|
||||
import { UserSessions } from '../../db/entities/UserSessions.entity';
|
||||
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 +36,8 @@ import { Module, type OnModuleDestroy } from '@nestjs/common';
|
||||
TripMembershipModule,
|
||||
EphemeralTokenModule,
|
||||
DatabaseLifecycleModule,
|
||||
MikroOrmModule.forFeature([Users, AppSettings, Trips, UserSessions]),
|
||||
SessionsModule,
|
||||
MikroOrmModule.forFeature([Users, AppSettings, Trips]),
|
||||
],
|
||||
// The room registry is the process-wide in-memory one; the constructor
|
||||
// below hands whichever one the container resolved to the broadcast
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
import { runningVersion } from '../../app-config';
|
||||
import { AppSettings } from '../../db/entities/AppSettings.entity';
|
||||
import { UserSessions } from '../../db/entities/UserSessions.entity';
|
||||
import { Users } from '../../db/entities/Users.entity';
|
||||
import type { AppSettingsRepository } from '../../db/repositories/AppSettings.repository';
|
||||
import type { UserSessionsRepository } from '../../db/repositories/UserSessions.repository';
|
||||
import type { UsersRepository } from '../../db/repositories/Users.repository';
|
||||
import { dbNow } from '../../db/types/db-timestamp.type';
|
||||
import { User } from '../../types';
|
||||
@@ -12,6 +10,7 @@ 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 {
|
||||
@@ -87,8 +86,9 @@ export class RealtimeGateway implements OnGatewayInit, OnGatewayConnection, OnGa
|
||||
@Inject(JOURNEY_ACCESS) private readonly journeys: JourneyAccess,
|
||||
@InjectRepository(Users) private readonly users: UsersRepository,
|
||||
@InjectRepository(AppSettings) private readonly appSettings: AppSettingsRepository,
|
||||
// A tab in front keeps its session's last activity current (presence below).
|
||||
@InjectRepository(UserSessions) private readonly sessions: UserSessionsRepository,
|
||||
// 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,
|
||||
// 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.
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import type { AppSettingsRepository } from '../../../src/db/repositories/AppSettings.repository';
|
||||
import type { TripsRepository } from '../../../src/db/repositories/Trips.repository';
|
||||
import type { UserSessionsRepository } from '../../../src/db/repositories/UserSessions.repository';
|
||||
import type { UsersRepository } from '../../../src/db/repositories/Users.repository';
|
||||
import { logError } from '../../../src/nest/audit/audit-log.logger';
|
||||
import type { EphemeralTokenService } from '../../../src/nest/auth-core/ephemeral-token.service';
|
||||
@@ -23,6 +22,7 @@ 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 UserSessionsRepository;
|
||||
const sessions = { touchLastSeen } as unknown as SessionsService;
|
||||
|
||||
const consumeWithMeta = vi.fn();
|
||||
const tokens = { consumeWithMeta } as unknown as EphemeralTokenService;
|
||||
@@ -741,7 +741,8 @@ describe('book rooms with unusable sockets in them', () => {
|
||||
* its session's last activity current without any request.
|
||||
*/
|
||||
describe('RealtimeGateway presence', () => {
|
||||
const gateway = () => new RealtimeGateway(new TripAccessService(db), tokens, journeys, users, appSettings, sessions);
|
||||
// The gateway a handshake built; its own socket stays out of the server's client list.
|
||||
const gateway = async () => (await connect('/ws?token=x')).gw;
|
||||
|
||||
it('WSGW-PRES-001: a tab in the background is not online, one in front is, one that never said is', async () => {
|
||||
const hidden = socket();
|
||||
@@ -751,7 +752,7 @@ describe('RealtimeGateway presence', () => {
|
||||
registerSocket(front, { id: 12, username: 'f' } as User);
|
||||
registerSocket(silent, { id: 13, username: 's' } as User);
|
||||
setServer({ clients: new Set([hidden, front, silent]) } as never);
|
||||
const gw = gateway();
|
||||
const gw = await gateway();
|
||||
|
||||
await gw.handlePresence({ visible: false }, hidden);
|
||||
await gw.handlePresence({ visible: true }, front);
|
||||
@@ -765,7 +766,7 @@ describe('RealtimeGateway presence', () => {
|
||||
vi.setSystemTime(new Date('2026-11-29T09:00:00Z'));
|
||||
const ws = socket();
|
||||
registerSocket(ws, { id: 14, username: 'p' } as User, 'sess-p');
|
||||
const gw = gateway();
|
||||
const gw = await gateway();
|
||||
|
||||
await gw.handlePresence({ visible: true }, ws);
|
||||
await gw.handlePresence({ visible: true }, ws);
|
||||
@@ -784,7 +785,7 @@ describe('RealtimeGateway presence', () => {
|
||||
const noSession = socket();
|
||||
registerSocket(hidden, { id: 15, username: 'h' } as User, 'sess-h');
|
||||
registerSocket(noSession, { id: 16, username: 'n' } as User);
|
||||
const gw = gateway();
|
||||
const gw = await gateway();
|
||||
|
||||
await gw.handlePresence({ visible: false }, hidden);
|
||||
await gw.handlePresence({ visible: true }, noSession);
|
||||
@@ -800,7 +801,7 @@ describe('RealtimeGateway presence', () => {
|
||||
registerSocket(ws, { id: 17, username: 'b' } as User, 'sess-b');
|
||||
setSocketVisible(ws, true);
|
||||
touchLastSeen.mockRejectedValueOnce(new Error('busy'));
|
||||
const gw = gateway();
|
||||
const gw = await gateway();
|
||||
gw.afterInit({ clients: new Set([ws]) } as never);
|
||||
|
||||
await vi.advanceTimersByTimeAsync(30_000);
|
||||
|
||||
Reference in New Issue
Block a user