Personal Telegram developer console for GitHub
test: define GitHub workflow plugin actions
davoodmehraban89 committed
Oct 3, 2026 at 05:43 UTC
9274ba7e9e2bcdbb0513476aab4761a15d37bb79
1 file changed
+72
-13
test/github-plugin.test.js
+72
-13
@@ -16,16 +16,35 @@ function makeMenu() {
16
async renderByCallback(data) {
17
calls.push(data);
18
return { text: data, reply_markup: { inline_keyboard: [] } };
19
+ },
20
+ async getWorkflowActionResultView(repoId, runId, action) {
21
+ calls.push(`result:${action}:${repoId}:${runId}`);
22
+ return { text: `done:${action}`, reply_markup: { inline_keyboard: [] } };
23
+ }
24
+ };
25
+}
26
+
27
+function makeGitHub() {
28
+ const calls = [];
29
+ return {
30
+ calls,
31
+ async rerunFailedWorkflowRun(repoId, runId) {
32
+ calls.push(`rerun:${repoId}:${runId}`);
33
+ return { accepted: true, status: 201 };
34
+ },
35
+ async cancelWorkflowRun(repoId, runId) {
36
+ calls.push(`cancel:${repoId}:${runId}`);
37
+ return { accepted: true, status: 202 };
38
}
39
};
40
}
41
23
-test('GitHub plugin manifest registers all Foundation v1 actions as READ', () => {
42
+test('GitHub plugin manifest registers read and write workflow actions with explicit risk', () => {
43
const menu = makeMenu();
25
- const plugin = createGitHubPlugin({ github: {}, menu });
44
+ const plugin = createGitHubPlugin({ github: makeGitHub(), menu });
45
const registry = new PluginRegistry([plugin]);
46
28
- const expected = [
47
+ const readActions = [
48
'github.repos.list',
49
'github.repo.detail',
50
'github.files.list',
@@ -33,17 +52,22 @@ test('GitHub plugin manifest registers all Foundation v1 actions as READ', () =>
52
'github.blob.read',
53
'github.pr.list',
54
'github.commits.list',
36
- 'github.status.read'
55
+ 'github.status.read',
56
+ 'github.workflow.runs.list',
57
+ 'github.workflow.run.detail',
58
+ 'github.workflow.jobs.list'
59
];
38
-
39
- for (const actionId of expected) {
60
+ for (const actionId of readActions) {
61
assert.equal(registry.getAction(actionId)?.risk, 'READ');
62
}
63
+
64
+ assert.equal(registry.getAction('github.workflow.run.rerun_failed')?.risk, 'WRITE');
65
+ assert.equal(registry.getAction('github.workflow.run.cancel')?.risk, 'WRITE');
66
});
67
68
test('GitHub plugin resolves /repos without executing the menu before policy', async () => {
69
const menu = makeMenu();
46
- const plugin = createGitHubPlugin({ github: {}, menu });
70
+ const plugin = createGitHubPlugin({ github: makeGitHub(), menu });
71
72
const route = plugin.resolveCommand('/repos');
73
@@ -54,9 +78,9 @@ test('GitHub plugin resolves /repos without executing the menu before policy', a
78
assert.equal(plugin.resolveCommand('/status'), null);
79
});
80
57
-test('GitHub plugin maps existing GitHub callback families to declared actions', async () => {
81
+test('GitHub plugin maps read callback families to declared actions without eager execution', async () => {
82
const menu = makeMenu();
59
- const plugin = createGitHubPlugin({ github: {}, menu });
83
+ const plugin = createGitHubPlugin({ github: makeGitHub(), menu });
84
const cases = [
85
['menu:repos', 'github.repos.list'],
86
['repo:123', 'github.repo.detail'],
@@ -65,13 +89,17 @@ test('GitHub plugin maps existing GitHub callback families to declared actions',
89
['blob:123:bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb', 'github.blob.read'],
90
['pr:123', 'github.pr.list'],
91
['commits:123', 'github.commits.list'],
68
- ['status:123', 'github.status.read']
92
+ ['status:123', 'github.status.read'],
93
+ ['runs:123', 'github.workflow.runs.list'],
94
+ ['run:123:77', 'github.workflow.run.detail'],
95
+ ['jobs:123:77', 'github.workflow.jobs.list']
96
];
97
98
for (const [callbackData, actionId] of cases) {
99
+ const before = menu.calls.length;
100
const route = plugin.resolveCallback(callbackData);
101
assert.equal(route.actionId, actionId);
74
- const before = menu.calls.length;
102
+ assert.equal(menu.calls.length, before, 'route resolution must be side-effect-free');
103
const view = await route.execute();
104
assert.equal(menu.calls.length, before + 1);
105
assert.equal(menu.calls.at(-1), callbackData);
@@ -79,10 +107,41 @@ test('GitHub plugin maps existing GitHub callback families to declared actions',
107
}
108
});
109
82
-test('GitHub plugin does not consume unrelated commands or callbacks', () => {
83
- const plugin = createGitHubPlugin({ github: {}, menu: makeMenu() });
110
+test('GitHub plugin write callbacks expose compact approval metadata and defer provider calls', async () => {
111
+ const menu = makeMenu();
112
+ const github = makeGitHub();
113
+ const plugin = createGitHubPlugin({ github, menu });
114
+
115
+ const rerun = plugin.resolveCallback('rerun:123:77');
116
+ assert.equal(rerun.actionId, 'github.workflow.run.rerun_failed');
117
+ assert.deepEqual(rerun.approval, {
118
+ input: { repoId: 123, runId: 77 },
119
+ label: 'اجرای مجدد jobهای ناموفق'
120
+ });
121
+ assert.deepEqual(github.calls, []);
122
+ const rerunView = await rerun.execute();
123
+ assert.deepEqual(github.calls, ['rerun:123:77']);
124
+ assert.equal(rerunView.text, 'done:rerun_failed');
125
+
126
+ github.calls.length = 0;
127
+ const cancel = plugin.resolveCallback('cancelrun:123:77');
128
+ assert.equal(cancel.actionId, 'github.workflow.run.cancel');
129
+ assert.deepEqual(cancel.approval, {
130
+ input: { repoId: 123, runId: 77 },
131
+ label: 'لغو Workflow در حال اجرا'
132
+ });
133
+ assert.deepEqual(github.calls, []);
134
+ const cancelView = await cancel.execute();
135
+ assert.deepEqual(github.calls, ['cancel:123:77']);
136
+ assert.equal(cancelView.text, 'done:cancel');
137
+});
138
+
139
+test('GitHub plugin rejects malformed workflow callback ids and unrelated callbacks', () => {
140
+ const plugin = createGitHubPlugin({ github: makeGitHub(), menu: makeMenu() });
141
142
assert.equal(plugin.resolveCommand('/start'), null);
143
+ assert.equal(plugin.resolveCallback('run:abc:77'), null);
144
+ assert.equal(plugin.resolveCallback('rerun:123:nope'), null);
145
assert.equal(plugin.resolveCallback('menu:main'), null);
146
assert.equal(plugin.resolveCallback('menu:status'), null);
147
assert.equal(plugin.resolveCallback('menu:tools'), null);