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 { readFileSync } from 'node:fs'; |
| 4 | import { RuntimeDiagnostics } from '../src/core/runtime-diagnostics.js'; |
| 5 | import { OpsMenuManager } from '../src/ops-menu.js'; |
| 6 | |
| 7 | function fakeRegistry() { |
| 8 | return { |
| 9 | getPlugins() { |
| 10 | return [ |
| 11 | { |
| 12 | manifest: { |
| 13 | id: 'github', |
| 14 | actions: { |
| 15 | 'github.repos.list': { risk: 'READ' }, |
| 16 | 'github.workspace.commit_branch': { risk: 'WRITE' } |
| 17 | } |
| 18 | } |
| 19 | } |
| 20 | ]; |
| 21 | } |
| 22 | }; |
| 23 | } |
| 24 | |
| 25 | function fullEnv() { |
| 26 | return { |
| 27 | TELEGRAM_BOT_TOKEN: 'tg-secret-value', |
| 28 | TELEGRAM_WEBHOOK_SECRET: 'webhook-secret-value', |
| 29 | GITHUB_TOKEN: 'github-secret-value', |
| 30 | OWNER_TELEGRAM_ID: '123', |
| 31 | APPROVAL_SIGNING_SECRET: 'approval-secret-value', |
| 32 | GITHUB_OWNER: 'davoodmehraban89' |
| 33 | }; |
| 34 | } |
| 35 | |
| 36 | function diagnosticsForMenus({ githubFailure = false } = {}) { |
| 37 | const github = { |
| 38 | owner: 'davoodmehraban89', |
| 39 | async listRepositories() { |
| 40 | if (githubFailure) throw new Error('GitHub 403 permission denied'); |
| 41 | return [{ id: 1 }, { id: 2 }]; |
| 42 | } |
| 43 | }; |
| 44 | const diagnostics = new RuntimeDiagnostics({ |
| 45 | env: fullEnv(), |
| 46 | github, |
| 47 | registry: fakeRegistry(), |
| 48 | replayStore: { isConfigured: () => true }, |
| 49 | workspaceStore: { isConfigured: () => true }, |
| 50 | approvals: { isReplayProtected: () => true } |
| 51 | }); |
| 52 | return { github, diagnostics }; |
| 53 | } |
| 54 | |
| 55 | function callbacks(view) { |
| 56 | return (view.reply_markup?.inline_keyboard || []) |
| 57 | .flat() |
| 58 | .map((button) => button.callback_data) |
| 59 | .filter(Boolean); |
| 60 | } |
| 61 | |
| 62 | describe('Nexa Dev Bot - operational diagnostics', () => { |
| 63 | it('reports configuration presence and plugin counts without exposing secret values', () => { |
| 64 | const env = fullEnv(); |
| 65 | const diagnostics = new RuntimeDiagnostics({ |
| 66 | env, |
| 67 | github: { owner: 'davoodmehraban89' }, |
| 68 | registry: fakeRegistry(), |
| 69 | replayStore: { isConfigured: () => true }, |
| 70 | workspaceStore: { isConfigured: () => true }, |
| 71 | approvals: { isReplayProtected: () => true } |
| 72 | }); |
| 73 | |
| 74 | const snapshot = diagnostics.getSnapshot(); |
| 75 | assert.equal(snapshot.telegramConfigured, true); |
| 76 | assert.equal(snapshot.webhookSecretConfigured, true); |
| 77 | assert.equal(snapshot.ownerConfigured, true); |
| 78 | assert.equal(snapshot.githubConfigured, true); |
| 79 | assert.equal(snapshot.replayGuardConfigured, true); |
| 80 | assert.equal(snapshot.workspaceStoreConfigured, true); |
| 81 | assert.equal(snapshot.approvalSignerConfigured, true); |
| 82 | assert.equal(snapshot.githubOwner, 'davoodmehraban89'); |
| 83 | assert.equal(snapshot.pluginCount, 1); |
| 84 | assert.equal(snapshot.actionCount, 2); |
| 85 | |
| 86 | const serialized = JSON.stringify(snapshot); |
| 87 | for (const secret of Object.values(env).filter((value) => |
| 88 | String(value).includes('secret') |
| 89 | )) { |
| 90 | assert.ok(!serialized.includes(secret), `snapshot leaked ${secret}`); |
| 91 | } |
| 92 | }); |
| 93 | |
| 94 | it('performs a bounded live GitHub READ probe and reports provider failure explicitly', async () => { |
| 95 | const success = diagnosticsForMenus().diagnostics; |
| 96 | assert.deepEqual(await success.probeGitHub(), { |
| 97 | ok: true, |
| 98 | owner: 'davoodmehraban89', |
| 99 | repositoryCount: 2 |
| 100 | }); |
| 101 | |
| 102 | const failed = diagnosticsForMenus({ githubFailure: true }).diagnostics; |
| 103 | const failure = await failed.probeGitHub(); |
| 104 | assert.equal(failure.ok, false); |
| 105 | assert.match(failure.error, /403/); |
| 106 | assert.doesNotMatch(failure.error, /github-secret-value/); |
| 107 | }); |
| 108 | |
| 109 | it('self-check is fail-closed when required bindings are missing', async () => { |
| 110 | const diagnostics = new RuntimeDiagnostics({ |
| 111 | env: {}, |
| 112 | github: { |
| 113 | owner: 'davoodmehraban89', |
| 114 | async listRepositories() { |
| 115 | throw new Error('GITHUB_TOKEN is missing'); |
| 116 | } |
| 117 | }, |
| 118 | registry: fakeRegistry(), |
| 119 | replayStore: { isConfigured: () => false }, |
| 120 | workspaceStore: { isConfigured: () => false }, |
| 121 | approvals: { isReplayProtected: () => false } |
| 122 | }); |
| 123 | |
| 124 | const report = await diagnostics.runSelfCheck(); |
| 125 | assert.equal(report.ok, false); |
| 126 | const byId = Object.fromEntries( |
| 127 | report.checks.map((check) => [check.id, check]) |
| 128 | ); |
| 129 | for (const id of [ |
| 130 | 'telegram', |
| 131 | 'webhook', |
| 132 | 'owner', |
| 133 | 'github-token', |
| 134 | 'replay-guard', |
| 135 | 'workspace-store', |
| 136 | 'approval-signer', |
| 137 | 'github-live' |
| 138 | ]) { |
| 139 | assert.equal(byId[id]?.ok, false, `${id} should fail closed`); |
| 140 | } |
| 141 | }); |
| 142 | |
| 143 | it('configures Cloudflare Worker Previews with isolated Durable Object bindings', () => { |
| 144 | const config = JSON.parse( |
| 145 | readFileSync(new URL('../wrangler.jsonc', import.meta.url), 'utf8') |
| 146 | ); |
| 147 | const production = config.durable_objects?.bindings || []; |
| 148 | const preview = config.previews?.durable_objects?.bindings || []; |
| 149 | assert.ok(config.previews, 'wrangler previews block is required'); |
| 150 | for (const binding of production) { |
| 151 | assert.ok( |
| 152 | preview.some( |
| 153 | (candidate) => |
| 154 | candidate.name === binding.name && |
| 155 | candidate.class_name === binding.class_name |
| 156 | ), |
| 157 | `preview missing durable binding ${binding.name}` |
| 158 | ); |
| 159 | } |
| 160 | }); |
| 161 | }); |
| 162 | |
| 163 | describe('Nexa Dev Bot - operational menu surfaces', () => { |
| 164 | it('turns Development Tools into useful READ-only diagnostics', async () => { |
| 165 | const { github, diagnostics } = diagnosticsForMenus(); |
| 166 | const menu = new OpsMenuManager(github, diagnostics); |
| 167 | const view = menu.getToolsView(); |
| 168 | const values = callbacks(view); |
| 169 | for (const callback of [ |
| 170 | 'ops:selfcheck', |
| 171 | 'ops:github', |
| 172 | 'ops:runtime', |
| 173 | 'ops:plugins', |
| 174 | 'tool:ping' |
| 175 | ]) { |
| 176 | assert.ok(values.includes(callback), `missing ${callback}`); |
| 177 | } |
| 178 | assert.match(view.text, /تشخیص|Diagnostics|عیب.?یابی/); |
| 179 | }); |
| 180 | |
| 181 | it('renders source-backed live service status and explicit provider failure', async () => { |
| 182 | const okContext = diagnosticsForMenus(); |
| 183 | const okMenu = new OpsMenuManager(okContext.github, okContext.diagnostics); |
| 184 | const okView = await okMenu.getServiceStatusView(); |
| 185 | assert.match(okView.text, /GitHub.*✅|✅.*GitHub/s); |
| 186 | assert.match(okView.text, /2/); |
| 187 | assert.match(okView.text, /Workspace|Durable/); |
| 188 | assert.doesNotMatch(okView.text, /99\.9|100% SLA|ms latency/i); |
| 189 | |
| 190 | const badContext = diagnosticsForMenus({ githubFailure: true }); |
| 191 | const badMenu = new OpsMenuManager( |
| 192 | badContext.github, |
| 193 | badContext.diagnostics |
| 194 | ); |
| 195 | const badView = await badMenu.getServiceStatusView(); |
| 196 | assert.match(badView.text, /GitHub.*❌|❌.*GitHub/s); |
| 197 | assert.match(badView.text, /403/); |
| 198 | }); |
| 199 | |
| 200 | it('provides a real Security Center and read-only Configuration Center', async () => { |
| 201 | const { github, diagnostics } = diagnosticsForMenus(); |
| 202 | const menu = new OpsMenuManager(github, diagnostics); |
| 203 | |
| 204 | const security = menu.getSecurityView(); |
| 205 | for (const callback of [ |
| 206 | 'security:selfcheck', |
| 207 | 'security:policy', |
| 208 | 'security:approval' |
| 209 | ]) { |
| 210 | assert.ok(callbacks(security).includes(callback), `missing ${callback}`); |
| 211 | } |
| 212 | assert.match(security.text, /مرکز امنیت/); |
| 213 | |
| 214 | const config = menu.getSettingsView(); |
| 215 | assert.match(config.text, /پیکربندی/); |
| 216 | assert.doesNotMatch(config.text, /تنظیمات Nexa Dev/); |
| 217 | for (const callback of [ |
| 218 | 'config:runtime', |
| 219 | 'config:providers', |
| 220 | 'config:editor', |
| 221 | 'config:plugins' |
| 222 | ]) { |
| 223 | assert.ok(callbacks(config).includes(callback), `missing ${callback}`); |
| 224 | } |
| 225 | }); |
| 226 | |
| 227 | it('routes every operational drill-down and keeps Telegram payloads bounded', async () => { |
| 228 | const { github, diagnostics } = diagnosticsForMenus(); |
| 229 | const menu = new OpsMenuManager(github, diagnostics); |
| 230 | const encoder = new TextEncoder(); |
| 231 | const routes = [ |
| 232 | 'menu:status', |
| 233 | 'menu:tools', |
| 234 | 'menu:security', |
| 235 | 'menu:settings', |
| 236 | 'ops:selfcheck', |
| 237 | 'ops:github', |
| 238 | 'ops:runtime', |
| 239 | 'ops:plugins', |
| 240 | 'security:selfcheck', |
| 241 | 'security:policy', |
| 242 | 'security:approval', |
| 243 | 'config:runtime', |
| 244 | 'config:providers', |
| 245 | 'config:editor', |
| 246 | 'config:plugins' |
| 247 | ]; |
| 248 | |
| 249 | for (const route of routes) { |
| 250 | const view = await menu.renderByCallback(route); |
| 251 | assert.ok(view?.text, `${route} returned no text`); |
| 252 | assert.ok( |
| 253 | view.text.length <= 4096, |
| 254 | `${route} exceeds Telegram message limit` |
| 255 | ); |
| 256 | for (const callback of callbacks(view)) { |
| 257 | assert.ok( |
| 258 | encoder.encode(callback).length <= 64, |
| 259 | `${callback} exceeds callback limit` |
| 260 | ); |
| 261 | } |
| 262 | } |
| 263 | }); |
| 264 | |
| 265 | it('configuration provider report offers an in-context live GitHub probe with configuration recovery', async () => { |
| 266 | const { github, diagnostics } = diagnosticsForMenus(); |
| 267 | const menu = new OpsMenuManager(github, diagnostics); |
| 268 | |
| 269 | const providers = await menu.renderByCallback('config:providers'); |
| 270 | assert.ok( |
| 271 | callbacks(providers).includes('config:github'), |
| 272 | 'provider report must offer a direct live GitHub probe' |
| 273 | ); |
| 274 | |
| 275 | const probe = await menu.renderByCallback('config:github'); |
| 276 | assert.match(probe.text, /READ زنده موفق/); |
| 277 | assert.ok( |
| 278 | callbacks(probe).includes('config:github'), |
| 279 | 'live probe must support refresh in the same context' |
| 280 | ); |
| 281 | assert.ok( |
| 282 | callbacks(probe).includes('menu:settings'), |
| 283 | 'live probe must recover to configuration, not strand the owner in tools' |
| 284 | ); |
| 285 | }); |
| 286 | |
| 287 | it('never renders configured secrets in operational pages', async () => { |
| 288 | const { github, diagnostics } = diagnosticsForMenus(); |
| 289 | const menu = new OpsMenuManager(github, diagnostics); |
| 290 | const pages = await Promise.all([ |
| 291 | menu.getServiceStatusView(), |
| 292 | menu.renderByCallback('ops:selfcheck'), |
| 293 | menu.renderByCallback('ops:runtime'), |
| 294 | menu.renderByCallback('security:selfcheck'), |
| 295 | menu.renderByCallback('config:providers') |
| 296 | ]); |
| 297 | const combined = pages.map((page) => page.text).join('\n'); |
| 298 | for (const secret of [ |
| 299 | 'tg-secret-value', |
| 300 | 'webhook-secret-value', |
| 301 | 'github-secret-value', |
| 302 | 'approval-secret-value' |
| 303 | ]) { |
| 304 | assert.ok( |
| 305 | !combined.includes(secret), |
| 306 | `operational page leaked ${secret}` |
| 307 | ); |
| 308 | } |
| 309 | }); |
| 310 | }); |