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
@@ -117,11 +117,11 @@ describe('PluginRuntimeService dev-link', () => {
try {
await expect(runtime.link(writeSource('oldplug-bypass', { trek: '>=2.0.0 <3.0.0' }))).resolves.toMatchObject({
id: 'oldplug-bypass',
trekRangeBypassed: { trekRange: '>=2.0.0 <3.0.0', hostVersion: '3.3.0' },
trekRangeBypassed: { trekRange: '>=2.0.0 <3.0.0', hostVersion: '3.3.0', acceptedByAdmin: false },
});
await expect(runtime.link(writeSource('rangeless-bypass', { trek: '' }))).resolves.toMatchObject({
id: 'rangeless-bypass',
trekRangeBypassed: { trekRange: null, hostVersion: '3.3.0' },
trekRangeBypassed: { trekRange: null, hostVersion: '3.3.0', acceptedByAdmin: false },
});
// A dir that fits is a plain link — no marker to alarm anyone with.
await expect(runtime.link(writeSource('fits-bypass'))).resolves.toMatchObject({ trekRangeBypassed: null });
@@ -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';
@@ -1193,6 +1193,43 @@ describe('TREK-version gating on install', () => {
expect(safeDownload).not.toHaveBeenCalled();
});
it("an admin's install-anyway takes the newest version when none fits, and keeps that consent on the row", async () => {
process.env.APP_VERSION = '4.0.0'; // both versions declare <4.0.0
stubMulti();
stageMulti('2.1.0', 0);
const warn = vi.spyOn(console, 'warn').mockImplementation(() => {});
await expect(svc.install('multi', { acceptTrekRange: true })).resolves.toEqual({
id: 'multi',
version: '2.1.0',
trekRangeBypassed: { trekRange: '>=3.4.0 <4.0.0', hostVersion: '4.0.0', acceptedByAdmin: true },
});
expect(warn.mock.calls.some((c) => /multi.*an admin chose to run it anyway/.test(String(c[0])))).toBe(true);
warn.mockRestore();
const row = await findRow(t, Plugins, { id: 'multi' });
expect(row).toMatchObject({ trek_range_accepted_version: '2.1.0', trek_range_accepted_host: '4.0.0' });
});
it("an admin's install-anyway still prefers a version that fits", async () => {
process.env.APP_VERSION = '3.3.0';
stubMulti();
stageMulti('2.0.0', 1);
await expect(svc.install('multi', { acceptTrekRange: true })).resolves.toEqual({
id: 'multi',
version: '2.0.0',
trekRangeBypassed: null,
});
expect(await findRow(t, Plugins, { id: 'multi' })).toMatchObject({ trek_range_accepted_version: null });
});
it("an admin's install-anyway covers the plugin they asked for, never a dependency", async () => {
process.env.APP_VERSION = '4.0.0';
stubMulti();
await expect(svc.resolveVersion('multi', undefined, false)).rejects.toMatchObject({
code: 'TREK_VERSION_INCOMPATIBLE',
});
await expect(svc.resolveVersion('multi', undefined, true)).resolves.toMatchObject({ version: '2.1.0' });
});
it('honours an EXCLUSIVE upper bound, which minTrekVersion alone cannot express', async () => {
// Both versions declare "<4.0.0" and neither carries a maxTrekVersion — under the old
// min-only check TREK 4 looked compatible with everything.
@@ -1223,7 +1260,7 @@ describe('TREK-version gating on install', () => {
await expect(svc.install('multi')).resolves.toEqual({
id: 'multi',
version: '2.1.0',
trekRangeBypassed: { trekRange: '>=3.4.0 <4.0.0', hostVersion: '3.3.0' },
trekRangeBypassed: { trekRange: '>=3.4.0 <4.0.0', hostVersion: '3.3.0', acceptedByAdmin: false },
});
expect(warn.mock.calls.some((c) => /multi.*>=3\.4\.0 <4\.0\.0.*3\.3\.0/.test(String(c[0])))).toBe(true);
warn.mockRestore();
@@ -1235,7 +1272,7 @@ describe('TREK-version gating on install', () => {
stageMulti('2.1.0', 0);
await expect(svc.install('multi', { version: '2.1.0' })).resolves.toMatchObject({
version: '2.1.0',
trekRangeBypassed: { trekRange: '>=3.4.0 <4.0.0', hostVersion: '3.3.0' },
trekRangeBypassed: { trekRange: '>=3.4.0 <4.0.0', hostVersion: '3.3.0', acceptedByAdmin: false },
});
});
@@ -1268,7 +1305,7 @@ describe('TREK-version gating on install', () => {
safeDownload.mockResolvedValue({ bytes: artifact, sha256: sha });
await expect(svc.install('flight-tracker')).resolves.toMatchObject({
id: 'flight-tracker',
trekRangeBypassed: { trekRange: '>=3.2.0 <3.4.0', hostVersion: '3.9.0' },
trekRangeBypassed: { trekRange: '>=3.2.0 <3.4.0', hostVersion: '3.9.0', acceptedByAdmin: false },
});
expect(fs.existsSync(path.join(codeRoot, 'flight-tracker'))).toBe(true);
});
@@ -1287,7 +1324,7 @@ describe('TREK-version gating on install', () => {
REGISTRY.plugins[0].versions[0].sha256 = sha;
safeDownload.mockResolvedValue({ bytes: artifact, sha256: sha });
await expect(svc.install('flight-tracker')).resolves.toMatchObject({
trekRangeBypassed: { trekRange: null, hostVersion: '3.9.0' },
trekRangeBypassed: { trekRange: null, hostVersion: '3.9.0', acceptedByAdmin: false },
});
});
@@ -1298,13 +1335,15 @@ describe('TREK-version gating on install', () => {
);
expect(old).toMatchObject({
id: 'my-upload',
trekRangeBypassed: { trekRange: '>=3.0.0 <3.5.0', hostVersion: '3.9.0' },
trekRangeBypassed: { trekRange: '>=3.0.0 <3.5.0', hostVersion: '3.9.0', acceptedByAdmin: false },
});
fs.rmSync(old.stagingDir, { recursive: true, force: true });
const rangeless = svc.stageUpload(
makeArtifact({ id: 'my-upload', name: 'Up', version: '1.0.0', type: 'integration', trek: undefined }),
);
expect(rangeless).toMatchObject({ trekRangeBypassed: { trekRange: null, hostVersion: '3.9.0' } });
expect(rangeless).toMatchObject({
trekRangeBypassed: { trekRange: null, hostVersion: '3.9.0', acceptedByAdmin: false },
});
fs.rmSync(rangeless.stagingDir, { recursive: true, force: true });
const fits = svc.stageUpload(
makeArtifact({ id: 'my-upload', name: 'Up', version: '1.0.0', type: 'integration' }),