Personal Telegram developer console for GitHub

fix/repository-pr-navigation
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 160 lines 9.22 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 []; },
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 return { text: 'repo', reply_markup: { inline_keyboard: [[{ text: 'PR', callback_data: 'pr:123' }], [{ text: 'back', callback_data: 'menu:repos' }]] } };
44 }
45 return { text: `legacy:${data}`, reply_markup: { inline_keyboard: [] } };
46 }
47 };
48 }
49
50 const advancedReadActions = [
51 'github.workflow.job.detail', 'github.workflow.job.log', 'github.workflow.artifacts.list',
52 'github.branches.list', 'github.compare.read', 'github.pr.advanced.list', 'github.pr.detail',
53 'github.pr.files.list', 'github.pr.checks.list', 'github.issues.list', 'github.releases.list'
54 ];
55
56 test('GitHub Advanced manifest declares every new action as READ', () => {
57 for (const actionId of advancedReadActions) assert.equal(githubPluginManifest.actions[actionId]?.risk, 'READ', actionId);
58 });
59
60 test('advanced callbacks resolve without provider side effects and callbacks stay Telegram-safe', async () => {
61 const github = makeGitHub();
62 const plugin = createGitHubPlugin({ github, menu: makeMenu() });
63 const samples = [
64 ['job:123:88', 'github.workflow.job.detail'],
65 ['joblog:123:88', 'github.workflow.job.log'],
66 ['artifacts:123:77', 'github.workflow.artifacts.list'],
67 ['branches:123', 'github.branches.list'],
68 [`compare:123:${sha}`, 'github.compare.read'],
69 ['pr:123', 'github.pr.advanced.list'],
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 ['runs:123', 'branches:123', 'issues:123', 'releases:123']) assert.ok(repoCallbacks.includes(expected), expected);
93 assert.deepEqual(repoCallbacks.filter(value => value === 'pr:123' || value === 'prs:123'), ['pr:123'], 'repository view must expose one useful PR entry');
94
95 const runView = await plugin.resolveCallback('run:123:77').execute();
96 assert.ok(callbacks(runView).includes('artifacts:123:77'));
97
98 const jobsView = await plugin.resolveCallback('jobs:123:77').execute();
99 assert.ok(callbacks(jobsView).includes('job:123:88'));
100
101 const jobView = await plugin.resolveCallback('job:123:88').execute();
102 assert.ok(callbacks(jobView).includes('joblog:123:88'));
103 });
104
105 test('failed job log is escaped and bounded-tail state is visible', async () => {
106 const plugin = createGitHubPlugin({ github: makeGitHub(), menu: makeMenu() });
107 const view = await plugin.resolveCallback('joblog:123:88').execute();
108 assert.match(view.text, /&lt;token&gt;/);
109 assert.doesNotMatch(view.text, /<token>/);
110 assert.match(view.text, /انتهای log|بخش پایانی|truncated/i);
111 });
112
113 test('branches, PRs, issues and releases provide useful drill-down and pagination', async () => {
114 const plugin = createGitHubPlugin({ github: makeGitHub(), menu: makeMenu() });
115 const branchView = await plugin.resolveCallback('branches:123').execute();
116 assert.ok(callbacks(branchView).includes(`compare:123:${sha}`));
117
118 const prList = await plugin.resolveCallback('prs:123').execute();
119 assert.ok(callbacks(prList).includes('prdetail:123:19'));
120 const prDetail = await plugin.resolveCallback('prdetail:123:19').execute();
121 assert.ok(callbacks(prDetail).includes('prfiles:123:19:1'));
122 assert.ok(callbacks(prDetail).includes('prchecks:123:19:1'));
123
124 const issues = await plugin.resolveCallback('issues:123').execute();
125 assert.match(issues.text, /#4/);
126 const releases = await plugin.resolveCallback('releases:123').execute();
127 assert.match(releases.text, /v1\.2\.0/);
128 });
129
130 test('artifacts support bounded page navigation instead of silently stopping at the first page', async () => {
131 const calls = [];
132 const github = makeGitHub();
133 github.listWorkflowArtifacts = async (repoId, runId, options) => {
134 calls.push({ repoId, runId, options });
135 return Array.from({ length: 10 }, (_, i) => ({ id: i + 1, name: `artifact-${i + 1}`, size: 1, expired: false }));
136 };
137 const plugin = createGitHubPlugin({ github, menu: makeMenu() });
138 const route = plugin.resolveCallback('artifacts:123:77:2');
139 assert.equal(route?.actionId, 'github.workflow.artifacts.list');
140 const view = await route.execute();
141 assert.deepEqual(calls[0], { repoId: 123, runId: 77, options: { perPage: 10, page: 2 } });
142 assert.ok(callbacks(view).includes('artifacts:123:77:1'));
143 assert.ok(callbacks(view).includes('artifacts:123:77:3'));
144 });
145
146 test('PR diff pages request only the number of files they can render and expose the next page', async () => {
147 const calls = [];
148 const github = makeGitHub();
149 github.listPullRequestFiles = async (repoId, prNumber, options) => {
150 calls.push({ repoId, prNumber, options });
151 return Array.from({ length: 8 }, (_, i) => ({
152 filename: `src/file-${i + 1}.js`, status: 'modified', additions: 1, deletions: 0, changes: 1, patch: '+x'
153 }));
154 };
155 const plugin = createGitHubPlugin({ github, menu: makeMenu() });
156 const view = await plugin.resolveCallback('prfiles:123:19:1').execute();
157 assert.deepEqual(calls[0], { repoId: 123, prNumber: 19, options: { perPage: 8, page: 1 } });
158 assert.match(view.text, /file-8\.js/);
159 assert.ok(callbacks(view).includes('prfiles:123:19:2'));
160 });