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
+37 -3
View File
@@ -6,6 +6,7 @@ import {
hostSatisfies,
trekRangeBypassed,
bypassedRange,
acceptanceHolds,
__resetHostWarningForTests,
} from '../../../src/nest/plugins/install/host-compat';
@@ -125,6 +126,27 @@ describe('hostSatisfies', () => {
* the truth (hostSatisfies) never changes — the UI still has to say the plugin is
* outside its range.
*/
describe('acceptanceHolds', () => {
it('holds for the same plugin version on the same TREK major only', () => {
process.env.APP_VERSION = '5.0.1';
const given = { acceptedVersion: '1.0.3', acceptedHost: '5.0.0' };
expect(acceptanceHolds('1.0.3', given)).toBe(true);
expect(acceptanceHolds('1.1.0', given)).toBe(false); // an update asks again
process.env.APP_VERSION = '6.0.0';
expect(acceptanceHolds('1.0.3', given)).toBe(false); // so does a new TREK major
});
it('holds nothing without a full consent or a version to compare', () => {
process.env.APP_VERSION = '5.0.0';
expect(acceptanceHolds('1.0.0', null)).toBe(false);
expect(acceptanceHolds('1.0.0', { acceptedVersion: '1.0.0', acceptedHost: null })).toBe(false);
expect(acceptanceHolds(null, { acceptedVersion: '1.0.0', acceptedHost: '5.0.0' })).toBe(false);
expect(acceptanceHolds('1.0.0', { acceptedVersion: '1.0.0', acceptedHost: 'not-a-version' })).toBe(false);
process.env.APP_VERSION = 'dev';
expect(acceptanceHolds('1.0.0', { acceptedVersion: '1.0.0', acceptedHost: '5.0.0' })).toBe(false);
});
});
describe('range bypass (TREK_PLUGINS_IGNORE_TREK_RANGE)', () => {
it('is off by default and only an explicit truthy value turns it on', () => {
expect(trekRangeBypassed()).toBe(false);
@@ -138,15 +160,27 @@ describe('range bypass (TREK_PLUGINS_IGNORE_TREK_RANGE)', () => {
process.env.APP_VERSION = '3.3.0';
expect(bypassedRange('>=4.0.0')).toBeNull(); // off → the gate refuses, nothing to report
process.env.TREK_PLUGINS_IGNORE_TREK_RANGE = 'true';
expect(bypassedRange('>=4.0.0')).toEqual({ trekRange: '>=4.0.0', hostVersion: '3.3.0' });
expect(bypassedRange('>=4.0.0')).toEqual({ trekRange: '>=4.0.0', hostVersion: '3.3.0', acceptedByAdmin: false });
expect(bypassedRange('>=3.2.0 <4.0.0')).toBeNull(); // fits → not a bypass, a normal install
});
it('covers a plugin that declared no range at all — the same author oversight', () => {
process.env.APP_VERSION = '3.3.0';
process.env.TREK_PLUGINS_IGNORE_TREK_RANGE = '1';
expect(bypassedRange(null)).toEqual({ trekRange: null, hostVersion: '3.3.0' });
expect(bypassedRange(undefined)).toEqual({ trekRange: null, hostVersion: '3.3.0' });
expect(bypassedRange(null)).toEqual({ trekRange: null, hostVersion: '3.3.0', acceptedByAdmin: false });
expect(bypassedRange(undefined)).toEqual({ trekRange: null, hostVersion: '3.3.0', acceptedByAdmin: false });
});
it("an admin's consent for one plugin lets it through without the switch, and says it was theirs", () => {
process.env.APP_VERSION = '5.0.0';
expect(bypassedRange('>=3.2.0 <4.0.0', true)).toEqual({
trekRange: '>=3.2.0 <4.0.0',
hostVersion: '5.0.0',
acceptedByAdmin: true,
});
expect(bypassedRange('>=5.0.0', true)).toBeNull(); // fits: nothing was set aside
process.env.TREK_PLUGINS_IGNORE_TREK_RANGE = '1';
expect(bypassedRange('>=3.2.0 <4.0.0', true)).toMatchObject({ acceptedByAdmin: false });
});
it('leaves hostSatisfies telling the truth while bypassed', () => {
@@ -134,10 +134,32 @@ describe('PluginsService.list', () => {
expect(out.ignoreTrekRange).toBe(true);
expect(out.plugins[0]).toMatchObject({
dependencyStatus: 'ok',
trekRangeBypassed: { trekRange: '>=3.0.0 <4.0.0', hostVersion: '4.1.0' },
trekRangeBypassed: { trekRange: '>=3.0.0 <4.0.0', hostVersion: '4.1.0', acceptedByAdmin: false },
});
});
it("an admin's consent for this version lets the outgrown plugin activate and names it as theirs", async () => {
process.env.APP_VERSION = '4.1.0';
await insertRow(orm, Plugins, {
id: 'old',
name: 'Old',
type: 'widget',
status: 'inactive',
version: '1.0.0',
trek_range: '>=3.0.0 <4.0.0',
trek_range_accepted_version: '1.0.0',
trek_range_accepted_host: '4.0.0',
});
const out = await (await makeService()).list();
expect(out.ignoreTrekRange).toBe(false);
expect(out.plugins[0]).toMatchObject({
dependencyStatus: 'ok',
trekRangeBypassed: { trekRange: '>=3.0.0 <4.0.0', hostVersion: '4.1.0', acceptedByAdmin: true },
});
// The consent stays on the server: the list does not hand its columns out.
expect(out.plugins[0]).not.toHaveProperty('trek_range_accepted_version');
});
it('a plugin inside its range carries no marker even with the switch on', async () => {
process.env.APP_VERSION = '3.5.0';
process.env.TREK_PLUGINS_IGNORE_TREK_RANGE = '1';