@kungfu-tech/buildchain 3.0.9-alpha.4 → 3.0.9-alpha.6

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 (42) hide show
  1. package/bin/buildchain.mjs +5 -1
  2. package/dist/site/buildchain-contract.json +9 -9
  3. package/dist/site/buildchain-site.json +56 -26
  4. package/dist/site/cli-registry.json +18 -2
  5. package/dist/site/kfd-claims.json +8 -5
  6. package/dist/site/kfd-upstream-aggregate.json +1 -1
  7. package/dist/site/manual-registry.json +6 -6
  8. package/dist/site/node-api-registry.json +290 -49
  9. package/dist/site/page-registry.json +46 -16
  10. package/dist/site/public-surface-audit.json +122 -6
  11. package/dist/site/publication-registry.json +4 -4
  12. package/dist/site/site-manifest.json +10 -10
  13. package/dist/site/workflow-registry.json +12 -6
  14. package/docs/cli-reference.md +79 -13
  15. package/docs/dev-delivery-warrant.md +53 -19
  16. package/docs/kfd-support.md +7 -2
  17. package/docs/node-api-reference.md +59 -51
  18. package/docs/release-governance.md +5 -4
  19. package/docs/release-passport.md +8 -2
  20. package/docs/versioning.md +1 -0
  21. package/package.json +3 -2
  22. package/packages/core/artifact-verification-envelope.js +5 -5
  23. package/packages/core/dev-delivery-native-proof.js +333 -0
  24. package/packages/core/dev-delivery-warrant-settlement.js +5 -1
  25. package/packages/core/dev-delivery-warrant.js +40 -6
  26. package/packages/core/kfd-adopter-manifest.js +46 -47
  27. package/packages/core/release-passport-contract.js +5 -5
  28. package/packages/core/release-passport.js +5 -4
  29. package/scripts/aws-macos-jit-controller-core.mjs +82 -2
  30. package/scripts/aws-macos-jit-controller.mjs +81 -1
  31. package/scripts/aws-macos-jit-source-rebind.mjs +147 -24
  32. package/scripts/buildchain-cli-help.mjs +6 -2
  33. package/scripts/check-internal-architecture.mjs +1 -0
  34. package/scripts/dev-delivery-native-run.mjs +187 -0
  35. package/scripts/dev-delivery-proof.mjs +54 -2
  36. package/scripts/dev-delivery-two-phase.mjs +598 -0
  37. package/scripts/dev-delivery-warrant.mjs +38 -3
  38. package/scripts/dev-pr-delivery-warrant.mjs +6 -1
  39. package/scripts/generate-channel-build-workflow.mjs +4 -0
  40. package/scripts/init-repo.mjs +16 -0
  41. package/scripts/release-candidate-tail-reseal.mjs +426 -0
  42. package/templates/native-dev-delivery.yml +82 -0
@@ -34,6 +34,11 @@ function exactActiveReadback(result) {
34
34
  const warrant = result.observation.activeWarrant;
35
35
  const candidate = result.observation.activeCandidate;
36
36
  requireMatch(warrant?.schema === "kungfu.buildchain.dev-delivery-warrant/v1", "delivery-warrant-missing");
37
+ requireMatch((warrant.phase || "qualified") === "qualified", "delivery-warrant-not-qualified");
38
+ if (warrant.phase === "qualified") {
39
+ requireMatch(ROOT_PATTERN.test(String(warrant.nativeProofRoot || "")), "delivery-warrant-native-proof-missing");
40
+ requireMatch(ROOT_PATTERN.test(String(warrant.nativeProofReuseRoot || "")), "delivery-warrant-native-reuse-missing");
41
+ }
37
42
  requireMatch(candidate?.candidateId === warrant.candidateId, "delivery-warrant-candidate-readback-missing");
38
43
  requireMatch(!result.warrant || JSON.stringify(result.warrant) === JSON.stringify(warrant), "delivery-warrant-readback-mismatch");
39
44
  return { warrant, candidate };
@@ -147,7 +152,7 @@ export async function verifyCurrentDeliveryWarrant(client, options, pullRequest,
147
152
  requireMatch(Number(active?.generation) === Number(warrant.generation), "delivery-warrant-current-generation-mismatch");
148
153
  requireMatch(Number(active?.pullRequestNumber) === Number(pullRequest.number), "delivery-warrant-current-pr-mismatch");
149
154
  requireMatch(String(active?.sourceHead || "").toLowerCase() === options.expectedHeadSha, "delivery-warrant-current-head-mismatch");
150
- requireMatch(["selected", "proving", "waiting", "blocked"].includes(candidate?.status), "delivery-warrant-current-candidate-not-selected");
155
+ requireMatch(["selected", "proving", "waiting", "blocked", "qualified"].includes(candidate?.status), "delivery-warrant-current-candidate-not-selected");
151
156
  requireMatch(candidate?.sourceHead === active.sourceHead, "delivery-warrant-current-candidate-head-mismatch");
152
157
  }
153
158
 
@@ -46,6 +46,10 @@ function routerInputs(inputBlock) {
46
46
 
47
47
  function routerOutputs(outputBlock) {
48
48
  const forwarded = outputBlock
49
+ .replace(
50
+ /^ value: \$\{\{ jobs\.[^.]+\.outputs\.([a-z0-9-]+) \|\| jobs\.[^.]+\.outputs\.\1 \}\}$/gm,
51
+ " value: ${{ jobs.alpha.outputs.$1 || jobs.stable.outputs.$1 }}",
52
+ )
49
53
  .replace(/^ value: \$\{\{ jobs\.[^.]+\.outputs\.([^ }]+) \}\}$/gm, " value: ${{ jobs.alpha.outputs.$1 || jobs.stable.outputs.$1 }}")
50
54
  .replaceAll("build-lifecycle", "build-channel-router")
51
55
  .replace("value: ${{ jobs.alpha.outputs.controller-plan-artifact || jobs.stable.outputs.controller-plan-artifact }}", "value: ${{ jobs.controller-plan.outputs.controller-plan-artifact }}")
@@ -420,6 +420,12 @@ jobs:
420
420
  `;
421
421
  }
422
422
 
423
+ function devDeliveryWorkflowYaml() {
424
+ return fs.readFileSync(
425
+ new URL("../templates/native-dev-delivery.yml", import.meta.url),
426
+ "utf8",
427
+ );
428
+ }
423
429
  function writeIfAllowed(filePath, content, { force }) {
424
430
  if (fs.existsSync(filePath) && !force) {
425
431
  throw new Error(
@@ -506,6 +512,16 @@ export function initBuildchainRepo({
506
512
  writeManagedAgentEntry(agentsPath, currentAgents),
507
513
  ];
508
514
 
515
+ if (type === "native") {
516
+ written.push(
517
+ writeIfAllowed(
518
+ path.join(resolvedCwd, ".github", "workflows", "dev-delivery.yml"),
519
+ devDeliveryWorkflowYaml(),
520
+ { force },
521
+ ),
522
+ );
523
+ }
524
+
509
525
  if (
510
526
  type === "anchored-package" &&
511
527
  !fs.existsSync(path.join(resolvedCwd, "release.json"))
@@ -0,0 +1,426 @@
1
+ #!/usr/bin/env node
2
+ import crypto from "node:crypto";
3
+ import fs from "node:fs";
4
+ import path from "node:path";
5
+ import { pathToFileURL } from "node:url";
6
+
7
+ const CONTRACT = "kungfu-buildchain-release-candidate-tail-reseal/v1";
8
+ const SHA = /^[0-9a-f]{40}$/u;
9
+ const ROOT = /^sha256:[0-9a-f]{64}$/u;
10
+ const REQUIRED_PLATFORMS = ["linux-arm64", "linux-x64", "macos-arm64", "windows-x64"];
11
+ const REQUIRED_SUCCESS_JOBS = [
12
+ "build / Linux ARM64",
13
+ "build / Linux x64",
14
+ "build / macOS ARM64",
15
+ "build / Windows x64",
16
+ "build / Control detached signing Linux ARM64",
17
+ "build / Control detached signing Linux x64",
18
+ "build / Control detached signing macOS ARM64",
19
+ "build / Control detached signing Windows x64",
20
+ "build / Finalize signed artifact Linux ARM64",
21
+ "build / Finalize signed artifact Linux x64",
22
+ "build / Finalize signed artifact Windows x64",
23
+ ];
24
+
25
+ function required(value, label) {
26
+ const result = String(value ?? "").trim();
27
+ if (!result) throw new Error(`${label} is required`);
28
+ return result;
29
+ }
30
+
31
+ function exactSha(value, label) {
32
+ const result = required(value, label);
33
+ if (!SHA.test(result)) throw new Error(`${label} must be an exact lowercase Git SHA`);
34
+ return result;
35
+ }
36
+
37
+ function contentRoot(value, label) {
38
+ const result = required(value, label);
39
+ if (!ROOT.test(result)) throw new Error(`${label} must be a sha256 content root`);
40
+ return result;
41
+ }
42
+
43
+ function integer(value, label) {
44
+ const result = Number(value);
45
+ if (!Number.isSafeInteger(result) || result <= 0) throw new Error(`${label} must be a positive integer`);
46
+ return result;
47
+ }
48
+
49
+ function object(value, label) {
50
+ if (!value || typeof value !== "object" || Array.isArray(value)) throw new Error(`${label} must be an object`);
51
+ return value;
52
+ }
53
+
54
+ function readJson(file, label = file) {
55
+ try {
56
+ return JSON.parse(fs.readFileSync(file, "utf8"));
57
+ } catch (error) {
58
+ throw new Error(`could not read ${label}: ${error.message}`);
59
+ }
60
+ }
61
+
62
+ function writeJson(file, value) {
63
+ fs.mkdirSync(path.dirname(file), { recursive: true });
64
+ fs.writeFileSync(file, `${JSON.stringify(value, null, 2)}\n`);
65
+ }
66
+
67
+ function sha256Json(value) {
68
+ return `sha256:${crypto.createHash("sha256").update(JSON.stringify(value)).digest("hex")}`;
69
+ }
70
+
71
+ function sha256File(file) {
72
+ const hash = crypto.createHash("sha256");
73
+ const descriptor = fs.openSync(file, "r");
74
+ const buffer = Buffer.allocUnsafe(1024 * 1024);
75
+ try {
76
+ for (;;) {
77
+ const count = fs.readSync(descriptor, buffer, 0, buffer.length, null);
78
+ if (count === 0) break;
79
+ hash.update(buffer.subarray(0, count));
80
+ }
81
+ } finally {
82
+ fs.closeSync(descriptor);
83
+ }
84
+ return `sha256:${hash.digest("hex")}`;
85
+ }
86
+
87
+ function appendOutputs(values) {
88
+ const output = process.env.GITHUB_OUTPUT;
89
+ if (!output) return;
90
+ const lines = [];
91
+ for (const [name, value] of Object.entries(values)) {
92
+ const text = String(value ?? "");
93
+ if (text.includes("\n")) {
94
+ const marker = `BUILDCHAIN_${crypto.randomBytes(8).toString("hex")}`;
95
+ lines.push(`${name}<<${marker}\n${text}\n${marker}`);
96
+ } else {
97
+ lines.push(`${name}=${text}`);
98
+ }
99
+ }
100
+ fs.appendFileSync(output, `${lines.join("\n")}\n`);
101
+ }
102
+
103
+ async function githubJson(repository, apiPath, token) {
104
+ const response = await fetch(`https://api.github.com/repos/${repository}${apiPath}`, {
105
+ headers: {
106
+ accept: "application/vnd.github+json",
107
+ authorization: `Bearer ${required(token, "GITHUB_TOKEN")}`,
108
+ "x-github-api-version": "2022-11-28",
109
+ },
110
+ });
111
+ if (!response.ok) throw new Error(`GitHub API ${apiPath} failed: HTTP ${response.status}`);
112
+ return response.json();
113
+ }
114
+
115
+ async function pagedGithubItems(repository, apiPath, key, token) {
116
+ const values = [];
117
+ for (let page = 1; ; page += 1) {
118
+ const separator = apiPath.includes("?") ? "&" : "?";
119
+ const response = await githubJson(repository, `${apiPath}${separator}per_page=100&page=${page}`, token);
120
+ const items = Array.isArray(response?.[key]) ? response[key] : [];
121
+ values.push(...items);
122
+ if (items.length < 100) return values;
123
+ }
124
+ }
125
+
126
+ export function normalizeTailResealRequest(raw) {
127
+ const request = object(raw, "tail reseal request");
128
+ if (request.contract !== CONTRACT) throw new Error(`tail reseal contract must be ${CONTRACT}`);
129
+ const source = object(request.source, "source");
130
+ const target = object(request.target, "target");
131
+ const candidateRuntime = object(request.candidateRuntime, "candidateRuntime");
132
+ const controller = object(request.consumerController, "consumerController");
133
+ const failure = object(request.failure, "failure");
134
+ const authority = object(request.authority, "authority");
135
+ const platforms = Array.isArray(request.platforms) ? request.platforms : [];
136
+ if (platforms.length !== REQUIRED_PLATFORMS.length) throw new Error("tail reseal requires exactly four platform bindings");
137
+ const normalizedPlatforms = platforms.map((entry, index) => {
138
+ const platform = object(entry, `platforms[${index}]`);
139
+ return {
140
+ id: required(platform.id, `platforms[${index}].id`),
141
+ name: required(platform.name, `platforms[${index}].name`),
142
+ runner: required(platform.runner, `platforms[${index}].runner`),
143
+ artifactName: required(platform.artifactName, `platforms[${index}].artifactName`),
144
+ artifactDigest: contentRoot(platform.artifactDigest, `platforms[${index}].artifactDigest`),
145
+ manifestArtifactName: required(platform.manifestArtifactName, `platforms[${index}].manifestArtifactName`),
146
+ manifestArtifactDigest: contentRoot(platform.manifestArtifactDigest, `platforms[${index}].manifestArtifactDigest`),
147
+ artifactPaths: required(platform.artifactPaths, `platforms[${index}].artifactPaths`),
148
+ };
149
+ }).sort((left, right) => left.id.localeCompare(right.id));
150
+ if (JSON.stringify(normalizedPlatforms.map(({ id }) => id)) !== JSON.stringify([...REQUIRED_PLATFORMS].sort())) {
151
+ throw new Error(`tail reseal platforms must be ${REQUIRED_PLATFORMS.join(", ")}`);
152
+ }
153
+ if (new Set(normalizedPlatforms.flatMap((entry) => [entry.artifactName, entry.manifestArtifactName])).size !== 8) {
154
+ throw new Error("tail reseal artifact names must be unique");
155
+ }
156
+ return {
157
+ contract: CONTRACT,
158
+ repository: required(request.repository, "repository"),
159
+ source: {
160
+ runId: integer(source.runId, "source.runId"),
161
+ runAttempt: integer(source.runAttempt, "source.runAttempt"),
162
+ sha: exactSha(source.sha, "source.sha"),
163
+ tree: exactSha(source.tree, "source.tree"),
164
+ workflowFile: required(source.workflowFile, "source.workflowFile").replace(/^\.github\/workflows\//u, ""),
165
+ workflowName: required(source.workflowName, "source.workflowName"),
166
+ },
167
+ target: {
168
+ channel: required(target.channel, "target.channel"),
169
+ ref: required(target.ref, "target.ref").replace(/^refs\/heads\//u, ""),
170
+ baseSha: exactSha(target.baseSha, "target.baseSha"),
171
+ version: required(target.version, "target.version"),
172
+ },
173
+ candidateRuntime: {
174
+ repository: required(candidateRuntime.repository, "candidateRuntime.repository"),
175
+ ref: required(candidateRuntime.ref, "candidateRuntime.ref"),
176
+ sha: exactSha(candidateRuntime.sha, "candidateRuntime.sha"),
177
+ contractDigest: contentRoot(candidateRuntime.contractDigest, "candidateRuntime.contractDigest"),
178
+ },
179
+ consumerController: {
180
+ repository: required(controller.repository, "consumerController.repository"),
181
+ sha: exactSha(controller.sha, "consumerController.sha"),
182
+ tree: exactSha(controller.tree, "consumerController.tree"),
183
+ },
184
+ failure: {
185
+ jobId: integer(failure.jobId, "failure.jobId"),
186
+ jobName: required(failure.jobName, "failure.jobName"),
187
+ stepName: required(failure.stepName, "failure.stepName"),
188
+ },
189
+ authority: {
190
+ repository: required(authority.repository, "authority.repository"),
191
+ runId: integer(authority.runId, "authority.runId"),
192
+ runtimeSha: exactSha(authority.runtimeSha, "authority.runtimeSha"),
193
+ resultArtifact: required(authority.resultArtifact, "authority.resultArtifact"),
194
+ resultArtifactDigest: contentRoot(authority.resultArtifactDigest, "authority.resultArtifactDigest"),
195
+ },
196
+ controllerPlanArtifact: required(request.controllerPlanArtifact, "controllerPlanArtifact"),
197
+ platforms: normalizedPlatforms,
198
+ };
199
+ }
200
+
201
+ function exactArtifact(artifacts, name, digest, label) {
202
+ const matches = artifacts.filter((artifact) => artifact.name === name);
203
+ if (matches.length !== 1) throw new Error(`${label} must resolve to exactly one retained artifact`);
204
+ const artifact = matches[0];
205
+ if (artifact.expired === true) throw new Error(`${label} is expired`);
206
+ if (artifact.digest !== digest) throw new Error(`${label} digest mismatch`);
207
+ return artifact;
208
+ }
209
+
210
+ function validateTailResealEvent({ request, event, repository }) {
211
+ const allowedActions = new Set(["opened", "synchronize", "reopened", "ready_for_review"]);
212
+ if (request.repository !== repository) throw new Error("tail reseal repository differs from the caller repository");
213
+ if (!allowedActions.has(event.action)) {
214
+ throw new Error(`tail reseal requires a pull_request source event, got ${event.action || "<none>"}`);
215
+ }
216
+ if (event.pull_request?.head?.repo?.full_name !== repository) throw new Error("tail reseal rejects fork pull requests");
217
+ if (event.pull_request?.head?.sha !== request.source.sha) throw new Error("tail reseal source SHA differs from the exact PR head");
218
+ if (event.pull_request?.base?.ref !== request.target.ref || event.pull_request?.base?.sha !== request.target.baseSha) {
219
+ throw new Error("tail reseal target ref or frozen base SHA differs from the exact PR event");
220
+ }
221
+ if (request.target.channel !== "alpha" || !/^alpha\/v\d+\/v\d+\.\d+$/u.test(request.target.ref)) {
222
+ throw new Error("tail reseal is limited to an exact Alpha channel");
223
+ }
224
+ if (request.candidateRuntime.repository !== "kungfu-systems/buildchain" || request.candidateRuntime.ref !== "v3-alpha") {
225
+ throw new Error("tail reseal requires the deployed floating v3-alpha candidate contract");
226
+ }
227
+ if (request.consumerController.repository !== repository) throw new Error("tail reseal consumer controller must remain in the caller repository");
228
+ }
229
+
230
+ function validateTailResealRun({ request, run }) {
231
+ const workflowFile = String(run.path || "").split("@")[0].replace(/^\.github\/workflows\//u, "");
232
+ const exactRun =
233
+ Number(run.id) === request.source.runId &&
234
+ Number(run.run_attempt) === request.source.runAttempt &&
235
+ run.event === "workflow_dispatch" &&
236
+ run.status === "completed" &&
237
+ run.conclusion === "failure" &&
238
+ run.head_sha === request.source.sha &&
239
+ workflowFile === request.source.workflowFile &&
240
+ run.name === request.source.workflowName;
241
+ if (!exactRun) throw new Error("tail reseal source run is not the exact retained failed Build run");
242
+ }
243
+
244
+ function validateTailResealJobs({ request, jobs }) {
245
+ const byName = new Map(jobs.map((job) => [job.name, job]));
246
+ for (const name of REQUIRED_SUCCESS_JOBS) {
247
+ if (byName.get(name)?.conclusion !== "success") throw new Error(`tail reseal required source job did not succeed: ${name}`);
248
+ }
249
+ const failedJob = jobs.find((job) => Number(job.id) === request.failure.jobId);
250
+ const failedSteps = (failedJob?.steps || []).filter((step) => step.conclusion === "failure").map((step) => step.name);
251
+ const exactFailure =
252
+ failedJob?.name === request.failure.jobName &&
253
+ failedJob?.conclusion === "failure" &&
254
+ JSON.stringify(failedSteps) === JSON.stringify([request.failure.stepName]);
255
+ if (!exactFailure) throw new Error("tail reseal failure boundary differs from the single allowed macOS finalization step");
256
+ if (request.failure.jobName !== "build / Finalize signed artifact macOS ARM64" || request.failure.stepName !== "Recompute manifest over final signed bytes") {
257
+ throw new Error("tail reseal only accepts the known macOS finalization blocker");
258
+ }
259
+ }
260
+
261
+ function validateTailResealArtifacts({ request, artifacts, authorityRun, authorityArtifacts }) {
262
+ for (const platform of request.platforms) {
263
+ exactArtifact(artifacts, platform.artifactName, platform.artifactDigest, `${platform.id} payload`);
264
+ exactArtifact(artifacts, platform.manifestArtifactName, platform.manifestArtifactDigest, `${platform.id} manifest`);
265
+ }
266
+ const controllerPlan = artifacts.filter((artifact) => artifact.name === request.controllerPlanArtifact);
267
+ if (controllerPlan.length !== 1 || controllerPlan[0].expired === true) throw new Error("tail reseal controller plan artifact is unavailable");
268
+ if (authorityRun.status !== "completed" || authorityRun.conclusion !== "success") throw new Error("tail reseal signing authority run is not successful");
269
+ exactArtifact(authorityArtifacts, request.authority.resultArtifact, request.authority.resultArtifactDigest, "macOS signing authority result");
270
+ }
271
+
272
+ function writeTailResealPlan(request) {
273
+ const output = path.resolve(process.env.BUILDCHAIN_TAIL_RESEAL_REQUEST_PATH || ".buildchain/tail-reseal/request.json");
274
+ writeJson(output, request);
275
+ appendOutputs({
276
+ enabled: "true",
277
+ "request-path": path.relative(process.cwd(), output),
278
+ "request-root": sha256Json(request),
279
+ "platforms-json": JSON.stringify(request.platforms),
280
+ "source-run-id": request.source.runId,
281
+ "source-run-attempt": request.source.runAttempt,
282
+ "source-sha": request.source.sha,
283
+ "source-tree": request.source.tree,
284
+ "target-channel": request.target.channel,
285
+ "target-ref": request.target.ref,
286
+ "target-version": request.target.version,
287
+ "candidate-runtime-ref": request.candidateRuntime.ref,
288
+ "candidate-runtime-sha": request.candidateRuntime.sha,
289
+ "candidate-runtime-contract-digest": request.candidateRuntime.contractDigest,
290
+ "consumer-controller-sha": request.consumerController.sha,
291
+ "authority-run-id": request.authority.runId,
292
+ "authority-result-artifact": request.authority.resultArtifact,
293
+ "controller-plan-artifact": request.controllerPlanArtifact,
294
+ });
295
+ }
296
+
297
+ async function plan() {
298
+ const token = required(process.env.GITHUB_TOKEN, "GITHUB_TOKEN");
299
+ const raw = required(process.env.BUILDCHAIN_TAIL_RESEAL_REQUEST_JSON, "BUILDCHAIN_TAIL_RESEAL_REQUEST_JSON");
300
+ const request = normalizeTailResealRequest(JSON.parse(raw));
301
+ const event = readJson(required(process.env.GITHUB_EVENT_PATH, "GITHUB_EVENT_PATH"), "GitHub event");
302
+ const repository = required(process.env.GITHUB_REPOSITORY, "GITHUB_REPOSITORY");
303
+ validateTailResealEvent({ request, event, repository });
304
+
305
+ const [sourceCommit, controllerCommit, run, jobs, artifacts, authorityRun, authorityArtifacts] = await Promise.all([
306
+ githubJson(repository, `/git/commits/${request.source.sha}`, token),
307
+ githubJson(repository, `/git/commits/${request.consumerController.sha}`, token),
308
+ githubJson(repository, `/actions/runs/${request.source.runId}`, token),
309
+ pagedGithubItems(repository, `/actions/runs/${request.source.runId}/jobs?filter=latest`, "jobs", token),
310
+ pagedGithubItems(repository, `/actions/runs/${request.source.runId}/artifacts`, "artifacts", token),
311
+ githubJson(request.authority.repository, `/actions/runs/${request.authority.runId}`, token),
312
+ pagedGithubItems(request.authority.repository, `/actions/runs/${request.authority.runId}/artifacts`, "artifacts", token),
313
+ ]);
314
+ if (sourceCommit.tree?.sha !== request.source.tree) throw new Error("tail reseal source tree mismatch");
315
+ if (controllerCommit.tree?.sha !== request.consumerController.tree) throw new Error("tail reseal consumer controller tree mismatch");
316
+ validateTailResealRun({ request, run });
317
+ validateTailResealJobs({ request, jobs });
318
+ validateTailResealArtifacts({ request, artifacts, authorityRun, authorityArtifacts });
319
+ writeTailResealPlan(request);
320
+ return request;
321
+ }
322
+
323
+ function locateManifest(root, platformId) {
324
+ const matches = [];
325
+ const visit = (directory) => {
326
+ for (const entry of fs.readdirSync(directory, { withFileTypes: true })) {
327
+ const absolute = path.join(directory, entry.name);
328
+ if (entry.isDirectory()) visit(absolute);
329
+ else if (entry.name === "manifest.json") {
330
+ const value = readJson(absolute);
331
+ if (value?.contract === "kungfu-buildchain-artifact" && value?.platform?.id === platformId) matches.push({ absolute, value });
332
+ }
333
+ }
334
+ };
335
+ visit(root);
336
+ if (matches.length !== 1) throw new Error(`expected exactly one ${platformId} platform manifest under ${root}, found ${matches.length}`);
337
+ return matches[0];
338
+ }
339
+
340
+ export function verifyTailResealPlatform() {
341
+ const request = normalizeTailResealRequest(readJson(required(process.env.BUILDCHAIN_TAIL_RESEAL_REQUEST_PATH, "BUILDCHAIN_TAIL_RESEAL_REQUEST_PATH")));
342
+ const platformId = required(process.env.BUILDCHAIN_TAIL_RESEAL_PLATFORM_ID, "BUILDCHAIN_TAIL_RESEAL_PLATFORM_ID");
343
+ const platform = request.platforms.find((entry) => entry.id === platformId);
344
+ if (!platform) throw new Error(`tail reseal request does not bind platform ${platformId}`);
345
+ const root = path.resolve(process.env.BUILDCHAIN_TAIL_RESEAL_ARTIFACT_ROOT || ".");
346
+ const { absolute, value: manifest } = locateManifest(root, platformId);
347
+ if (manifest.artifactName !== platform.artifactName) throw new Error(`${platformId} manifest artifact name mismatch`);
348
+ if (manifest.git?.repository !== request.repository || manifest.git?.sha !== request.source.sha) throw new Error(`${platformId} manifest source mismatch`);
349
+ if (String(manifest.git?.runId || "") !== String(request.source.runId) || String(manifest.git?.runAttempt || "") !== String(request.source.runAttempt)) {
350
+ throw new Error(`${platformId} manifest original run mismatch`);
351
+ }
352
+ const files = Array.isArray(manifest.files) ? manifest.files : [];
353
+ if (files.length === 0) throw new Error(`${platformId} manifest has no files`);
354
+ for (const file of files) {
355
+ const relative = required(file.path || file.name, `${platformId} manifest file path`);
356
+ const absoluteFile = path.resolve(root, relative);
357
+ if (!absoluteFile.startsWith(`${root}${path.sep}`) || !fs.existsSync(absoluteFile) || !fs.statSync(absoluteFile).isFile()) {
358
+ throw new Error(`${platformId} manifest file is missing: ${relative}`);
359
+ }
360
+ if (Number(file.size ?? file.bytes) !== fs.statSync(absoluteFile).size) throw new Error(`${platformId} manifest file size mismatch: ${relative}`);
361
+ const expected = contentRoot(`sha256:${String(file.sha256 || "").replace(/^sha256:/u, "")}`, `${platformId} ${relative} digest`);
362
+ if (sha256File(absoluteFile) !== expected) throw new Error(`${platformId} manifest file digest mismatch: ${relative}`);
363
+ }
364
+ appendOutputs({ "manifest-path": path.relative(process.cwd(), absolute), "manifest-root": sha256File(absolute) });
365
+ return manifest;
366
+ }
367
+
368
+ export function sealTailResealReceipt() {
369
+ const request = normalizeTailResealRequest(readJson(required(process.env.BUILDCHAIN_TAIL_RESEAL_REQUEST_PATH, "BUILDCHAIN_TAIL_RESEAL_REQUEST_PATH")));
370
+ const manifestsRoot = path.resolve(required(process.env.BUILDCHAIN_TAIL_RESEAL_MANIFESTS_ROOT, "BUILDCHAIN_TAIL_RESEAL_MANIFESTS_ROOT"));
371
+ const manifests = request.platforms.map((platform) => {
372
+ const { absolute, value } = locateManifest(manifestsRoot, platform.id);
373
+ if (value.artifactName !== platform.artifactName || value.git?.sha !== request.source.sha) throw new Error(`${platform.id} resealed manifest identity mismatch`);
374
+ return { platformId: platform.id, artifactName: platform.artifactName, manifestRoot: sha256File(absolute) };
375
+ });
376
+ const receipt = {
377
+ contract: CONTRACT,
378
+ action: "reused-tail-reseal",
379
+ repository: request.repository,
380
+ source: request.source,
381
+ target: request.target,
382
+ candidateRuntime: request.candidateRuntime,
383
+ recoveryTooling: {
384
+ ref: required(process.env.BUILDCHAIN_TAIL_RESEAL_TOOLING_REF, "BUILDCHAIN_TAIL_RESEAL_TOOLING_REF"),
385
+ sha: exactSha(process.env.BUILDCHAIN_TAIL_RESEAL_TOOLING_SHA, "BUILDCHAIN_TAIL_RESEAL_TOOLING_SHA"),
386
+ },
387
+ consumerController: request.consumerController,
388
+ originalFailure: request.failure,
389
+ signingAuthority: request.authority,
390
+ artifacts: request.platforms.map(({ id, artifactName, artifactDigest, manifestArtifactName, manifestArtifactDigest }) => ({
391
+ platformId: id,
392
+ artifactName,
393
+ originalArtifactDigest: artifactDigest,
394
+ manifestArtifactName,
395
+ originalManifestArtifactDigest: manifestArtifactDigest,
396
+ })),
397
+ resealedManifests: manifests,
398
+ skippedStages: ["install", "build", "verify", "platform-matrix"],
399
+ rerunStages: ["macos-signing-finalization", "aggregate", "candidate-passport"],
400
+ payloadPolicy: "reuse-exact-platform-bytes-except-authoritative-macos-signing-import",
401
+ currentRun: {
402
+ id: required(process.env.GITHUB_RUN_ID, "GITHUB_RUN_ID"),
403
+ attempt: required(process.env.GITHUB_RUN_ATTEMPT, "GITHUB_RUN_ATTEMPT"),
404
+ },
405
+ };
406
+ receipt.root = sha256Json(receipt);
407
+ const output = path.resolve(process.env.BUILDCHAIN_TAIL_RESEAL_RECEIPT_PATH || ".buildchain/tail-reseal/receipt.json");
408
+ writeJson(output, receipt);
409
+ appendOutputs({ "receipt-path": path.relative(process.cwd(), output), "receipt-root": receipt.root, "receipt-json": JSON.stringify(receipt) });
410
+ return receipt;
411
+ }
412
+
413
+ export async function releaseCandidateTailResealCli(argv = process.argv.slice(2)) {
414
+ const command = argv[0];
415
+ if (command === "plan") return plan();
416
+ if (command === "verify-platform") return verifyTailResealPlatform();
417
+ if (command === "seal") return sealTailResealReceipt();
418
+ throw new Error("usage: release-candidate-tail-reseal.mjs <plan|verify-platform|seal>");
419
+ }
420
+
421
+ if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
422
+ releaseCandidateTailResealCli().catch((error) => {
423
+ console.error(`::error::${String(error.message || error).replace(/\r?\n/gu, "%0A")}`);
424
+ process.exitCode = 1;
425
+ });
426
+ }
@@ -0,0 +1,82 @@
1
+ name: Protected Dev Delivery
2
+
3
+ on:
4
+ repository_dispatch:
5
+ types: [buildchain-dev-delivery-wake]
6
+ workflow_dispatch:
7
+ inputs:
8
+ target-branch:
9
+ description: "Protected dev/vN/vN.M branch"
10
+ required: true
11
+ expected-pr-number:
12
+ description: "Exact ready and approved PR number"
13
+ required: true
14
+ type: number
15
+ expected-head-sha:
16
+ description: "Exact immutable PR head"
17
+ required: true
18
+ source-identity-root:
19
+ description: "Semantic source identity root"
20
+ required: true
21
+ source-patch-root:
22
+ description: "Semantic patch root"
23
+ required: true
24
+ assignment-root:
25
+ description: "Native Assignment root"
26
+ required: true
27
+ initiative-root:
28
+ description: "Parent Initiative root"
29
+ required: true
30
+ plan-root:
31
+ description: "Native qualification plan root"
32
+ required: true
33
+ closure-root:
34
+ description: "Affected closure root"
35
+ required: true
36
+ dependency-root:
37
+ description: "Dependency graph root"
38
+ required: true
39
+ toolchain-root:
40
+ description: "Native toolchain root"
41
+ required: true
42
+ affected-paths-json:
43
+ description: "JSON array representing the affected closure"
44
+ required: true
45
+ native-proof-json:
46
+ description: "Optional reusable native proof"
47
+ required: false
48
+ default: ""
49
+
50
+ permissions:
51
+ actions: write
52
+ contents: write
53
+ pull-requests: write
54
+ checks: read
55
+ statuses: write
56
+
57
+ jobs:
58
+ deliver:
59
+ uses: kungfu-systems/buildchain/.github/workflows/dev-pr-auto-merge.yml@v3
60
+ with:
61
+ target-branch: ${{ github.event.client_payload.targetBranch || inputs.target-branch }}
62
+ expected-pr-number: ${{ github.event.client_payload.pullRequestNumber || inputs.expected-pr-number }}
63
+ expected-head-sha: ${{ github.event.client_payload.sourceHead || inputs.expected-head-sha }}
64
+ source-workflow-run-id: ${{ github.event.client_payload.sourceWorkflowRunId || github.run_id }}
65
+ delivery-warrant-mode: required
66
+ assignment-root: ${{ github.event.client_payload.assignmentRoot || inputs.assignment-root }}
67
+ initiative-root: ${{ github.event.client_payload.initiativeRoot || inputs.initiative-root }}
68
+ source-identity-root: ${{ github.event.client_payload.sourceIdentityRoot || inputs.source-identity-root }}
69
+ source-patch-root: ${{ github.event.client_payload.sourcePatchRoot || inputs.source-patch-root }}
70
+ plan-root: ${{ github.event.client_payload.planRoot || inputs.plan-root }}
71
+ closure-root: ${{ github.event.client_payload.closureRoot || inputs.closure-root }}
72
+ dependency-root: ${{ github.event.client_payload.dependencyRoot || inputs.dependency-root }}
73
+ toolchain-root: ${{ github.event.client_payload.toolchainRoot || inputs.toolchain-root }}
74
+ affected-paths-json: ${{ github.event_name == 'repository_dispatch' && toJSON(github.event.client_payload.affectedPaths) || inputs.affected-paths-json }}
75
+ native-proof-json: ${{ inputs.native-proof-json || '' }}
76
+ native-command: cmake -S . -B build && cmake --build build --parallel && ctest --test-dir build --output-on-failure
77
+ native-heartbeat-seconds: 300
78
+ delivery-class: native-proof-required
79
+ landing-mode: queue
80
+ dry-run: false
81
+ secrets:
82
+ github-token: ${{ secrets.BUILDCHAIN_PROMOTION_TOKEN }}