Personal Telegram developer console for GitHub

fix/approval-expiry-feedback
audit/commit-drilldown audit/finalize-workspace-menu-security audit/ops-actionability audit/pr-menu-consolidation audit/status-menu-consolidation audit/telegram-menu-e2e audit/telegram-menu-e2e-wave2 chore/actions-node24-runtime cleanup/remove-diag design/cloudflare-ops-read docs/control-plane-2-7-design docs/guide-v2-1-sync docs/menu-audit-final-sync docs/phase2-acceptance-closeout docs/phase2-multifile-design feat/bootstrap-worker feat/cloudflare-ops-read feat/cp2-multifile-final feat/cp2-multifile-workspace feat/cp3-github-write-final feat/cp4-cloudflare-ops-final feat/cp5-cicd-control-plane feat/cp6-incident-manager feat/cp7-automation-engine feat/deep-file-browser feat/final-delivery-16-20 feat/github-advanced-read feat/in-app-guide-v2 feat/navigation-recovery-ux-v2 feat/ops-console-v2-1 feat/persistent-menu-code-input feat/phase2-multifile-workspace feat/phase2-multifile-workspace-v2 feat/plugin-foundation-v1 feat/safe-github-ops feat/self-register-webhook feat/studio-g0-foundation feat/telegram-main-inline-menu feat/telegram-pr-merge feat/ux-platform-8-12 feat/v3a-readonly-copilot feat/workspace-file-upload feature/mobile-repo-browser feature/multi-file-change-set fix/approval-expiry-feedback fix/callback-resilience-and-docs fix/ci-actions-pagination fix/cloudflare-fetch-binding fix/editor-request-body-cap fix/editor-safe-file-options fix/issues-permission-release-empty-ux fix/main-menu-callback-fallback fix/phase2-file-editor-selection fix/phase2-final-ux fix/phase2-workspace-ref-persistence fix/production-auto-deploy fix/provider-write-error-feedback fix/repository-id-navigation-fallback fix/repository-pr-navigation fix/telegram-callback-updates fix/telegram-runtime-diagnostics fix/workspace-editor-flow-v2 fix/workspace-recovery-validation hardening/ci-zero-test-telegram-token hardening/pr1-destructive-totp hardening/pr2-kill-switch main multifile-workspace nexa/edit-BwJEIIY3PW nexa/edit-IPHT8irO7b nexa/edit-b4Od3BIMYd p2-multifile phase2-20261005 phase2-20261005-a phase2-20261005-b phase2-20261005-c phase2-20261005-d phase2-20261005-e phase2-20261005-f phase2-20261005-g phase2-20261005-h phase2-20261005-i phase2-20261005-j phase2-20261005-k phase2-20261005-l phase2-20261005-m phase2-20261005-n phase2-20261005-o phase2-20261005-p phase2-20261005-q phase2-20261005-r phase2-20261005-s phase2-20261005-t phase2-20261005-u phase2-20261005-v phase2-20261005-w phase2-20261005-x phase2-20261005-y phase2-20261005-z phase2-acceptance-closeout phase2-add-file-hotfix phase2-change-set phase2-design-20261005 phase2-design-final phase2-implementation phase2-multifile-implementation phase2-multifile-spec phase2-spec-final phase2-workspace phase2/multifile-workspace plan/nexa-studio-v2-reviewed security/remove-telegram-setup spec/repository-workspace-editor v3a/multifile work/multifile
js 219 lines 7.83 KB
Raw
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 {
19 text: data,
20 reply_markup: {
21 inline_keyboard: data.startsWith('repo:')
22 ? [[{ text: '🔙 بازگشت', callback_data: 'menu:repos' }]]
23 : []
24 }
25 };
26 }
27 };
28 }
29
30 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 };
78 },
79 async cancelWorkflowRun(repoId, runId) {
80 calls.push(`cancel:${repoId}:${runId}`);
81 return { accepted: true, status: 202 };
82 }
83 };
84 }
85
86 test('GitHub plugin manifest registers read and write workflow actions with explicit risk', () => {
87 const plugin = createGitHubPlugin({ github: makeGitHub(), menu: makeMenu() });
88 const registry = new PluginRegistry([plugin]);
89
90 const readActions = [
91 'github.repos.list',
92 'github.repo.detail',
93 'github.files.list',
94 'github.tree.read',
95 'github.blob.read',
96 'github.pr.list',
97 'github.commits.list',
98 'github.status.read',
99 'github.workflow.runs.list',
100 'github.workflow.run.detail',
101 'github.workflow.jobs.list'
102 ];
103 for (const actionId of readActions) {
104 assert.equal(registry.getAction(actionId)?.risk, 'READ');
105 }
106
107 assert.equal(registry.getAction('github.workflow.run.rerun_failed')?.risk, 'WRITE');
108 assert.equal(registry.getAction('github.workflow.run.cancel')?.risk, 'WRITE');
109 });
110
111 test('GitHub plugin resolves /repos without executing the menu before policy', async () => {
112 const menu = makeMenu();
113 const plugin = createGitHubPlugin({ github: makeGitHub(), menu });
114
115 const route = plugin.resolveCommand('/repos');
116
117 assert.equal(route.actionId, 'github.repos.list');
118 assert.deepEqual(menu.calls, []);
119 assert.equal(await route.execute(), menu.reposView);
120 assert.deepEqual(menu.calls, ['/repos']);
121 assert.equal(plugin.resolveCommand('/status'), null);
122 });
123
124 test('GitHub plugin maps read callback families to declared actions without eager execution', async () => {
125 const menu = makeMenu();
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'],
131 ['files:123', 'github.files.list'],
132 ['tree:123:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', 'github.tree.read'],
133 ['blob:123:bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb', 'github.blob.read'],
134 ['pr:123', 'github.pr.list'],
135 ['commits:123', 'github.commits.list'],
136 ['status:123', 'github.status.read'],
137 ['runs:123', 'github.workflow.runs.list'],
138 ['run:123:77', 'github.workflow.run.detail'],
139 ['jobs:123:77', 'github.workflow.jobs.list']
140 ];
141
142 for (const [callbackData, actionId] of cases) {
143 const beforeMenu = menu.calls.length;
144 const beforeGitHub = github.calls.length;
145 const route = plugin.resolveCallback(callbackData);
146 assert.equal(route.actionId, actionId);
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();
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();
165 const plugin = createGitHubPlugin({ github, menu });
166
167 const rerun = plugin.resolveCallback('rerun:123:77');
168 assert.equal(rerun.actionId, 'github.workflow.run.rerun_failed');
169 assert.deepEqual(rerun.approval, {
170 input: { repoId: 123, runId: 77 },
171 label: 'اجرای مجدد jobهای ناموفق'
172 });
173 assert.deepEqual(github.calls, []);
174 const rerunView = await rerun.execute();
175 assert.deepEqual(github.calls, ['rerun:123:77']);
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');
181 assert.equal(cancel.actionId, 'github.workflow.run.cancel');
182 assert.deepEqual(cancel.approval, {
183 input: { repoId: 123, runId: 77 },
184 label: 'لغو Workflow در حال اجرا'
185 });
186 assert.deepEqual(github.calls, []);
187 const cancelView = await cancel.execute();
188 assert.deepEqual(github.calls, ['cancel:123:77']);
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', () => {
210 const plugin = createGitHubPlugin({ github: makeGitHub(), menu: makeMenu() });
211
212 assert.equal(plugin.resolveCommand('/start'), null);
213 assert.equal(plugin.resolveCallback('run:abc:77'), null);
214 assert.equal(plugin.resolveCallback('rerun:123:nope'), null);
215 assert.equal(plugin.resolveCallback('menu:main'), null);
216 assert.equal(plugin.resolveCallback('menu:status'), null);
217 assert.equal(plugin.resolveCallback('menu:tools'), null);
218 assert.equal(plugin.resolveCallback('tool:ping'), null);
219 });