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:
Maurice
2026-11-29 10:13:53 +01:00
parent 5401728c41
commit 10ad92574d
9 changed files with 45 additions and 42 deletions
@@ -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);