mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-28 23:50:08 +00:00
feat(plugins): enable the plugin system by default
The runtime and the Admin -> Plugins panel are now available out of the box; TREK_PLUGINS_ENABLED becomes an opt-out (set it to false to switch the whole system off). Installed plugins are still registered inactive and have to be activated one by one, so no third-party code runs until an admin turns a specific plugin on. Update the kill-switch default test and the plugin/env-var wiki pages to match.
This commit is contained in:
@@ -1,10 +1,15 @@
|
||||
/**
|
||||
* Plugin-system kill switch (#plugins). Off by default — a brand-new, high-risk
|
||||
* surface an instance owner must deliberately opt into. Lives in its own module
|
||||
* (not config.ts) so the many tests that mock config with a partial export set
|
||||
* don't have to know about it: the plugin runtime reads the env directly here.
|
||||
* Read at call time so tests and runtime env changes take effect immediately.
|
||||
* Plugin-system kill switch (#plugins). On by default — the runtime and the
|
||||
* Admin → Plugins panel are available out of the box, but installed plugins
|
||||
* still have to be activated one by one, so no third-party code runs until an
|
||||
* admin turns a specific plugin on. Set TREK_PLUGINS_ENABLED=false to switch the
|
||||
* whole system off (installed plugins stay on disk, deactivated). Lives in its
|
||||
* own module (not config.ts) so the many tests that mock config with a partial
|
||||
* export set don't have to know about it: the plugin runtime reads the env
|
||||
* directly here. Read at call time so tests and runtime env changes take effect
|
||||
* immediately.
|
||||
*/
|
||||
export function pluginsEnabled(): boolean {
|
||||
return (process.env.TREK_PLUGINS_ENABLED || '').trim().toLowerCase() === 'true';
|
||||
const v = (process.env.TREK_PLUGINS_ENABLED || '').trim().toLowerCase();
|
||||
return !['false', '0', 'off', 'no'].includes(v);
|
||||
}
|
||||
|
||||
@@ -43,7 +43,18 @@ describe('PluginsService.list', () => {
|
||||
expect(out.plugins[0]).toMatchObject({ id: 'flight', name: 'Flight', status: 'inactive' });
|
||||
});
|
||||
|
||||
it('reports disabled when the kill switch is off (default)', () => {
|
||||
it('reports enabled by default (no kill switch set)', () => {
|
||||
testDb
|
||||
.prepare('INSERT INTO plugins (id, name, description, type, status, version) VALUES (?,?,?,?,?,?)')
|
||||
.run('flight', 'Flight', 'desc', 'widget', 'inactive', '1.0.0');
|
||||
|
||||
const out = new PluginsService().list();
|
||||
expect(out.enabled).toBe(true);
|
||||
expect(out.plugins).toHaveLength(1);
|
||||
});
|
||||
|
||||
it('reports disabled when the kill switch is off (TREK_PLUGINS_ENABLED=false)', () => {
|
||||
process.env.TREK_PLUGINS_ENABLED = 'false';
|
||||
const out = new PluginsService().list();
|
||||
expect(out.enabled).toBe(false);
|
||||
expect(out.plugins).toEqual([]);
|
||||
|
||||
Reference in New Issue
Block a user