Personal Telegram developer console for GitHub
test: define github plugin adapter contract
davoodmehraban89 committed
Oct 3, 2026 at 01:31 UTC
ae6829729779c2f656e99958a379c805eb1bebc4
1 file changed
+90
test/github-plugin.test.js
new
+90
@@ -0,0 +1,90 @@
1
+import test from 'node:test';
2
+import assert from 'node:assert/strict';
3
+import { PluginRegistry } from '../src/core/plugin-registry.js';
4
+import { createGitHubPlugin } from '../src/plugins/github/plugin.js';
5
+
6
+function makeMenu() {
7
+ const calls = [];
8
+ const reposView = { text: 'repos', reply_markup: { inline_keyboard: [] } };
9
+ return {
10
+ calls,
11
+ reposView,
12
+ async getReposListView() {
13
+ calls.push('/repos');
14
+ return reposView;
15
+ },
16
+ async renderByCallback(data) {
17
+ calls.push(data);
18
+ return { text: data, reply_markup: { inline_keyboard: [] } };
19
+ }
20
+ };
21
+}
22
+
23
+test('GitHub plugin manifest registers all Foundation v1 actions as READ', () => {
24
+ const menu = makeMenu();
25
+ const plugin = createGitHubPlugin({ github: {}, menu });
26
+ const registry = new PluginRegistry([plugin]);
27
+
28
+ const expected = [
29
+ 'github.repos.list',
30
+ 'github.repo.detail',
31
+ 'github.files.list',
32
+ 'github.tree.read',
33
+ 'github.blob.read',
34
+ 'github.pr.list',
35
+ 'github.commits.list',
36
+ 'github.status.read'
37
+ ];
38
+
39
+ for (const actionId of expected) {
40
+ assert.equal(registry.getAction(actionId)?.risk, 'READ');
41
+ }
42
+});
43
+
44
+test('GitHub plugin resolves /repos without executing the menu before policy', async () => {
45
+ const menu = makeMenu();
46
+ const plugin = createGitHubPlugin({ github: {}, menu });
47
+
48
+ const route = plugin.resolveCommand('/repos');
49
+
50
+ assert.equal(route.actionId, 'github.repos.list');
51
+ assert.deepEqual(menu.calls, []);
52
+ assert.equal(await route.execute(), menu.reposView);
53
+ assert.deepEqual(menu.calls, ['/repos']);
54
+ assert.equal(plugin.resolveCommand('/status'), null);
55
+});
56
+
57
+test('GitHub plugin maps existing GitHub callback families to declared actions', async () => {
58
+ const menu = makeMenu();
59
+ const plugin = createGitHubPlugin({ github: {}, menu });
60
+ const cases = [
61
+ ['menu:repos', 'github.repos.list'],
62
+ ['repo:123', 'github.repo.detail'],
63
+ ['files:123', 'github.files.list'],
64
+ ['tree:123:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', 'github.tree.read'],
65
+ ['blob:123:bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb', 'github.blob.read'],
66
+ ['pr:123', 'github.pr.list'],
67
+ ['commits:123', 'github.commits.list'],
68
+ ['status:123', 'github.status.read']
69
+ ];
70
+
71
+ for (const [callbackData, actionId] of cases) {
72
+ const route = plugin.resolveCallback(callbackData);
73
+ assert.equal(route.actionId, actionId);
74
+ const before = menu.calls.length;
75
+ const view = await route.execute();
76
+ assert.equal(menu.calls.length, before + 1);
77
+ assert.equal(menu.calls.at(-1), callbackData);
78
+ assert.equal(view.text, callbackData);
79
+ }
80
+});
81
+
82
+test('GitHub plugin does not consume unrelated commands or callbacks', () => {
83
+ const plugin = createGitHubPlugin({ github: {}, menu: makeMenu() });
84
+
85
+ assert.equal(plugin.resolveCommand('/start'), null);
86
+ assert.equal(plugin.resolveCallback('menu:main'), null);
87
+ assert.equal(plugin.resolveCallback('menu:status'), null);
88
+ assert.equal(plugin.resolveCallback('menu:tools'), null);
89
+ assert.equal(plugin.resolveCallback('tool:ping'), null);
90
+});