mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-24 13:53:09 +00:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 7fe4fbb683 |
@@ -13,7 +13,7 @@
|
||||
"src/nest/doc-sync/providers/synology-drive.client.ts": 1160,
|
||||
"src/nest/journey/journey-domain.service.ts": 1659,
|
||||
"src/nest/places/places.service.ts": 1546,
|
||||
"src/nest/plugins/plugin-runtime.service.ts": 1459,
|
||||
"src/nest/plugins/plugin-runtime.service.ts": 1458,
|
||||
"src/nest/plugins/runtime/plugin-sdk.ts": 1093,
|
||||
"src/nest/reservations/reservations.service.ts": 1163,
|
||||
"src/nest/vacay/vacay.service.ts": 1393
|
||||
|
||||
@@ -386,31 +386,25 @@ export class PluginRuntimeService implements OnApplicationBootstrap, OnModuleDes
|
||||
// own gate still refuses to spawn, so nothing boots into a broken state.
|
||||
order = enabledIds;
|
||||
}
|
||||
// task-6-rereview.md I1: assertActivatable (inside activate) reads
|
||||
// AddonsService.isAddonEnabled — repository-backed — so this boot loop needs
|
||||
// the same request-context wrap every other D6 choke point got, or an
|
||||
// enabled plugin with a non-empty requiredAddons throws cannotUseGlobalContext
|
||||
// here, silently: the .catch below only reconciles PluginDependencyError /
|
||||
// DependencyCycleError, and the outer try/catch around this whole block eats
|
||||
// everything else.
|
||||
// `activate()` itself stays unwrapped (its HTTP callers already run inside a
|
||||
// request); only this boot-time call site needs it. Fail closed the same way
|
||||
// the boot RULING (task-6-rereview.md §2) settled for CronRegistrarService.
|
||||
// runOnBoot: no ORM means skip loudly and never call activate — never abort
|
||||
// app.init() over a partially-wired test graph.
|
||||
// activate() reads repositories, so this boot-time call site opens its own request
|
||||
// context (its HTTP callers already run inside one). No ORM means skip loudly and
|
||||
// never call activate, never abort app.init() over a partially-wired test graph.
|
||||
if (!this.orm) {
|
||||
// Plan 3j Task 2: `order`/`enabledIds` are always empty here now (see the
|
||||
// `installed = new Map()` note above) — the message can no longer name
|
||||
// specific plugins, only that boot skipped activation entirely.
|
||||
logError('PluginRuntimeService.onApplicationBootstrap: no MikroORM available — plugin activation skipped');
|
||||
} else {
|
||||
const orm = this.orm;
|
||||
for (const id of order) {
|
||||
withRequestContext(this.orm, () => this.activate(id)).catch((e) => {
|
||||
withRequestContext(orm, () => this.activate(id)).catch((e) => {
|
||||
// A plugin whose required addon is off (or a dependency is missing) at boot
|
||||
// must not stay marked enabled — reconcile the row so the UI reflects reality.
|
||||
if (e instanceof PluginDependencyError || e instanceof DependencyCycleError) {
|
||||
this.deactivate(id).catch(() => {});
|
||||
}
|
||||
// A refused re-consent never reaches the supervisor hook, which leaves last run's 'active' row.
|
||||
if (e instanceof PluginConsentRequired) void this.markBootRefused(orm, id, e.message);
|
||||
/* other failures: status is persisted as error by the supervisor hook */
|
||||
});
|
||||
}
|
||||
@@ -820,6 +814,11 @@ export class PluginRuntimeService implements OnApplicationBootstrap, OnModuleDes
|
||||
return true;
|
||||
}
|
||||
|
||||
/** @txStandalone a status note on one plugin row that stands whatever the boot loop does. */
|
||||
private async markBootRefused(orm: MikroORM, id: string, message: string): Promise<void> {
|
||||
await withRequestContext(orm, () => this.plugins.updateStatusAndError(id, 'error', message)).catch(() => {});
|
||||
}
|
||||
|
||||
async deactivate(id: string): Promise<void> {
|
||||
await this.supervisor.disable(id);
|
||||
closePluginDataDb(id);
|
||||
|
||||
@@ -573,3 +573,38 @@ describe('Plan 3j Task 2 — two racing ticks (scheduler claim/re-arm + erasure
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe('onApplicationBootstrap: a plugin that cannot start keeps no stale active row', () => {
|
||||
async function bootAndSettle(id: string, status: string) {
|
||||
const rt = await buildRuntime();
|
||||
await rt.onApplicationBootstrap();
|
||||
await vi.waitFor(async () => expect((await pluginRow(id)).status).toBe(status), { timeout: 1000, interval: 25 });
|
||||
await rt.onModuleDestroy();
|
||||
}
|
||||
|
||||
it('BOOT-STATUS-001: new permissions awaiting consent leave the row in error with the reason', async () => {
|
||||
const id = 'boot-widened';
|
||||
// active from the last run; the stored manifest now declares db:read:users on top of the grant
|
||||
await seedPlugin(id, { enabled: 1, permissions: '["db:own","db:read:users"]', granted_permissions: '["db:own"]' });
|
||||
await updateRows(t, Plugins, { id }, { status: 'active' });
|
||||
|
||||
await bootAndSettle(id, 'error');
|
||||
|
||||
const row = await pluginRow(id);
|
||||
expect(row.status).toBe('error');
|
||||
expect(row.last_error).toBe(`plugin ${id} requests new permissions; explicit re-consent is required`);
|
||||
expect(row.enabled).toBe(1);
|
||||
});
|
||||
|
||||
it('BOOT-STATUS-002: a dependency refusal still turns the plugin off instead of marking it error', async () => {
|
||||
const id = 'boot-api-too-new';
|
||||
await seedPlugin(id, { enabled: 1, api_version: 999 });
|
||||
await updateRows(t, Plugins, { id }, { status: 'active' });
|
||||
|
||||
await bootAndSettle(id, 'inactive');
|
||||
|
||||
const row = await pluginRow(id);
|
||||
expect(row.status).toBe('inactive');
|
||||
expect(row.enabled).toBe(0);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user