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 worker from '../src/index.js'; |
| 4 | import { |
| 5 | makeReplayNamespace, |
| 6 | withUpdateId |
| 7 | } from './helpers/replay-namespace.js'; |
| 8 | |
| 9 | const runtime = { |
| 10 | APPROVAL_REPLAY_GUARD: makeReplayNamespace(), |
| 11 | TELEGRAM_WEBHOOK_SECRET: 'unit-test-secret', |
| 12 | OWNER_TELEGRAM_ID: '123', |
| 13 | TELEGRAM_BOT_TOKEN: 'unit-test-token', |
| 14 | GITHUB_TOKEN: 'unit-test-github' |
| 15 | }; |
| 16 | |
| 17 | const startUpdate = { |
| 18 | message: { |
| 19 | message_id: 202, |
| 20 | from: { id: 123 }, |
| 21 | chat: { id: 123, type: 'private' }, |
| 22 | text: '/start' |
| 23 | } |
| 24 | }; |
| 25 | |
| 26 | function webhookRequest(update = startUpdate) { |
| 27 | return new Request('https://example.test/telegram/webhook', { |
| 28 | method: 'POST', |
| 29 | headers: { |
| 30 | 'Content-Type': 'application/json', |
| 31 | 'X-Telegram-Bot-Api-Secret-Token': 'unit-test-secret' |
| 32 | }, |
| 33 | body: JSON.stringify(withUpdateId(update)) |
| 34 | }); |
| 35 | } |
| 36 | |
| 37 | describe('Nexa Dev Bot - Cloudflare Worker Entrypoint', () => { |
| 38 | it('GET / returns online status without fabricated uptime', async () => { |
| 39 | const res = await worker.fetch( |
| 40 | new Request('https://example.test/', { method: 'GET' }), |
| 41 | runtime |
| 42 | ); |
| 43 | assert.equal(res.status, 200); |
| 44 | const body = await res.json(); |
| 45 | assert.equal(body.status, 'online'); |
| 46 | assert.equal(body.bot, 'Nexa Dev Bot'); |
| 47 | assert.equal(body.version, '1.1.1'); |
| 48 | assert.equal('uptime' in body, false); |
| 49 | }); |
| 50 | |
| 51 | it('GET /status stays public-minimal and does not expose owner-only operational diagnostics', async () => { |
| 52 | const res = await worker.fetch( |
| 53 | new Request('https://example.test/status', { method: 'GET' }), |
| 54 | runtime |
| 55 | ); |
| 56 | assert.equal(res.status, 200); |
| 57 | const body = await res.json(); |
| 58 | assert.deepEqual(Object.keys(body).sort(), [ |
| 59 | 'bot', |
| 60 | 'mode', |
| 61 | 'status', |
| 62 | 'version' |
| 63 | ]); |
| 64 | assert.equal(body.status, 'online'); |
| 65 | const serialized = JSON.stringify(body); |
| 66 | for (const privateDetail of [ |
| 67 | 'WORKSPACE_STORE', |
| 68 | 'APPROVAL_REPLAY_GUARD', |
| 69 | 'GitHub live READ', |
| 70 | 'Cloudflare deployment', |
| 71 | 'observability', |
| 72 | 'credential', |
| 73 | 'configured' |
| 74 | ]) { |
| 75 | assert.ok( |
| 76 | !serialized.includes(privateDetail), |
| 77 | `public status leaked ${privateDetail}` |
| 78 | ); |
| 79 | } |
| 80 | }); |
| 81 | |
| 82 | it('authorized Telegram webhook processes /start', async () => { |
| 83 | const originalFetch = globalThis.fetch; |
| 84 | globalThis.fetch = async (url) => { |
| 85 | if (String(url).startsWith('https://api.telegram.org/')) { |
| 86 | return new Response( |
| 87 | JSON.stringify({ ok: true, result: { message_id: 303 } }), |
| 88 | { |
| 89 | status: 200, |
| 90 | headers: { 'content-type': 'application/json' } |
| 91 | } |
| 92 | ); |
| 93 | } |
| 94 | return originalFetch(url); |
| 95 | }; |
| 96 | |
| 97 | try { |
| 98 | const res = await worker.fetch(webhookRequest(), runtime); |
| 99 | assert.equal(res.status, 200); |
| 100 | const body = await res.json(); |
| 101 | assert.equal(body.ok, true); |
| 102 | assert.equal(body.command, 'start'); |
| 103 | assert.equal(body.studioEntry, true); |
| 104 | assert.equal(body.menuButtonConfigured, true); |
| 105 | } finally { |
| 106 | globalThis.fetch = originalFetch; |
| 107 | } |
| 108 | }); |
| 109 | |
| 110 | it('webhook fails closed when TELEGRAM_BOT_TOKEN is missing', async () => { |
| 111 | const res = await worker.fetch(webhookRequest(), { |
| 112 | ...runtime, |
| 113 | TELEGRAM_BOT_TOKEN: '' |
| 114 | }); |
| 115 | |
| 116 | assert.equal(res.status, 503); |
| 117 | assert.match(await res.text(), /Telegram bot token not configured/i); |
| 118 | }); |
| 119 | |
| 120 | it('arbitrary POST paths are not treated as webhooks', async () => { |
| 121 | const res = await worker.fetch( |
| 122 | new Request('https://example.test/', { |
| 123 | method: 'POST', |
| 124 | headers: { 'Content-Type': 'application/json' }, |
| 125 | body: '{}' |
| 126 | }), |
| 127 | runtime |
| 128 | ); |
| 129 | assert.equal(res.status, 404); |
| 130 | }); |
| 131 | |
| 132 | it('logs Telegram webhook processing failures without exposing configured secrets', async () => { |
| 133 | const originalFetch = globalThis.fetch; |
| 134 | const originalError = console.error; |
| 135 | const logs = []; |
| 136 | const secretToken = 'telegram-secret-token-for-test'; |
| 137 | const approvalSecret = 'approval-secret-for-test'; |
| 138 | const cloudflareSecret = 'cloudflare-secret-for-test'; |
| 139 | |
| 140 | globalThis.fetch = async (url) => { |
| 141 | if (String(url).startsWith('https://api.telegram.org/')) { |
| 142 | return new Response( |
| 143 | JSON.stringify({ |
| 144 | ok: false, |
| 145 | description: `Unauthorized ${approvalSecret} ${cloudflareSecret}` |
| 146 | }), |
| 147 | { |
| 148 | status: 401, |
| 149 | headers: { 'content-type': 'application/json' } |
| 150 | } |
| 151 | ); |
| 152 | } |
| 153 | return originalFetch(url); |
| 154 | }; |
| 155 | console.error = (...args) => logs.push(args.map(String).join(' ')); |
| 156 | |
| 157 | try { |
| 158 | const res = await worker.fetch(webhookRequest(), { |
| 159 | ...runtime, |
| 160 | TELEGRAM_BOT_TOKEN: secretToken, |
| 161 | APPROVAL_SIGNING_SECRET: approvalSecret, |
| 162 | CLOUDFLARE_API_TOKEN: cloudflareSecret |
| 163 | }); |
| 164 | assert.equal(res.status, 200); |
| 165 | assert.equal((await res.json()).processed_error, true); |
| 166 | assert.ok(logs.some((line) => /telegram_webhook_error/i.test(line))); |
| 167 | assert.ok(logs.every((line) => !/401|Unauthorized/i.test(line))); |
| 168 | assert.ok(logs.some((line) => /processed_error/i.test(line))); |
| 169 | assert.ok(logs.every((line) => !line.includes(secretToken))); |
| 170 | assert.ok(logs.every((line) => !line.includes(approvalSecret))); |
| 171 | assert.ok(logs.every((line) => !line.includes(cloudflareSecret))); |
| 172 | } finally { |
| 173 | globalThis.fetch = originalFetch; |
| 174 | console.error = originalError; |
| 175 | } |
| 176 | }); |
| 177 | }); |