mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-05 10:24:05 +00:00
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:
@@ -74,5 +74,8 @@ from the generated `plugin-sdk/src/generated/host-facts.ts` instead.
|
||||
A `@PluginController()` class that is missing from its module's `providers: []` is
|
||||
invisible to discovery. Its methods are simply never bound, and every call to them
|
||||
comes back `PERMISSION_DENIED` with no other symptom. The compiler cannot see this.
|
||||
What catches it is `server/tests/unit/plugins/rpc-coverage.test.ts`, and, once the
|
||||
rollout is finished, `requireTotalCoverage: true` turning it into a boot failure.
|
||||
|
||||
`requireTotalCoverage` is now on, so the app refuses to boot instead: `validate()`
|
||||
names every `KNOWN_METHOD` left without a handler, and every hook left without a
|
||||
host-side consumer. `server/tests/unit/plugins/rpc-coverage.test.ts` catches the same
|
||||
gap in CI, before anyone starts the server.
|
||||
|
||||
@@ -17,12 +17,29 @@ export class PluginRpcRegistryService extends PluginRpcRegistry implements OnMod
|
||||
private readonly discovery: DiscoveryService,
|
||||
private readonly scanner: MetadataScanner,
|
||||
) {
|
||||
// Flipped to true in the closing PR of the rollout, once the legacy router map
|
||||
// in rpc-host.ts is empty and every KNOWN_METHOD has a decorated owner.
|
||||
super({ requireTotalCoverage: false });
|
||||
// The rollout is done: the legacy router map is gone, every KNOWN_METHOD has a
|
||||
// decorated owner and every hook has a host-side consumer. Boot now FAILS on a
|
||||
// gap rather than letting it surface as a runtime PERMISSION_DENIED, or as a
|
||||
// hook:* grant on the consent screen that nothing behind it ever calls.
|
||||
super({ requireTotalCoverage: true });
|
||||
}
|
||||
|
||||
onModuleInit(): void {
|
||||
this.scanProviders();
|
||||
// Fail app boot on a wrong decorator argument, a double-owned method or a gap in
|
||||
// the surface, rather than failing per-plugin at activation time.
|
||||
this.validate();
|
||||
}
|
||||
|
||||
/**
|
||||
* Records every `@PluginController()` provider the container knows about.
|
||||
*
|
||||
* Separate from validate() because the two answer different questions: this one is
|
||||
* about discovery (which providers were found, and once each), validate() is about
|
||||
* the surface being complete and correctly declared. Keeping them apart lets the
|
||||
* discovery behaviour be tested without assembling all 113 methods first.
|
||||
*/
|
||||
scanProviders(): void {
|
||||
// A provider can be wrapped once per module that lists it, so dedupe by instance
|
||||
// or every entry is recorded twice and the duplicate check fires spuriously.
|
||||
const seen = new Set<object>();
|
||||
@@ -33,8 +50,5 @@ export class PluginRpcRegistryService extends PluginRpcRegistry implements OnMod
|
||||
seen.add(instance);
|
||||
this.register(instance, this.scanner.getAllMethodNames(Object.getPrototypeOf(instance)));
|
||||
}
|
||||
// Fail app boot on a wrong decorator argument or a double-owned method rather
|
||||
// than failing per-plugin at activation time.
|
||||
this.validate();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,22 @@ export interface PluginRpcContext {
|
||||
readonly pluginId: string;
|
||||
readonly actingUserId: number | undefined;
|
||||
readonly data: PluginDataDb;
|
||||
/**
|
||||
* The inter-plugin capabilities. PER HOST, like everything else on this context:
|
||||
* the router that backs them is created per plugin and binds THIS plugin as the
|
||||
* caller, which is what lets it authorise a call against the declared dependency
|
||||
* edge and the target's provides/emits allowlist.
|
||||
*
|
||||
* Typed structurally rather than imported, so the kit stays free of host imports
|
||||
* (see rpc-kit/README.md). The host supplies the real router when it binds.
|
||||
*/
|
||||
readonly plugins: PluginRpcPeers;
|
||||
}
|
||||
|
||||
/** What a plugin may do to its declared dependencies. */
|
||||
export interface PluginRpcPeers {
|
||||
call(targetId: string, fn: string, args: unknown, actingUserId: number | undefined): Promise<unknown>;
|
||||
emit(event: string, payload: unknown): void;
|
||||
}
|
||||
|
||||
export type PluginRpcHandler = (params: Record<string, unknown>, ctx: PluginRpcContext) => unknown;
|
||||
|
||||
Reference in New Issue
Block a user