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 worker from '../src/index.js'; |
| 4 | import { |
| 5 | makeReplayNamespace, |
| 6 | withUpdateId |
| 7 | } from './helpers/replay-namespace.js'; |
| 8 | |
| 9 | const env = { |
| 10 | TELEGRAM_WEBHOOK_SECRET: 'right', |
| 11 | OWNER_TELEGRAM_ID: '123', |
| 12 | TELEGRAM_BOT_TOKEN: 'telegram-test-token', |
| 13 | GITHUB_TOKEN: 'github-test-token', |
| 14 | GITHUB_OWNER: 'davoodmehraban89', |
| 15 | APPROVAL_SIGNING_SECRET: 'approval-test-secret', |
| 16 | APPROVAL_REPLAY_GUARD: makeReplayNamespace() |
| 17 | }; |
| 18 | |
| 19 | function webhook(update) { |
| 20 | return new Request('https://example.test/telegram/webhook', { |
| 21 | method: 'POST', |
| 22 | headers: { |
| 23 | 'content-type': 'application/json', |
| 24 | 'X-Telegram-Bot-Api-Secret-Token': 'right' |
| 25 | }, |
| 26 | body: JSON.stringify(withUpdateId(update)) |
| 27 | }); |
| 28 | } |
| 29 | |
| 30 | function json(data, status = 200) { |
| 31 | return new Response(JSON.stringify(data), { |
| 32 | status, |
| 33 | headers: { 'content-type': 'application/json' } |
| 34 | }); |
| 35 | } |
| 36 | |
| 37 | function installMock() { |
| 38 | const telegramCalls = []; |
| 39 | const githubCalls = []; |
| 40 | const originalFetch = globalThis.fetch; |
| 41 | |
| 42 | globalThis.fetch = async (url, options = {}) => { |
| 43 | const value = String(url); |
| 44 | if (value.startsWith('https://api.telegram.org/')) { |
| 45 | const method = value.split('/').at(-1); |
| 46 | const body = options.body ? JSON.parse(options.body) : {}; |
| 47 | telegramCalls.push({ method, body }); |
| 48 | return json({ |
| 49 | ok: true, |
| 50 | result: { message_id: body.message_id || 950, ...body } |
| 51 | }); |
| 52 | } |
| 53 | if (value === 'https://api.github.com/repositories/1001') { |
| 54 | githubCalls.push({ url: value, method: options.method || 'GET' }); |
| 55 | return json({ |
| 56 | id: 1001, |
| 57 | name: 'demo', |
| 58 | full_name: 'davoodmehraban89/demo' |
| 59 | }); |
| 60 | } |
| 61 | if ( |
| 62 | value === |
| 63 | 'https://api.github.com/repos/davoodmehraban89/demo/actions/runs/55/rerun-failed-jobs' |
| 64 | ) { |
| 65 | githubCalls.push({ url: value, method: options.method || 'GET' }); |
| 66 | return json( |
| 67 | { message: 'Resource not accessible by personal access token' }, |
| 68 | 403 |
| 69 | ); |
| 70 | } |
| 71 | throw new Error(`Unexpected URL: ${value}`); |
| 72 | }; |
| 73 | |
| 74 | return { |
| 75 | telegramCalls, |
| 76 | githubCalls, |
| 77 | restore() { |
| 78 | globalThis.fetch = originalFetch; |
| 79 | } |
| 80 | }; |
| 81 | } |
| 82 | |
| 83 | async function sendUpdate(update) { |
| 84 | const response = await worker.fetch(webhook(update), env); |
| 85 | assert.equal(response.status, 200); |
| 86 | return response.json(); |
| 87 | } |
| 88 | |
| 89 | test('approved GitHub WRITE provider failure visibly updates Telegram and does not claim success', async () => { |
| 90 | const mock = installMock(); |
| 91 | try { |
| 92 | const menuMessage = { message_id: 950, chat: { id: 123 } }; |
| 93 | const issued = await sendUpdate({ |
| 94 | callback_query: { |
| 95 | id: 'issue-provider-failure-approval', |
| 96 | from: { id: 123 }, |
| 97 | data: 'rerun:1001:55', |
| 98 | message: menuMessage |
| 99 | } |
| 100 | }); |
| 101 | assert.equal(issued.approvalRequired, true); |
| 102 | |
| 103 | const approvalEdit = mock.telegramCalls |
| 104 | .filter((call) => call.method === 'editMessageText') |
| 105 | .at(-1); |
| 106 | const approveButton = approvalEdit.body.reply_markup.inline_keyboard |
| 107 | .flat() |
| 108 | .find((button) => |
| 109 | String(button.callback_data || '').startsWith('approve:') |
| 110 | ); |
| 111 | assert.ok(approveButton); |
| 112 | |
| 113 | const result = await sendUpdate({ |
| 114 | callback_query: { |
| 115 | id: 'approve-provider-failure', |
| 116 | from: { id: 123 }, |
| 117 | data: approveButton.callback_data, |
| 118 | message: { |
| 119 | ...menuMessage, |
| 120 | text: approvalEdit.body.text, |
| 121 | reply_markup: approvalEdit.body.reply_markup |
| 122 | } |
| 123 | } |
| 124 | }); |
| 125 | |
| 126 | assert.equal(result.ok, false); |
| 127 | const posts = mock.githubCalls.filter((call) => call.method === 'POST'); |
| 128 | assert.equal( |
| 129 | posts.length, |
| 130 | 1, |
| 131 | 'approved provider write should be attempted exactly once' |
| 132 | ); |
| 133 | |
| 134 | const edits = mock.telegramCalls.filter( |
| 135 | (call) => call.method === 'editMessageText' |
| 136 | ); |
| 137 | assert.equal( |
| 138 | edits.length, |
| 139 | 2, |
| 140 | 'provider failure must visibly replace the approval message' |
| 141 | ); |
| 142 | const feedback = edits.at(-1); |
| 143 | assert.match(feedback.body.text, /اجرا نشد|GitHub|403|دسترسی/); |
| 144 | assert.doesNotMatch(feedback.body.text, /عملیات با موفقیت|success/i); |
| 145 | assert.ok( |
| 146 | feedback.body.reply_markup.inline_keyboard |
| 147 | .flat() |
| 148 | .some((button) => button.callback_data === 'run:1001:55'), |
| 149 | 'provider failure must provide a safe route back to the run' |
| 150 | ); |
| 151 | } finally { |
| 152 | mock.restore(); |
| 153 | } |
| 154 | }); |