Personal Telegram developer console for GitHub
feat(cp5): add exact-SHA delivery correlation model
davoodmehraban89 committed
Oct 5, 2026 at 06:09 UTC
8a1f2c18ac0fb05a832be95696b5e2792833c1c0
1 file changed
+38
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
+}