Personal Telegram developer console for GitHub

phase2/multifile-workspace
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 223 lines 8.01 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 listPullRequests(repoId) {
39 calls.push(`pr:${repoId}`);
40 return [{ number: 19, title: 'Feature', author: 'dev', state: 'open', merged: false }];
41 },
42 async listWorkflowRuns(repoId) {
43 calls.push(`runs:${repoId}`);
44 return [{
45 id: 77,
46 name: 'CI',
47 status: 'completed',
48 conclusion: 'failure',
49 branch: 'main',
50 sha: 'abcdef0',
51 runNumber: 12
52 }];
53 },
54 async getWorkflowRun(repoId, runId) {
55 calls.push(`run:${repoId}:${runId}`);
56 return {
57 id: Number(runId),
58 name: 'CI',
59 status: 'completed',
60 conclusion: 'failure',
61 branch: 'main',
62 sha: 'abcdef0',
63 runNumber: 12
64 };
65 },
66 async listWorkflowJobs(repoId, runId) {
67 calls.push(`jobs:${repoId}:${runId}`);
68 return [{
69 id: 88,
70 name: 'test',
71 status: 'completed',
72 conclusion: 'failure',
73 steps: [
74 { number: 1, name: 'checkout', status: 'completed', conclusion: 'success' },
75 { number: 2, name: 'test', status: 'completed', conclusion: 'failure' }
76 ]
77 }];
78 },
79 async rerunFailedWorkflowRun(repoId, runId) {
80 calls.push(`rerun:${repoId}:${runId}`);
81 return { accepted: true, status: 201 };
82 },
83 async cancelWorkflowRun(repoId, runId) {
84 calls.push(`cancel:${repoId}:${runId}`);
85 return { accepted: true, status: 202 };
86 }
87 };
88 }
89
90 test('GitHub plugin manifest registers read and write workflow actions with explicit risk', () => {
91 const plugin = createGitHubPlugin({ github: makeGitHub(), menu: makeMenu() });
92 const registry = new PluginRegistry([plugin]);
93
94 const readActions = [
95 'github.repos.list',
96 'github.repo.detail',
97 'github.files.list',
98 'github.tree.read',
99 'github.blob.read',
100 'github.pr.list',
101 'github.commits.list',
102 'github.status.read',
103 'github.workflow.runs.list',
104 'github.workflow.run.detail',
105 'github.workflow.jobs.list'
106 ];
107 for (const actionId of readActions) {
108 assert.equal(registry.getAction(actionId)?.risk, 'READ');
109 }
110
111 assert.equal(registry.getAction('github.workflow.run.rerun_failed')?.risk, 'WRITE');
112 assert.equal(registry.getAction('github.workflow.run.cancel')?.risk, 'WRITE');
113 });
114
115 test('GitHub plugin resolves /repos without executing the menu before policy', async () => {
116 const menu = makeMenu();
117 const plugin = createGitHubPlugin({ github: makeGitHub(), menu });
118
119 const route = plugin.resolveCommand('/repos');
120
121 assert.equal(route.actionId, 'github.repos.list');
122 assert.deepEqual(menu.calls, []);
123 assert.equal(await route.execute(), menu.reposView);
124 assert.deepEqual(menu.calls, ['/repos']);
125 assert.equal(plugin.resolveCommand('/status'), null);
126 });
127
128 test('GitHub plugin maps read callback families to declared actions without eager execution', async () => {
129 const menu = makeMenu();
130 const github = makeGitHub();
131 const plugin = createGitHubPlugin({ github, menu });
132 const cases = [
133 ['menu:repos', 'github.repos.list'],
134 ['repo:123', 'github.repo.detail'],
135 ['files:123', 'github.files.list'],
136 ['tree:123:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', 'github.tree.read'],
137 ['blob:123:bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb', 'github.blob.read'],
138 ['pr:123', 'github.pr.advanced.list'],
139 ['commits:123', 'github.commits.list'],
140 ['status:123', 'github.workflow.runs.list'],
141 ['runs:123', 'github.workflow.runs.list'],
142 ['run:123:77', 'github.workflow.run.detail'],
143 ['jobs:123:77', 'github.workflow.jobs.list']
144 ];
145
146 for (const [callbackData, actionId] of cases) {
147 const beforeMenu = menu.calls.length;
148 const beforeGitHub = github.calls.length;
149 const route = plugin.resolveCallback(callbackData);
150 assert.equal(route.actionId, actionId);
151 assert.equal(menu.calls.length, beforeMenu, 'route resolution must be side-effect-free');
152 assert.equal(github.calls.length, beforeGitHub, 'route resolution must not call GitHub');
153 const view = await route.execute();
154 assert.ok(view?.text);
155 }
156 });
157
158 test('repository detail view keeps its existing status entry without duplicate CI navigation', async () => {
159 const menu = makeMenu();
160 const plugin = createGitHubPlugin({ github: makeGitHub(), menu });
161 const view = await plugin.resolveCallback('repo:123').execute();
162 const buttons = view.reply_markup.inline_keyboard.flat();
163 assert.ok(!buttons.some(button => button.callback_data === 'runs:123'));
164 });
165
166 test('GitHub plugin write callbacks expose compact approval metadata and defer provider calls', async () => {
167 const menu = makeMenu();
168 const github = makeGitHub();
169 const plugin = createGitHubPlugin({ github, menu });
170
171 const rerun = plugin.resolveCallback('rerun:123:77');
172 assert.equal(rerun.actionId, 'github.workflow.run.rerun_failed');
173 assert.deepEqual(rerun.approval, {
174 input: { repoId: 123, runId: 77 },
175 label: 'اجرای مجدد jobهای ناموفق'
176 });
177 assert.deepEqual(github.calls, []);
178 const rerunView = await rerun.execute();
179 assert.deepEqual(github.calls, ['rerun:123:77']);
180 assert.match(rerunView.text, /اجرا.*مجدد|دوباره/i);
181 assert.ok(rerunView.reply_markup.inline_keyboard.flat().some(button => button.callback_data === 'run:123:77'));
182
183 github.calls.length = 0;
184 const cancel = plugin.resolveCallback('cancelrun:123:77');
185 assert.equal(cancel.actionId, 'github.workflow.run.cancel');
186 assert.deepEqual(cancel.approval, {
187 input: { repoId: 123, runId: 77 },
188 label: 'لغو Workflow در حال اجرا'
189 });
190 assert.deepEqual(github.calls, []);
191 const cancelView = await cancel.execute();
192 assert.deepEqual(github.calls, ['cancel:123:77']);
193 assert.match(cancelView.text, /لغو/);
194 });
195
196 test('GitHub workflow views expose bounded navigation and write-action callbacks', async () => {
197 const plugin = createGitHubPlugin({ github: makeGitHub(), menu: makeMenu() });
198
199 const runsView = await plugin.resolveCallback('runs:123').execute();
200 assert.match(runsView.text, /CI/);
201 assert.ok(runsView.reply_markup.inline_keyboard.flat().some(button => button.callback_data === 'run:123:77'));
202
203 const runView = await plugin.resolveCallback('run:123:77').execute();
204 const runButtons = runView.reply_markup.inline_keyboard.flat();
205 assert.ok(runButtons.some(button => button.callback_data === 'jobs:123:77'));
206 assert.ok(runButtons.some(button => button.callback_data === 'rerun:123:77'));
207
208 const jobsView = await plugin.resolveCallback('jobs:123:77').execute();
209 assert.match(jobsView.text, /checkout/);
210 assert.match(jobsView.text, /test/);
211 });
212
213 test('GitHub plugin rejects malformed workflow callback ids and unrelated callbacks', () => {
214 const plugin = createGitHubPlugin({ github: makeGitHub(), menu: makeMenu() });
215
216 assert.equal(plugin.resolveCommand('/start'), null);
217 assert.equal(plugin.resolveCallback('run:abc:77'), null);
218 assert.equal(plugin.resolveCallback('rerun:123:nope'), null);
219 assert.equal(plugin.resolveCallback('menu:main'), null);
220 assert.equal(plugin.resolveCallback('menu:status'), null);
221 assert.equal(plugin.resolveCallback('menu:tools'), null);
222 assert.equal(plugin.resolveCallback('tool:ping'), null);
223 });