Personal Telegram developer console for GitHub

test: keep workflow action result rendering inside GitHub plugin

davoodmehraban89 committed Oct 3, 2026 at 05:44 UTC 67da71e5e2180aaff259c25bbe984322865d01d8
1 file changed +85 -15
test/github-plugin.test.js
+85 -15
@@ -15,11 +15,14 @@ function makeMenu() {
15 },
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: [] } };
18 + return {
19 + text: data,
20 + reply_markup: {
21 + inline_keyboard: data.startsWith('repo:')
22 + ? [[{ text: '🔙 بازگشت', callback_data: 'menu:repos' }]]
23 + : []
24 + }
25 + };
26 }
27 };
28 }
@@ -28,6 +31,47 @@ function makeGitHub() {
31 const calls = [];
32 return {
33 calls,
34 + async getRepository(repoId) {
35 + calls.push(`repo:${repoId}`);
36 + return { id: String(repoId), name: 'demo', fullName: 'davood/demo' };
37 + },
38 + async listWorkflowRuns(repoId) {
39 + calls.push(`runs:${repoId}`);
40 + return [{
41 + id: 77,
42 + name: 'CI',
43 + status: 'completed',
44 + conclusion: 'failure',
45 + branch: 'main',
46 + sha: 'abcdef0',
47 + runNumber: 12
48 + }];
49 + },
50 + async getWorkflowRun(repoId, runId) {
51 + calls.push(`run:${repoId}:${runId}`);
52 + return {
53 + id: Number(runId),
54 + name: 'CI',
55 + status: 'completed',
56 + conclusion: 'failure',
57 + branch: 'main',
58 + sha: 'abcdef0',
59 + runNumber: 12
60 + };
61 + },
62 + async listWorkflowJobs(repoId, runId) {
63 + calls.push(`jobs:${repoId}:${runId}`);
64 + return [{
65 + id: 88,
66 + name: 'test',
67 + status: 'completed',
68 + conclusion: 'failure',
69 + steps: [
70 + { number: 1, name: 'checkout', status: 'completed', conclusion: 'success' },
71 + { number: 2, name: 'test', status: 'completed', conclusion: 'failure' }
72 + ]
73 + }];
74 + },
75 async rerunFailedWorkflowRun(repoId, runId) {
76 calls.push(`rerun:${repoId}:${runId}`);
77 return { accepted: true, status: 201 };
@@ -40,8 +84,7 @@ function makeGitHub() {
84 }
85
86 test('GitHub plugin manifest registers read and write workflow actions with explicit risk', () => {
43 - const menu = makeMenu();
44 - const plugin = createGitHubPlugin({ github: makeGitHub(), menu });
87 + const plugin = createGitHubPlugin({ github: makeGitHub(), menu: makeMenu() });
88 const registry = new PluginRegistry([plugin]);
89
90 const readActions = [
@@ -80,7 +123,8 @@ test('GitHub plugin resolves /repos without executing the menu before policy', a
123
124 test('GitHub plugin maps read callback families to declared actions without eager execution', async () => {
125 const menu = makeMenu();
83 - const plugin = createGitHubPlugin({ github: makeGitHub(), menu });
126 + const github = makeGitHub();
127 + const plugin = createGitHubPlugin({ github, menu });
128 const cases = [
129 ['menu:repos', 'github.repos.list'],
130 ['repo:123', 'github.repo.detail'],
@@ -96,17 +140,25 @@ test('GitHub plugin maps read callback families to declared actions without eage
140 ];
141
142 for (const [callbackData, actionId] of cases) {
99 - const before = menu.calls.length;
143 + const beforeMenu = menu.calls.length;
144 + const beforeGitHub = github.calls.length;
145 const route = plugin.resolveCallback(callbackData);
146 assert.equal(route.actionId, actionId);
102 - assert.equal(menu.calls.length, before, 'route resolution must be side-effect-free');
147 + assert.equal(menu.calls.length, beforeMenu, 'route resolution must be side-effect-free');
148 + assert.equal(github.calls.length, beforeGitHub, 'route resolution must not call GitHub');
149 const view = await route.execute();
104 - assert.equal(menu.calls.length, before + 1);
105 - assert.equal(menu.calls.at(-1), callbackData);
106 - assert.equal(view.text, callbackData);
150 + assert.ok(view?.text);
151 }
152 });
153
154 +test('repository detail view is augmented with CI / Actions navigation without changing menu manager', async () => {
155 + const menu = makeMenu();
156 + const plugin = createGitHubPlugin({ github: makeGitHub(), menu });
157 + const view = await plugin.resolveCallback('repo:123').execute();
158 + const buttons = view.reply_markup.inline_keyboard.flat();
159 + assert.ok(buttons.some(button => button.callback_data === 'runs:123'));
160 +});
161 +
162 test('GitHub plugin write callbacks expose compact approval metadata and defer provider calls', async () => {
163 const menu = makeMenu();
164 const github = makeGitHub();
@@ -121,7 +173,8 @@ test('GitHub plugin write callbacks expose compact approval metadata and defer p
173 assert.deepEqual(github.calls, []);
174 const rerunView = await rerun.execute();
175 assert.deepEqual(github.calls, ['rerun:123:77']);
124 - assert.equal(rerunView.text, 'done:rerun_failed');
176 + assert.match(rerunView.text, /اجرا.*مجدد|دوباره/i);
177 + assert.ok(rerunView.reply_markup.inline_keyboard.flat().some(button => button.callback_data === 'run:123:77'));
178
179 github.calls.length = 0;
180 const cancel = plugin.resolveCallback('cancelrun:123:77');
@@ -133,7 +186,24 @@ test('GitHub plugin write callbacks expose compact approval metadata and defer p
186 assert.deepEqual(github.calls, []);
187 const cancelView = await cancel.execute();
188 assert.deepEqual(github.calls, ['cancel:123:77']);
136 - assert.equal(cancelView.text, 'done:cancel');
189 + assert.match(cancelView.text, /لغو/);
190 +});
191 +
192 +test('GitHub workflow views expose bounded navigation and write-action callbacks', async () => {
193 + const plugin = createGitHubPlugin({ github: makeGitHub(), menu: makeMenu() });
194 +
195 + const runsView = await plugin.resolveCallback('runs:123').execute();
196 + assert.match(runsView.text, /CI/);
197 + assert.ok(runsView.reply_markup.inline_keyboard.flat().some(button => button.callback_data === 'run:123:77'));
198 +
199 + const runView = await plugin.resolveCallback('run:123:77').execute();
200 + const runButtons = runView.reply_markup.inline_keyboard.flat();
201 + assert.ok(runButtons.some(button => button.callback_data === 'jobs:123:77'));
202 + assert.ok(runButtons.some(button => button.callback_data === 'rerun:123:77'));
203 +
204 + const jobsView = await plugin.resolveCallback('jobs:123:77').execute();
205 + assert.match(jobsView.text, /checkout/);
206 + assert.match(jobsView.text, /test/);
207 });
208
209 test('GitHub plugin rejects malformed workflow callback ids and unrelated callbacks', () => {