fix(plugins): let an admin run a plugin outside its TREK range, and tidy the plugins panel

TREK 5.0 left most registry plugins blocked because their authors still declare
"<5.0.0", and the only way past that was TREK_PLUGINS_IGNORE_TREK_RANGE for every
plugin at once. An admin can now install or switch on one such plugin after a
warning; the consent is kept on its row for that plugin version and TREK major,
so an update or a new major asks again. The environment switch works as before.

Discover marks a plugin not confirmed for this TREK on its card, and Install opens
the warning first. Admin > Plugins reads cleaner: one row of alike facts per plugin
with each state that needs attention on its own line, type, status and order behind
one Filter button, and the containment notes in a dialog behind the shield in the
header. The row, the filter menu and the dialog moved into their own files.
This commit is contained in:
Maurice
2026-10-26 00:48:13 +01:00
parent d589da59f2
commit 0067b0ff19
62 changed files with 1673 additions and 575 deletions
@@ -818,14 +818,27 @@ describe('PluginRuntimeService.retrust', () => {
* host it declared it doesn't support — would otherwise be spawned on the next boot.
*/
describe('TREK host-version gating', () => {
const seedRanged = (id: string, trekRange: string | null, enabled = 0) => {
const seedRanged = (
id: string,
trekRange: string | null,
enabled = 0,
accepted: { version?: string; acceptedVersion?: string; acceptedHost?: string } = {},
) => {
fs.mkdirSync(path.join(codeRoot, id, 'server'), { recursive: true });
fs.writeFileSync(path.join(codeRoot, id, 'server', 'index.js'), 'module.exports = { async onLoad() {} };');
testDb
.prepare(
"INSERT INTO plugins (id, status, enabled, permissions, granted_permissions, config, trek_range) VALUES (?, ?, ?, '[]', '[]', '{}', ?)",
"INSERT INTO plugins (id, status, enabled, permissions, granted_permissions, config, trek_range, version, trek_range_accepted_version, trek_range_accepted_host) VALUES (?, ?, ?, '[]', '[]', '{}', ?, ?, ?, ?)",
)
.run(id, enabled ? 'active' : 'inactive', enabled, trekRange);
.run(
id,
enabled ? 'active' : 'inactive',
enabled,
trekRange,
accepted.version ?? null,
accepted.acceptedVersion ?? null,
accepted.acceptedHost ?? null,
);
};
const cleanup = (...ids: string[]) => {
for (const id of ids) testDb.prepare('DELETE FROM plugins WHERE id = ?').run(id);
@@ -919,6 +932,43 @@ describe('TREK host-version gating', () => {
});
});
it("runs an outgrown plugin on the admin's say-so, and does not ask a second time", async () => {
process.env.APP_VERSION = '5.0.0';
seedRanged('say-so', '>=3.2.0 <4.0.0', 0, { version: '1.0.3' });
const warn = vi.spyOn(console, 'warn').mockImplementation(() => {});
const rt = await createPluginRuntime(dbConn);
await rt.activate('say-so', false, true);
expect(rt.isActive('say-so')).toBe(true);
expect(warn.mock.calls.some((c) => /say-so.*an admin chose to run it anyway/.test(String(c[0])))).toBe(true);
await rt.deactivate('say-so');
// The consent was kept with the row, so switching it on again needs no second one.
await rt.activate('say-so');
expect(rt.isActive('say-so')).toBe(true);
await rt.deactivate('say-so');
warn.mockRestore();
cleanup('say-so');
});
it("keeps the admin's consent for the version and TREK major it was given on only", async () => {
const given = { acceptedVersion: '1.0.3', acceptedHost: '5.0.0' };
const warn = vi.spyOn(console, 'warn').mockImplementation(() => {});
process.env.APP_VERSION = '5.0.1';
seedRanged('kept', '>=3.2.0 <4.0.0', 0, { version: '1.0.3', ...given });
seedRanged('updated', '>=3.2.0 <4.0.0', 0, { version: '1.1.0', ...given });
const rt = await createPluginRuntime(dbConn);
await rt.activate('kept');
expect(rt.isActive('kept')).toBe(true);
await rt.deactivate('kept');
// An update of the plugin asks again.
await expect(rt.activate('updated')).rejects.toMatchObject({ code: 'TREK_VERSION_INCOMPATIBLE' });
// So does a new TREK major.
process.env.APP_VERSION = '6.0.0';
await expect(rt.activate('kept')).rejects.toMatchObject({ code: 'TREK_VERSION_INCOMPATIBLE' });
warn.mockRestore();
cleanup('kept', 'updated');
});
it('checks the version BEFORE permissions — an unrunnable plugin gets no consent dialog', async () => {
// Consenting to permissions would not make it start, so offering the dialog is a lie.
process.env.APP_VERSION = '4.0.0';