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 { describe, it } from 'node:test'; |
| 2 | import assert from 'node:assert/strict'; |
| 3 | import { NexaDevBot } from '../src/bot.js'; |
| 4 | import { GuidedNexaDevBot } from '../src/guide-bot.js'; |
| 5 | |
| 6 | const fakeGitHub = { |
| 7 | owner: 'davoodmehraban89', |
| 8 | async listRepositories() { |
| 9 | return [{ id: 'Factor-easy', name: 'Factor-easy', private: true }]; |
| 10 | }, |
| 11 | async getRepository(repo) { |
| 12 | return { |
| 13 | id: repo, |
| 14 | name: repo, |
| 15 | fullName: `davoodmehraban89/${repo}`, |
| 16 | private: true, |
| 17 | description: 'Factor-easy project', |
| 18 | defaultBranch: 'main', |
| 19 | archived: false |
| 20 | }; |
| 21 | }, |
| 22 | async listPullRequests() { |
| 23 | return [ |
| 24 | { |
| 25 | number: 43, |
| 26 | title: 'Ops: strengthen long-running execution heartbeat rule', |
| 27 | author: 'davoodmehraban89', |
| 28 | state: 'open', |
| 29 | merged: false |
| 30 | } |
| 31 | ]; |
| 32 | }, |
| 33 | async listCommits() { |
| 34 | return []; |
| 35 | }, |
| 36 | async listFiles() { |
| 37 | return []; |
| 38 | }, |
| 39 | async getRepoStatus() { |
| 40 | return { defaultBranch: 'main', lastRuns: [] }; |
| 41 | } |
| 42 | }; |
| 43 | |
| 44 | function makeBot() { |
| 45 | const bot = new NexaDevBot(); |
| 46 | bot.menu.github = fakeGitHub; |
| 47 | return bot; |
| 48 | } |
| 49 | |
| 50 | describe('Nexa Dev Bot - Cloudflare plugin registration', () => { |
| 51 | it('registers the Cloudflare READ plugin and fails closed when provider config is absent', async () => { |
| 52 | const bot = new NexaDevBot(); |
| 53 | assert.ok( |
| 54 | bot.registry.getPlugin('cloudflare'), |
| 55 | 'cloudflare plugin must be registered' |
| 56 | ); |
| 57 | assert.deepEqual(bot.registry.getAction('cloudflare.worker.status'), { |
| 58 | pluginId: 'cloudflare', |
| 59 | actionId: 'cloudflare.worker.status', |
| 60 | risk: 'READ' |
| 61 | }); |
| 62 | |
| 63 | const view = await bot.router.dispatchCallback('cf:status', { |
| 64 | isOwner: true, |
| 65 | ownerId: '123' |
| 66 | }); |
| 67 | assert.match(view.text, /پیکربندی نشده|not configured/i); |
| 68 | }); |
| 69 | }); |
| 70 | |
| 71 | describe('Nexa Dev Bot - Webhook Dispatcher & In-Place Editing', () => { |
| 72 | it('/start on the deployed guided bot clears the old keyboard and opens Studio', async () => { |
| 73 | const sentMessages = []; |
| 74 | const bot = new GuidedNexaDevBot({ OWNER_TELEGRAM_ID: '123456' }); |
| 75 | bot.telegram.sendMessage = async (chatId, text, replyMarkup) => { |
| 76 | sentMessages.push({ chatId, text, replyMarkup }); |
| 77 | return { ok: true, result: { message_id: 500 + sentMessages.length } }; |
| 78 | }; |
| 79 | bot.telegram.setChatMenuButton = async () => ({ ok: true }); |
| 80 | |
| 81 | const res = await bot.handleUpdate({ |
| 82 | message: { |
| 83 | message_id: 100, |
| 84 | from: { id: 123456 }, |
| 85 | chat: { id: 123456, type: 'private' }, |
| 86 | text: '/start' |
| 87 | } |
| 88 | }); |
| 89 | |
| 90 | assert.equal(res.ok, true); |
| 91 | assert.equal(res.command, 'start'); |
| 92 | assert.equal(res.studioEntry, true); |
| 93 | assert.equal(sentMessages.length, 2); |
| 94 | assert.equal(sentMessages[0].chatId, 123456); |
| 95 | assert.deepEqual(sentMessages[0].replyMarkup, { remove_keyboard: true }); |
| 96 | assert.equal(sentMessages[1].chatId, 123456); |
| 97 | assert.match(sentMessages[1].text, /Nexa Studio/); |
| 98 | assert.deepEqual(sentMessages[1].replyMarkup, { |
| 99 | inline_keyboard: [ |
| 100 | [ |
| 101 | { |
| 102 | text: 'باز کردن Nexa Studio', |
| 103 | web_app: { |
| 104 | url: 'https://nexa-dev-bot.davoodmehraban89.workers.dev/studio/' |
| 105 | } |
| 106 | } |
| 107 | ] |
| 108 | ] |
| 109 | }); |
| 110 | }); |
| 111 | |
| 112 | it('/repos is dispatched through the plugin router', async () => { |
| 113 | const sentMessages = []; |
| 114 | const bot = makeBot(); |
| 115 | const routedView = { |
| 116 | text: 'routed repositories', |
| 117 | reply_markup: { inline_keyboard: [] } |
| 118 | }; |
| 119 | let dispatchCount = 0; |
| 120 | |
| 121 | bot.menu.getReposListView = async () => { |
| 122 | throw new Error('direct repository path must not be used'); |
| 123 | }; |
| 124 | bot.router.dispatchCommand = async (command, context) => { |
| 125 | dispatchCount += 1; |
| 126 | assert.equal(command, '/repos'); |
| 127 | assert.equal(context.isOwner, true); |
| 128 | return routedView; |
| 129 | }; |
| 130 | bot.telegram.sendMessage = async (chatId, text, replyMarkup) => { |
| 131 | sentMessages.push({ chatId, text, replyMarkup }); |
| 132 | return { ok: true }; |
| 133 | }; |
| 134 | |
| 135 | const res = await bot.handleUpdate({ |
| 136 | message: { message_id: 101, chat: { id: 123456 }, text: '/repos' } |
| 137 | }); |
| 138 | |
| 139 | assert.equal(res.ok, true); |
| 140 | assert.equal(res.command, 'repos'); |
| 141 | assert.equal(dispatchCount, 1); |
| 142 | assert.equal(sentMessages.length, 1); |
| 143 | assert.equal(sentMessages[0].text, 'routed repositories'); |
| 144 | }); |
| 145 | |
| 146 | it('callback answers Telegram and edits the existing message in place', async () => { |
| 147 | const answeredCallbacks = []; |
| 148 | const editedMessages = []; |
| 149 | const sentMessages = []; |
| 150 | const bot = makeBot(); |
| 151 | |
| 152 | bot.telegram.answerCallbackQuery = async (id) => { |
| 153 | answeredCallbacks.push(id); |
| 154 | return { ok: true }; |
| 155 | }; |
| 156 | bot.telegram.editMessageText = async ( |
| 157 | chatId, |
| 158 | messageId, |
| 159 | text, |
| 160 | replyMarkup |
| 161 | ) => { |
| 162 | editedMessages.push({ chatId, messageId, text, replyMarkup }); |
| 163 | return { ok: true }; |
| 164 | }; |
| 165 | bot.telegram.sendMessage = async () => { |
| 166 | sentMessages.push(true); |
| 167 | return { ok: true }; |
| 168 | }; |
| 169 | |
| 170 | const res = await bot.handleUpdate({ |
| 171 | callback_query: { |
| 172 | id: 'cb_999', |
| 173 | data: 'menu:repos', |
| 174 | message: { message_id: 501, chat: { id: 123456 } } |
| 175 | } |
| 176 | }); |
| 177 | |
| 178 | assert.equal(res.ok, true); |
| 179 | assert.equal(res.edited, true); |
| 180 | assert.deepEqual(answeredCallbacks, ['cb_999']); |
| 181 | assert.equal(editedMessages.length, 1); |
| 182 | assert.equal(sentMessages.length, 0); |
| 183 | assert.equal(editedMessages[0].messageId, 501); |
| 184 | assert.match(editedMessages[0].text, /فهرست مخزنها/); |
| 185 | }); |
| 186 | |
| 187 | it('github callbacks are dispatched through the plugin router before editing', async () => { |
| 188 | const bot = makeBot(); |
| 189 | const edits = []; |
| 190 | let dispatchCount = 0; |
| 191 | |
| 192 | bot.telegram.answerCallbackQuery = async () => ({ ok: true }); |
| 193 | bot.menu.renderByCallback = async () => { |
| 194 | throw new Error('direct github callback path must not be used'); |
| 195 | }; |
| 196 | bot.router.dispatchCallback = async (data, context) => { |
| 197 | dispatchCount += 1; |
| 198 | assert.equal(data, 'repo:Factor-easy'); |
| 199 | assert.equal(context.isOwner, true); |
| 200 | return { |
| 201 | text: 'routed project', |
| 202 | reply_markup: { inline_keyboard: [] } |
| 203 | }; |
| 204 | }; |
| 205 | bot.telegram.editMessageText = async ( |
| 206 | chatId, |
| 207 | messageId, |
| 208 | text, |
| 209 | replyMarkup |
| 210 | ) => { |
| 211 | edits.push({ chatId, messageId, text, replyMarkup }); |
| 212 | return { ok: true }; |
| 213 | }; |
| 214 | |
| 215 | const res = await bot.handleUpdate({ |
| 216 | callback_query: { |
| 217 | id: 'cb_route', |
| 218 | data: 'repo:Factor-easy', |
| 219 | message: { message_id: 501, chat: { id: 123456 } } |
| 220 | } |
| 221 | }); |
| 222 | |
| 223 | assert.equal(res.ok, true); |
| 224 | assert.equal(res.edited, true); |
| 225 | assert.equal(dispatchCount, 1); |
| 226 | assert.equal(edits.length, 1); |
| 227 | assert.equal(edits[0].text, 'routed project'); |
| 228 | }); |
| 229 | |
| 230 | it('menu:main falls back to local menu when no plugin route claims it', async () => { |
| 231 | const bot = makeBot(); |
| 232 | const edits = []; |
| 233 | bot.telegram.answerCallbackQuery = async () => ({ ok: true }); |
| 234 | bot.router.dispatchCallback = async () => null; |
| 235 | bot.telegram.editMessageText = async ( |
| 236 | chatId, |
| 237 | messageId, |
| 238 | text, |
| 239 | replyMarkup |
| 240 | ) => { |
| 241 | edits.push({ chatId, messageId, text, replyMarkup }); |
| 242 | return { ok: true }; |
| 243 | }; |
| 244 | const res = await bot.handleUpdate({ |
| 245 | callback_query: { |
| 246 | id: 'cb_main_local', |
| 247 | data: 'menu:main', |
| 248 | from: { id: 123456 }, |
| 249 | message: { message_id: 501, chat: { id: 123456 } } |
| 250 | } |
| 251 | }); |
| 252 | assert.equal(res.ok, true); |
| 253 | assert.equal(res.edited, true); |
| 254 | assert.equal(edits.length, 1); |
| 255 | assert.match(edits[0].text, /Nexa Dev Bot/); |
| 256 | }); |
| 257 | |
| 258 | it('callback navigation still edits when answerCallbackQuery fails', async () => { |
| 259 | const editedMessages = []; |
| 260 | const bot = makeBot(); |
| 261 | |
| 262 | bot.telegram.answerCallbackQuery = async () => { |
| 263 | throw new Error( |
| 264 | 'Telegram API answerCallbackQuery failed: query is too old' |
| 265 | ); |
| 266 | }; |
| 267 | bot.telegram.editMessageText = async ( |
| 268 | chatId, |
| 269 | messageId, |
| 270 | text, |
| 271 | replyMarkup |
| 272 | ) => { |
| 273 | editedMessages.push({ chatId, messageId, text, replyMarkup }); |
| 274 | return { ok: true }; |
| 275 | }; |
| 276 | |
| 277 | const res = await bot.handleUpdate({ |
| 278 | callback_query: { |
| 279 | id: 'cb_stale', |
| 280 | data: 'menu:main', |
| 281 | message: { message_id: 501, chat: { id: 123456 } } |
| 282 | } |
| 283 | }); |
| 284 | |
| 285 | assert.equal(res.ok, true); |
| 286 | assert.equal(res.edited, true); |
| 287 | assert.equal(editedMessages.length, 1); |
| 288 | assert.equal(editedMessages[0].messageId, 501); |
| 289 | assert.match(editedMessages[0].text, /Nexa Dev Bot/); |
| 290 | }); |
| 291 | |
| 292 | it('multi-tier back navigation stays on the same Telegram message', async () => { |
| 293 | const edits = []; |
| 294 | const bot = makeBot(); |
| 295 | bot.telegram.answerCallbackQuery = async () => ({ ok: true }); |
| 296 | bot.telegram.editMessageText = async ( |
| 297 | chatId, |
| 298 | messageId, |
| 299 | text, |
| 300 | replyMarkup |
| 301 | ) => { |
| 302 | edits.push({ chatId, messageId, text, replyMarkup }); |
| 303 | return { ok: true }; |
| 304 | }; |
| 305 | |
| 306 | const message = { message_id: 501, chat: { id: 123456 } }; |
| 307 | for (const data of [ |
| 308 | 'repo:Factor-easy', |
| 309 | 'pr:Factor-easy', |
| 310 | 'repo:Factor-easy', |
| 311 | 'menu:repos', |
| 312 | 'menu:main' |
| 313 | ]) { |
| 314 | const result = await bot.handleUpdate({ |
| 315 | callback_query: { id: data, data, message } |
| 316 | }); |
| 317 | assert.equal(result.ok, true); |
| 318 | } |
| 319 | |
| 320 | assert.equal(edits.length, 5); |
| 321 | assert.ok(edits.every((edit) => edit.messageId === 501)); |
| 322 | assert.match(edits[0].text, /پروژه: Factor-easy/); |
| 323 | assert.match(edits[1].text, /#43/); |
| 324 | assert.match(edits[3].text, /فهرست مخزنها/); |
| 325 | assert.match(edits[4].text, /Nexa Dev Bot/); |
| 326 | }); |
| 327 | }); |