Personal Telegram developer console for GitHub
feat/studio-g0-foundation
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
| 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 || []) |
| 10 | .flat() |
| 11 | .map((button) => button.callback_data) |
| 12 | .filter(Boolean); |
| 13 | } |
| 14 | |
| 15 | function makeGitHub() { |
| 16 | const calls = []; |
| 17 | const hit = (name, value) => { |
| 18 | calls.push([name, value]); |
| 19 | return value; |
| 20 | }; |
| 21 | return { |
| 22 | calls, |
| 23 | async getRepository(id) { |
| 24 | return hit('getRepository', { |
| 25 | id: String(id), |
| 26 | name: 'nexa-dev-bot', |
| 27 | defaultBranch: 'main' |
| 28 | }); |
| 29 | }, |
| 30 | async listWorkflowRuns() { |
| 31 | return [ |
| 32 | { |
| 33 | id: 77, |
| 34 | name: 'CI', |
| 35 | status: 'completed', |
| 36 | conclusion: 'success', |
| 37 | branch: 'main', |
| 38 | sha: 'abc1234', |
| 39 | runNumber: 44 |
| 40 | } |
| 41 | ]; |
| 42 | }, |
| 43 | async getWorkflowRun(repo, run) { |
| 44 | return hit('getWorkflowRun', { |
| 45 | id: run, |
| 46 | name: 'CI', |
| 47 | status: 'completed', |
| 48 | conclusion: 'failure', |
| 49 | runNumber: 134, |
| 50 | branch: 'main', |
| 51 | sha: 'abc1234', |
| 52 | event: 'push' |
| 53 | }); |
| 54 | }, |
| 55 | async listWorkflowJobs() { |
| 56 | return hit('listWorkflowJobs', [ |
| 57 | { |
| 58 | id: 88, |
| 59 | name: 'test', |
| 60 | status: 'completed', |
| 61 | conclusion: 'failure', |
| 62 | steps: [{ number: 1, name: 'Run tests', conclusion: 'failure' }] |
| 63 | } |
| 64 | ]); |
| 65 | }, |
| 66 | async getWorkflowJob() { |
| 67 | return hit('getWorkflowJob', { |
| 68 | id: 88, |
| 69 | name: 'test', |
| 70 | status: 'completed', |
| 71 | conclusion: 'failure', |
| 72 | steps: [{ number: 1, name: 'Run tests', conclusion: 'failure' }] |
| 73 | }); |
| 74 | }, |
| 75 | async getWorkflowJobLog() { |
| 76 | return hit('getWorkflowJobLog', { |
| 77 | text: '<token>\nFAIL expected', |
| 78 | truncated: true |
| 79 | }); |
| 80 | }, |
| 81 | async listWorkflowArtifacts() { |
| 82 | return hit('listWorkflowArtifacts', [ |
| 83 | { |
| 84 | id: 9, |
| 85 | name: 'coverage', |
| 86 | size: 1234, |
| 87 | expired: false, |
| 88 | createdAt: '2026-10-03T00:00:00Z', |
| 89 | expiresAt: '2026-10-10T00:00:00Z' |
| 90 | } |
| 91 | ]); |
| 92 | }, |
| 93 | async listBranches() { |
| 94 | return hit('listBranches', [ |
| 95 | { name: 'feature/x', sha, protected: false } |
| 96 | ]); |
| 97 | }, |
| 98 | async compareWithDefault() { |
| 99 | return hit('compareWithDefault', { |
| 100 | base: 'main', |
| 101 | head: sha, |
| 102 | status: 'ahead', |
| 103 | aheadBy: 2, |
| 104 | behindBy: 0, |
| 105 | totalCommits: 2, |
| 106 | files: [ |
| 107 | { |
| 108 | filename: 'src/x.js', |
| 109 | status: 'modified', |
| 110 | additions: 3, |
| 111 | deletions: 1, |
| 112 | changes: 4, |
| 113 | patch: '+x' |
| 114 | } |
| 115 | ] |
| 116 | }); |
| 117 | }, |
| 118 | async listPullRequests() { |
| 119 | return hit('listPullRequests', [ |
| 120 | { |
| 121 | number: 19, |
| 122 | title: 'Feature', |
| 123 | author: 'dev', |
| 124 | state: 'open', |
| 125 | merged: false |
| 126 | } |
| 127 | ]); |
| 128 | }, |
| 129 | async getPullRequest() { |
| 130 | return hit('getPullRequest', { |
| 131 | number: 19, |
| 132 | title: 'Feature', |
| 133 | author: 'dev', |
| 134 | state: 'open', |
| 135 | merged: false, |
| 136 | body: 'Body', |
| 137 | head: 'feature/x', |
| 138 | headSha: sha, |
| 139 | base: 'main', |
| 140 | additions: 3, |
| 141 | deletions: 1, |
| 142 | changedFiles: 1 |
| 143 | }); |
| 144 | }, |
| 145 | async listPullRequestFiles() { |
| 146 | return hit('listPullRequestFiles', [ |
| 147 | { |
| 148 | filename: 'src/x.js', |
| 149 | status: 'modified', |
| 150 | additions: 3, |
| 151 | deletions: 1, |
| 152 | changes: 4, |
| 153 | patch: '+x' |
| 154 | } |
| 155 | ]); |
| 156 | }, |
| 157 | async listCommitChecks() { |
| 158 | return hit('listCommitChecks', [ |
| 159 | { id: 7, name: 'CI', status: 'completed', conclusion: 'success' } |
| 160 | ]); |
| 161 | }, |
| 162 | async listIssues() { |
| 163 | return hit('listIssues', [ |
| 164 | { number: 4, title: 'Bug', state: 'open', author: 'u', comments: 2 } |
| 165 | ]); |
| 166 | }, |
| 167 | async listIssuesPage() { |
| 168 | return hit('listIssuesPage', { |
| 169 | items: [ |
| 170 | { number: 4, title: 'Bug', state: 'open', author: 'u', comments: 2 } |
| 171 | ], |
| 172 | hasMore: false |
| 173 | }); |
| 174 | }, |
| 175 | async listReleases() { |
| 176 | return hit('listReleases', [ |
| 177 | { |
| 178 | id: 6, |
| 179 | tag: 'v1.2.0', |
| 180 | name: 'Release 1.2', |
| 181 | draft: false, |
| 182 | prerelease: false, |
| 183 | publishedAt: '2026-10-03T00:00:00Z' |
| 184 | } |
| 185 | ]); |
| 186 | }, |
| 187 | async rerunFailedWorkflowRun() {}, |
| 188 | async cancelWorkflowRun() {} |
| 189 | }; |
| 190 | } |
| 191 | |
| 192 | function makeMenu() { |
| 193 | return { |
| 194 | async getReposListView() { |
| 195 | return { text: 'repos', reply_markup: { inline_keyboard: [] } }; |
| 196 | }, |
| 197 | async renderByCallback(data) { |
| 198 | if (String(data).startsWith('repo:')) { |
| 199 | const repoId = String(data).split(':')[1]; |
| 200 | return { |
| 201 | text: 'repo', |
| 202 | reply_markup: { |
| 203 | inline_keyboard: [ |
| 204 | [ |
| 205 | { text: 'PRها', callback_data: `pr:${repoId}` }, |
| 206 | { text: 'وضعیت', callback_data: `status:${repoId}` } |
| 207 | ], |
| 208 | [{ text: 'back', callback_data: 'menu:repos' }] |
| 209 | ] |
| 210 | } |
| 211 | }; |
| 212 | } |
| 213 | return { text: `legacy:${data}`, reply_markup: { inline_keyboard: [] } }; |
| 214 | } |
| 215 | }; |
| 216 | } |
| 217 | |
| 218 | const advancedReadActions = [ |
| 219 | 'github.workflow.job.detail', |
| 220 | 'github.workflow.job.log', |
| 221 | 'github.workflow.artifacts.list', |
| 222 | 'github.branches.list', |
| 223 | 'github.compare.read', |
| 224 | 'github.pr.advanced.list', |
| 225 | 'github.pr.detail', |
| 226 | 'github.pr.files.list', |
| 227 | 'github.pr.checks.list', |
| 228 | 'github.issues.list', |
| 229 | 'github.releases.list' |
| 230 | ]; |
| 231 | |
| 232 | test('GitHub Advanced manifest declares every new action as READ', () => { |
| 233 | for (const actionId of advancedReadActions) |
| 234 | assert.equal( |
| 235 | githubPluginManifest.actions[actionId]?.risk, |
| 236 | 'READ', |
| 237 | actionId |
| 238 | ); |
| 239 | }); |
| 240 | |
| 241 | test('advanced callbacks resolve without provider side effects and callbacks stay Telegram-safe', async () => { |
| 242 | const github = makeGitHub(); |
| 243 | const plugin = createGitHubPlugin({ github, menu: makeMenu() }); |
| 244 | const samples = [ |
| 245 | ['job:123:88', 'github.workflow.job.detail'], |
| 246 | ['joblog:123:88', 'github.workflow.job.log'], |
| 247 | ['artifacts:123:77', 'github.workflow.artifacts.list'], |
| 248 | ['branches:123', 'github.branches.list'], |
| 249 | [`compare:123:${sha}`, 'github.compare.read'], |
| 250 | ['prs:123', 'github.pr.advanced.list'], |
| 251 | ['prdetail:123:19', 'github.pr.detail'], |
| 252 | ['prfiles:123:19:1', 'github.pr.files.list'], |
| 253 | ['prchecks:123:19:1', 'github.pr.checks.list'], |
| 254 | ['issues:123', 'github.issues.list'], |
| 255 | ['releases:123', 'github.releases.list'] |
| 256 | ]; |
| 257 | for (const [data, actionId] of samples) { |
| 258 | const route = plugin.resolveCallback(data); |
| 259 | assert.equal(route?.actionId, actionId, data); |
| 260 | assert.equal( |
| 261 | github.calls.length, |
| 262 | 0, |
| 263 | `provider called during resolve: ${data}` |
| 264 | ); |
| 265 | const view = await route.execute(); |
| 266 | for (const callback of callbacks(view)) |
| 267 | assert.ok( |
| 268 | callback.length <= 64, |
| 269 | `${callback} exceeds Telegram callback_data limit` |
| 270 | ); |
| 271 | github.calls.length = 0; |
| 272 | } |
| 273 | }); |
| 274 | |
| 275 | test('repository and workflow views expose Advanced READ navigation', async () => { |
| 276 | const github = makeGitHub(); |
| 277 | const plugin = createGitHubPlugin({ github, menu: makeMenu() }); |
| 278 | const repoView = await plugin.resolveCallback('repo:123').execute(); |
| 279 | const repoCallbacks = callbacks(repoView); |
| 280 | for (const expected of [ |
| 281 | 'status:123', |
| 282 | 'branches:123', |
| 283 | 'pr:123', |
| 284 | 'issues:123', |
| 285 | 'releases:123' |
| 286 | ]) |
| 287 | assert.ok(repoCallbacks.includes(expected), expected); |
| 288 | assert.ok( |
| 289 | !repoCallbacks.includes('prs:123'), |
| 290 | 'repository view must not expose a duplicate advanced PR entry' |
| 291 | ); |
| 292 | assert.ok( |
| 293 | !repoCallbacks.includes('runs:123'), |
| 294 | 'repository view must not expose a duplicate CI entry' |
| 295 | ); |
| 296 | |
| 297 | const runView = await plugin.resolveCallback('run:123:77').execute(); |
| 298 | assert.ok(callbacks(runView).includes('artifacts:123:77')); |
| 299 | |
| 300 | const jobsView = await plugin.resolveCallback('jobs:123:77').execute(); |
| 301 | assert.ok(callbacks(jobsView).includes('job:123:88')); |
| 302 | |
| 303 | const jobView = await plugin.resolveCallback('job:123:88').execute(); |
| 304 | assert.ok(callbacks(jobView).includes('joblog:123:88')); |
| 305 | }); |
| 306 | |
| 307 | test('legacy repository status button resolves to actionable workflow runs', async () => { |
| 308 | const plugin = createGitHubPlugin({ github: makeGitHub(), menu: makeMenu() }); |
| 309 | const route = plugin.resolveCallback('status:123'); |
| 310 | assert.equal(route?.actionId, 'github.workflow.runs.list'); |
| 311 | const view = await route.execute(); |
| 312 | assert.ok( |
| 313 | callbacks(view).includes('run:123:77'), |
| 314 | 'repository status button must drill into workflow run detail' |
| 315 | ); |
| 316 | }); |
| 317 | |
| 318 | test('legacy repository PR button resolves to the actionable advanced PR report', async () => { |
| 319 | const plugin = createGitHubPlugin({ github: makeGitHub(), menu: makeMenu() }); |
| 320 | const route = plugin.resolveCallback('pr:123'); |
| 321 | assert.equal(route?.actionId, 'github.pr.advanced.list'); |
| 322 | const view = await route.execute(); |
| 323 | assert.ok( |
| 324 | callbacks(view).includes('prdetail:123:19'), |
| 325 | 'repository PR button must drill into PR detail' |
| 326 | ); |
| 327 | }); |
| 328 | |
| 329 | test('job-log callback keeps raw log and source out of Telegram', async () => { |
| 330 | const github = makeGitHub(); |
| 331 | const plugin = createGitHubPlugin({ github, menu: makeMenu() }); |
| 332 | const view = await plugin.resolveCallback('joblog:123:88').execute(); |
| 333 | assert.doesNotMatch(view.text, /token|FAIL expected/); |
| 334 | assert.match(view.text, /GitHub/); |
| 335 | assert.equal( |
| 336 | github.calls.some(([name]) => name === 'getWorkflowJobLog'), |
| 337 | false |
| 338 | ); |
| 339 | }); |
| 340 | |
| 341 | test('branches, PRs, issues and releases provide useful drill-down and pagination', async () => { |
| 342 | const plugin = createGitHubPlugin({ github: makeGitHub(), menu: makeMenu() }); |
| 343 | const branchView = await plugin.resolveCallback('branches:123').execute(); |
| 344 | assert.ok(callbacks(branchView).includes(`compare:123:${sha}`)); |
| 345 | |
| 346 | const prList = await plugin.resolveCallback('prs:123').execute(); |
| 347 | assert.ok(callbacks(prList).includes('prdetail:123:19')); |
| 348 | const prDetail = await plugin.resolveCallback('prdetail:123:19').execute(); |
| 349 | assert.ok(callbacks(prDetail).includes('prfiles:123:19:1')); |
| 350 | assert.ok(callbacks(prDetail).includes('prchecks:123:19:1')); |
| 351 | |
| 352 | const issues = await plugin.resolveCallback('issues:123').execute(); |
| 353 | assert.match(issues.text, /#4/); |
| 354 | const releases = await plugin.resolveCallback('releases:123').execute(); |
| 355 | assert.match(releases.text, /v1\.2\.0/); |
| 356 | }); |
| 357 | |
| 358 | test('artifacts support bounded page navigation instead of silently stopping at the first page', async () => { |
| 359 | const calls = []; |
| 360 | const github = makeGitHub(); |
| 361 | github.listWorkflowArtifacts = async (repoId, runId, options) => { |
| 362 | calls.push({ repoId, runId, options }); |
| 363 | return Array.from({ length: 10 }, (_, i) => ({ |
| 364 | id: i + 1, |
| 365 | name: `artifact-${i + 1}`, |
| 366 | size: 1, |
| 367 | expired: false |
| 368 | })); |
| 369 | }; |
| 370 | const plugin = createGitHubPlugin({ github, menu: makeMenu() }); |
| 371 | const route = plugin.resolveCallback('artifacts:123:77:2'); |
| 372 | assert.equal(route?.actionId, 'github.workflow.artifacts.list'); |
| 373 | const view = await route.execute(); |
| 374 | assert.deepEqual(calls[0], { |
| 375 | repoId: 123, |
| 376 | runId: 77, |
| 377 | options: { perPage: 10, page: 2 } |
| 378 | }); |
| 379 | assert.ok(callbacks(view).includes('artifacts:123:77:1')); |
| 380 | assert.ok(callbacks(view).includes('artifacts:123:77:3')); |
| 381 | }); |
| 382 | |
| 383 | test('PR diff pages request only the number of files they can render and expose the next page', async () => { |
| 384 | const calls = []; |
| 385 | const github = makeGitHub(); |
| 386 | github.listPullRequestFiles = async (repoId, prNumber, options) => { |
| 387 | calls.push({ repoId, prNumber, options }); |
| 388 | return Array.from({ length: 8 }, (_, i) => ({ |
| 389 | filename: `src/file-${i + 1}.js`, |
| 390 | status: 'modified', |
| 391 | additions: 1, |
| 392 | deletions: 0, |
| 393 | changes: 1, |
| 394 | patch: '+x' |
| 395 | })); |
| 396 | }; |
| 397 | const plugin = createGitHubPlugin({ github, menu: makeMenu() }); |
| 398 | const view = await plugin.resolveCallback('prfiles:123:19:1').execute(); |
| 399 | assert.deepEqual(calls[0], { |
| 400 | repoId: 123, |
| 401 | prNumber: 19, |
| 402 | options: { perPage: 8, page: 1 } |
| 403 | }); |
| 404 | assert.match(view.text, /file-8\.js/); |
| 405 | assert.ok(callbacks(view).includes('prfiles:123:19:2')); |
| 406 | }); |
| 407 | |
| 408 | test('PR file list never renders provider patch contents in Telegram', async () => { |
| 409 | const github = makeGitHub(); |
| 410 | github.listPullRequestFiles = async () => [ |
| 411 | { |
| 412 | filename: 'src/example.js', |
| 413 | status: 'modified', |
| 414 | additions: 1, |
| 415 | deletions: 0, |
| 416 | patch: '+PRIVATE_SOURCE_SENTINEL_9281' |
| 417 | } |
| 418 | ]; |
| 419 | const plugin = createGitHubPlugin({ github, menu: makeMenu() }); |
| 420 | const view = await plugin.resolveCallback('prfiles:123:19:1').execute(); |
| 421 | assert.match(view.text, /src\/example\.js/); |
| 422 | assert.doesNotMatch(view.text, /PRIVATE_SOURCE_SENTINEL_9281/); |
| 423 | assert.doesNotMatch(view.text, /<pre>/); |
| 424 | }); |