Keep the mobile FX widget off the network after unmount

Client CI was red on this branch while dev was green, and no client file had
changed. The 536 test files all passed; the job failed on three unhandled
rejections, all `window is not defined` from MDashWidgets, attributed to
whichever case happened to be running when they landed.

The widget fetches api.frankfurter.dev directly and sets state from both
handlers with no unmount guard. MSW runs with onUnhandledRequest: 'warn', so
that request was never intercepted: it left the runner, came back after the
environment was gone, and React tried to schedule an update against a torn
down tree. Load dependent by construction, which is why dev happened to pass.

Two halves, because either alone leaves the other broken. The widget now
aborts in flight work on unmount and on refetch, and treats an abort as "no
one is waiting" rather than as a failure to report. That matters outside the
runner too: this is a third party call on a mobile screen a user can leave
immediately.

The handler set gains the third party endpoints the app calls directly rather
than through /api, so no suite reaches the real host. An empty rate list is
the shape the widget already handles.

Also clears twenty more test files, each at its root cause. Two more were
passing for the wrong reason: oidc.service.test.ts built AuthService with an
AtlasService in the membership slot, undefined for userCleanup and mailer,
and the mailer stub in the tokens slot, the same shift admin.service.test.ts
had. And CAL-010 claims to serialise a flight byte for byte, but
createReservation ignores reservation_time, so the row is written with a null
time and CalendarService drops it: the recorded snapshot is truthful about
the data the case builds and silent about the flight it advertises.
This commit is contained in:
Maurice
2026-08-10 18:45:07 +02:00
committed by Maurice
parent 49c3c57c31
commit 7078ac7a4d
23 changed files with 195 additions and 51 deletions
+5 -3
View File
@@ -72,7 +72,9 @@ import type { LlmConfigResolver } from '../../../src/nest/llm-parse/llm-config.r
import type { PluginOAuthService } from '../../../src/nest/plugins/oauth/plugin-oauth.service';
import type { RpcError, RpcResponse } from '../../../src/nest/plugins/protocol/envelope';
const checkPermission = vi.fn(() => true as boolean);
// Typed from the real method rather than from the always-true body below, so a case that
// swaps in an implementation reading the action key (HOSTRPC-015) still type-checks.
const checkPermission = vi.fn<PermissionsService['checkPermission']>(() => true);
const permissions = { checkPermission } as unknown as PermissionsService;
const addons = { isAddonEnabled: vi.fn(() => true) } as unknown as AddonsService;
const notifications = { send: notifySend } as unknown as NotificationsService;
@@ -310,8 +312,8 @@ describe('MetaRpc — namespaced entity metadata', () => {
it('HOSTRPC-015 every entity type resolves its own edit action, and a read-only member is refused a write', async () => {
const host = makeHost('meta', 'db:meta');
const seen: string[] = [];
checkPermission.mockImplementation((action: unknown) => {
seen.push(String(action));
checkPermission.mockImplementation((action) => {
seen.push(action);
return true;
});
for (const [entityType, entityId] of [['trip', 1], ['place', 7], ['day', 3], ['reservation', 40], ['accommodation', 11]] as const) {
@@ -12,10 +12,19 @@ import type { PermissionsService } from '../../../src/nest/permissions/permissio
import type { AddonsService } from '../../../src/nest/addons/addons.service';
import type { PluginRpcContext } from '../../../src/nest/plugins/host/rpc-kit/types';
/**
* The guards read `actingUserId` and nothing else off the context, so the two per-host
* collaborators are inert here. `plugins` gets real no-op functions rather than a cast,
* so a guard that ever reached for a peer would hit a callable, not undefined.
*/
const ctx = (actingUserId: number | undefined): PluginRpcContext => ({
pluginId: 'p',
actingUserId,
data: {} as PluginRpcContext['data'],
plugins: {
call: vi.fn(async () => undefined),
emit: vi.fn(),
},
});
/** Trip 1 belongs to user 42 and only user 42 may reach it, mirroring rpc-host.test.ts. */
@@ -51,7 +51,10 @@ describe('PluginHooks contracts', () => {
const registry = createTestPluginRegistry([new PluginHooks({} as never)]);
it('PLUGHOOK-001 every hook the consent screen offers has a host-side consumer', () => {
const covered = new Set([...registry.hookContracts().values()].map((c) => c.hook));
// A plain string set on purpose: the keys probed against it come from
// HOOK_PERMISSION, and whether each one is a hook the host consumes is the
// very thing under test, not something to assert into the element type.
const covered = new Set<string>([...registry.hookContracts().values()].map((c) => c.hook));
expect([...Object.keys(HOOK_PERMISSION)].filter((h) => !covered.has(h))).toEqual([]);
});
@@ -17,6 +17,7 @@ const { getDb } = vi.hoisted(() => ({ getDb: { current: null as unknown } }));
vi.mock('../../../src/db/database', () => ({ get db() { return getDb.current; } }));
import { db as dbConn } from '../../../src/db/database';
import { DatabaseService } from '../../../src/nest/database/database.service';
import { AddonsService } from '../../../src/nest/addons/addons.service';
import Database from 'better-sqlite3';
import { PluginsService } from '../../../src/nest/plugins/plugins.service';
@@ -40,7 +41,13 @@ function freshDb() {
describe('per-user plugin settings', () => {
let svc: PluginsService;
beforeEach(() => { getDb.current = freshDb(); svc = new PluginsService(new DatabaseService(dbConn)); });
// AddonsService only feeds PluginsService.list(), which no case here calls, but it is a
// real collaborator on the same connection rather than a stand-in.
beforeEach(() => {
getDb.current = freshDb();
const dbs = new DatabaseService(dbConn);
svc = new PluginsService(dbs, new AddonsService(dbs));
});
it('lists only the user-scope fields, in order', () => {
const fields = svc.userSettingsFields('p');
@@ -118,7 +118,11 @@ describe('PluginsService.list', () => {
it('never leaks the raw pinned key into the list response (only the fingerprint)', () => {
insert('signed-one', 'acme/signed-one', 'RWTvBn0aBcDeFgHiJkLmNoPqRsTuVwXyZ0123456789abcd');
const p = new PluginsService(new DatabaseService(dbConn), new AddonsService(new DatabaseService(dbConn))).list().plugins[0] as Record<string, unknown>;
// PluginListItem is an interface, so it has no implicit index signature and cannot
// be narrowed to a record directly. Widening through unknown is what lets this case
// probe for a key the contract deliberately does not declare.
const p = new PluginsService(new DatabaseService(dbConn), new AddonsService(new DatabaseService(dbConn))).list()
.plugins[0] as unknown as Record<string, unknown>;
expect(p.author_pubkey).toBeUndefined();
});
});
@@ -18,11 +18,19 @@ import { TripsRpc } from '../../../src/nest/trips/trips.rpc';
import { DbRpc } from '../../../src/nest/plugins/host/rpc/db.rpc';
import { PluginGuards } from '../../../src/nest/plugins/host/plugin-guards.service';
import type { DatabaseService } from '../../../src/nest/database/database.service';
import type { PluginUserSettingsService } from '../../../src/nest/plugins/plugin-user-settings.service';
const req = (method: string, params: Record<string, unknown>): RpcRequest => ({ k: 'req', id: 'x', method, params });
/** db.* is the cheapest handler to watch, and it needs no services of its own. */
const dbRegistry = () => createTestPluginRegistry([new DbRpc()]);
/**
* db.* is the cheapest handler to watch. The only service it needs is the per-user
* settings store behind `settings.get`, which none of these cases dispatch, so the stub
* carries just that read, typed off the real signature.
*/
const dbRegistry = () => {
const settings: Pick<PluginUserSettingsService, 'readOne'> = { readOne: () => undefined };
return createTestPluginRegistry([new DbRpc(settings as PluginUserSettingsService)]);
};
/** trips.getById lives on the decorators now, so the audit cases bind it through them. */
const tripsRegistry = () => {
+9 -1
View File
@@ -16,6 +16,14 @@ import type { RpcRequest, RpcResponse, RpcError } from '../../../src/nest/plugin
import { makeDeps } from '../../helpers/rpc-host-deps';
const req = (method: string, params: Record<string, unknown> = {}): RpcRequest => ({ k: 'req', id: 'x', method, params });
/**
* A request as it arrives when the child never set `params`: the IPC hop is JSON, which
* drops an undefined field, so the key is genuinely absent by the time the router sees
* it. `RpcRequest` declares `params` as required, so leaving it out only type-checks
* through this cast — writing `params: undefined` instead would put the key back and
* stop covering the case the host's `req.params ?? {}` exists for.
*/
const reqWithoutParams = (method: string): RpcRequest => ({ k: 'req', id: 'x', method }) as RpcRequest;
const ok = (r: RpcResponse | RpcError): r is RpcResponse => r.ok === true;
const code = (r: RpcResponse | RpcError): string => (r as RpcError).error.code;
@@ -158,7 +166,7 @@ describe('PluginRpcHost — capability enforcement', () => {
seen = params;
return null;
});
expect(ok(await host.dispatch({ k: 'req', id: 'x', method: 'tags.list' }, 42))).toBe(true);
expect(ok(await host.dispatch(reqWithoutParams('tags.list'), 42))).toBe(true);
expect(seen).toEqual({});
});
@@ -20,6 +20,15 @@ const ctxFor = (actingUserId: number | undefined): PluginRpcContext => ({
pluginId: 'p',
actingUserId,
data: {} as PluginRpcContext['data'],
// No case below dispatches to a peer plugin, but the peers are a real collaborator
// on the context, so they get a stub that fails loudly rather than an empty object
// whose methods would be undefined the moment a handler reached for one.
plugins: {
call: () => Promise.reject(new Error('ctxFor: no peer plugin router in these cases')),
emit: () => {
throw new Error('ctxFor: no peer plugin router in these cases');
},
},
});
/** A well-formed controller: two tags methods with the permissions the table assigns. */