Personal Telegram developer console for GitHub

fix/editor-request-body-cap
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 177 lines 10.3 KB
Raw
1 import test from 'node:test';
2 import assert from 'node:assert/strict';
3 import { createGitHubPlugin } from '../src/plugins/github/plugin.js';
4 import { githubPluginManifest } from '../src/plugins/github/manifest.js';
5
6 const sha = 'a'.repeat(40);
7
8 function callbacks(view) {
9 return (view?.reply_markup?.inline_keyboard || []).flat().map(button => button.callback_data).filter(Boolean);
10 }
11
12 function makeGitHub() {
13 const calls = [];
14 const hit = (name, value) => { calls.push([name, value]); return value; };
15 return {
16 calls,
17 async getRepository(id) { return hit('getRepository', { id: String(id), name: 'nexa-dev-bot', defaultBranch: 'main' }); },
18 async listWorkflowRuns() { return [{ id: 77, name: 'CI', status: 'completed', conclusion: 'success', branch: 'main', sha: 'abc1234', runNumber: 44 }]; },
19 async getWorkflowRun(repo, run) { return hit('getWorkflowRun', { id: run, name: 'CI', status: 'completed', conclusion: 'failure', runNumber: 134, branch: 'main', sha: 'abc1234', event: 'push' }); },
20 async listWorkflowJobs() { return hit('listWorkflowJobs', [{ id: 88, name: 'test', status: 'completed', conclusion: 'failure', steps: [{ number: 1, name: 'Run tests', conclusion: 'failure' }] }]); },
21 async getWorkflowJob() { return hit('getWorkflowJob', { id: 88, name: 'test', status: 'completed', conclusion: 'failure', steps: [{ number: 1, name: 'Run tests', conclusion: 'failure' }] }); },
22 async getWorkflowJobLog() { return hit('getWorkflowJobLog', { text: '<token>\nFAIL expected', truncated: true }); },
23 async listWorkflowArtifacts() { return hit('listWorkflowArtifacts', [{ id: 9, name: 'coverage', size: 1234, expired: false, createdAt: '2026-10-03T00:00:00Z', expiresAt: '2026-10-10T00:00:00Z' }]); },
24 async listBranches() { return hit('listBranches', [{ name: 'feature/x', sha, protected: false }]); },
25 async compareWithDefault() { return hit('compareWithDefault', { base: 'main', head: sha, status: 'ahead', aheadBy: 2, behindBy: 0, totalCommits: 2, files: [{ filename: 'src/x.js', status: 'modified', additions: 3, deletions: 1, changes: 4, patch: '+x' }] }); },
26 async listPullRequests() { return hit('listPullRequests', [{ number: 19, title: 'Feature', author: 'dev', state: 'open', merged: false }]); },
27 async getPullRequest() { return hit('getPullRequest', { number: 19, title: 'Feature', author: 'dev', state: 'open', merged: false, body: 'Body', head: 'feature/x', headSha: sha, base: 'main', additions: 3, deletions: 1, changedFiles: 1 }); },
28 async listPullRequestFiles() { return hit('listPullRequestFiles', [{ filename: 'src/x.js', status: 'modified', additions: 3, deletions: 1, changes: 4, patch: '+x' }]); },
29 async listCommitChecks() { return hit('listCommitChecks', [{ id: 7, name: 'CI', status: 'completed', conclusion: 'success' }]); },
30 async listIssues() { return hit('listIssues', [{ number: 4, title: 'Bug', state: 'open', author: 'u', comments: 2 }]); },
31 async listIssuesPage() { return hit('listIssuesPage', { items: [{ number: 4, title: 'Bug', state: 'open', author: 'u', comments: 2 }], hasMore: false }); },
32 async listReleases() { return hit('listReleases', [{ id: 6, tag: 'v1.2.0', name: 'Release 1.2', draft: false, prerelease: false, publishedAt: '2026-10-03T00:00:00Z' }]); },
33 async rerunFailedWorkflowRun() {},
34 async cancelWorkflowRun() {}
35 };
36 }
37
38 function makeMenu() {
39 return {
40 async getReposListView() { return { text: 'repos', reply_markup: { inline_keyboard: [] } }; },
41 async renderByCallback(data) {
42 if (String(data).startsWith('repo:')) {
43 const repoId = String(data).split(':')[1];
44 return { text: 'repo', reply_markup: { inline_keyboard: [[{ text: 'PRها', callback_data: `pr:${repoId}` }, { text: 'وضعیت', callback_data: `status:${repoId}` }], [{ text: 'back', callback_data: 'menu:repos' }]] } };
45 }
46 return { text: `legacy:${data}`, reply_markup: { inline_keyboard: [] } };
47 }
48 };
49 }
50
51 const advancedReadActions = [
52 'github.workflow.job.detail', 'github.workflow.job.log', 'github.workflow.artifacts.list',
53 'github.branches.list', 'github.compare.read', 'github.pr.advanced.list', 'github.pr.detail',
54 'github.pr.files.list', 'github.pr.checks.list', 'github.issues.list', 'github.releases.list'
55 ];
56
57 test('GitHub Advanced manifest declares every new action as READ', () => {
58 for (const actionId of advancedReadActions) assert.equal(githubPluginManifest.actions[actionId]?.risk, 'READ', actionId);
59 });
60
61 test('advanced callbacks resolve without provider side effects and callbacks stay Telegram-safe', async () => {
62 const github = makeGitHub();
63 const plugin = createGitHubPlugin({ github, menu: makeMenu() });
64 const samples = [
65 ['job:123:88', 'github.workflow.job.detail'],
66 ['joblog:123:88', 'github.workflow.job.log'],
67 ['artifacts:123:77', 'github.workflow.artifacts.list'],
68 ['branches:123', 'github.branches.list'],
69 [`compare:123:${sha}`, 'github.compare.read'],
70 ['prs:123', 'github.pr.advanced.list'],
71 ['prdetail:123:19', 'github.pr.detail'],
72 ['prfiles:123:19:1', 'github.pr.files.list'],
73 ['prchecks:123:19:1', 'github.pr.checks.list'],
74 ['issues:123', 'github.issues.list'],
75 ['releases:123', 'github.releases.list']
76 ];
77 for (const [data, actionId] of samples) {
78 const route = plugin.resolveCallback(data);
79 assert.equal(route?.actionId, actionId, data);
80 assert.equal(github.calls.length, 0, `provider called during resolve: ${data}`);
81 const view = await route.execute();
82 for (const callback of callbacks(view)) assert.ok(callback.length <= 64, `${callback} exceeds Telegram callback_data limit`);
83 github.calls.length = 0;
84 }
85 });
86
87 test('repository and workflow views expose Advanced READ navigation', async () => {
88 const github = makeGitHub();
89 const plugin = createGitHubPlugin({ github, menu: makeMenu() });
90 const repoView = await plugin.resolveCallback('repo:123').execute();
91 const repoCallbacks = callbacks(repoView);
92 for (const expected of ['status:123', 'branches:123', 'pr:123', 'issues:123', 'releases:123']) assert.ok(repoCallbacks.includes(expected), expected);
93 assert.ok(!repoCallbacks.includes('prs:123'), 'repository view must not expose a duplicate advanced PR entry');
94 assert.ok(!repoCallbacks.includes('runs:123'), 'repository view must not expose a duplicate CI entry');
95
96 const runView = await plugin.resolveCallback('run:123:77').execute();
97 assert.ok(callbacks(runView).includes('artifacts:123:77'));
98
99 const jobsView = await plugin.resolveCallback('jobs:123:77').execute();
100 assert.ok(callbacks(jobsView).includes('job:123:88'));
101
102 const jobView = await plugin.resolveCallback('job:123:88').execute();
103 assert.ok(callbacks(jobView).includes('joblog:123:88'));
104 });
105
106 test('legacy repository status button resolves to actionable workflow runs', async () => {
107 const plugin = createGitHubPlugin({ github: makeGitHub(), menu: makeMenu() });
108 const route = plugin.resolveCallback('status:123');
109 assert.equal(route?.actionId, 'github.workflow.runs.list');
110 const view = await route.execute();
111 assert.ok(callbacks(view).includes('run:123:77'), 'repository status button must drill into workflow run detail');
112 });
113
114 test('legacy repository PR button resolves to the actionable advanced PR report', async () => {
115 const plugin = createGitHubPlugin({ github: makeGitHub(), menu: makeMenu() });
116 const route = plugin.resolveCallback('pr:123');
117 assert.equal(route?.actionId, 'github.pr.advanced.list');
118 const view = await route.execute();
119 assert.ok(callbacks(view).includes('prdetail:123:19'), 'repository PR button must drill into PR detail');
120 });
121
122 test('failed job log is escaped and bounded-tail state is visible', async () => {
123 const plugin = createGitHubPlugin({ github: makeGitHub(), menu: makeMenu() });
124 const view = await plugin.resolveCallback('joblog:123:88').execute();
125 assert.match(view.text, /&lt;token&gt;/);
126 assert.doesNotMatch(view.text, /<token>/);
127 assert.match(view.text, /انتهای log|بخش پایانی|truncated/i);
128 });
129
130 test('branches, PRs, issues and releases provide useful drill-down and pagination', async () => {
131 const plugin = createGitHubPlugin({ github: makeGitHub(), menu: makeMenu() });
132 const branchView = await plugin.resolveCallback('branches:123').execute();
133 assert.ok(callbacks(branchView).includes(`compare:123:${sha}`));
134
135 const prList = await plugin.resolveCallback('prs:123').execute();
136 assert.ok(callbacks(prList).includes('prdetail:123:19'));
137 const prDetail = await plugin.resolveCallback('prdetail:123:19').execute();
138 assert.ok(callbacks(prDetail).includes('prfiles:123:19:1'));
139 assert.ok(callbacks(prDetail).includes('prchecks:123:19:1'));
140
141 const issues = await plugin.resolveCallback('issues:123').execute();
142 assert.match(issues.text, /#4/);
143 const releases = await plugin.resolveCallback('releases:123').execute();
144 assert.match(releases.text, /v1\.2\.0/);
145 });
146
147 test('artifacts support bounded page navigation instead of silently stopping at the first page', async () => {
148 const calls = [];
149 const github = makeGitHub();
150 github.listWorkflowArtifacts = async (repoId, runId, options) => {
151 calls.push({ repoId, runId, options });
152 return Array.from({ length: 10 }, (_, i) => ({ id: i + 1, name: `artifact-${i + 1}`, size: 1, expired: false }));
153 };
154 const plugin = createGitHubPlugin({ github, menu: makeMenu() });
155 const route = plugin.resolveCallback('artifacts:123:77:2');
156 assert.equal(route?.actionId, 'github.workflow.artifacts.list');
157 const view = await route.execute();
158 assert.deepEqual(calls[0], { repoId: 123, runId: 77, options: { perPage: 10, page: 2 } });
159 assert.ok(callbacks(view).includes('artifacts:123:77:1'));
160 assert.ok(callbacks(view).includes('artifacts:123:77:3'));
161 });
162
163 test('PR diff pages request only the number of files they can render and expose the next page', async () => {
164 const calls = [];
165 const github = makeGitHub();
166 github.listPullRequestFiles = async (repoId, prNumber, options) => {
167 calls.push({ repoId, prNumber, options });
168 return Array.from({ length: 8 }, (_, i) => ({
169 filename: `src/file-${i + 1}.js`, status: 'modified', additions: 1, deletions: 0, changes: 1, patch: '+x'
170 }));
171 };
172 const plugin = createGitHubPlugin({ github, menu: makeMenu() });
173 const view = await plugin.resolveCallback('prfiles:123:19:1').execute();
174 assert.deepEqual(calls[0], { repoId: 123, prNumber: 19, options: { perPage: 8, page: 1 } });
175 assert.match(view.text, /file-8\.js/);
176 assert.ok(callbacks(view).includes('prfiles:123:19:2'));
177 });