@kungfu-tech/buildchain 4.0.2-alpha.17 → 4.0.2-alpha.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kungfu-tech/buildchain",
3
- "version": "4.0.2-alpha.17",
3
+ "version": "4.0.2-alpha.19",
4
4
  "private": false,
5
5
  "description": "Buildchain Release Passport, release governance, CLI toolkit, and site facts.",
6
6
  "repository": "https://github.com/kungfu-systems/buildchain",
@@ -10,11 +10,9 @@ const DESCRIPTORS = Object.freeze([
10
10
  [".github/workflows/.release-candidate-promote.yml", "product-publication", true, ["npm-publish", "github-release", "channel-ref"], "trusted-publishing", "none", "fixed", "caller-bound"],
11
11
  [".github/workflows/.publication-authority.yml", "evidence-publication"],
12
12
  [".github/workflows/.release-verify.yml", "governance-write"],
13
- [".github/workflows/.sam-release.yml", "retired-deny"],
14
13
  [".github/workflows/.sam-verify.yml", "retired-deny"],
15
14
  [".github/workflows/.sync-remote-git.yml", "governance-write"],
16
15
  [".github/workflows/.web-surface.yml", "product-publication", true, ["web-production"], "oidc", "consumer-defined", "caller-bound", "caller-bound"],
17
- [".github/workflows/.wheel-release.yml", "retired-deny"],
18
16
  [".github/workflows/.wheel-verify.yml", "retired-deny"],
19
17
  [".github/workflows/.binary-release-assets.yml", "product-publication", true, ["github-release"], "github-token", "buildchain-release-assets"],
20
18
  [".github/workflows/binary-distribution.yml", "evidence-publication"],
@@ -266,7 +266,6 @@ export function validateV4UniversalWorkflowRequest(value) {
266
266
  payload: canonical(value.payload),
267
267
  };
268
268
  }
269
-
270
269
  export function v4UniversalWorkflowRequestRoot(value) {
271
270
  return documentRoot(
272
271
  "universal-workflow-request",
@@ -274,9 +273,10 @@ export function v4UniversalWorkflowRequestRoot(value) {
274
273
  );
275
274
  }
276
275
  export function v4ProductStateVersion(value, requestedSha) { const sourceSha = exactSha(requestedSha, "requestedSha"), ref = nonEmpty(value?.ref, "productStateRef.ref"), prefix = `refs/heads/buildchain/v4-product-state/${sourceSha}-`; if (!ref.startsWith(prefix)) fail("recovery-state-mismatch", "release recovery product state does not bind the requested source"); const match = ref.slice(prefix.length).match(/^(\d+)-(\d+)-(\d+)(?:-alpha-(\d+))?$/u); if (!match) fail("invalid-recovery-version", "release recovery product state version is invalid"); return `${match[1]}.${match[2]}.${match[3]}${match[4] === undefined ? "" : `-alpha.${match[4]}`}`; }
276
+ export function selectV4FinalizedProductPublicationVersion(value) { const requestedSha = exactSha(value.requestedSha, "requestedSha"), requestedTree = exactSha(value.requestedTree, "requestedTree"), lane = nonEmpty(value.targetRef, "targetRef").match(/^(alpha|release)\/v(\d+)\/v(\d+)\.(\d+)$/u); if (!lane || lane[2] !== lane[3]) fail("invalid-finalization-lane", "product publication finalization target is not a release lane"); const expectedAlpha = lane[1] === "alpha", versions = []; for (const row of Array.isArray(value.recoveryStates) ? value.recoveryStates : []) { const stateRef = row?.stateRef, match = String(stateRef?.ref || "").match(/^refs\/heads\/buildchain\/v4-product-state\/([0-9a-f]{40})-(\d+)-(\d+)-(\d+)(?:-alpha-(\d+))?$/u); if (!match || match[2] !== lane[2] || match[3] !== lane[4]) continue; const stateTree = exactSha(row?.stateCommit?.tree?.sha, "productStateCommit.tree.sha"); if (stateTree !== requestedTree || !new Set(["ahead", "identical"]).has(row.headComparisonStatus)) continue; const sourceSha = exactSha(match[1], "productStateRef.sourceSha"), version = v4ProductStateVersion(stateRef, sourceSha), parsed = version.match(/^(\d+)\.(\d+)\.(\d+)(?:-alpha\.(\d+))?$/u); if ((parsed[4] !== undefined) !== expectedAlpha) continue; if (stateRef?.object?.type !== "commit" || exactSha(stateRef?.object?.sha, "productStateRef.object.sha") !== exactSha(row?.stateCommit?.sha, "productStateCommit.sha") || row.stateCommit.parents?.length !== 1 || exactSha(row.stateCommit.parents[0]?.sha, "productStateCommit.parents[0].sha") !== sourceSha) fail("finalization-state-mismatch", "product publication finalization state does not bind its source"); if (row.exactTagRef && (row.exactTagRef.ref !== `refs/tags/v${version}` || row.exactTagRef.object?.type !== "commit" || exactSha(row.exactTagRef.object?.sha, "exactTagRef.object.sha") !== sourceSha)) fail("finalization-tag-mismatch", "product publication finalization tag does not bind its source"); versions.push(version); } const selected = [...new Set(versions)].sort(); if (selected.length > 1) fail("finalization-state-ambiguous", `publication head ${requestedSha} matches multiple product versions`); return selected[0] || ""; }
277
277
  export function selectV4RecoveredProductPublicationVersion(value) {
278
278
  if (value.routeDecision !== "Resume") return ""; const version = nonEmpty(value.candidateVersion, "candidateVersion"), sourceSha = exactSha(value.requestedSha, "requestedSha"), candidate = version.match(/^(\d+)\.(\d+)\.(\d+)(?:-alpha\.(\d+))?$/u); if (!candidate) fail("invalid-recovery-version", "release recovery candidate version is invalid"); if (value.explicitResume) return version;
279
- const states = Array.isArray(value.recoveryStates) ? value.recoveryStates : []; if (states.length) { const recovered = states.map(({ stateRef, stateCommit, exactTagRef }) => { const selected = v4ProductStateVersion(stateRef, sourceSha), parsed = selected.match(/^(\d+)\.(\d+)\.(\d+)(?:-alpha\.(\d+))?$/u), parents = stateCommit?.parents || []; if (stateRef?.object?.type !== "commit" || exactSha(stateRef?.object?.sha, "productStateRef.object.sha") !== exactSha(stateCommit?.sha, "productStateCommit.sha") || parents.length !== 1 || exactSha(parents[0]?.sha, "productStateCommit.parents[0].sha") !== sourceSha) fail("recovery-state-mismatch", "release recovery product state commit does not bind the requested source"); if (exactTagRef && (exactTagRef.ref !== `refs/tags/v${selected}` || exactTagRef.object?.type !== "commit" || exactSha(exactTagRef.object?.sha, "exactTagRef.object.sha") !== sourceSha)) fail("recovery-tag-mismatch", "release recovery exact tag does not bind the requested source"); if (parsed[1] !== candidate[1] || parsed[2] !== candidate[2] || parsed[3] !== candidate[3] || (parsed[4] === undefined) !== (candidate[4] === undefined)) fail("recovery-state-mismatch", "release recovery product state is outside the candidate release line"); return selected; }); recovered.sort((left, right) => Number(left.match(/(?:-alpha\.)?(\d+)$/u)[1]) - Number(right.match(/(?:-alpha\.)?(\d+)$/u)[1])); return recovered.at(-1); }
279
+ const states = Array.isArray(value.recoveryStates) ? value.recoveryStates : []; if (states.length) { const recovered = [...new Set(states.map(({ stateRef, stateCommit, exactTagRef }) => { const selected = v4ProductStateVersion(stateRef, sourceSha), parsed = selected.match(/^(\d+)\.(\d+)\.(\d+)(?:-alpha\.(\d+))?$/u), parents = stateCommit?.parents || []; if (stateRef?.object?.type !== "commit" || exactSha(stateRef?.object?.sha, "productStateRef.object.sha") !== exactSha(stateCommit?.sha, "productStateCommit.sha") || parents.length !== 1 || exactSha(parents[0]?.sha, "productStateCommit.parents[0].sha") !== sourceSha) fail("recovery-state-mismatch", "release recovery product state commit does not bind the requested source"); if (exactTagRef && (exactTagRef.ref !== `refs/tags/v${selected}` || exactTagRef.object?.type !== "commit" || exactSha(exactTagRef.object?.sha, "exactTagRef.object.sha") !== sourceSha)) fail("recovery-tag-mismatch", "release recovery exact tag does not bind the requested source"); if (parsed[1] !== candidate[1] || parsed[2] !== candidate[2] || parsed[3] !== candidate[3] || (parsed[4] === undefined) !== (candidate[4] === undefined)) fail("recovery-state-mismatch", "release recovery product state is outside the candidate release line"); return selected; }))]; if (recovered.length !== 1) fail("recovery-state-ambiguous", "release recovery requires one exact product publication state; provide an exact transaction identity"); return recovered[0]; }
280
280
  if (!value.exactTagRef) fail("recovery-tag-missing", "release recovery requires an exact partial-publication tag"); if (value.exactTagRef.ref !== `refs/tags/v${version}` || value.exactTagRef.object?.type !== "commit" || exactSha(value.exactTagRef.object?.sha, "exactTagRef.object.sha") !== sourceSha) fail("recovery-tag-mismatch", "release recovery exact tag does not bind the requested source");
281
281
  return version;
282
282
  }
@@ -345,69 +345,55 @@ function validatePolicy(value) {
345
345
  }
346
346
 
347
347
  function validateReviewEvidence(value) {
348
- exactKeys(
349
- value,
350
- [
351
- "repository",
352
- "pullRequest",
353
- "headSha",
354
- "baseRef",
355
- "approvals",
356
- "checks",
357
- "observedAt",
358
- ],
359
- "reviewEvidence",
360
- );
348
+ const hasBinding = Object.hasOwn(value || {}, "runtimeBinding");
349
+ exactKeys(value, ["repository", "pullRequest", "headSha", "baseRef", "approvals", "checks", "observedAt", ...(hasBinding ? ["runtimeBinding"] : [])], "reviewEvidence");
361
350
  const approvals = value.approvals.map((approval, index) => {
362
- exactKeys(
363
- approval,
364
- ["reviewer", "commitSha", "submittedAt"],
365
- `reviewEvidence.approvals[${index}]`,
366
- );
351
+ exactKeys(approval, ["reviewer", "commitSha", "submittedAt"], `reviewEvidence.approvals[${index}]`);
367
352
  return {
368
- reviewer: nonEmpty(
369
- approval.reviewer,
370
- `reviewEvidence.approvals[${index}].reviewer`,
371
- ),
372
- commitSha: exactSha(
373
- approval.commitSha,
374
- `reviewEvidence.approvals[${index}].commitSha`,
375
- ),
376
- submittedAt: timestamp(
377
- approval.submittedAt,
378
- `reviewEvidence.approvals[${index}].submittedAt`,
379
- ),
353
+ reviewer: nonEmpty(approval.reviewer, `reviewEvidence.approvals[${index}].reviewer`),
354
+ commitSha: exactSha(approval.commitSha, `reviewEvidence.approvals[${index}].commitSha`),
355
+ submittedAt: timestamp(approval.submittedAt, `reviewEvidence.approvals[${index}].submittedAt`),
380
356
  };
381
357
  });
382
358
  const checks = value.checks.map((check, index) => {
383
- exactKeys(
384
- check,
385
- ["name", "status", "conclusion"],
386
- `reviewEvidence.checks[${index}]`,
387
- );
359
+ const hasCommit = Object.hasOwn(check || {}, "commitSha");
360
+ exactKeys(check, ["name", "status", "conclusion", ...(hasCommit ? ["commitSha"] : [])], `reviewEvidence.checks[${index}]`);
388
361
  return {
389
362
  name: nonEmpty(check.name, `reviewEvidence.checks[${index}].name`),
390
363
  status: nonEmpty(check.status, `reviewEvidence.checks[${index}].status`),
391
- conclusion: nonEmpty(
392
- check.conclusion,
393
- `reviewEvidence.checks[${index}].conclusion`,
394
- ),
364
+ conclusion: nonEmpty(check.conclusion, `reviewEvidence.checks[${index}].conclusion`),
365
+ ...(hasCommit ? { commitSha: exactSha(check.commitSha, `reviewEvidence.checks[${index}].commitSha`) } : {}),
395
366
  };
396
367
  });
368
+ let runtimeBinding;
369
+ if (hasBinding) {
370
+ exactKeys(value.runtimeBinding, ["kind", "runtimeSha", "parentShas", "mergedAt"], "reviewEvidence.runtimeBinding");
371
+ const kind = nonEmpty(value.runtimeBinding.kind, "reviewEvidence.runtimeBinding.kind");
372
+ if (!new Set(["reviewed-head", "protected-alpha-merge"]).has(kind)) fail("invalid-runtime-binding", "review evidence runtime binding kind is unsupported");
373
+ const parentShas = value.runtimeBinding.parentShas.map((parent, index) => exactSha(parent, `reviewEvidence.runtimeBinding.parentShas[${index}]`));
374
+ if (new Set(parentShas).size !== parentShas.length) fail("invalid-runtime-binding", "review evidence runtime parents must be duplicate-free");
375
+ runtimeBinding = { kind, runtimeSha: exactSha(value.runtimeBinding.runtimeSha, "reviewEvidence.runtimeBinding.runtimeSha"), parentShas, mergedAt: value.runtimeBinding.mergedAt === null ? null : timestamp(value.runtimeBinding.mergedAt, "reviewEvidence.runtimeBinding.mergedAt") };
376
+ }
397
377
  return {
398
378
  repository: repository(value.repository, "reviewEvidence.repository"),
399
- pullRequest: positiveInteger(
400
- value.pullRequest,
401
- "reviewEvidence.pullRequest",
402
- ),
379
+ pullRequest: positiveInteger(value.pullRequest, "reviewEvidence.pullRequest"),
403
380
  headSha: exactSha(value.headSha, "reviewEvidence.headSha"),
404
381
  baseRef: nonEmpty(value.baseRef, "reviewEvidence.baseRef"),
405
- approvals,
406
- checks,
382
+ approvals, checks,
407
383
  observedAt: timestamp(value.observedAt, "reviewEvidence.observedAt"),
384
+ ...(runtimeBinding ? { runtimeBinding } : {}),
408
385
  };
409
386
  }
410
387
 
388
+ function reviewedRuntimeSha(request, policy, evidence, runtimeSha) {
389
+ const binding = evidence.runtimeBinding || { kind: "reviewed-head", runtimeSha: evidence.headSha, parentShas: [], mergedAt: null };
390
+ if (binding.runtimeSha !== runtimeSha) fail("review-runtime-mismatch", "review evidence runtime binding does not match the candidate");
391
+ const direct = binding.kind === "reviewed-head" && evidence.headSha === runtimeSha && evidence.baseRef === policy.targetRef && binding.mergedAt === null;
392
+ const alphaMerge = binding.kind === "protected-alpha-merge" && request.mode === "alpha" && evidence.baseRef === "alpha/v4/v4.0" && binding.parentShas.length === 2 && binding.parentShas.includes(evidence.headSha) && binding.mergedAt !== null && Date.parse(binding.mergedAt) <= Date.parse(evidence.observedAt);
393
+ if (!direct && !alphaMerge) fail("review-identity-mismatch", "review evidence does not bind the candidate runtime");
394
+ return evidence.headSha;
395
+ }
396
+
411
397
  export function v4UniversalWorkflowAdmissionRoot(value) {
412
398
  return documentRoot("universal-workflow-admission", validatePolicy(value));
413
399
  }
@@ -478,17 +464,16 @@ export function admitV4UniversalWorkflow({
478
464
  const reviewEvidence = validateReviewEvidence(reviewEvidenceValue);
479
465
  if (
480
466
  reviewEvidence.repository !== request.candidate.repository ||
481
- reviewEvidence.pullRequest !== request.candidate.reviewPullRequest ||
482
- reviewEvidence.headSha !== runtimeSha ||
483
- reviewEvidence.baseRef !== policy.targetRef
467
+ reviewEvidence.pullRequest !== request.candidate.reviewPullRequest
484
468
  )
485
469
  fail(
486
470
  "review-identity-mismatch",
487
471
  "review evidence does not bind the candidate",
488
472
  );
473
+ const reviewedSha = reviewedRuntimeSha(request, policy, reviewEvidence, runtimeSha);
489
474
  const approvedReviewers = new Set(
490
475
  reviewEvidence.approvals
491
- .filter((approval) => approval.commitSha === runtimeSha)
476
+ .filter((approval) => approval.commitSha === reviewedSha)
492
477
  .map((approval) => approval.reviewer),
493
478
  );
494
479
  const admittedApprovalCount = policy.allowedReviewers.filter((reviewer) =>
@@ -512,7 +497,8 @@ export function admitV4UniversalWorkflow({
512
497
  checks.length === 0 ||
513
498
  checks.some(
514
499
  (check) =>
515
- check.status !== "completed" || check.conclusion !== "success",
500
+ check.status !== "completed" || check.conclusion !== "success" ||
501
+ (check.commitSha !== undefined && check.commitSha !== runtimeSha),
516
502
  )
517
503
  );
518
504
  })
@@ -1043,8 +1043,8 @@ for (const requiredSnippet of [
1043
1043
  "actions: write",
1044
1044
  "uses: kungfu-systems/buildchain/.github/workflows/.release-candidate-promote.yml@v4-alpha",
1045
1045
  "github.event.workflow_run.event == 'push'",
1046
- "!startsWith(github.event.workflow_run.display_title, 'chore(release): prepare v')",
1047
- "!startsWith(github.event.workflow_run.display_title, 'chore(release): release v')",
1046
+ "name: Classify generated product-state finalization",
1047
+ "selectV4FinalizedProductPublicationVersion",
1048
1048
  "resume-candidate-run-id:",
1049
1049
  "resume-expected-source-tree:",
1050
1050
  "resume-buildchain-runtime-ref:",
@@ -1056,12 +1056,19 @@ for (const requiredSnippet of [
1056
1056
  throw new Error(`buildchain ref promotion workflow missing npm transaction snippet: ${requiredSnippet}`);
1057
1057
  }
1058
1058
  }
1059
+ if (buildchainRefPromotionWorkflow.includes("workflow_run.display_title")) {
1060
+ throw new Error(
1061
+ "buildchain ref promotion must classify finalization from rooted product state, not a display title",
1062
+ );
1063
+ }
1059
1064
  const releaseCandidatePromoteWorkflow = fs.readFileSync(path.join(root, ".github/workflows/.release-candidate-promote.yml"), "utf8");
1060
1065
  for (const requiredSnippet of [
1061
1066
  "name: QUALIFY canonical v4 release invocation inputs",
1062
1067
  "name: APPLY one rooted provider transaction",
1063
1068
  "name: SETTLE terminal ReleaseReceipt projection",
1064
1069
  "uses: ./.buildchain/runtime/actions/v4-release-candidate-promote",
1070
+ "name: Resolve one exact product publication recovery",
1071
+ "selectV4RecoveredProductPublicationVersion",
1065
1072
  "publisher-workflow-sha:",
1066
1073
  "runtime-commit:",
1067
1074
  "runtime-tree:",
@@ -1101,31 +1108,15 @@ for (const workflowFile of fs.readdirSync(workflowDir).filter((entry) => entry.e
1101
1108
  }
1102
1109
  }
1103
1110
  for (const retiredWorkflow of [
1111
+ ".release-docker.yml",
1104
1112
  ".release-new-version.yml",
1105
1113
  ".release-elastic-beanstalk.yml",
1106
1114
  ".sam-release.yml",
1107
1115
  ".wheel-release.yml",
1116
+ "schedule-purge-artifacts.yml",
1108
1117
  ]) {
1109
- const retiredSource = fs.readFileSync(path.join(workflowDir, retiredWorkflow), "utf8");
1110
- for (const requiredSnippet of [
1111
- "release path is retired",
1112
- "release-candidate-promote.yml@v3",
1113
- "publish-gate source-lock enforcement",
1114
- ]) {
1115
- if (!retiredSource.includes(requiredSnippet)) {
1116
- throw new Error(`${retiredWorkflow} must fail closed and point callers at the source-locked release-candidate-promote model: ${requiredSnippet}`);
1117
- }
1118
- }
1119
- for (const forbiddenSnippet of [
1120
- "npm publish --access=public",
1121
- "actions/publish-prebuilt@v2",
1122
- "actions/bump-version@v2",
1123
- "beanstalk-deploy@",
1124
- "sam deploy",
1125
- ]) {
1126
- if (retiredSource.includes(forbiddenSnippet)) {
1127
- throw new Error(`${retiredWorkflow} must not keep retired publish side effects: ${forbiddenSnippet}`);
1128
- }
1118
+ if (fs.existsSync(path.join(workflowDir, retiredWorkflow))) {
1119
+ throw new Error(`${retiredWorkflow} is fully retired and must remain deleted`);
1129
1120
  }
1130
1121
  }
1131
1122
  const promoteBuildchainRefAction = fs.readFileSync(path.join(root, "actions/promote-buildchain-ref/action.yml"), "utf8");
@@ -118,6 +118,10 @@ assert.equal(contract.bootstrap.consumerSourceMutationPerIncident, false);
118
118
  assert.equal(contract.bootstrap.buildchainReleasePromotionPerIncident, false);
119
119
  assert.equal(contract.bootstrap.selfDogfoodUsesPublicContract, true);
120
120
  assert.equal(contract.bootstrap.recoveryDependsOnPublishedBuildchain, false);
121
+ assert.equal(
122
+ contract.bootstrap.reviewRuntimeBinding,
123
+ "reviewed-head-or-protected-alpha-merge-to-exact-runtime",
124
+ );
121
125
  assert.deepEqual(
122
126
  contract.capabilityAdapters.map(({ id }) => id).sort(),
123
127
  [...admissionPolicy.allowedCapabilities].sort(),
@@ -168,6 +172,10 @@ assert.match(
168
172
  bootstrapSource,
169
173
  /ascii_downcase\) == "kungfu-origin"[\s\S]*\.name == "check"[\s\S]*map\(select\(\.status == "completed" and \(\.conclusion \/\/ ""\) != ""\)\)[\s\S]*candidate\/architecture\/v4-universal-workflow-train-admission\.json/u,
170
174
  );
175
+ assert.match(
176
+ bootstrapSource,
177
+ /CANDIDATE_MODE:[\s\S]*\.merged == true[\s\S]*\.merge_commit_sha == \$expected[\s\S]*\.base\.ref == "alpha\/v4\/v4\.0"[\s\S]*commitSha: \$expected[\s\S]*runtimeBinding:/u,
178
+ );
171
179
  const consumerTemplate = fs.readFileSync(
172
180
  path.join(root, contract.bootstrap.consumerTemplate),
173
181
  "utf8",