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 { GuidedNexaDevBot } from '../src/guide-bot.js'; |
| 4 | |
| 5 | const repository = { |
| 6 | id: 1001, |
| 7 | name: 'nexa-dev-bot', |
| 8 | full_name: 'owner/nexa-dev-bot', |
| 9 | default_branch: 'main', |
| 10 | private: true |
| 11 | }; |
| 12 | const targetSha = 'a'.repeat(40); |
| 13 | const versionId = '11111111-1111-4111-8111-111111111111'; |
| 14 | |
| 15 | function installProviders(t, { githubFailure = false } = {}) { |
| 16 | const telegramCalls = []; |
| 17 | t.mock.method(globalThis, 'fetch', async (url, options = {}) => { |
| 18 | const endpoint = new URL(url); |
| 19 | if (endpoint.hostname === 'api.telegram.org') { |
| 20 | const body = JSON.parse(options.body); |
| 21 | telegramCalls.push({ method: endpoint.pathname.split('/').at(-1), body }); |
| 22 | return Response.json({ ok: true, result: { message_id: 700 } }); |
| 23 | } |
| 24 | assert.equal( |
| 25 | options.method || 'GET', |
| 26 | 'GET', |
| 27 | 'diagnostics must remain read-only' |
| 28 | ); |
| 29 | if (endpoint.hostname === 'api.github.com') { |
| 30 | if (endpoint.pathname === '/user/repos') { |
| 31 | return githubFailure |
| 32 | ? Response.json({ message: 'Permission denied' }, { status: 403 }) |
| 33 | : Response.json([repository]); |
| 34 | } |
| 35 | if (endpoint.pathname === '/repositories/1001') |
| 36 | return Response.json(repository); |
| 37 | if (endpoint.pathname === '/repos/owner/nexa-dev-bot/commits') { |
| 38 | return Response.json([ |
| 39 | { sha: targetSha, commit: { message: 'docs: verify delivery' } } |
| 40 | ]); |
| 41 | } |
| 42 | if (endpoint.pathname === '/repos/owner/nexa-dev-bot/actions/runs') { |
| 43 | return Response.json({ workflow_runs: [] }); |
| 44 | } |
| 45 | } |
| 46 | if (endpoint.hostname === 'api.cloudflare.com') { |
| 47 | const resource = endpoint.pathname.split('/').at(-1); |
| 48 | const result = { |
| 49 | deployments: { |
| 50 | deployments: [ |
| 51 | { |
| 52 | id: 'deployment-1', |
| 53 | versions: [{ version_id: versionId, percentage: 100 }] |
| 54 | } |
| 55 | ] |
| 56 | }, |
| 57 | versions: { items: [{ id: versionId }] }, |
| 58 | [versionId]: { id: versionId }, |
| 59 | settings: { bindings: [], observability: {} } |
| 60 | }[resource]; |
| 61 | if (result) return Response.json({ success: true, result }); |
| 62 | } |
| 63 | throw new Error( |
| 64 | `Unexpected provider request: ${endpoint.hostname}${endpoint.pathname}` |
| 65 | ); |
| 66 | }); |
| 67 | return telegramCalls; |
| 68 | } |
| 69 | |
| 70 | function createBot() { |
| 71 | return new GuidedNexaDevBot({ |
| 72 | TELEGRAM_BOT_TOKEN: 'telegram-test-token', |
| 73 | TELEGRAM_WEBHOOK_SECRET: 'webhook-test-secret', |
| 74 | OWNER_TELEGRAM_ID: '123', |
| 75 | GITHUB_TOKEN: 'github-test-token', |
| 76 | GITHUB_OWNER: 'owner', |
| 77 | CLOUDFLARE_API_TOKEN: 'cloudflare-test-token', |
| 78 | CLOUDFLARE_ACCOUNT_ID: 'account-1', |
| 79 | CLOUDFLARE_WORKER_NAME: 'nexa-dev-bot' |
| 80 | }); |
| 81 | } |
| 82 | |
| 83 | for (const text of ['/status', '📊 وضعیت']) { |
| 84 | for (const githubFailure of [false, true]) { |
| 85 | test(`${text} sends the resolved live status when GitHub ${githubFailure ? 'fails' : 'succeeds'}`, async (t) => { |
| 86 | const calls = installProviders(t, { githubFailure }); |
| 87 | const result = await createBot().handleMessage({ |
| 88 | chat: { id: 123 }, |
| 89 | from: { id: 123 }, |
| 90 | text |
| 91 | }); |
| 92 | |
| 93 | assert.equal(result.ok, true); |
| 94 | assert.equal(calls.length, 1); |
| 95 | assert.equal(calls[0].method, 'sendMessage'); |
| 96 | assert.equal( |
| 97 | typeof calls[0].body.text, |
| 98 | 'string', |
| 99 | 'status must resolve before sending' |
| 100 | ); |
| 101 | assert.match(calls[0].body.text, /GitHub live READ/); |
| 102 | assert.match( |
| 103 | calls[0].body.text, |
| 104 | githubFailure ? /❌ ناموفق.*403/ : /✅ متصل؛ 1 Repository/ |
| 105 | ); |
| 106 | assert.ok( |
| 107 | calls[0].body.reply_markup.inline_keyboard |
| 108 | .flat() |
| 109 | .some((button) => button.callback_data === 'menu:status') |
| 110 | ); |
| 111 | }); |
| 112 | } |
| 113 | } |
| 114 | |
| 115 | test('Cloudflare delivery callback sends balanced Telegram HTML with provider evidence', async (t) => { |
| 116 | const calls = installProviders(t); |
| 117 | const result = await createBot().handleCallbackQuery({ |
| 118 | id: 'delivery-audit', |
| 119 | from: { id: 123 }, |
| 120 | data: 'cf:delivery', |
| 121 | message: { chat: { id: 123 }, message_id: 700 } |
| 122 | }); |
| 123 | |
| 124 | assert.equal(result.ok, true); |
| 125 | const edited = calls.find((call) => call.method === 'editMessageText'); |
| 126 | assert.equal(edited.body.message_id, 700); |
| 127 | assert.equal(edited.body.parse_mode, 'HTML'); |
| 128 | assert.match(edited.body.text, /CI\/CD Control Plane/); |
| 129 | assert.match(edited.body.text, /State: <b>UNKNOWN<\/b>/); |
| 130 | assert.match(edited.body.text, /aaaaaaaaaaaa/); |
| 131 | assert.match(edited.body.text, /Delivery evidence is incomplete/); |
| 132 | assert.match(edited.body.text, new RegExp(versionId)); |
| 133 | const tags = []; |
| 134 | for (const [, closing, tag] of edited.body.text.matchAll( |
| 135 | /<(\/?)(b|code)>/g |
| 136 | )) { |
| 137 | if (closing) assert.equal(tags.pop(), tag, `unmatched closing ${tag} tag`); |
| 138 | else tags.push(tag); |
| 139 | } |
| 140 | assert.deepEqual(tags, [], 'Telegram HTML must close every opened tag'); |
| 141 | }); |