Finish the plugin RPC decorator rollout

The last 20 wire methods move onto the decorators: db.* and the three
unconditional methods (DbRpc), meta.* (MetaRpc) and the host-mediated surface
of users/broadcasts/notify/ai/oauth/scheduler (HostSurfaceRpc). That closes the
ledger at 113/113, so the legacy has() blocks in rpc-host.ts are gone and the
router is down to what was never domain-specific: build the granted subset of
the dispatch map, dispatch, audit, map errors.

PluginHostDepsFactory was the 26-argument wiring sheet behind those blocks. With
the handlers in the domains it has two dependencies left, so it is now
PluginRpcHostFactory: the plugin's own sqlite handle, the inter-plugin router
bound with this plugin as the caller, and the audit sink.

The 18 host-to-plugin hook calls get the same treatment. They used to spell out
the fn name and the timeout at each controller, which meant nothing checked that
a hook:* grant on the consent screen had a consumer behind it, that the fn
matched what the SDK documents, or that two call sites agreed on the budget.
PluginHooks declares all 18 with @PluginHook and performs them, and the
controllers call it by name.

With both halves complete, requireTotalCoverage goes on: a KNOWN_METHOD without
a handler, or a hook without a consumer, now fails app boot instead of surfacing
as a PERMISSION_DENIED nobody can explain.
This commit is contained in:
Maurice
2026-08-09 17:15:53 +02:00
committed by Maurice
parent 611f94e820
commit f72aba0c91
74 changed files with 1942 additions and 2164 deletions
@@ -21,15 +21,15 @@ import { DatabaseService } from '../../../src/nest/database/database.service';
vi.mock('../../../src/nest/plugins/kill-switch', () => ({ pluginsEnabled }));
import { PluginRoutesController } from '../../../src/nest/plugins/plugin-routes.controller';
import type { PluginRuntimeService } from '../../../src/nest/plugins/plugin-runtime.service';
import type { PluginHooks } from '../../../src/nest/plugins/plugin-hooks.service';
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const req = (id?: number) => ({ user: id === undefined ? undefined : { id } }) as any;
function controller(invoke: () => unknown, providers = ['ev-plug']) {
const runtime = {
providersOf: vi.fn(() => providers),
invokeHook: vi.fn(async () => invoke()),
} as unknown as PluginRuntimeService;
route: vi.fn(async () => invoke()),
} as unknown as PluginHooks;
return { c: new PluginRoutesController(runtime, new DatabaseService(dbConn)), runtime };
}
const wp = (n = 3) => Array.from({ length: n }, (_, i) => ({ lat: 48 + i * 0.1, lng: 2 + i * 0.1 }));
@@ -74,7 +74,7 @@ describe('PluginRoutesController', () => {
for (const b of cases) {
const { c, runtime } = controller(() => goodRoute());
expect((await c.route('ev-plug', 'ev', b as never, req(5))).route).toBeNull();
expect(runtime.invokeHook).not.toHaveBeenCalled();
expect(runtime.route).not.toHaveBeenCalled();
}
});
@@ -97,11 +97,7 @@ describe('PluginRoutesController', () => {
expect(route!.profile).toBe('ev');
expect(route!.legs[0].note).toBe('charge to 80%');
expect(route!.viaPoints[0]).toMatchObject({ label: 'Fastned', tone: 'success', dwellSeconds: 1501 });
expect(runtime.invokeHook).toHaveBeenCalledWith(
'ev-plug', 'routeProvider', 'getRoute',
[{ tripId: 1, dayId: 7, profile: 'ev', waypoints: wp() }],
5, 20_000,
);
expect(runtime.route).toHaveBeenCalledWith('ev-plug', { tripId: 1, dayId: 7, profile: 'ev', waypoints: wp() }, 5);
});
it('rejects a malformed route whole: wrong leg count, bad vertex, negative numbers', async () => {