@kungfu-tech/buildchain 4.0.1-alpha.5 → 4.0.1-alpha.8

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.
Files changed (108) hide show
  1. package/actions/release-tail/README.md +8 -0
  2. package/architecture/ci-lane-change-budget.json +187 -0
  3. package/architecture/internal-capabilities.json +65 -5
  4. package/architecture/maintainability-policy.json +27 -21
  5. package/architecture/release-tail-contract-inventory.json +5 -2
  6. package/architecture/v4-adopter-delivery-parity.json +32 -5
  7. package/architecture/v4-floating-consumer-policy.json +6 -0
  8. package/architecture/v4-publication-rehearsal-parity.json +84 -0
  9. package/bin/buildchain.mjs +7 -1
  10. package/bin/internal/adopter-delivery-cli.mjs +70 -0
  11. package/bin/internal/command-registry.mjs +1 -0
  12. package/contracts/fixtures/v4-adopter-delivery-v1/archive-template.json +19 -0
  13. package/contracts/fixtures/v4-adopter-delivery-v1/bootstrap-positive.json +93 -0
  14. package/contracts/fixtures/v4-adopter-delivery-v1/gate-positive.json +29 -0
  15. package/contracts/fixtures/v4-adopter-delivery-v1/gate-unknown-selector.json +26 -0
  16. package/contracts/fixtures/v4-adopter-delivery-v1/offline-vectors.json +50 -0
  17. package/contracts/fixtures/v4-publication-rehearsal-v1/candidate/artifacts/product.bin +1 -0
  18. package/contracts/fixtures/v4-publication-rehearsal-v1/candidate/config/buildchain.toml +5 -0
  19. package/contracts/fixtures/v4-publication-rehearsal-v1/candidate/documents/release-activation.json +1 -0
  20. package/contracts/fixtures/v4-publication-rehearsal-v1/candidate/documents/signed-channel.json +1 -0
  21. package/contracts/fixtures/v4-publication-rehearsal-v1/candidate/evidence/qualification.json +1 -0
  22. package/contracts/fixtures/v4-publication-rehearsal-v1/candidate/manifests/candidate.json +5 -0
  23. package/contracts/fixtures/v4-publication-rehearsal-v1/candidate/manifests/release-passport.json +1 -0
  24. package/contracts/fixtures/v4-publication-rehearsal-v1/capsule.json +707 -0
  25. package/contracts/fixtures/v4-publication-rehearsal-v1/offline-vectors.json +27 -0
  26. package/contracts/fixtures/v4-tail-reseal-v1/valid.json +1 -1
  27. package/contracts/v4-adopter-delivery-v1.schema.json +81 -0
  28. package/contracts/v4-floating-consumer-policy-receipt-v1.schema.json +4 -2
  29. package/contracts/v4-publication-rehearsal-capsule-v1.schema.json +233 -0
  30. package/dist/site/agent-index.json +3 -0
  31. package/dist/site/artifact-schemas.json +6 -0
  32. package/dist/site/buildchain-contract.json +14 -14
  33. package/dist/site/buildchain-site.json +231 -24
  34. package/dist/site/capability-registry.json +11 -10
  35. package/dist/site/cli-registry.json +53 -1
  36. package/dist/site/kfd-claims.json +279 -14
  37. package/dist/site/kfd-upstream-aggregate.json +1 -1
  38. package/dist/site/manual-registry.json +20 -5
  39. package/dist/site/node-api-registry.json +11569 -9299
  40. package/dist/site/page-registry.json +214 -15
  41. package/dist/site/public-surface-audit.json +206 -11
  42. package/dist/site/publication-authority-registry.json +39 -8
  43. package/dist/site/publication-registry.json +4 -4
  44. package/dist/site/release-provenance.json +15 -0
  45. package/dist/site/schemas/release-tail-capabilities-v1.schema.json +199 -0
  46. package/dist/site/schemas/v4-adopter-delivery-v1.schema.json +81 -0
  47. package/dist/site/schemas/v4-publication-rehearsal-capsule-v1.schema.json +233 -0
  48. package/dist/site/site-manifest.json +17 -9
  49. package/dist/site/workflow-registry.json +110 -8
  50. package/docs/MAP.md +3 -1
  51. package/docs/cli-reference.md +68 -0
  52. package/docs/cli.md +8 -0
  53. package/docs/dev-delivery-warrant.md +22 -1
  54. package/docs/node-api-reference.md +332 -172
  55. package/docs/release-tail-provider-plane.md +30 -0
  56. package/docs/v4-adopter-delivery.md +133 -0
  57. package/docs/v4-publication-rehearsal.md +130 -0
  58. package/package.json +18 -3
  59. package/packages/core/adopter-delivery-passport.js +259 -0
  60. package/packages/core/adopter-delivery-vectors.js +158 -0
  61. package/packages/core/adopter-delivery-vectors.json +77 -0
  62. package/packages/core/buildchain-agent-manuals.js +1 -0
  63. package/packages/core/buildchain-config.js +84 -0
  64. package/packages/core/buildchain-delivery-bootstrap.js +240 -0
  65. package/packages/core/buildchain-delivery-infrastructure.js +164 -0
  66. package/packages/core/buildchain-delivery-self-dogfood.js +395 -0
  67. package/packages/core/buildchain-publication-authority.js +1 -0
  68. package/packages/core/ci-lane-change-budget.js +247 -0
  69. package/packages/core/dev-delivery-native-proof.js +43 -27
  70. package/packages/core/dev-delivery-warrant-state.js +31 -8
  71. package/packages/core/dev-delivery-warrant.js +8 -3
  72. package/packages/core/github-governance-authority.js +1 -0
  73. package/packages/core/index.js +5 -0
  74. package/packages/core/legacy-kfd-adopter-driver.js +167 -0
  75. package/packages/core/published-delivery-authority.js +266 -0
  76. package/packages/core/release-candidate-recovery.js +66 -11
  77. package/packages/core/release-candidate.js +2 -2
  78. package/packages/core/release-passport.js +36 -9
  79. package/packages/core/v4-adopter-delivery-parity.js +3 -3
  80. package/packages/core/v4-adopter-delivery.js +359 -0
  81. package/packages/core/v4-delivery-warrant-read-candidate.js +10 -3
  82. package/packages/core/v4-floating-consumer-evidence.js +18 -4
  83. package/packages/core/v4-floating-consumer-policy.js +138 -35
  84. package/packages/core/v4-floating-consumer-release-passport.js +30 -3
  85. package/packages/core/v4-publication-rehearsal-capsule.js +468 -0
  86. package/packages/core/v4-publication-rehearsal-provider-bindings.js +212 -0
  87. package/packages/core/v4-publication-rehearsal.js +481 -0
  88. package/packages/core/workflow-yaml-contract.js +24 -2
  89. package/scripts/buildchain-cli-help.mjs +10 -0
  90. package/scripts/check-ci-lane-change-budget.mjs +100 -0
  91. package/scripts/check-inventory.mjs +3 -3
  92. package/scripts/check-v4-floating-consumer-policy-contract.mjs +23 -4
  93. package/scripts/dev-delivery-source-proof-replay.mjs +153 -0
  94. package/scripts/dev-delivery-source-proof-reuse.mjs +13 -97
  95. package/scripts/dev-delivery-warrant-store.mjs +10 -6
  96. package/scripts/dev-delivery-warrant.mjs +5 -1
  97. package/scripts/dev-pr-delivery-warrant.mjs +1 -0
  98. package/scripts/dev-qualification-patrol.mjs +9 -9
  99. package/scripts/generate-channel-promotion-workflow.mjs +2 -2
  100. package/scripts/generate-release-candidate-passport.mjs +152 -0
  101. package/scripts/generate-site-bundle.mjs +30 -0
  102. package/scripts/promotion-channel-router.mjs +4 -4
  103. package/scripts/release-candidate-anchor-provenance.mjs +99 -0
  104. package/scripts/release-tail.mjs +51 -3
  105. package/scripts/resume-from-candidate-run.mjs +556 -29
  106. package/scripts/site-capability-metadata.mjs +17 -0
  107. package/scripts/v4-consumer-policy.mjs +4 -0
  108. package/scripts/v4-publication-rehearsal-fixture.mjs +144 -0
@@ -0,0 +1,266 @@
1
+ import { createHash } from "node:crypto";
2
+ import { createReadStream } from "node:fs";
3
+ import {
4
+ copyFile,
5
+ mkdir,
6
+ mkdtemp,
7
+ readFile,
8
+ realpath,
9
+ rm,
10
+ } from "node:fs/promises";
11
+ import { tmpdir } from "node:os";
12
+ import path from "node:path";
13
+ import { promisify } from "node:util";
14
+ import { pathToFileURL } from "node:url";
15
+ import { execFile } from "node:child_process";
16
+
17
+ import { adopterDeliveryGateDigest } from "./adopter-delivery-gate.js";
18
+
19
+ export const PUBLISHED_DELIVERY_AUTHORITY_CONTRACT =
20
+ "kungfu-buildchain-published-delivery-authority/v1";
21
+
22
+ const execFileAsync = promisify(execFile);
23
+ const ROOT_PATTERN = /^sha256:[0-9a-f]{64}$/;
24
+ const PACKAGES = [
25
+ {
26
+ key: "buildchain",
27
+ name: "@kungfu-tech/buildchain",
28
+ packageRoot: "archive",
29
+ modules: {
30
+ adopterDeliveryGate: "packages/core/adopter-delivery-gate.js",
31
+ bootstrap: "packages/core/buildchain-delivery-bootstrap.js",
32
+ infrastructure: "packages/core/buildchain-delivery-infrastructure.js",
33
+ kfdCategoryDriver: "packages/core/kfd-adopter-category-driver.js",
34
+ },
35
+ },
36
+ {
37
+ key: "kfd",
38
+ name: "@kungfu-tech/kfd",
39
+ packageRoot: "profiles/adopter-conformance/adopters/kfd/manifest.json",
40
+ modules: {},
41
+ },
42
+ ];
43
+
44
+ async function sha256File(file) {
45
+ const hash = createHash("sha256");
46
+ for await (const chunk of createReadStream(file)) hash.update(chunk);
47
+ return `sha256:${hash.digest("hex")}`;
48
+ }
49
+
50
+ function exactDeclaration(value, expectedName, label) {
51
+ if (
52
+ value?.name !== expectedName ||
53
+ typeof value.version !== "string" ||
54
+ value.version.length === 0 ||
55
+ typeof value.archivePath !== "string" ||
56
+ value.archivePath.length === 0 ||
57
+ !ROOT_PATTERN.test(value.archiveRoot ?? "") ||
58
+ !ROOT_PATTERN.test(value.artifactRoot ?? "")
59
+ ) {
60
+ throw new TypeError(`${label} package declaration is incomplete`);
61
+ }
62
+ return structuredClone(value);
63
+ }
64
+
65
+ function safeArchiveEntries(listing, verboseListing, label) {
66
+ const entries = listing.split("\n").filter(Boolean);
67
+ const types = verboseListing.split("\n").filter(Boolean);
68
+ if (entries.length === 0 || entries.length !== types.length) {
69
+ throw new Error(`${label} archive listing is incomplete`);
70
+ }
71
+ for (let index = 0; index < entries.length; index += 1) {
72
+ const entry = entries[index];
73
+ const parts = entry.split("/");
74
+ if (
75
+ parts[0] !== "package" ||
76
+ parts.some((part, partIndex) =>
77
+ partIndex === parts.length - 1 && part === ""
78
+ ? false
79
+ : part === "" || part === "." || part === "..",
80
+ )
81
+ ) {
82
+ throw new Error(`${label} archive contains an unsafe path`);
83
+ }
84
+ if (!["-", "d"].includes(types[index][0])) {
85
+ throw new Error(`${label} archive contains a non-file entry`);
86
+ }
87
+ }
88
+ }
89
+
90
+ async function extractPackage(declaration, destination, definition, label) {
91
+ const archivePath = path.resolve(declaration.archivePath);
92
+ const observedRoot = await sha256File(archivePath);
93
+ if (observedRoot !== declaration.archiveRoot) {
94
+ throw new Error(`${label} archive bytes do not match archiveRoot`);
95
+ }
96
+ await mkdir(destination, { recursive: true });
97
+ const stagedArchiveName = `.buildchain-${definition.key}-authority.tgz`;
98
+ const stagedArchivePath = path.join(
99
+ path.dirname(destination),
100
+ stagedArchiveName,
101
+ );
102
+ const stagedArchiveFile = `../${stagedArchiveName}`;
103
+ await copyFile(archivePath, stagedArchivePath);
104
+ try {
105
+ if ((await sha256File(stagedArchivePath)) !== declaration.archiveRoot) {
106
+ throw new Error(`${label} staged archive bytes do not match archiveRoot`);
107
+ }
108
+ const [{ stdout: listing }, { stdout: verboseListing }] = await Promise.all(
109
+ [
110
+ execFileAsync("tar", ["-tzf", stagedArchiveFile], {
111
+ cwd: destination,
112
+ maxBuffer: 16 * 1024 * 1024,
113
+ }),
114
+ execFileAsync("tar", ["-tvzf", stagedArchiveFile], {
115
+ cwd: destination,
116
+ maxBuffer: 16 * 1024 * 1024,
117
+ }),
118
+ ],
119
+ );
120
+ safeArchiveEntries(listing, verboseListing, label);
121
+ await execFileAsync(
122
+ "tar",
123
+ ["-xzf", stagedArchiveFile, "--strip-components", "1"],
124
+ { cwd: destination, maxBuffer: 16 * 1024 * 1024 },
125
+ );
126
+ } finally {
127
+ await rm(stagedArchivePath, { force: true });
128
+ }
129
+ const packageJsonPath = path.join(destination, "package.json");
130
+ const packageJson = JSON.parse(await readFile(packageJsonPath, "utf8"));
131
+ if (
132
+ packageJson.name !== declaration.name ||
133
+ packageJson.version !== declaration.version
134
+ ) {
135
+ throw new Error(`${label} extracted package identity does not match`);
136
+ }
137
+ if (definition.packageRoot === "archive") {
138
+ if (declaration.artifactRoot !== declaration.archiveRoot) {
139
+ throw new Error(`${label} package artifactRoot must match archiveRoot`);
140
+ }
141
+ } else {
142
+ const packageManifest = JSON.parse(
143
+ await readFile(path.join(destination, definition.packageRoot), "utf8"),
144
+ );
145
+ const packageCut = packageManifest?.kfdCut?.package;
146
+ if (
147
+ packageCut?.name !== declaration.name ||
148
+ packageCut?.version !== declaration.version ||
149
+ packageCut?.artifactRoot !== declaration.artifactRoot
150
+ ) {
151
+ throw new Error(`${label} semantic package identity does not match`);
152
+ }
153
+ }
154
+ const destinationRoot = await realpath(destination);
155
+ if (!destinationRoot.endsWith(path.join(...declaration.name.split("/")))) {
156
+ throw new Error(`${label} extraction escaped its package coordinate`);
157
+ }
158
+ return {
159
+ name: declaration.name,
160
+ version: declaration.version,
161
+ archiveRoot: declaration.archiveRoot,
162
+ artifactRoot: declaration.artifactRoot,
163
+ };
164
+ }
165
+
166
+ async function importAuthorityRuntime(buildchainRoot) {
167
+ const definition = PACKAGES[0];
168
+ const imported = {};
169
+ for (const [key, relativePath] of Object.entries(definition.modules)) {
170
+ imported[key] = await import(
171
+ pathToFileURL(path.join(buildchainRoot, relativePath)).href
172
+ );
173
+ }
174
+ const runtime = {
175
+ createAdopterDeliveryGate:
176
+ imported.adopterDeliveryGate.createAdopterDeliveryGate,
177
+ createPackageArtifactProfile:
178
+ imported.adopterDeliveryGate.createPackageArtifactProfile,
179
+ qualifyBuildchainDeliveryInfrastructureBootstrap:
180
+ imported.bootstrap.qualifyBuildchainDeliveryInfrastructureBootstrap,
181
+ createBuildchainDeliveryInfrastructureInstanceManifest:
182
+ imported.infrastructure
183
+ .createBuildchainDeliveryInfrastructureInstanceManifest,
184
+ verifyBuildchainDeliveryInfrastructureInstance:
185
+ imported.infrastructure.verifyBuildchainDeliveryInfrastructureInstance,
186
+ createKfdAdopterCategoryProtocolDriver:
187
+ imported.kfdCategoryDriver.createKfdAdopterCategoryProtocolDriver,
188
+ };
189
+ for (const [name, implementation] of Object.entries(runtime)) {
190
+ if (typeof implementation !== "function") {
191
+ throw new Error(`published Buildchain authority is missing ${name}`);
192
+ }
193
+ }
194
+ return runtime;
195
+ }
196
+
197
+ export async function loadPublishedBuildchainDeliveryAuthority({
198
+ buildchain,
199
+ kfd,
200
+ } = {}) {
201
+ const declarations = {
202
+ buildchain: exactDeclaration(
203
+ buildchain,
204
+ "@kungfu-tech/buildchain",
205
+ "Buildchain authority",
206
+ ),
207
+ kfd: exactDeclaration(kfd, "@kungfu-tech/kfd", "KFD authority"),
208
+ };
209
+ const temporaryRoot = await mkdtemp(
210
+ path.join(tmpdir(), "buildchain-published-delivery-authority-"),
211
+ );
212
+ let retained = false;
213
+ try {
214
+ const identities = {};
215
+ for (const definition of PACKAGES) {
216
+ identities[definition.key] = await extractPackage(
217
+ declarations[definition.key],
218
+ path.join(temporaryRoot, "node_modules", ...definition.name.split("/")),
219
+ definition,
220
+ `${definition.key} authority`,
221
+ );
222
+ }
223
+ const authorityRuntime = await importAuthorityRuntime(
224
+ path.join(temporaryRoot, "node_modules", ...PACKAGES[0].name.split("/")),
225
+ );
226
+ const authority = {
227
+ schemaVersion: 1,
228
+ contract: PUBLISHED_DELIVERY_AUTHORITY_CONTRACT,
229
+ packages: identities,
230
+ moduleCoordinates: structuredClone(PACKAGES[0].modules),
231
+ qualifying: false,
232
+ selfCertified: false,
233
+ releaseAuthorized: false,
234
+ finalAuthority:
235
+ "caller-bound-public-npm-archive-bytes-and-package-identity",
236
+ };
237
+ authority.authorityRoot = adopterDeliveryGateDigest(authority);
238
+ retained = true;
239
+ return {
240
+ ...authority,
241
+ authorityRuntime,
242
+ temporaryRoot,
243
+ async dispose() {
244
+ await rm(temporaryRoot, { recursive: true, force: true });
245
+ },
246
+ };
247
+ } finally {
248
+ if (!retained) await rm(temporaryRoot, { recursive: true, force: true });
249
+ }
250
+ }
251
+
252
+ export async function withPublishedBuildchainDeliveryAuthority(
253
+ declarations,
254
+ operation,
255
+ ) {
256
+ if (typeof operation !== "function") {
257
+ throw new TypeError("published authority operation must be a function");
258
+ }
259
+ const authority =
260
+ await loadPublishedBuildchainDeliveryAuthority(declarations);
261
+ try {
262
+ return await operation(authority);
263
+ } finally {
264
+ await authority.dispose();
265
+ }
266
+ }
@@ -308,6 +308,42 @@ function validateProductPayloads({ passport, artifacts, productPayloadManifests,
308
308
  }
309
309
  }
310
310
 
311
+ function assertAnchorEqual(actual, expected, label) {
312
+ assertEqual(actual, expected, "anchored-provenance-invalid", label, "Preserve both candidate runs and repair the explicit anchor provenance before retrying.");
313
+ }
314
+
315
+ function validateAnchorProvenance({ run, passport, anchorProvenance, expectedTransactionId, workflowFile, expectedWorkflowName, repository, targetRef }) {
316
+ const request = anchorProvenance.request;
317
+ const provenanceRun = anchorProvenance.run;
318
+ const provenanceWorkflow = anchorProvenance.workflow;
319
+ const provenancePassport = anchorProvenance.passport;
320
+ assertAnchorEqual(run?.status, "completed", "anchored candidate run status");
321
+ assertAnchorEqual(run?.conclusion, "success", "anchored candidate run conclusion");
322
+ assertAnchorEqual(run?.event, "workflow_dispatch", "anchored candidate run event");
323
+ assertAnchorEqual(passport?.target?.channel, "anchor", "anchored candidate channel");
324
+ assertAnchorEqual(passport?.target?.ref, "publish-gate/anchor", "anchored candidate ref");
325
+ assertAnchorEqual(run?.headSha, passport?.buildchain?.sha, "anchored candidate runtime");
326
+ assertAnchorEqual(request?.schema, 1, "anchor request schema");
327
+ assertAnchorEqual(request?.contract, "kungfu-buildchain-explicit-publish-anchor-request/v1", "anchor request contract");
328
+ assertAnchorEqual(Boolean(request?.assignmentId), true, "anchor request Assignment");
329
+ assertAnchorEqual(/^native:[0-9a-f-]+$/u.test(String(request?.attemptId || "")), true, "anchor request Attempt");
330
+ assertAnchorEqual(request?.transactionId, expectedTransactionId, "anchor request transaction");
331
+ assertAnchorEqual(String(provenanceRun?.id || ""), String(request?.supersededCandidate?.workflowRunId || ""), "superseded candidate run");
332
+ assertAnchorEqual(provenancePassport?.workflow?.runId, String(request?.supersededCandidate?.workflowRunId || ""), "superseded candidate Passport run");
333
+ assertAnchorEqual(request?.source?.sha, passport?.source?.headSha, "anchor request source SHA");
334
+ assertAnchorEqual(request?.source?.tree, passport?.source?.treeHash, "anchor request source tree");
335
+ assertAnchorEqual(request?.supersededCandidate?.sha, provenancePassport?.source?.headSha, "superseded candidate source SHA");
336
+ assertAnchorEqual(request?.supersededCandidate?.root, `sha256:${provenancePassport?.candidateHash || ""}`, "superseded candidate root");
337
+ assertAnchorEqual(request?.runtime?.sha, passport?.buildchain?.sha, "anchor request runtime");
338
+ const provenanceWorkflowPath = String(provenanceWorkflow?.path || provenanceRun?.path || "").split("@")[0].replace(/^\.github\/workflows\//, "");
339
+ assertEqual(provenanceWorkflowPath, workflowFile, "workflow-mismatch", "superseded candidate workflow file", "Use the exact trusted original candidate workflow.");
340
+ assertEqual(String(provenanceWorkflow?.name || provenanceRun?.name || ""), expectedWorkflowName, "workflow-mismatch", "superseded candidate workflow name", "Use the exact trusted original candidate workflow.");
341
+ if (provenanceWorkflow?.state && provenanceWorkflow.state !== "active") fail("untrusted-build-run", `superseded candidate workflow is not active: ${provenanceWorkflow.state}`, "Restore or select an allowed active Build workflow.");
342
+ const validation = validateReleaseCandidatePassport({ passport: provenancePassport, repository, targetChannel: normalizedRef(targetRef).split("/")[0], buildSummary: anchorProvenance.buildSummary });
343
+ if (!validation.ok) fail("anchored-provenance-invalid", `superseded candidate Passport validation failed: ${validation.errors.join("; ")}`, "Preserve both candidate runs and repair the explicit anchor provenance before retrying.");
344
+ return { provenanceRun, provenanceWorkflow, provenancePassport };
345
+ }
346
+
311
347
  function validateCandidateProvenance({
312
348
  candidateRepository,
313
349
  targetRepository,
@@ -319,26 +355,33 @@ function validateCandidateProvenance({
319
355
  workflow,
320
356
  pullRequest,
321
357
  ancestry,
358
+ passport,
359
+ anchorProvenance,
360
+ expectedTransactionId,
322
361
  }) {
323
362
  const repository = required(candidateRepository, "candidateRepository");
324
363
  assertEqual(repository, required(targetRepository, "targetRepository"), "repository-mismatch", "candidate repository", "Dispatch recovery in the repository that created the candidate.");
325
364
  assertEqual(String(run?.id || ""), required(expectedRunId, "expectedRunId"), "run-mismatch", "candidate run ID", "Select the exact successful candidate run.");
326
365
  assertEqual(run?.repository, repository, "repository-mismatch", "run repository", "Use a candidate run from the target repository.");
327
366
  assertEqual(run?.headRepository, repository, "provenance-insufficient", "run head repository", "Fork candidates are not recoverable; create a same-repository candidate.");
328
- if (run?.status !== "completed" || run?.conclusion !== "success" || run?.event !== "pull_request") {
329
- fail("untrusted-build-run", "candidate run must be a successful completed pull_request build", "Choose a successful allowed Build workflow run.");
330
- }
331
367
  const workflowFile = required(expectedWorkflowFile, "expectedWorkflowFile").replace(/^\.github\/workflows\//, "");
332
368
  const actualWorkflowPath = String(workflow?.path || run?.path || "").split("@")[0].replace(/^\.github\/workflows\//, "");
333
369
  assertEqual(actualWorkflowPath, workflowFile, "workflow-mismatch", "candidate workflow file", "Select a run from the documented trusted Build workflow.");
334
370
  assertEqual(String(workflow?.name || run?.name || ""), required(expectedWorkflowName, "expectedWorkflowName"), "workflow-mismatch", "candidate workflow name", "Select a run from the documented trusted Build workflow.");
335
371
  if (workflow?.state && workflow.state !== "active") fail("untrusted-build-run", `candidate workflow is not active: ${workflow.state}`, "Restore or select an allowed active Build workflow.");
372
+ const anchor = anchorProvenance ? validateAnchorProvenance({ run, passport, anchorProvenance, expectedTransactionId, workflowFile, expectedWorkflowName: required(expectedWorkflowName, "expectedWorkflowName"), repository, targetRef }) : undefined;
373
+ const provenanceRun = anchor?.provenanceRun || run;
374
+ if (provenanceRun?.status !== "completed" || provenanceRun?.conclusion !== "success" || provenanceRun?.event !== "pull_request") {
375
+ fail("untrusted-build-run", "candidate provenance run must be a successful completed pull_request build", "Choose a successful allowed Build workflow run.");
376
+ }
377
+ assertEqual(provenanceRun?.repository, repository, "repository-mismatch", "provenance run repository", "Use a candidate run from the target repository.");
378
+ assertEqual(provenanceRun?.headRepository, repository, "provenance-insufficient", "provenance run head repository", "Fork candidates are not recoverable; create a same-repository candidate.");
336
379
  if (!TRUSTED_ASSOCIATIONS.has(String(pullRequest?.authorAssociation || ""))) fail("permission-evidence-insufficient", "candidate PR author lacks trusted repository association evidence", "Have a repository member create or approve a same-repository candidate PR.");
337
380
  assertEqual(pullRequest?.headRepository, repository, "provenance-insufficient", "candidate PR head repository", "Fork candidates are outside the recovery permission boundary.");
338
381
  if (!pullRequest?.merged) fail("pr-identity-invalid", "candidate PR is not merged", "Use a merged channel candidate PR.");
339
382
  assertEqual(normalizedRef(pullRequest?.baseRef), normalizedRef(targetRef), "target-mismatch", "candidate PR target ref", "Use the original release channel target.");
340
- const boundByNumber = Array.isArray(run?.pullRequestNumbers) && run.pullRequestNumbers.includes(Number(pullRequest?.number));
341
- const boundByHead = run?.headSha === pullRequest?.headSha && normalizedRef(run?.headBranch) === normalizedRef(pullRequest?.headRef);
383
+ const boundByNumber = Array.isArray(provenanceRun?.pullRequestNumbers) && provenanceRun.pullRequestNumbers.includes(Number(pullRequest?.number));
384
+ const boundByHead = provenanceRun?.headSha === pullRequest?.headSha && normalizedRef(provenanceRun?.headBranch) === normalizedRef(pullRequest?.headRef);
342
385
  if (!boundByNumber && !boundByHead) fail("pr-identity-invalid", "candidate run is not bound to the merged candidate PR", "Select the exact PR-stage Build run.");
343
386
  if (!ancestry?.mergeIsAncestor && ancestry?.status !== "identical") fail("ancestry-invalid", "candidate merge is not an ancestor of the promotion SHA", "Promote a descendant of the verified merged candidate identity.");
344
387
  return { repository, workflowFile };
@@ -354,12 +397,13 @@ function validateCandidateIdentity({
354
397
  currentToolingSha,
355
398
  passport,
356
399
  buildSummary,
400
+ anchorProvenance,
357
401
  }) {
358
402
  const sha = exactSha(targetSha, "targetSha");
359
403
  const tree = exactSha(targetTree, "targetTree");
360
404
  const runtimeSha = exactSha(expectedRuntimeSha, "expectedRuntimeSha");
361
405
  const toolingSha = exactSha(currentToolingSha, "currentToolingSha");
362
- const validation = validateReleaseCandidatePassport({ passport, repository, targetChannel: channel, buildSummary });
406
+ const validation = validateReleaseCandidatePassport({ passport, repository, targetChannel: anchorProvenance ? "" : channel, buildSummary });
363
407
  if (!validation.ok) fail("passport-invalid", `Release Candidate Passport validation failed: ${validation.errors.join("; ")}`, "Preserve the candidate evidence and explicitly create a new candidate after fixing the producer.");
364
408
  const expectedPassportHash = sha256Json({
365
409
  repository: passport.repository,
@@ -369,6 +413,7 @@ function validateCandidateIdentity({
369
413
  buildchain: passport.buildchain,
370
414
  ...(passport.gateProfileEvidence ? { gateProfileEvidence: passport.gateProfileEvidence } : {}),
371
415
  ...(passport.familyEvidence ? { familyEvidence: passport.familyEvidence } : {}),
416
+ ...(passport.consumerPolicy ? { consumerPolicy: passport.consumerPolicy } : {}),
372
417
  ...(passport.controllerReceipts ? { controllerReceipts: passport.controllerReceipts } : {}),
373
418
  });
374
419
  if (passport.candidateHash !== expectedPassportHash) fail("candidate-root-mismatch", "Release Candidate Passport candidate hash does not match its content", "Preserve the run evidence and explicitly create a new candidate after fixing the producer.");
@@ -378,7 +423,7 @@ function validateCandidateIdentity({
378
423
  return { sha, tree, runtimeSha, toolingSha };
379
424
  }
380
425
 
381
- function validateRecoveryTransaction({ existingTransaction, expectedTransactionId, repository, version, passport, sha, targetRef, candidateRoot }) {
426
+ function validateRecoveryTransaction({ existingTransaction, expectedTransactionId, repository, version, passport, channel, sha, targetRef, candidateRoot }) {
382
427
  const actualTransactionId = String(existingTransaction?.id || "");
383
428
  if (expectedTransactionId && !actualTransactionId) fail("transaction-identity-conflict", `expected transaction ${expectedTransactionId} does not exist`, "Remove the stale transaction identity only if no durable transaction was ever sealed; otherwise preserve evidence and enter repair_required.");
384
429
  if (expectedTransactionId && expectedTransactionId !== actualTransactionId) fail("transaction-identity-conflict", `existing transaction ${actualTransactionId} conflicts with expected ${expectedTransactionId}`, "Enter repair_required and inspect the durable transaction before any retry.");
@@ -389,7 +434,7 @@ function validateRecoveryTransaction({ existingTransaction, expectedTransactionI
389
434
  assertEqual(normalizedRef(existingTransaction.target_ref), normalizedRef(targetRef), "transaction-identity-conflict", "durable transaction target ref", "Enter repair_required; never retarget a sealed transaction.");
390
435
  assertEqual(existingTransaction.source_sha, sha, "transaction-identity-conflict", "durable transaction source SHA", "Resume with the transaction's exact promotion SHA or enter repair_required.");
391
436
  assertEqual(existingTransaction.version, version, "transaction-identity-conflict", "durable transaction version", "Enter repair_required; never change a sealed publication version.");
392
- assertEqual(existingTransaction.channel, passport.target.channel, "transaction-identity-conflict", "durable transaction channel", "Enter repair_required; never move a transaction between channels.");
437
+ assertEqual(existingTransaction.channel, channel || passport.target.channel, "transaction-identity-conflict", "durable transaction channel", "Enter repair_required; never move a transaction between channels.");
393
438
  }
394
439
  if (existingTransaction?.candidateRoot && existingTransaction.candidateRoot !== candidateRoot) fail("transaction-identity-conflict", "existing transaction is sealed to a different candidate root", "Enter repair_required; never reuse the conflicting transaction.");
395
440
  return actualTransactionId;
@@ -415,6 +460,7 @@ export function verifyReleaseCandidateRecovery({
415
460
  workflow,
416
461
  pullRequest,
417
462
  ancestry,
463
+ anchorProvenance = undefined,
418
464
  passport,
419
465
  buildSummary,
420
466
  controllerReceipts = [],
@@ -430,10 +476,11 @@ export function verifyReleaseCandidateRecovery({
430
476
  const { repository, workflowFile } = validateCandidateProvenance({
431
477
  candidateRepository, targetRepository, expectedRunId, expectedWorkflowFile,
432
478
  expectedWorkflowName, targetRef, run, workflow, pullRequest, ancestry,
479
+ passport, anchorProvenance, expectedTransactionId,
433
480
  });
434
481
  const { sha, tree, runtimeSha, toolingSha } = validateCandidateIdentity({
435
482
  repository, channel, targetSha, targetTree, expectedSourceTree,
436
- expectedRuntimeSha, currentToolingSha, passport, buildSummary,
483
+ expectedRuntimeSha, currentToolingSha, passport, buildSummary, anchorProvenance,
437
484
  });
438
485
 
439
486
  const recoveredArtifacts = artifacts.map(normalizeArtifact).sort((left, right) => left.name.localeCompare(right.name));
@@ -478,7 +525,7 @@ export function verifyReleaseCandidateRecovery({
478
525
 
479
526
  const version = required(publicationVersion || passport.target?.version, "publicationVersion");
480
527
  const actualTransactionId = validateRecoveryTransaction({
481
- existingTransaction, expectedTransactionId, repository, version, passport, sha, targetRef, candidateRoot,
528
+ existingTransaction, expectedTransactionId, repository, version, passport, channel, sha, targetRef, candidateRoot,
482
529
  });
483
530
 
484
531
  const receipt = {
@@ -496,9 +543,17 @@ export function verifyReleaseCandidateRecovery({
496
543
  sourceSha: passport.source.headSha,
497
544
  mergeSha: String(pullRequest.mergeSha || ""),
498
545
  tree: passport.source.treeHash,
546
+ ...(anchorProvenance ? {
547
+ provenance: "anchored-rematerialization",
548
+ supersededCandidate: {
549
+ runId: String(anchorProvenance.run.id),
550
+ candidateRoot: String(anchorProvenance.request.supersededCandidate.root),
551
+ sourceSha: String(anchorProvenance.request.supersededCandidate.sha),
552
+ },
553
+ } : {}),
499
554
  },
500
555
  target: {
501
- channel: passport.target.channel,
556
+ channel,
502
557
  ref: normalizedRef(targetRef),
503
558
  sha,
504
559
  observedRefSha: exactSha(targetRefSha, "targetRefSha"),
@@ -206,7 +206,7 @@ function validateConsumerPolicyEvidence(passport, check) {
206
206
  receipt: passport.consumerPolicy.receipt,
207
207
  receiptRoot: passport.consumerPolicy.receiptRoot,
208
208
  repository: passport.repository,
209
- sourceSha: passport.source?.headSha,
209
+ sourceSha: passport.target?.ref === "publish-gate/anchor" ? passport.consumerPolicy.receipt?.caller?.sourceSha : passport.source?.headSha,
210
210
  resolvedRuntimeSha: passport.buildchain?.sha,
211
211
  });
212
212
  for (const failure of verification.failures) {
@@ -403,7 +403,7 @@ export function createReleaseCandidatePassport({
403
403
  };
404
404
  const normalizedConsumerPolicy = normalizeConsumerPolicyEvidence(consumerPolicyReceipt, {
405
405
  repository: repository || normalizedSummary.git?.repository || "",
406
- sourceSha,
406
+ sourceSha: normalizedSummary.publishSource?.ref === "publish-gate/anchor" ? (consumerPolicyReceipt?.receipt || consumerPolicyReceipt)?.caller?.sourceSha : sourceSha,
407
407
  runtimeSha: resolvedBuildchain.sha,
408
408
  });
409
409
  if (isV4BuildchainRuntime(resolvedBuildchain) && !normalizedConsumerPolicy) {
@@ -38,6 +38,7 @@ import {
38
38
  isV4PromotionRouting,
39
39
  releasePassportCertificationVerificationOptions,
40
40
  requireV4ConsumerPolicyCertification,
41
+ resolveV4ConsumerPolicyCertificationIdentity,
41
42
  } from "./v4-floating-consumer-release-passport.js";
42
43
  import {
43
44
  verifyV4RuntimeAuthorizationReceipt,
@@ -439,11 +440,17 @@ function mergeAuthoritativePassportBase(passport, basePassport = undefined, { re
439
440
  kfd3: basePassport.evidence?.kfd3 || passport.evidence?.kfd3 || "",
440
441
  },
441
442
  };
442
- for (const key of ["versionImpact", "surfaceImpacts"]) {
443
- if (basePassport[key] !== undefined) {
444
- merged[key] = basePassport[key];
445
- }
446
- }
443
+ for (const key of [
444
+ "versionImpact",
445
+ "surfaceImpacts",
446
+ "promotionRouting",
447
+ "v4ConsumerPolicy",
448
+ "v4RuntimeResume",
449
+ "transaction",
450
+ "trustedPublishing",
451
+ "distTagPromotion",
452
+ ])
453
+ if (basePassport[key] !== undefined) merged[key] = basePassport[key];
447
454
  if (basePassport.controllerReceipts !== undefined) {
448
455
  merged.controllerReceipts = basePassport.controllerReceipts;
449
456
  }
@@ -1106,17 +1113,25 @@ function normalizePromotionEvidence({
1106
1113
  release = {},
1107
1114
  v4ConsumerPolicyCertification: certification,
1108
1115
  v4ConsumerPolicyCertificationRoot: certificationRoot,
1116
+ v4RuntimeResumeEvidence,
1109
1117
  repository,
1110
1118
  sourceSha,
1111
1119
  cwd,
1112
1120
  }) {
1113
1121
  const routing = normalizePromotionRouting(release.promotionRouting);
1122
+ const identity = resolveV4ConsumerPolicyCertificationIdentity({
1123
+ release,
1124
+ routing,
1125
+ runtimeResume: v4RuntimeResumeEvidence,
1126
+ sourceSha,
1127
+ });
1114
1128
  return {
1115
1129
  routing,
1116
1130
  consumerPolicy: requireV4ConsumerPolicyCertification({
1117
1131
  value: certification,
1118
1132
  repository,
1119
- sourceSha,
1133
+ sourceSha: identity.sourceSha,
1134
+ runtimeSha: identity.runtimeSha,
1120
1135
  routing,
1121
1136
  cwd,
1122
1137
  certificationRoot,
@@ -1162,6 +1177,18 @@ function normalizeV4RuntimeResumeEvidence(value, expected = {}) {
1162
1177
  };
1163
1178
  }
1164
1179
 
1180
+ function v4RuntimeResumeSourceSha(release, fallback = "") {
1181
+ const builtSourceSha = releaseField(
1182
+ release || {},
1183
+ "builtSourceSha",
1184
+ "built_source_sha",
1185
+ );
1186
+ return release?.treeEquivalent === true && builtSourceSha
1187
+ ? builtSourceSha
1188
+ : fallback;
1189
+ }
1190
+
1191
+
1165
1192
  function prepareBuildEvidence({
1166
1193
  buildSummary,
1167
1194
  buildFacts,
@@ -1317,7 +1344,7 @@ export function createReleasePassport(options = {}) {
1317
1344
  const { promotion, buildEvidence } = preparePromotionBuild(options);
1318
1345
  const normalizedV4RuntimeResume = normalizeV4RuntimeResumeEvidence(v4RuntimeResumeEvidence, {
1319
1346
  repository,
1320
- sourceSha,
1347
+ sourceSha: v4RuntimeResumeSourceSha(release, sourceSha),
1321
1348
  resumeRuntimeSha: promotion.routing?.runtime?.resolvedSha || "",
1322
1349
  consumerPolicyReceiptRoot: promotion.consumerPolicy?.certification?.receiptRoot || "",
1323
1350
  });
@@ -2302,7 +2329,7 @@ function validateV4RuntimeResumePassportSection({ passport, issues }) {
2302
2329
  receipt: evidence.authorization,
2303
2330
  receiptRoot: evidence.authorizationRoot,
2304
2331
  repository: passport?.product?.repository || "",
2305
- sourceSha: passport?.release?.sourceSha || "",
2332
+ sourceSha: v4RuntimeResumeSourceSha(passport?.release, passport?.release?.sourceSha || ""),
2306
2333
  runtimeSha: passport?.promotionRouting?.runtime?.resolvedSha || "",
2307
2334
  consumerPolicyReceiptRoot,
2308
2335
  });
@@ -2313,7 +2340,7 @@ function validateV4RuntimeResumePassportSection({ passport, issues }) {
2313
2340
  lineage: evidence.lineage,
2314
2341
  lineageRoot: evidence.lineageRoot,
2315
2342
  repository: passport?.product?.repository || "",
2316
- sourceSha: passport?.release?.sourceSha || "",
2343
+ sourceSha: v4RuntimeResumeSourceSha(passport?.release, passport?.release?.sourceSha || ""),
2317
2344
  resumeRuntimeSha: passport?.promotionRouting?.runtime?.resolvedSha || "",
2318
2345
  consumerPolicyReceiptRoot,
2319
2346
  });
@@ -31,10 +31,10 @@ const root = path.resolve(
31
31
  );
32
32
 
33
33
  export const V4_ADOPTER_DELIVERY_PARITY_SOURCE = Object.freeze({
34
- v3Commit: "c3f58d76391c1c6ceddfc900a68e91c7ab82a575",
34
+ v3Commit: "6b96bdad8d9f8ccf9275f27d9370a226a9c78465",
35
35
  vectorSuiteRoot:
36
- "sha256:cf329805d928a9883cbafbdfdf21ef66c6a0889ed8dfe14356b4e0d25d6738f9",
37
- kfdPackage: "@kungfu-tech/kfd@1.0.0-alpha.62",
36
+ "sha256:c978707556406ffda4ef4192032332c01c2da1cebb6ad8c4f0edfc65d5cef0c7",
37
+ kfdPackage: "@kungfu-tech/kfd@1.0.0-alpha.65",
38
38
  });
39
39
 
40
40
  function clone(value) {