Personal Telegram developer console for GitHub
nexa/edit-IPHT8irO7b
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 { describe, it } from 'node:test'; |
| 2 | import assert from 'node:assert/strict'; |
| 3 | import { NexaDevBot } from '../src/bot.js'; |
| 4 | |
| 5 | const fakeGitHub = { |
| 6 | owner: 'davoodmehraban89', |
| 7 | async listRepositories() { |
| 8 | return [{ id: 'Factor-easy', name: 'Factor-easy', private: true }]; |
| 9 | }, |
| 10 | async getRepository(repo) { |
| 11 | return { |
| 12 | id: repo, |
| 13 | name: repo, |
| 14 | fullName: `davoodmehraban89/${repo}`, |
| 15 | private: true, |
| 16 | description: 'Factor-easy project', |
| 17 | defaultBranch: 'main', |
| 18 | archived: false |
| 19 | }; |
| 20 | }, |
| 21 | async listPullRequests() { |
| 22 | return [{ |
| 23 | number: 43, |
| 24 | title: 'Ops: strengthen long-running execution heartbeat rule', |
| 25 | author: 'davoodmehraban89', |
| 26 | state: 'open', |
| 27 | merged: false |
| 28 | }]; |
| 29 | }, |
| 30 | async listCommits() { |
| 31 | return []; |
| 32 | }, |
| 33 | async listFiles() { |
| 34 | return []; |
| 35 | }, |
| 36 | async getRepoStatus() { |
| 37 | return { defaultBranch: 'main', lastRuns: [] }; |
| 38 | } |
| 39 | }; |
| 40 | |
| 41 | function makeBot() { |
| 42 | const bot = new NexaDevBot(); |
| 43 | bot.menu.github = fakeGitHub; |
| 44 | return bot; |
| 45 | } |
| 46 | |
| 47 | describe('Nexa Dev Bot - Webhook Dispatcher & In-Place Editing', () => { |
| 48 | it('/start installs the bottom quick menu and sends the inline Main Menu', async () => { |
| 49 | const sentMessages = []; |
| 50 | const bot = makeBot(); |
| 51 | bot.telegram.sendMessage = async (chatId, text, replyMarkup) => { |
| 52 | sentMessages.push({ chatId, text, replyMarkup }); |
| 53 | return { ok: true, result: { message_id: 500 + sentMessages.length } }; |
| 54 | }; |
| 55 | |
| 56 | const res = await bot.handleUpdate({ |
| 57 | message: { message_id: 100, chat: { id: 123456 }, text: '/start' } |
| 58 | }); |
| 59 | |
| 60 | assert.equal(res.ok, true); |
| 61 | assert.equal(res.command, 'start'); |
| 62 | assert.equal(res.persistentMenu, true); |
| 63 | assert.equal(sentMessages.length, 2); |
| 64 | assert.equal(sentMessages[0].chatId, 123456); |
| 65 | assert.equal(sentMessages[0].replyMarkup.is_persistent, true); |
| 66 | assert.ok(sentMessages[0].replyMarkup.keyboard); |
| 67 | assert.equal(sentMessages[1].chatId, 123456); |
| 68 | assert.match(sentMessages[1].text, /Nexa Dev Bot/); |
| 69 | assert.ok(sentMessages[1].replyMarkup.inline_keyboard); |
| 70 | }); |
| 71 | |
| 72 | it('/repos is dispatched through the plugin router', async () => { |
| 73 | const sentMessages = []; |
| 74 | const bot = makeBot(); |
| 75 | const routedView = { |
| 76 | text: 'routed repositories', |
| 77 | reply_markup: { inline_keyboard: [] } |
| 78 | }; |
| 79 | let dispatchCount = 0; |
| 80 | |
| 81 | bot.menu.getReposListView = async () => { |
| 82 | throw new Error('direct repository path must not be used'); |
| 83 | }; |
| 84 | bot.router.dispatchCommand = async (command, context) => { |
| 85 | dispatchCount += 1; |
| 86 | assert.equal(command, '/repos'); |
| 87 | assert.equal(context.isOwner, true); |
| 88 | return routedView; |
| 89 | }; |
| 90 | bot.telegram.sendMessage = async (chatId, text, replyMarkup) => { |
| 91 | sentMessages.push({ chatId, text, replyMarkup }); |
| 92 | return { ok: true }; |
| 93 | }; |
| 94 | |
| 95 | const res = await bot.handleUpdate({ |
| 96 | message: { message_id: 101, chat: { id: 123456 }, text: '/repos' } |
| 97 | }); |
| 98 | |
| 99 | assert.equal(res.ok, true); |
| 100 | assert.equal(res.command, 'repos'); |
| 101 | assert.equal(dispatchCount, 1); |
| 102 | assert.equal(sentMessages.length, 1); |
| 103 | assert.equal(sentMessages[0].text, 'routed repositories'); |
| 104 | }); |
| 105 | |
| 106 | it('callback answers Telegram and edits the existing message in place', async () => { |
| 107 | const answeredCallbacks = []; |
| 108 | const editedMessages = []; |
| 109 | const sentMessages = []; |
| 110 | const bot = makeBot(); |
| 111 | |
| 112 | bot.telegram.answerCallbackQuery = async (id) => { |
| 113 | answeredCallbacks.push(id); |
| 114 | return { ok: true }; |
| 115 | }; |
| 116 | bot.telegram.editMessageText = async (chatId, messageId, text, replyMarkup) => { |
| 117 | editedMessages.push({ chatId, messageId, text, replyMarkup }); |
| 118 | return { ok: true }; |
| 119 | }; |
| 120 | bot.telegram.sendMessage = async () => { |
| 121 | sentMessages.push(true); |
| 122 | return { ok: true }; |
| 123 | }; |
| 124 | |
| 125 | const res = await bot.handleUpdate({ |
| 126 | callback_query: { |
| 127 | id: 'cb_999', |
| 128 | data: 'menu:repos', |
| 129 | message: { message_id: 501, chat: { id: 123456 } } |
| 130 | } |
| 131 | }); |
| 132 | |
| 133 | assert.equal(res.ok, true); |
| 134 | assert.equal(res.edited, true); |
| 135 | assert.deepEqual(answeredCallbacks, ['cb_999']); |
| 136 | assert.equal(editedMessages.length, 1); |
| 137 | assert.equal(sentMessages.length, 0); |
| 138 | assert.equal(editedMessages[0].messageId, 501); |
| 139 | assert.match(editedMessages[0].text, /فهرست مخزنها/); |
| 140 | }); |
| 141 | |
| 142 | it('github callbacks are dispatched through the plugin router before editing', async () => { |
| 143 | const bot = makeBot(); |
| 144 | const edits = []; |
| 145 | let dispatchCount = 0; |
| 146 | |
| 147 | bot.telegram.answerCallbackQuery = async () => ({ ok: true }); |
| 148 | bot.menu.renderByCallback = async () => { |
| 149 | throw new Error('direct github callback path must not be used'); |
| 150 | }; |
| 151 | bot.router.dispatchCallback = async (data, context) => { |
| 152 | dispatchCount += 1; |
| 153 | assert.equal(data, 'repo:Factor-easy'); |
| 154 | assert.equal(context.isOwner, true); |
| 155 | return { |
| 156 | text: 'routed project', |
| 157 | reply_markup: { inline_keyboard: [] } |
| 158 | }; |
| 159 | }; |
| 160 | bot.telegram.editMessageText = async (chatId, messageId, text, replyMarkup) => { |
| 161 | edits.push({ chatId, messageId, text, replyMarkup }); |
| 162 | return { ok: true }; |
| 163 | }; |
| 164 | |
| 165 | const res = await bot.handleUpdate({ |
| 166 | callback_query: { |
| 167 | id: 'cb_route', |
| 168 | data: 'repo:Factor-easy', |
| 169 | message: { message_id: 501, chat: { id: 123456 } } |
| 170 | } |
| 171 | }); |
| 172 | |
| 173 | assert.equal(res.ok, true); |
| 174 | assert.equal(res.edited, true); |
| 175 | assert.equal(dispatchCount, 1); |
| 176 | assert.equal(edits.length, 1); |
| 177 | assert.equal(edits[0].text, 'routed project'); |
| 178 | }); |
| 179 | |
| 180 | it('callback navigation still edits when answerCallbackQuery fails', async () => { |
| 181 | const editedMessages = []; |
| 182 | const bot = makeBot(); |
| 183 | |
| 184 | bot.telegram.answerCallbackQuery = async () => { |
| 185 | throw new Error('Telegram API answerCallbackQuery failed: query is too old'); |
| 186 | }; |
| 187 | bot.telegram.editMessageText = async (chatId, messageId, text, replyMarkup) => { |
| 188 | editedMessages.push({ chatId, messageId, text, replyMarkup }); |
| 189 | return { ok: true }; |
| 190 | }; |
| 191 | |
| 192 | const res = await bot.handleUpdate({ |
| 193 | callback_query: { |
| 194 | id: 'cb_stale', |
| 195 | data: 'menu:main', |
| 196 | message: { message_id: 501, chat: { id: 123456 } } |
| 197 | } |
| 198 | }); |
| 199 | |
| 200 | assert.equal(res.ok, true); |
| 201 | assert.equal(res.edited, true); |
| 202 | assert.equal(editedMessages.length, 1); |
| 203 | assert.equal(editedMessages[0].messageId, 501); |
| 204 | assert.match(editedMessages[0].text, /Nexa Dev Bot/); |
| 205 | }); |
| 206 | |
| 207 | it('multi-tier back navigation stays on the same Telegram message', async () => { |
| 208 | const edits = []; |
| 209 | const bot = makeBot(); |
| 210 | bot.telegram.answerCallbackQuery = async () => ({ ok: true }); |
| 211 | bot.telegram.editMessageText = async (chatId, messageId, text, replyMarkup) => { |
| 212 | edits.push({ chatId, messageId, text, replyMarkup }); |
| 213 | return { ok: true }; |
| 214 | }; |
| 215 | |
| 216 | const message = { message_id: 501, chat: { id: 123456 } }; |
| 217 | for (const data of ['repo:Factor-easy', 'pr:Factor-easy', 'repo:Factor-easy', 'menu:repos', 'menu:main']) { |
| 218 | const result = await bot.handleUpdate({ |
| 219 | callback_query: { id: data, data, message } |
| 220 | }); |
| 221 | assert.equal(result.ok, true); |
| 222 | } |
| 223 | |
| 224 | assert.equal(edits.length, 5); |
| 225 | assert.ok(edits.every(edit => edit.messageId === 501)); |
| 226 | assert.match(edits[0].text, /پروژه: Factor-easy/); |
| 227 | assert.match(edits[1].text, /#43/); |
| 228 | assert.match(edits[3].text, /فهرست مخزنها/); |
| 229 | assert.match(edits[4].text, /Nexa Dev Bot/); |
| 230 | }); |
| 231 | }); |