mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-28 23:50:08 +00:00
6680bc7c74
PluginsModule was 21 controllers, 24 domain imports and 10 providers in one class, which made it the hub most of the Nest graph ran through: AdminModule imported it for a single cascade-disable call and inherited all of it. It is now PluginsRuntimeModule (supervisor, capability router, hook contracts), PluginContributionsModule (the 14 read-only hook controllers, moved to contributions/), PluginOAuthModule (the credential leaf, moved to oauth/) and a composition root that keeps the install and delivery controllers. AdminModule imports the runtime alone. The three plugin files that reached for the db singleton alongside the injected DatabaseService no longer do. plugin-host-state and signature-status take the connection from the caller, and the three per-user settings functions that were bare exports 'so the RPC host wiring can call them directly' are now PluginUserSettingsService - the host wiring is providers, so it injects them. Coverage moves from one repo-wide 80% to a per-domain ratchet. The single number let a well-covered domain subsidise a thin one: booking-import sits at 50% and integrations at 20%, and the aggregate still cleared the bar, so either could have lost another ten points unnoticed. Each domain now carries its own measured floor, regenerated by scripts/coverage-thresholds.mjs. Two test-side findings on the way: expect(undefined).toContain(SomeClass) PASSES in this vitest version - it only throws for a string needle. Every '<X> is listed in its module providers' guard was written that way, so all twelve of them silently stopped guarding the moment their class moved. They go through expectRegisteredProvider now, which asserts the array shape first. The atlas region test paid for the one-off decompression of the multi-MB admin1 bundle inside its own 5s budget, which is why it failed under load and passed alone. The bundle is warmed in beforeAll instead.
90 lines
4.5 KiB
TypeScript
90 lines
4.5 KiB
TypeScript
import { vi } from 'vitest';
|
|
import type { HostDeps } from '../../src/nest/plugins/host/rpc-host';
|
|
import { TagsRpc } from '../../src/nest/tags/tags.rpc';
|
|
import { CategoriesRpc } from '../../src/nest/categories/categories.rpc';
|
|
import { WeatherRpc } from '../../src/nest/weather/weather.rpc';
|
|
import { ExchangeRatesRpc } from '../../src/nest/budget/exchange-rates.rpc';
|
|
import { TodoRpc } from '../../src/nest/todo/todo.rpc';
|
|
import { DayNotesRpc } from '../../src/nest/days/day-notes.rpc';
|
|
import { PackingRpc } from '../../src/nest/packing/packing.rpc';
|
|
import { FilesRpc } from '../../src/nest/files/files.rpc';
|
|
import { PlacesRpc } from '../../src/nest/places/places.rpc';
|
|
import { DaysRpc } from '../../src/nest/days/days.rpc';
|
|
import { ItineraryRpc } from '../../src/nest/assignments/itinerary.rpc';
|
|
import { TripsRpc } from '../../src/nest/trips/trips.rpc';
|
|
import { CostsRpc } from '../../src/nest/budget/costs.rpc';
|
|
import { ReservationsRpc } from '../../src/nest/reservations/reservations.rpc';
|
|
import { AccommodationsRpc } from '../../src/nest/days/accommodations.rpc';
|
|
import { CollabRpc } from '../../src/nest/collab/collab.rpc';
|
|
import { AtlasRpc } from '../../src/nest/atlas/atlas.rpc';
|
|
import { VacayRpc } from '../../src/nest/vacay/vacay.rpc';
|
|
import { JournalRpc } from '../../src/nest/journey/journal.rpc';
|
|
import { CollectionsRpc } from '../../src/nest/collections/collections.rpc';
|
|
import { DbRpc } from '../../src/nest/plugins/host/rpc/db.rpc';
|
|
import { MetaRpc } from '../../src/nest/plugins/host/rpc/meta.rpc';
|
|
import { HostSurfaceRpc } from '../../src/nest/plugins/host/rpc/host-surface.rpc';
|
|
import { PluginHooks } from '../../src/nest/plugins/plugin-hooks.service';
|
|
|
|
/**
|
|
* The stubbed HostDeps every plugin router test builds on.
|
|
*
|
|
* It used to be a 150-line sheet of domain stubs, because the router held every
|
|
* handler. The handlers now live on the domains' `@PluginController()` classes and
|
|
* stub their own services, so what is left here is what the router itself still
|
|
* touches: the plugin's own db handle, the inter-plugin router, and the audit sink.
|
|
*/
|
|
export function makeDeps(): HostDeps {
|
|
return {
|
|
data: {
|
|
query: vi.fn(() => [{ n: 1 }]),
|
|
exec: vi.fn(() => ({ changes: 1 })),
|
|
migrate: vi.fn(() => ({ applied: true })),
|
|
tx: vi.fn(() => ({ ok: true })),
|
|
close: vi.fn(),
|
|
} as unknown as HostDeps['data'],
|
|
callPlugin: vi.fn(async (targetId: string, fn: string) => ({ calledTarget: targetId, calledFn: fn })),
|
|
emitPluginEvent: vi.fn(),
|
|
};
|
|
}
|
|
|
|
/**
|
|
* Every @PluginController() class that owns wire methods, in the order the container
|
|
* would discover them. The coverage ledger test (tests/unit/plugins/rpc-coverage.test.ts)
|
|
* is what turns a forgotten entry into a red build instead of a silent
|
|
* PERMISSION_DENIED in production.
|
|
*
|
|
* The services handed in are stubs: the ledger only binds the handlers, it never runs
|
|
* them. Behaviour is asserted in each domain's own <domain>.rpc.test.ts.
|
|
*/
|
|
export function allRpcControllers(): object[] {
|
|
const anyService = () =>
|
|
new Proxy({}, { get: () => vi.fn(() => undefined) }) as unknown as never;
|
|
return [
|
|
new TagsRpc(anyService()),
|
|
new CategoriesRpc(anyService()),
|
|
new WeatherRpc(anyService()),
|
|
new ExchangeRatesRpc(anyService()),
|
|
new TodoRpc(anyService(), anyService(), anyService()),
|
|
new DayNotesRpc(anyService(), anyService(), anyService()),
|
|
new PackingRpc(anyService(), anyService(), anyService()),
|
|
new FilesRpc(anyService(), anyService(), anyService(), anyService()),
|
|
new PlacesRpc(anyService(), anyService(), anyService(), anyService()),
|
|
new DaysRpc(anyService(), anyService(), anyService()),
|
|
new ItineraryRpc(anyService(), anyService(), anyService()),
|
|
new TripsRpc(anyService(), anyService(), anyService(), anyService(), anyService(), anyService(), anyService()),
|
|
new CostsRpc(anyService(), anyService(), anyService(), anyService()),
|
|
new ReservationsRpc(anyService(), anyService(), anyService()),
|
|
new AccommodationsRpc(anyService(), anyService(), anyService()),
|
|
new CollabRpc(anyService(), anyService(), anyService()),
|
|
new AtlasRpc(anyService(), anyService()),
|
|
new VacayRpc(anyService(), anyService()),
|
|
new JournalRpc(anyService(), anyService()),
|
|
new CollectionsRpc(anyService(), anyService()),
|
|
new DbRpc(anyService()),
|
|
new MetaRpc(anyService(), anyService()),
|
|
new HostSurfaceRpc(anyService(), anyService(), anyService(), anyService(), anyService(), anyService()),
|
|
// Owns no wire method, but declares all 18 hook contracts, which requireTotalCoverage checks too.
|
|
new PluginHooks(anyService()),
|
|
];
|
|
}
|