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 { createWorkspaceController } from '../src/plugins/github/workspace.js'; |
| 4 | |
| 5 | const ws = { |
| 6 | id: 'W000000001', |
| 7 | repoId: 1, |
| 8 | repoFullName: 'o/r', |
| 9 | baseBranch: 'main', |
| 10 | baseHeadSha: 'a'.repeat(40), |
| 11 | baseTreeSha: 'b'.repeat(40), |
| 12 | state: 'DRAFT', |
| 13 | path: 'README.md', |
| 14 | originalText: 'one', |
| 15 | draftText: 'two', |
| 16 | commitMessage: 'msg', |
| 17 | files: [ |
| 18 | { |
| 19 | path: 'README.md', |
| 20 | blobSha: 'c'.repeat(40), |
| 21 | originalText: 'one', |
| 22 | draftText: 'two', |
| 23 | draftDigest: '1'.repeat(64) |
| 24 | }, |
| 25 | { |
| 26 | path: 'src/a.js', |
| 27 | blobSha: 'd'.repeat(40), |
| 28 | originalText: 'a', |
| 29 | draftText: 'b', |
| 30 | draftDigest: '2'.repeat(64) |
| 31 | } |
| 32 | ] |
| 33 | }; |
| 34 | |
| 35 | test('workspace view lists every change-set file and exposes add control', async () => { |
| 36 | const workspaces = { |
| 37 | async getWorkspace() { |
| 38 | return structuredClone(ws); |
| 39 | }, |
| 40 | async createNavigationRefs({ refs }) { |
| 41 | return refs.map((_, i) => ({ refId: `R00000000${i}` })); |
| 42 | } |
| 43 | }; |
| 44 | const c = createWorkspaceController({ |
| 45 | github: {}, |
| 46 | workspaces, |
| 47 | editorUrl: 'https://example.com/editor' |
| 48 | }); |
| 49 | const v = await c |
| 50 | .resolveCallback('ws:W000000001', { ownerId: '42' }) |
| 51 | .execute(); |
| 52 | assert.match(v.text, /README\.md/); |
| 53 | assert.match(v.text, /src\/a\.js/); |
| 54 | assert.match(v.text, /2 فایل/); |
| 55 | assert.ok( |
| 56 | v.reply_markup.inline_keyboard |
| 57 | .flat() |
| 58 | .some((b) => b.callback_data === 'wfiles:W000000001:1') |
| 59 | ); |
| 60 | }); |
| 61 | |
| 62 | test('adding a file reads pinned source then upserts durable workspace only', async () => { |
| 63 | const calls = []; |
| 64 | const workspaces = { |
| 65 | async resolveNavigationRef() { |
| 66 | return { |
| 67 | repoId: 1, |
| 68 | path: 'src/b.js', |
| 69 | type: 'workspace-add', |
| 70 | workspaceId: 'W000000001' |
| 71 | }; |
| 72 | }, |
| 73 | async getWorkspace() { |
| 74 | return structuredClone(ws); |
| 75 | }, |
| 76 | async upsertWorkspaceFile(x) { |
| 77 | calls.push(['upsert', x]); |
| 78 | return { ...ws, files: [...ws.files, x.file] }; |
| 79 | }, |
| 80 | async createNavigationRefs({ refs }) { |
| 81 | return refs.map((_, i) => ({ refId: `R00000000${i}` })); |
| 82 | } |
| 83 | }; |
| 84 | const github = { |
| 85 | async getRepository() { |
| 86 | return { fullName: 'o/r', defaultBranch: 'main' }; |
| 87 | }, |
| 88 | async getBranchSnapshot() { |
| 89 | return { headSha: ws.baseHeadSha, treeSha: ws.baseTreeSha }; |
| 90 | }, |
| 91 | async getFileAtRef(_r, path) { |
| 92 | calls.push(['read', path]); |
| 93 | return { path, sha: 'e'.repeat(40), content: 'safe', size: 4 }; |
| 94 | } |
| 95 | }; |
| 96 | const c = createWorkspaceController({ github, workspaces }); |
| 97 | const v = await c |
| 98 | .resolveCallback('wadd:R000000001', { ownerId: '42' }) |
| 99 | .execute(); |
| 100 | assert.equal(calls[0][0], 'read'); |
| 101 | assert.equal(calls[1][0], 'upsert'); |
| 102 | assert.match(v.text, /اضافه|added/i); |
| 103 | }); |
| 104 | |
| 105 | test('removing a change-set file uses opaque ref and durable remove', async () => { |
| 106 | let removed = ''; |
| 107 | const workspaces = { |
| 108 | async resolveNavigationRef() { |
| 109 | return { |
| 110 | workspaceId: 'W000000001', |
| 111 | path: 'src/a.js', |
| 112 | type: 'workspace-file' |
| 113 | }; |
| 114 | }, |
| 115 | async removeWorkspaceFile({ path }) { |
| 116 | removed = path; |
| 117 | return { ...ws, files: [ws.files[0]] }; |
| 118 | }, |
| 119 | async createNavigationRefs({ refs }) { |
| 120 | return refs.map((_, i) => ({ refId: `R00000000${i}` })); |
| 121 | } |
| 122 | }; |
| 123 | const c = createWorkspaceController({ github: {}, workspaces }); |
| 124 | const v = await c |
| 125 | .resolveCallback('wremove:R000000001', { ownerId: '42' }) |
| 126 | .execute(); |
| 127 | assert.equal(removed, 'src/a.js'); |
| 128 | assert.match(v.text, /README\.md/); |
| 129 | }); |
| 130 | |
| 131 | test('add-file callback actions are declared READ in the GitHub manifest', async () => { |
| 132 | const { githubPluginManifest } = await import( |
| 133 | '../src/plugins/github/manifest.js' |
| 134 | ); |
| 135 | for (const action of [ |
| 136 | 'github.workspace.file.pick', |
| 137 | 'github.workspace.file.add', |
| 138 | 'github.workspace.file.remove' |
| 139 | ]) { |
| 140 | assert.equal( |
| 141 | githubPluginManifest.actions[action]?.risk, |
| 142 | 'READ', |
| 143 | action + ' must be routed as owner-only READ' |
| 144 | ); |
| 145 | } |
| 146 | }); |
| 147 | |
| 148 | test('file picker rejects a repo id that is not bound to the workspace', async () => { |
| 149 | const workspaces = { |
| 150 | async getWorkspace() { |
| 151 | return structuredClone(ws); |
| 152 | } |
| 153 | }; |
| 154 | const c = createWorkspaceController({ |
| 155 | github: { |
| 156 | async listFiles() { |
| 157 | throw new Error('must not read mismatched repo'); |
| 158 | } |
| 159 | }, |
| 160 | workspaces |
| 161 | }); |
| 162 | await assert.rejects( |
| 163 | () => c.resolveCallback('wfiles:W000000001:2', { ownerId: '42' }).execute(), |
| 164 | /repository mismatch/i |
| 165 | ); |
| 166 | }); |
| 167 | |
| 168 | test('file picker lists candidates from the exact workspace base snapshot', async () => { |
| 169 | let seen; |
| 170 | const workspaces = { |
| 171 | async getWorkspace() { |
| 172 | return structuredClone(ws); |
| 173 | }, |
| 174 | async createNavigationRefs({ refs }) { |
| 175 | return refs.map((_, i) => ({ refId: 'R' + String(i).padStart(9, '0') })); |
| 176 | } |
| 177 | }; |
| 178 | const github = { |
| 179 | async listFiles(repoId, path, options) { |
| 180 | seen = { repoId, path, options }; |
| 181 | return [{ type: 'file', path: 'src/new.js', sha: 'e'.repeat(40) }]; |
| 182 | } |
| 183 | }; |
| 184 | const c = createWorkspaceController({ github, workspaces }); |
| 185 | await c.resolveCallback('wfiles:W000000001:1', { ownerId: '42' }).execute(); |
| 186 | assert.deepEqual(seen, { |
| 187 | repoId: 1, |
| 188 | path: '', |
| 189 | options: { ref: ws.baseHeadSha } |
| 190 | }); |
| 191 | }); |
| 192 | |
| 193 | test('multi-file workspace exposes a direct editor button for every file', async () => { |
| 194 | const workspaces = { |
| 195 | async getWorkspace() { |
| 196 | return structuredClone(ws); |
| 197 | }, |
| 198 | async createNavigationRefs({ refs }) { |
| 199 | return refs.map((_, i) => ({ refId: 'R' + String(i).padStart(9, '0') })); |
| 200 | } |
| 201 | }; |
| 202 | const c = createWorkspaceController({ |
| 203 | github: {}, |
| 204 | workspaces, |
| 205 | editorUrl: 'https://example.com/workspace/editor' |
| 206 | }); |
| 207 | const v = await c |
| 208 | .resolveCallback('ws:W000000001', { ownerId: '42' }) |
| 209 | .execute(); |
| 210 | const editors = v.reply_markup.inline_keyboard |
| 211 | .flat() |
| 212 | .filter((button) => button.web_app?.url); |
| 213 | assert.equal(editors.length, 2); |
| 214 | assert.equal( |
| 215 | editors[0].web_app.url, |
| 216 | 'https://example.com/workspace/editor?workspaceId=W000000001&path=README.md' |
| 217 | ); |
| 218 | assert.equal( |
| 219 | editors[1].web_app.url, |
| 220 | 'https://example.com/workspace/editor?workspaceId=W000000001&path=src%2Fa.js' |
| 221 | ); |
| 222 | assert.match(editors[1].text, /src\/a\.js/); |
| 223 | }); |
| 224 | |
| 225 | test('ready view lists every changed file in the sealed change set', async () => { |
| 226 | const workspaces = { |
| 227 | async getWorkspace() { |
| 228 | return structuredClone(ws); |
| 229 | }, |
| 230 | async sealIntent({ intent }) { |
| 231 | return { id: 'INTENT01', ...intent }; |
| 232 | } |
| 233 | }; |
| 234 | const c = createWorkspaceController({ github: {}, workspaces }); |
| 235 | const v = await c |
| 236 | .resolveCallback('wready:W000000001', { ownerId: '42' }) |
| 237 | .execute(); |
| 238 | assert.match(v.text, /README\.md/); |
| 239 | assert.match(v.text, /src\/a\.js/); |
| 240 | assert.match(v.text, /2/); |
| 241 | }); |