Personal Telegram developer console for GitHub
feat(cp5): add exact-SHA CI/CD control plane
* test(cp5): define exact-SHA delivery correlation contract * feat(cp5): add exact-SHA delivery correlation model * test(cp5): define integrated delivery control-plane view * feat(cp5): preserve exact workflow SHA for correlation * feat(cp5): declare delivery control-plane read * feat(cp5): add exact-SHA CI/CD control-plane view * feat(cp5): connect GitHub evidence to delivery control plane * test(cp5): extend Cloudflare manifest contract for delivery status
davoodmehraban89 committed
Oct 5, 2026 at 06:12 UTC
c66a36b63c2fa421060e498f722b4132d44a1bd7
7 files changed
+103
-5
src/bot-legacy.js
+1
-1
@@ -133,7 +133,7 @@ export class NexaDevBot {
133
accountId: env.CLOUDFLARE_ACCOUNT_ID || '',
134
workerName: env.CLOUDFLARE_WORKER_NAME || 'nexa-dev-bot'
135
});
136
- this.cloudflarePlugin = createCloudflarePlugin({ cloudflare: this.cloudflare });
136
+ this.cloudflarePlugin = createCloudflarePlugin({ cloudflare: this.cloudflare, github: this.github });
137
this.registry = new PluginRegistry([this.githubPlugin, this.cloudflarePlugin]);
138
this.policy = new ActionPolicy();
139
this.audit = new AuditLogger({
src/core/cicd-control-plane.js
new
+38
@@ -0,0 +1,38 @@
1
+const fullSha = value => /^[a-f0-9]{40}$/i.test(String(value || '')) ? String(value).toLowerCase() : '';
2
+
3
+export function correlateDeliveryState({ targetSha, ci, deploy, runtime } = {}) {
4
+ const target = fullSha(targetSha);
5
+ if (!target || !ci || !deploy) return { state: 'unknown', reason: 'Delivery evidence is incomplete' };
6
+
7
+ const ciSha = fullSha(ci.sha);
8
+ const deploySha = fullSha(deploy.sha);
9
+ if (!ciSha || !deploySha || ciSha !== target || deploySha !== target) {
10
+ return { state: 'mismatch', reason: 'CI/deploy SHA does not match target' };
11
+ }
12
+
13
+ const ciState = String(ci.conclusion || ci.status || '');
14
+ const deployState = String(deploy.conclusion || deploy.status || '');
15
+ if (['failure', 'cancelled', 'timed_out', 'action_required'].includes(ciState) ||
16
+ ['failure', 'cancelled', 'timed_out', 'action_required'].includes(deployState)) {
17
+ return { state: 'failed', reason: 'CI or deploy failed' };
18
+ }
19
+ if (ci.status !== 'completed' || deploy.status !== 'completed') {
20
+ return { state: 'pending', reason: 'CI or deploy is still pending' };
21
+ }
22
+ if (ci.conclusion !== 'success' || deploy.conclusion !== 'success') {
23
+ return { state: 'failed', reason: 'CI or deploy did not succeed' };
24
+ }
25
+
26
+ const versions = runtime?.deployment?.versions;
27
+ if (!Array.isArray(versions) || versions.length !== 1 || Number(versions[0]?.percentage) !== 100 || !versions[0]?.versionId) {
28
+ return { state: 'mismatch', reason: 'Runtime traffic is not pinned to one verified version' };
29
+ }
30
+
31
+ return {
32
+ state: 'success',
33
+ reason: 'Exact SHA CI/deploy evidence and runtime traffic agree',
34
+ sha: target,
35
+ deploymentId: String(runtime?.deployment?.id || ''),
36
+ versionId: String(versions[0].versionId)
37
+ };
38
+}
src/github.js
+1
-1
@@ -21,7 +21,7 @@ export class GitHubService {
21
repositoryApiBase(fullName) { const parts = String(fullName || '').split('/').filter(Boolean); if (parts.length !== 2) throw new Error('GitHub repository full_name is invalid'); return `${this.baseUrl}/repos/${parts.map(encodeURIComponent).join('/')}`; }
22
async getRepositoryContext(repoRef) { const value = String(repoRef || ''); try { const raw = await this.requestJson(this.repositoryLookupUrl(value), 'GitHub repository'); return { raw, apiBase: this.repositoryApiBase(raw.full_name) }; } catch (error) { if (!/^\d+$/.test(value) || error?.status !== 404) throw error; const repositories = await this.listRepositories(); const match = repositories.find(repo => repo.id === value); if (!match?.fullName) throw error; const apiBase = this.repositoryApiBase(match.fullName); const raw = await this.requestJson(apiBase, 'GitHub repository'); return { raw, apiBase: this.repositoryApiBase(raw.full_name) }; } }
23
mapRepository(r) { return { id: String(r.id ?? r.name), name: r.name, fullName: r.full_name, private: !!r.private, description: r.description || '', defaultBranch: r.default_branch || 'main', archived: !!r.archived, htmlUrl: r.html_url || '', stars: r.stargazers_count ?? 0, forks: r.forks_count ?? 0 }; }
24
- mapWorkflowRun(run = {}) { const mapped = { id: run.id, name: run.name || 'Workflow', status: run.status || '', conclusion: run.conclusion || null, event: run.event || '', branch: run.head_branch || '', sha: String(run.head_sha || '').slice(0, 7), runNumber: run.run_number ?? null, url: run.html_url || '', createdAt: run.created_at || '', updatedAt: run.updated_at || '' }; if (Number.isSafeInteger(Number(run.workflow_id))) mapped.workflowId = Number(run.workflow_id); return mapped; }
24
+ mapWorkflowRun(run = {}) { const headSha = String(run.head_sha || ''); const mapped = { id: run.id, name: run.name || 'Workflow', status: run.status || '', conclusion: run.conclusion || null, event: run.event || '', branch: run.head_branch || '', sha: headSha.slice(0, 7), runNumber: run.run_number ?? null, url: run.html_url || '', createdAt: run.created_at || '', updatedAt: run.updated_at || '' }; if (/^[a-f0-9]{40}$/i.test(headSha)) mapped.fullSha = headSha.toLowerCase(); if (Number.isSafeInteger(Number(run.workflow_id))) mapped.workflowId = Number(run.workflow_id); return mapped; }
25
mapWorkflowJob(job = {}) { return { id: job.id, name: job.name || 'Job', status: job.status || '', conclusion: job.conclusion || null, startedAt: job.started_at || '', completedAt: job.completed_at || '', url: job.html_url || '', steps: (job.steps || []).slice(0, 30).map(step => ({ number: step.number, name: step.name || 'Step', status: step.status || '', conclusion: step.conclusion || null })) }; }
26
mapPullRequestFile(file = {}) { return { filename: file.filename || '', status: file.status || '', additions: file.additions ?? 0, deletions: file.deletions ?? 0, changes: file.changes ?? 0, patch: boundedPatch(file.patch) }; }
27
mapIssue(issue = {}) { return { number: issue.number, title: issue.title || '', state: issue.state || '', author: issue.user?.login || 'unknown', comments: issue.comments ?? 0, url: issue.html_url || '' }; }
src/plugins/cloudflare/manifest.js
+2
-1
@@ -6,6 +6,7 @@ export const cloudflarePluginManifest = Object.freeze({
6
actions: Object.freeze({
7
'cloudflare.worker.status': Object.freeze({ risk: 'READ' }),
8
'cloudflare.worker.versions': Object.freeze({ risk: 'READ' }),
9
- 'cloudflare.worker.deploy_version': Object.freeze({ risk: 'DESTRUCTIVE' })
9
+ 'cloudflare.worker.deploy_version': Object.freeze({ risk: 'DESTRUCTIVE' }),
10
+ 'cloudflare.delivery.status': Object.freeze({ risk: 'READ' })
11
})
12
});
src/plugins/cloudflare/plugin.js
+16
-1
@@ -1,3 +1,4 @@
1
+import { correlateDeliveryState } from '../../core/cicd-control-plane.js';
2
import { cloudflarePluginManifest } from './manifest.js';
3
4
const escapeHtml = value => String(value ?? '')
@@ -39,6 +40,7 @@ ${bindings}
40
41
Secret values نمایش داده نمیشوند.`,
42
reply_markup:{inline_keyboard:[
43
+ [{text:'🚦 CI/CD Control Plane',callback_data:'cf:delivery'}],
44
[{text:'📚 نسخهها / Rollback',callback_data:'cf:versions'}],
45
[{text:'🔄 بروزرسانی',callback_data:'cf:status'}],
46
[{text:'🔙 ابزارها',callback_data:'menu:tools'}]
@@ -59,13 +61,26 @@ ${versions.slice(0,10).map(v=>`• <code>${escapeHtml(v.id)}</code>\n ${escapeH
61
};
62
}
63
62
-export function createCloudflarePlugin({ cloudflare } = {}) {
64
+export function createCloudflarePlugin({ cloudflare, github } = {}) {
65
return {
66
manifest: cloudflarePluginManifest,
67
resolveCallback(data) {
68
const value=String(data||'');
69
if(value==='cf:status') return {actionId:'cloudflare.worker.status',kind:'worker-status',async execute(){if(!cloudflare?.isConfigured?.())return unavailableView();return snapshotView(await cloudflare.getWorkerSnapshot());}};
70
if(value==='cf:versions') return {actionId:'cloudflare.worker.versions',kind:'versions',async execute(){if(!cloudflare?.isConfigured?.())return unavailableView();return versionsView(await cloudflare.listVersions());}};
71
+ if(value==='cf:delivery') return {actionId:'cloudflare.delivery.status',kind:'delivery-status',async execute(){
72
+ if(!cloudflare?.isConfigured?.() || !github) return {text:'🚦 <b>Delivery Control Plane</b>\n❌ Provider evidence is not configured.',reply_markup:{inline_keyboard:[[{text:'🔙 Cloudflare',callback_data:'cf:status'}]]}};
73
+ const repos=await github.listRepositories();
74
+ const repo=repos.find(item=>item.name===cloudflare.workerName) || repos[0];
75
+ if(!repo) throw new Error('GitHub repository evidence is unavailable');
76
+ const [commits,runs,runtime]=await Promise.all([github.listCommits(repo.id),github.listWorkflowRuns(repo.id,{perPage:20,page:1}),cloudflare.getWorkerSnapshot()]);
77
+ const targetSha=String(commits[0]?.fullSha||'');
78
+ const ci=runs.find(run=>run.name==='CI' && run.branch===(repo.defaultBranch||'main') && run.fullSha===targetSha) || null;
79
+ const deploy=runs.find(run=>/Deploy Cloudflare Worker/i.test(run.name) && run.branch===(repo.defaultBranch||'main') && run.fullSha===targetSha) || null;
80
+ const state=correlateDeliveryState({targetSha,ci,deploy,runtime});
81
+ const label=state.state==='success'?'SUCCESS / موفق':state.state.toUpperCase();
82
+ return {text:`🚦 <b>CI/CD Control Plane</b>\nState: <b>${label}</b>\nSHA: <code>${escapeHtml(targetSha.slice(0,12)||'-')}</code>\nCI: <b>${escapeHtml(ci?.conclusion||ci?.status||'unknown')}</b>\nDeploy: <b>${escapeHtml(deploy?.conclusion||deploy?.status||'unknown')}</b>\nRuntime: <code>${escapeHtml(state.versionId||runtime?.deployment?.versions?.[0]?.versionId||'-')}</code>\n\n${escapeHtml(state.reason)}</b>`,reply_markup:{inline_keyboard:[[{text:'🔄 بروزرسانی',callback_data:'cf:delivery'}],[{text:'🔙 Cloudflare',callback_data:'cf:status'}]]}};
83
+ }};
84
const m=value.match(/^cfdeploy:([0-9a-f-]{36})$/i);
85
if(m) {
86
const versionId=m[1];
test/cicd-control-plane.test.js
new
+43
@@ -0,0 +1,43 @@
1
+import test from 'node:test';
2
+import assert from 'node:assert/strict';
3
+import { correlateDeliveryState } from '../src/core/cicd-control-plane.js';
4
+
5
+const sha='a'.repeat(40);
6
+const active={deployment:{id:'dep',versions:[{versionId:'v1',percentage:100}]}};
7
+
8
+test('CP5 correlates exact SHA across CI and deploy before declaring success',()=>{
9
+ assert.equal(correlateDeliveryState({targetSha:sha,ci:{sha,status:'completed',conclusion:'success'},deploy:{sha,status:'completed',conclusion:'success'},runtime:active}).state,'success');
10
+ assert.equal(correlateDeliveryState({targetSha:sha,ci:{sha,status:'completed',conclusion:'success'},deploy:{sha:'b'.repeat(40),status:'completed',conclusion:'success'},runtime:active}).state,'mismatch');
11
+});
12
+
13
+test('CP5 never promotes pending, failed, or missing evidence to success',()=>{
14
+ assert.equal(correlateDeliveryState({targetSha:sha,ci:{sha,status:'in_progress'},deploy:{sha,status:'queued'},runtime:active}).state,'pending');
15
+ assert.equal(correlateDeliveryState({targetSha:sha,ci:{sha,status:'completed',conclusion:'failure'},deploy:{sha,status:'completed',conclusion:'success'},runtime:active}).state,'failed');
16
+ assert.equal(correlateDeliveryState({targetSha:sha,ci:null,deploy:null,runtime:null}).state,'unknown');
17
+});
18
+
19
+test('CP5 flags runtime traffic that is absent or split as mismatch',()=>{
20
+ assert.equal(correlateDeliveryState({targetSha:sha,ci:{sha,status:'completed',conclusion:'success'},deploy:{sha,status:'completed',conclusion:'success'},runtime:{deployment:null}}).state,'mismatch');
21
+ assert.equal(correlateDeliveryState({targetSha:sha,ci:{sha,status:'completed',conclusion:'success'},deploy:{sha,status:'completed',conclusion:'success'},runtime:{deployment:{versions:[{versionId:'v1',percentage:50},{versionId:'v2',percentage:50}]}}}).state,'mismatch');
22
+});
23
+
24
+
25
+test('CP5 Cloudflare plugin exposes owner delivery view from live provider evidence', async()=>{
26
+ const { createCloudflarePlugin } = await import('../src/plugins/cloudflare/plugin.js');
27
+ const target='c'.repeat(40);
28
+ const github={
29
+ async listRepositories(){return [{id:'123',name:'nexa-dev-bot',defaultBranch:'main'}]},
30
+ async listCommits(){return [{fullSha:target}]},
31
+ async listWorkflowRuns(){return [
32
+ {name:'CI',branch:'main',fullSha:target,sha:target.slice(0,7),status:'completed',conclusion:'success'},
33
+ {name:'Deploy Cloudflare Worker',branch:'main',fullSha:target,sha:target.slice(0,7),status:'completed',conclusion:'success'}
34
+ ]}
35
+ };
36
+ const cloudflare={isConfigured(){return true},async getWorkerSnapshot(){return {workerName:'nexa-dev-bot',deployment:{id:'dep',versions:[{versionId:'v1',percentage:100}]},version:{id:'v1'},bindings:[],observability:{}}}};
37
+ const plugin=createCloudflarePlugin({cloudflare,github});
38
+ const route=plugin.resolveCallback('cf:delivery');
39
+ assert.equal(route.actionId,'cloudflare.delivery.status');
40
+ const view=await route.execute();
41
+ assert.match(view.text,/SUCCESS|موفق/i);
42
+ assert.match(view.text,new RegExp(target.slice(0,12)));
43
+});
test/cloudflare-plugin.test.js
+2
-1
@@ -20,7 +20,8 @@ test('Cloudflare plugin exposes CP4 read and destructive actions explicitly', ()
20
assert.deepEqual(plugin.manifest.actions, {
21
'cloudflare.worker.status': { risk: 'READ' },
22
'cloudflare.worker.versions': { risk: 'READ' },
23
- 'cloudflare.worker.deploy_version': { risk: 'DESTRUCTIVE' }
23
+ 'cloudflare.worker.deploy_version': { risk: 'DESTRUCTIVE' },
24
+ 'cloudflare.delivery.status': { risk: 'READ' }
25
});
26
});
27