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 { readFileSync } from 'node:fs'; |
| 4 | import { correlateDeliveryState } from '../src/core/cicd-control-plane.js'; |
| 5 | import { CloudflareService } from '../src/plugins/cloudflare/service.js'; |
| 6 | import { createCloudflarePlugin } from '../src/plugins/cloudflare/plugin.js'; |
| 7 | |
| 8 | const sha = 'a'.repeat(40); |
| 9 | const otherSha = 'b'.repeat(40); |
| 10 | const activeId = '11111111-1111-4111-8111-111111111111'; |
| 11 | const latestId = '22222222-2222-4222-8222-222222222222'; |
| 12 | const deployment = { |
| 13 | id: 'dep-active', |
| 14 | versions: [{ versionId: activeId, percentage: 100 }] |
| 15 | }; |
| 16 | const runs = { |
| 17 | targetSha: sha, |
| 18 | ci: { sha, status: 'completed', conclusion: 'success' }, |
| 19 | deploy: { sha, status: 'completed', conclusion: 'success' } |
| 20 | }; |
| 21 | const version = (annotations = { 'workers/tag': sha }, id = activeId) => ({ |
| 22 | id, |
| 23 | annotations |
| 24 | }); |
| 25 | |
| 26 | test('delivery requires explicit SHA metadata for the version receiving traffic', () => { |
| 27 | for (const runtime of [ |
| 28 | { deployment }, |
| 29 | { deployment, version: { id: activeId } }, |
| 30 | { deployment, version: { id: activeId, sha } }, |
| 31 | { deployment, version: version({ 'workers/message': sha }) }, |
| 32 | { deployment, version: version({ 'workers/sha': sha }) }, |
| 33 | { deployment, version: version({ 'workers/tag': sha.slice(0, 12) }) }, |
| 34 | { deployment, version: version({ 'workers/commit_sha': 'invalid' }) }, |
| 35 | { deployment, version: version({ 'workers/tag': [sha] }) } |
| 36 | ]) { |
| 37 | const state = correlateDeliveryState({ ...runs, runtime }); |
| 38 | assert.equal(state.state, 'unknown', JSON.stringify(runtime)); |
| 39 | assert.match(state.reason, /SHA|evidence/i); |
| 40 | } |
| 41 | }); |
| 42 | |
| 43 | test('delivery rejects another version metadata even when its SHA matches', () => { |
| 44 | const state = correlateDeliveryState({ |
| 45 | ...runs, |
| 46 | runtime: { deployment, version: version(undefined, latestId) } |
| 47 | }); |
| 48 | assert.equal(state.state, 'mismatch'); |
| 49 | }); |
| 50 | |
| 51 | test('delivery rejects an active version whose explicit SHA differs from target', () => { |
| 52 | for (const annotations of [ |
| 53 | { 'workers/tag': otherSha }, |
| 54 | { 'workers/commit_sha': otherSha }, |
| 55 | { 'workers/commit_sha': otherSha, 'workers/tag': sha } |
| 56 | ]) { |
| 57 | const state = correlateDeliveryState({ |
| 58 | ...runs, |
| 59 | runtime: { deployment, version: version(annotations) } |
| 60 | }); |
| 61 | assert.equal(state.state, 'mismatch'); |
| 62 | assert.match(state.reason, /SHA/i); |
| 63 | } |
| 64 | }); |
| 65 | |
| 66 | test('delivery accepts only full matching SHA markers tied to the active version', () => { |
| 67 | for (const annotations of [ |
| 68 | { 'workers/tag': sha }, |
| 69 | { 'workers/commit_sha': sha }, |
| 70 | { 'workers/tag': sha.toUpperCase(), 'workers/commit_sha': sha }, |
| 71 | { 'workers/commit_sha': sha, 'workers/tag': 'release-1' } |
| 72 | ]) { |
| 73 | const state = correlateDeliveryState({ |
| 74 | ...runs, |
| 75 | runtime: { deployment, version: version(annotations) } |
| 76 | }); |
| 77 | assert.equal(state.state, 'success'); |
| 78 | assert.equal(state.sha, sha); |
| 79 | assert.equal(state.versionId, activeId); |
| 80 | assert.equal(state.deploymentId, deployment.id); |
| 81 | } |
| 82 | }); |
| 83 | |
| 84 | function serviceFor({ items = [], active = deployment.versions, detail } = {}) { |
| 85 | const calls = []; |
| 86 | const service = new CloudflareService({ |
| 87 | token: 'cf-token', |
| 88 | accountId: 'account', |
| 89 | workerName: 'nexa-dev-bot', |
| 90 | async fetchImpl(url, options) { |
| 91 | const path = new URL(url).pathname; |
| 92 | calls.push({ path, method: options.method }); |
| 93 | let result; |
| 94 | if (path.endsWith('/deployments')) { |
| 95 | result = { |
| 96 | deployments: [ |
| 97 | { |
| 98 | id: deployment.id, |
| 99 | versions: active.map(({ versionId, percentage }) => ({ |
| 100 | version_id: versionId, |
| 101 | percentage |
| 102 | })) |
| 103 | } |
| 104 | ] |
| 105 | }; |
| 106 | } else if (path.endsWith('/versions')) result = { items }; |
| 107 | else if (path.endsWith(`/versions/${activeId}`)) result = detail; |
| 108 | else if (path.endsWith('/settings')) result = {}; |
| 109 | else throw new Error('Unexpected Cloudflare path'); |
| 110 | return new Response(JSON.stringify({ success: true, result })); |
| 111 | } |
| 112 | }); |
| 113 | return { service, calls }; |
| 114 | } |
| 115 | |
| 116 | test('snapshot selects deployed version metadata instead of a newer unused upload', async () => { |
| 117 | const { service, calls } = serviceFor({ |
| 118 | items: [ |
| 119 | version({ 'workers/tag': sha }, latestId), |
| 120 | { |
| 121 | ...version({ 'workers/commit_sha': otherSha }), |
| 122 | metadata: { created_on: '2026-10-24T00:00:00Z' } |
| 123 | } |
| 124 | ] |
| 125 | }); |
| 126 | const snapshot = await service.getWorkerSnapshot(); |
| 127 | assert.equal(snapshot.version.id, activeId); |
| 128 | assert.equal(snapshot.version.createdOn, '2026-10-24T00:00:00Z'); |
| 129 | assert.deepEqual(snapshot.version.annotations, { |
| 130 | 'workers/commit_sha': otherSha |
| 131 | }); |
| 132 | assert.equal( |
| 133 | correlateDeliveryState({ ...runs, runtime: snapshot }).state, |
| 134 | 'mismatch' |
| 135 | ); |
| 136 | assert.equal(calls.length, 3); |
| 137 | }); |
| 138 | |
| 139 | test('snapshot fetches deployed version when it is absent from the latest versions page', async () => { |
| 140 | const { service, calls } = serviceFor({ |
| 141 | items: [version({ 'workers/tag': otherSha }, latestId)], |
| 142 | detail: version() |
| 143 | }); |
| 144 | const snapshot = await service.getWorkerSnapshot(); |
| 145 | assert.equal(snapshot.version.id, activeId); |
| 146 | assert.deepEqual(snapshot.version.annotations, { 'workers/tag': sha }); |
| 147 | assert.equal( |
| 148 | correlateDeliveryState({ ...runs, runtime: snapshot }).state, |
| 149 | 'success' |
| 150 | ); |
| 151 | assert.ok(calls.some(({ path }) => path.endsWith(`/versions/${activeId}`))); |
| 152 | assert.ok(calls.every(({ method }) => method === 'GET')); |
| 153 | }); |
| 154 | |
| 155 | test('snapshot fetches SHA annotations absent from the minimal deployed version listing', async () => { |
| 156 | const { service, calls } = serviceFor({ |
| 157 | items: [{ id: activeId, metadata: { source: 'wrangler' } }], |
| 158 | detail: version({ 'workers/commit_sha': sha }) |
| 159 | }); |
| 160 | const snapshot = await service.getWorkerSnapshot(); |
| 161 | assert.equal( |
| 162 | correlateDeliveryState({ ...runs, runtime: snapshot }).state, |
| 163 | 'success' |
| 164 | ); |
| 165 | assert.ok(calls.some(({ path }) => path.endsWith(`/versions/${activeId}`))); |
| 166 | }); |
| 167 | |
| 168 | test('snapshot stays unverified when deployed version detail lacks SHA annotations', async () => { |
| 169 | const { service } = serviceFor({ |
| 170 | items: [{ id: activeId }], |
| 171 | detail: { id: activeId } |
| 172 | }); |
| 173 | const snapshot = await service.getWorkerSnapshot(); |
| 174 | assert.equal(snapshot.version.id, activeId); |
| 175 | assert.equal( |
| 176 | correlateDeliveryState({ ...runs, runtime: snapshot }).state, |
| 177 | 'unknown' |
| 178 | ); |
| 179 | }); |
| 180 | |
| 181 | test('snapshot detail errors propagate through the existing redacted provider boundary', async () => { |
| 182 | const service = new CloudflareService({ |
| 183 | token: 'cf-token', |
| 184 | accountId: 'account', |
| 185 | workerName: 'nexa-dev-bot', |
| 186 | async fetchImpl(url) { |
| 187 | let result; |
| 188 | if (String(url).endsWith('/deployments')) { |
| 189 | result = { |
| 190 | deployments: [ |
| 191 | { versions: [{ version_id: activeId, percentage: 100 }] } |
| 192 | ] |
| 193 | }; |
| 194 | } else if (String(url).endsWith('/versions')) result = { items: [] }; |
| 195 | else if (String(url).endsWith('/settings')) result = {}; |
| 196 | else |
| 197 | return new Response( |
| 198 | JSON.stringify({ |
| 199 | success: false, |
| 200 | errors: [{ message: 'bad credential cf-token' }] |
| 201 | }), |
| 202 | { status: 403 } |
| 203 | ); |
| 204 | return new Response(JSON.stringify({ success: true, result })); |
| 205 | } |
| 206 | }); |
| 207 | await assert.rejects(service.getWorkerSnapshot(), (error) => { |
| 208 | assert.match(error.message, /403.*\[REDACTED\]/); |
| 209 | assert.doesNotMatch(error.message, /cf-token/); |
| 210 | return true; |
| 211 | }); |
| 212 | }); |
| 213 | |
| 214 | test('snapshot never substitutes unrelated metadata returned by a version detail read', async () => { |
| 215 | const { service } = serviceFor({ |
| 216 | items: [version(undefined, latestId)], |
| 217 | detail: version(undefined, latestId) |
| 218 | }); |
| 219 | const snapshot = await service.getWorkerSnapshot(); |
| 220 | assert.equal(snapshot.version, null); |
| 221 | assert.equal( |
| 222 | correlateDeliveryState({ ...runs, runtime: snapshot }).state, |
| 223 | 'unknown' |
| 224 | ); |
| 225 | }); |
| 226 | |
| 227 | test('snapshot has no single active version for absent or split traffic', async () => { |
| 228 | for (const active of [ |
| 229 | [], |
| 230 | [ |
| 231 | { versionId: activeId, percentage: 50 }, |
| 232 | { versionId: latestId, percentage: 50 } |
| 233 | ] |
| 234 | ]) { |
| 235 | const { service } = serviceFor({ items: [version()], active }); |
| 236 | const snapshot = await service.getWorkerSnapshot(); |
| 237 | assert.equal(snapshot.version, null); |
| 238 | assert.equal( |
| 239 | correlateDeliveryState({ ...runs, runtime: snapshot }).state, |
| 240 | 'mismatch' |
| 241 | ); |
| 242 | } |
| 243 | }); |
| 244 | |
| 245 | test('delivery view reports unknown when workflow success has no runtime SHA evidence', async () => { |
| 246 | const plugin = createCloudflarePlugin({ |
| 247 | cloudflare: { |
| 248 | workerName: 'nexa-dev-bot', |
| 249 | isConfigured: () => true, |
| 250 | getWorkerSnapshot: async () => ({ deployment, version: { id: activeId } }) |
| 251 | }, |
| 252 | github: { |
| 253 | listRepositories: async () => [ |
| 254 | { id: '123', name: 'nexa-dev-bot', defaultBranch: 'main' } |
| 255 | ], |
| 256 | listCommits: async () => [{ fullSha: sha }], |
| 257 | listWorkflowRuns: async () => |
| 258 | ['CI', 'Deploy Cloudflare Worker'].map((name) => ({ |
| 259 | name, |
| 260 | branch: 'main', |
| 261 | fullSha: sha, |
| 262 | ...runs.ci |
| 263 | })) |
| 264 | } |
| 265 | }); |
| 266 | const view = await plugin.resolveCallback('cf:delivery').execute(); |
| 267 | assert.match(view.text, /UNKNOWN/); |
| 268 | assert.doesNotMatch(view.text, /SUCCESS|موفق/); |
| 269 | }); |
| 270 | |
| 271 | test('production deployment pins Wrangler and tags the checked out verified commit', () => { |
| 272 | const workflow = readFileSync( |
| 273 | new URL('../.github/workflows/deploy.yml', import.meta.url), |
| 274 | 'utf8' |
| 275 | ); |
| 276 | assert.match( |
| 277 | workflow, |
| 278 | /ref: \$\{\{ github\.event\.workflow_run\.head_sha \}\}/ |
| 279 | ); |
| 280 | assert.match( |
| 281 | workflow, |
| 282 | /DEPLOY_COMMIT_SHA: \$\{\{ github\.event\.workflow_run\.head_sha \}\}/ |
| 283 | ); |
| 284 | assert.match( |
| 285 | workflow, |
| 286 | /wrangler@4\.152\.0 deploy --tag "\$DEPLOY_COMMIT_SHA"/ |
| 287 | ); |
| 288 | assert.doesNotMatch(workflow, /wrangler@4\s/); |
| 289 | }); |