mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-10-19 21:46:49 +00:00
Split PluginsModule into four, and gate coverage per domain
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.
This commit is contained in:
@@ -1,88 +1,44 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { DiscoveryModule } from '@nestjs/core';
|
||||
import { JourneyDomainModule } from '../journey/journey-domain.module';
|
||||
import { PluginsController } from './plugins.controller';
|
||||
import { PluginsFeedController } from './plugins-feed.controller';
|
||||
import { PluginsProxyController } from './plugins-proxy.controller';
|
||||
import { PluginFrameController } from './plugin-frame.controller';
|
||||
import { PlaceDetailsController } from './place-details.controller';
|
||||
import { TripWarningsController } from './trip-warnings.controller';
|
||||
import { ViewContributionsController } from './view-contributions.controller';
|
||||
import { TripCardContributionsController } from './trip-card-contributions.controller';
|
||||
import { PluginPhotosController } from './plugin-photos.controller';
|
||||
import { PluginCalendarController } from './plugin-calendar.controller';
|
||||
import { MapMarkersController } from './map-markers.controller';
|
||||
import { MapLayersController } from './map-layers.controller';
|
||||
import { PluginRoutesController } from './plugin-routes.controller';
|
||||
import { DayScheduleController } from './day-schedule.controller';
|
||||
import { DayTintsController } from './day-tints.controller';
|
||||
import { PluginActivityController } from './plugin-activity.controller';
|
||||
import { PdfSectionsController } from './pdf-sections.controller';
|
||||
import { AtlasLayersController } from './atlas-layers.controller';
|
||||
import { JournalEntryRowsController } from './journal-entry-rows.controller';
|
||||
import { PluginUserSettingsController } from './plugin-user-settings.controller';
|
||||
import { PluginOAuthController } from './plugin-oauth.controller';
|
||||
import { PluginOAuthService } from './plugin-oauth.service';
|
||||
import { PluginsService } from './plugins.service';
|
||||
import { PluginRuntimeService } from './plugin-runtime.service';
|
||||
import { PluginHooks } from './plugin-hooks.service';
|
||||
import { PluginRegistryService } from './registry/registry.service';
|
||||
import { PluginRpcHostFactory } from './host/plugin-rpc-host.factory';
|
||||
import { PluginRpcRegistryService } from './host/rpc-kit/registry.service';
|
||||
import { PluginGuardsModule } from './host/plugin-guards.module';
|
||||
import { DbRpc } from './host/rpc/db.rpc';
|
||||
import { MetaRpc } from './host/rpc/meta.rpc';
|
||||
import { HostSurfaceRpc } from './host/rpc/host-surface.rpc';
|
||||
import { WeatherModule } from '../weather/weather.module';
|
||||
import { TagsModule } from '../tags/tags.module';
|
||||
import { CategoriesModule } from '../categories/categories.module';
|
||||
import { BudgetModule } from '../budget/budget.module';
|
||||
import { ReservationsModule } from '../reservations/reservations.module';
|
||||
import { TodoModule } from '../todo/todo.module';
|
||||
import { PackingModule } from '../packing/packing.module';
|
||||
import { DaysModule } from '../days/days.module';
|
||||
import { AssignmentsModule } from '../assignments/assignments.module';
|
||||
import { LlmParseModule } from '../llm-parse/llm-parse.module';
|
||||
import { FilesModule } from '../files/files.module';
|
||||
import { CollabModule } from '../collab/collab.module';
|
||||
import { VacayModule } from '../vacay/vacay.module';
|
||||
import { TripsModule } from '../trips/trips.module';
|
||||
import { PlacesModule } from '../places/places.module';
|
||||
import { PermissionsModule } from '../permissions/permissions.module';
|
||||
import { AuditModule } from '../audit/audit.module';
|
||||
import { AddonsModule } from '../addons/addons.module';
|
||||
import { CollectionsModule } from '../collections/collections.module';
|
||||
import { AtlasModule } from '../atlas/atlas.module';
|
||||
import { NotificationsModule } from '../notifications/notifications.module';
|
||||
import { TripMembershipModule } from '../trip-membership/trip-membership.module';
|
||||
import { PluginsRuntimeModule } from './plugins-runtime.module';
|
||||
import { PluginOAuthModule } from './oauth/plugin-oauth.module';
|
||||
import { PluginContributionsModule } from './contributions/plugin-contributions.module';
|
||||
|
||||
/**
|
||||
* Plugin system (#plugins). M0 read side + M2 isolated runtime + M3 frontend:
|
||||
* the runtime service owns the process supervisor and boots active plugins on
|
||||
* startup; the proxy forwards /api/plugins/:id/* to the child; the feed lists
|
||||
* active plugins for the client; the frame controller serves sandboxed page/
|
||||
* widget assets at /plugin-frame/:id/*.
|
||||
* Plugin system (#plugins), composition root.
|
||||
*
|
||||
* It used to be one module with 21 controllers, 24 domain imports and 10 providers,
|
||||
* which made it the hub almost the whole Nest graph ran through — AdminModule
|
||||
* imported it for one method and inherited all of that. It is now three pieces plus
|
||||
* this one:
|
||||
*
|
||||
* - `PluginsRuntimeModule` — supervisor, capability router, hook contracts. The half
|
||||
* with the domain imports, and the only half AdminModule needs.
|
||||
* - `PluginContributionsModule` — the 14 read-only hook controllers.
|
||||
* - `PluginOAuthModule` — the outbound-OAuth leaf.
|
||||
*
|
||||
* What is left here is the CRUD and delivery surface: install/activate/configure, the
|
||||
* feed the client reads, the proxy to a child's HTTP routes, and the sandboxed frame
|
||||
* that serves page and widget assets.
|
||||
*/
|
||||
@Module({
|
||||
// Every domain module whose @PluginController providers own part of the plugin wire
|
||||
// surface. The list has to be COMPLETE, not just "whatever this module's own code
|
||||
// needs": PluginRpcRegistryService validates total coverage at boot, so a domain
|
||||
// reachable only via AppModule would make PluginsModule fail to start in any test
|
||||
// app that assembles a subset (WeatherModule is here for exactly that reason, and
|
||||
// for nothing else). Importing PluginsModule therefore pulls in the whole surface.
|
||||
//
|
||||
// DatabaseModule is @Global, so not listed. DiscoveryModule is what lets
|
||||
// PluginRpcRegistryService find those providers at boot. PluginGuardsModule is a leaf
|
||||
// that hands the resource gates to the domain modules; it must not be this module,
|
||||
// because the domains would then have to import PluginsModule back and close a cycle.
|
||||
imports: [DiscoveryModule, PluginGuardsModule, WeatherModule, TagsModule, CategoriesModule, BudgetModule, ReservationsModule, TodoModule, PackingModule, DaysModule, AssignmentsModule, LlmParseModule, FilesModule, CollabModule, VacayModule, TripsModule, PermissionsModule, AuditModule, AddonsModule, PlacesModule, CollectionsModule, AtlasModule, NotificationsModule, TripMembershipModule, JourneyDomainModule],
|
||||
controllers: [PluginsController, PluginsFeedController, PluginsProxyController, PluginFrameController, PlaceDetailsController, TripWarningsController, ViewContributionsController, TripCardContributionsController, PluginPhotosController, PluginCalendarController, MapMarkersController, MapLayersController, PluginRoutesController, DayScheduleController, DayTintsController, PdfSectionsController, AtlasLayersController, JournalEntryRowsController, PluginUserSettingsController, PluginOAuthController, PluginActivityController],
|
||||
// DbRpc, MetaRpc and HostSurfaceRpc are the plugin surface that belongs to no
|
||||
// domain: the plugin's own sqlite, its namespaced entity metadata, and the
|
||||
// host-mediated calls (user lookup, broadcasts, notifications, LLM, OAuth, scheduler).
|
||||
providers: [PluginsService, PluginRuntimeService, PluginRegistryService, PluginOAuthService, PluginRpcHostFactory, PluginRpcRegistryService, PluginHooks, DbRpc, MetaRpc, HostSurfaceRpc],
|
||||
// Exported so the admin addon-toggle handler can cascade-disable plugins whose
|
||||
// required addon was just turned off (#plugins dependencies).
|
||||
exports: [PluginRuntimeService],
|
||||
imports: [PluginsRuntimeModule, PluginOAuthModule, PluginContributionsModule],
|
||||
controllers: [
|
||||
PluginsController,
|
||||
PluginsFeedController,
|
||||
PluginsProxyController,
|
||||
PluginFrameController,
|
||||
PluginUserSettingsController,
|
||||
PluginActivityController,
|
||||
],
|
||||
// Re-exported so AppModule keeps working unchanged. A consumer that only needs the
|
||||
// runtime imports PluginsRuntimeModule directly instead — that is the point of the
|
||||
// split.
|
||||
exports: [PluginsRuntimeModule],
|
||||
})
|
||||
export class PluginsModule {}
|
||||
|
||||
Reference in New Issue
Block a user