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 { GitHubService } from '../src/github.js'; |
| 4 | import { createGitHubPlugin } from '../src/plugins/github/plugin.js'; |
| 5 | import { createWorkspaceController } from '../src/plugins/github/workspace.js'; |
| 6 | |
| 7 | const HEAD_SHA = 'a'.repeat(40); |
| 8 | const TREE_SHA = 'b'.repeat(40); |
| 9 | const REPO_URL = 'https://api.github.com/repos/owner/demo'; |
| 10 | const REPO = { |
| 11 | id: 123, |
| 12 | name: 'demo', |
| 13 | full_name: 'owner/demo', |
| 14 | default_branch: 'main', |
| 15 | archived: false |
| 16 | }; |
| 17 | |
| 18 | async function withGitHubFetch(handler, run) { |
| 19 | const originalFetch = globalThis.fetch; |
| 20 | globalThis.fetch = async (url, options = {}) => { |
| 21 | const value = String(url); |
| 22 | if (value === 'https://api.github.com/repositories/123') { |
| 23 | return Response.json(REPO); |
| 24 | } |
| 25 | return handler(value, options); |
| 26 | }; |
| 27 | try { |
| 28 | return await run(new GitHubService('fixture-token')); |
| 29 | } finally { |
| 30 | globalThis.fetch = originalFetch; |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | async function filePreview(path, content) { |
| 35 | return withGitHubFetch( |
| 36 | async (url) => { |
| 37 | if (url === `${REPO_URL}/git/ref/heads/main`) { |
| 38 | return Response.json({ object: { sha: HEAD_SHA } }); |
| 39 | } |
| 40 | if (url === `${REPO_URL}/git/commits/${HEAD_SHA}`) { |
| 41 | return Response.json({ tree: { sha: TREE_SHA } }); |
| 42 | } |
| 43 | if (url === `${REPO_URL}/contents/${path}?ref=${HEAD_SHA}`) { |
| 44 | return Response.json({ |
| 45 | type: 'file', |
| 46 | path, |
| 47 | sha: 'c'.repeat(40), |
| 48 | size: content.length, |
| 49 | encoding: 'base64', |
| 50 | content: btoa(content) |
| 51 | }); |
| 52 | } |
| 53 | throw new Error(`Unexpected fixture request: ${url}`); |
| 54 | }, |
| 55 | async (github) => { |
| 56 | const controller = createWorkspaceController({ |
| 57 | github, |
| 58 | workspaces: { |
| 59 | async resolveNavigationRef({ ownerId, refId }) { |
| 60 | assert.equal(ownerId, '42'); |
| 61 | assert.equal(refId, 'R123456789'); |
| 62 | return { repoId: 123, path, type: 'file' }; |
| 63 | } |
| 64 | } |
| 65 | }); |
| 66 | return controller |
| 67 | .resolveCallback('wnav:R123456789', { ownerId: '42' }) |
| 68 | .execute(); |
| 69 | } |
| 70 | ); |
| 71 | } |
| 72 | |
| 73 | test('sensitive file previews withhold source from the Telegram payload and offer no Edit', async () => { |
| 74 | const content = 'AUDIT_SECRET_SENTINEL=<private-value>\n'; |
| 75 | const view = await filePreview('.env.production', content); |
| 76 | |
| 77 | assert.doesNotMatch( |
| 78 | JSON.stringify(view), |
| 79 | /AUDIT_SECRET_SENTINEL|private-value/ |
| 80 | ); |
| 81 | assert.equal( |
| 82 | view.reply_markup.inline_keyboard |
| 83 | .flat() |
| 84 | .some((button) => button.callback_data?.startsWith('wedit:')), |
| 85 | false |
| 86 | ); |
| 87 | assert.match(view.text, /حساس|Sensitive/); |
| 88 | }); |
| 89 | |
| 90 | test('ordinary file views retain the Edit action without forwarding source', async () => { |
| 91 | const view = await filePreview('app.js', 'console.log("<ordinary>");\n'); |
| 92 | |
| 93 | assert.doesNotMatch(view.text, /ordinary|console\.log/); |
| 94 | assert.ok( |
| 95 | view.reply_markup.inline_keyboard.flat().some((button) => button.web_app) |
| 96 | ); |
| 97 | assert.ok( |
| 98 | view.reply_markup.inline_keyboard |
| 99 | .flat() |
| 100 | .some((button) => button.callback_data === 'wedit:R123456789') |
| 101 | ); |
| 102 | }); |
| 103 | |
| 104 | test('draft PRs remain draft through the provider and cannot reach the merge mutation', async () => { |
| 105 | let mergeRequests = 0; |
| 106 | await withGitHubFetch( |
| 107 | async (url, options) => { |
| 108 | if (url === `${REPO_URL}/pulls/19`) { |
| 109 | return Response.json({ |
| 110 | number: 19, |
| 111 | title: 'Draft change', |
| 112 | state: 'open', |
| 113 | draft: true, |
| 114 | merged: false, |
| 115 | user: { login: 'developer' }, |
| 116 | head: { ref: 'feature/draft', sha: HEAD_SHA }, |
| 117 | base: { ref: 'main' } |
| 118 | }); |
| 119 | } |
| 120 | if (url === `${REPO_URL}/pulls/19/merge` && options.method === 'PUT') { |
| 121 | mergeRequests += 1; |
| 122 | return Response.json({ merged: true, sha: 'd'.repeat(40) }); |
| 123 | } |
| 124 | throw new Error(`Unexpected fixture request: ${url}`); |
| 125 | }, |
| 126 | async (github) => { |
| 127 | const plugin = createGitHubPlugin({ github, menu: {} }); |
| 128 | const merge = plugin.resolveCallback(`mergepr:3f:j:${HEAD_SHA}`); |
| 129 | |
| 130 | await assert.rejects(merge.execute(), /not mergeable/i); |
| 131 | assert.equal(mergeRequests, 0); |
| 132 | assert.equal((await github.getPullRequest(123, 19)).draft, true); |
| 133 | const detail = await plugin.resolveCallback('prdetail:123:19').execute(); |
| 134 | assert.equal( |
| 135 | detail.reply_markup.inline_keyboard |
| 136 | .flat() |
| 137 | .some((button) => button.callback_data?.startsWith('mergepr:')), |
| 138 | false |
| 139 | ); |
| 140 | } |
| 141 | ); |
| 142 | }); |