Personal Telegram developer console for GitHub
test: define plugin registry contract
davoodmehraban89 committed
Oct 3, 2026 at 01:20 UTC
2460b0854f6dbd99a80cfb9561850fdd23f1ac0e
1 file changed
+49
test/plugin-registry.test.js
new
+49
@@ -0,0 +1,49 @@
1
+import test from 'node:test';
2
+import assert from 'node:assert/strict';
3
+import { PluginRegistry } from '../src/core/plugin-registry.js';
4
+
5
+const plugin = (id, actions = {}) => ({
6
+ manifest: { id, name: id, version: 1, actions }
7
+});
8
+
9
+test('PluginRegistry registers valid plugins and exposes lookups', () => {
10
+ const github = plugin('github', {
11
+ 'github.repos.list': { risk: 'READ' }
12
+ });
13
+
14
+ const registry = new PluginRegistry([github]);
15
+
16
+ assert.deepEqual(registry.getPlugins(), [github]);
17
+ assert.equal(registry.getPlugin('github'), github);
18
+ assert.deepEqual(registry.getAction('github.repos.list'), {
19
+ pluginId: 'github',
20
+ actionId: 'github.repos.list',
21
+ risk: 'READ'
22
+ });
23
+});
24
+
25
+test('PluginRegistry rejects duplicate plugin ids', () => {
26
+ assert.throws(
27
+ () => new PluginRegistry([plugin('github'), plugin('github')]),
28
+ /duplicate plugin id/i
29
+ );
30
+});
31
+
32
+test('PluginRegistry rejects duplicate action ids across plugins', () => {
33
+ assert.throws(
34
+ () => new PluginRegistry([
35
+ plugin('github', { 'shared.read': { risk: 'READ' } }),
36
+ plugin('cloudflare', { 'shared.read': { risk: 'READ' } })
37
+ ]),
38
+ /duplicate action id/i
39
+ );
40
+});
41
+
42
+test('PluginRegistry rejects unknown action risk levels', () => {
43
+ assert.throws(
44
+ () => new PluginRegistry([
45
+ plugin('github', { 'github.repos.list': { risk: 'SUPERUSER' } })
46
+ ]),
47
+ /invalid action risk/i
48
+ );
49
+});