@kungfu-tech/buildchain 4.0.2-alpha.0 → 4.0.2-alpha.11

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 (82) hide show
  1. package/architecture/agent-change-map.md +52 -5
  2. package/architecture/ci-lane-change-budget.json +408 -8
  3. package/architecture/internal-capabilities.json +44 -1
  4. package/architecture/maintainability-debt.json +65 -133
  5. package/architecture/maintainability-policy.json +20 -15
  6. package/architecture/release-tail-contract-inventory.json +4 -4
  7. package/architecture/v3-core-mechanism-inventory.json +1 -0
  8. package/architecture/v3-v4-live-capability-inventory.json +17 -17
  9. package/architecture/v4-delivery-warrant-shadow-fixtures.json +5 -5
  10. package/architecture/v4-release-invocation-fixtures.json +139 -0
  11. package/architecture/v4-release-topology.json +317 -0
  12. package/architecture/v4-runtime-semantic-closure.json +4 -1
  13. package/architecture/v4-universal-workflow-bootstrap.json +181 -0
  14. package/architecture/v4-universal-workflow-fault-campaign.json +72 -0
  15. package/architecture/v4-universal-workflow-train-admission.json +40 -0
  16. package/contracts/buildchain-v2-residuals-v1.json +0 -9
  17. package/contracts/fixtures/v4-tail-reseal-v1/valid.json +1 -1
  18. package/contracts/v4-release-invocation-v1.schema.json +134 -0
  19. package/dist/site/buildchain-contract.json +87 -42
  20. package/dist/site/buildchain-site.json +15 -10
  21. package/dist/site/capability-registry.json +1 -1
  22. package/dist/site/controller-registry.json +46 -10
  23. package/dist/site/kfd-claims.json +176 -69
  24. package/dist/site/kfd-upstream-aggregate.json +1 -1
  25. package/dist/site/manual-registry.json +2 -2
  26. package/dist/site/node-api-registry.json +97 -22
  27. package/dist/site/page-registry.json +9 -4
  28. package/dist/site/public-surface-audit.json +190 -71
  29. package/dist/site/publication-authority-registry.json +68 -3
  30. package/dist/site/publication-registry.json +4 -4
  31. package/dist/site/site-manifest.json +6 -6
  32. package/dist/site/workflow-registry.json +221 -72
  33. package/docs/node-api-reference.md +28 -25
  34. package/docs/reusable-build-surface.md +16 -0
  35. package/package.json +2 -2
  36. package/packages/core/buildchain-publication-authority.js +3 -0
  37. package/packages/core/ci-lane-change-budget.js +14 -1
  38. package/packages/core/dev-delivery-candidate-identity.js +45 -17
  39. package/packages/core/dev-delivery-execution-transfer.js +6 -7
  40. package/packages/core/dev-delivery-provider-heartbeat.js +22 -6
  41. package/packages/core/dev-delivery-warrant-legacy-recovery.js +4 -2
  42. package/packages/core/dev-delivery-warrant-native-compatibility.js +33 -0
  43. package/packages/core/dev-delivery-warrant-state.js +54 -54
  44. package/packages/core/dev-delivery-warrant.js +8 -0
  45. package/packages/core/dev-delivery-writer-protocol-transition.js +72 -0
  46. package/packages/core/release-tail-product-capabilities.js +29 -0
  47. package/packages/core/release-tail-provider-plane.js +3 -3
  48. package/packages/core/v4-canonical-contracts.js +14 -0
  49. package/packages/core/v4-floating-consumer-policy.js +4 -1
  50. package/packages/core/v4-product-publication.js +387 -0
  51. package/packages/core/v4-protected-publication-source.js +93 -0
  52. package/packages/core/v4-publication-qualification.js +1 -0
  53. package/packages/core/v4-release-invocation.js +425 -0
  54. package/packages/core/v4-universal-workflow-bootstrap.js +596 -0
  55. package/scripts/audit-publication-control-plane.mjs +0 -1
  56. package/scripts/check-inventory.mjs +27 -59
  57. package/scripts/check-maintainability.mjs +29 -118
  58. package/scripts/check-v3-v4-capability-inventory.mjs +3 -61
  59. package/scripts/check-v4-floating-consumer-policy-contract.mjs +10 -20
  60. package/scripts/check-v4-release-topology.mjs +493 -0
  61. package/scripts/check-v4-universal-workflow-bootstrap.mjs +257 -0
  62. package/scripts/dev-delivery-warrant.mjs +26 -5
  63. package/scripts/generate-channel-build-workflow.mjs +5 -1
  64. package/scripts/generate-channel-promotion-workflow.mjs +17 -57
  65. package/scripts/generate-v4-universal-workflow-facades.mjs +415 -0
  66. package/scripts/maintainability-public-surface.mjs +115 -0
  67. package/scripts/release-candidate-resolver.mjs +23 -24
  68. package/scripts/resume-from-candidate-run.mjs +16 -17
  69. package/scripts/universal-facade-maintainability.mjs +82 -0
  70. package/scripts/v3-v4-capability-catalog.mjs +107 -0
  71. package/scripts/v4-declarative-promotion-admission.mjs +4 -1
  72. package/scripts/v4-product-publication-intent.mjs +114 -0
  73. package/scripts/v4-release-candidate-adapter.mjs +41 -0
  74. package/scripts/v4-universal-workflow-backflow.mjs +212 -0
  75. package/scripts/v4-universal-workflow-engine.mjs +586 -0
  76. package/scripts/v4-universal-workflow-self-dogfood.mjs +205 -0
  77. package/templates/universal-buildchain-bootstrap-recovery.yml +282 -0
  78. package/templates/universal-buildchain-bootstrap.yml +28 -0
  79. package/scripts/capture-package-release-propagation.mjs +0 -263
  80. package/scripts/publication-commit-evidence.mjs +0 -444
  81. package/scripts/publish-github-artifact-attestation-evidence.mjs +0 -201
  82. package/scripts/stage-github-artifact-attestation-inputs.mjs +0 -65
@@ -0,0 +1,493 @@
1
+ #!/usr/bin/env node
2
+
3
+ import assert from "node:assert/strict";
4
+ import crypto from "node:crypto";
5
+ import fs from "node:fs";
6
+ import path from "node:path";
7
+ import { fileURLToPath, pathToFileURL } from "node:url";
8
+
9
+ import {
10
+ parseWorkflowDocument,
11
+ parseYamlUses,
12
+ } from "../packages/core/workflow-yaml-contract.js";
13
+
14
+ const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
15
+ const ledgerPath = path.join(root, "architecture/v4-release-topology.json");
16
+
17
+ function read(relative) {
18
+ return fs.readFileSync(path.join(root, relative), "utf8");
19
+ }
20
+
21
+ const LOCAL_MODULE_EXTENSIONS = ["", ".js", ".mjs", ".cjs"];
22
+ const PRIVILEGED_ENTRYPOINTS = [
23
+ "actions/v4-release-candidate-promote/index.js",
24
+ ];
25
+
26
+ function localModuleSpecifiers(source) {
27
+ const specifiers = [];
28
+ const expression =
29
+ /(?:\bfrom\s+|\bimport\s*\(\s*|\bimport\s+)["'](\.[^"']+)["']/gu;
30
+ for (const match of source.matchAll(expression)) specifiers.push(match[1]);
31
+ return [...new Set(specifiers)].sort();
32
+ }
33
+
34
+ function resolveLocalModule(importer, specifier) {
35
+ const unresolved = path.posix.normalize(
36
+ path.posix.join(path.posix.dirname(importer), specifier),
37
+ );
38
+ assert.ok(
39
+ !unresolved.startsWith("../") && !path.posix.isAbsolute(unresolved),
40
+ `local module import escapes the repository: ${importer} -> ${specifier}`,
41
+ );
42
+ const candidates = [
43
+ ...LOCAL_MODULE_EXTENSIONS.map((extension) => `${unresolved}${extension}`),
44
+ ...LOCAL_MODULE_EXTENSIONS.slice(1).map((extension) =>
45
+ path.posix.join(unresolved, `index${extension}`),
46
+ ),
47
+ ];
48
+ const matches = candidates.filter((relative) => {
49
+ const absolute = path.join(root, relative);
50
+ return fs.existsSync(absolute) && fs.statSync(absolute).isFile();
51
+ });
52
+ assert.equal(
53
+ matches.length,
54
+ 1,
55
+ `local module import must resolve exactly once: ${importer} -> ${specifier}`,
56
+ );
57
+ return matches[0];
58
+ }
59
+
60
+ export function discoverStaticModuleClosure(entrypoints) {
61
+ const pending = [...entrypoints];
62
+ const visited = new Set();
63
+ while (pending.length > 0) {
64
+ const relative = pending.pop();
65
+ if (visited.has(relative)) continue;
66
+ assert.ok(
67
+ fs.statSync(path.join(root, relative)).isFile(),
68
+ `privileged entry is not a file: ${relative}`,
69
+ );
70
+ visited.add(relative);
71
+ for (const specifier of localModuleSpecifiers(read(relative))) {
72
+ const dependency = resolveLocalModule(relative, specifier);
73
+ if (!visited.has(dependency)) pending.push(dependency);
74
+ }
75
+ }
76
+ return [...visited].sort();
77
+ }
78
+
79
+ function rootedPathSet(paths) {
80
+ return `sha256:${crypto
81
+ .createHash("sha256")
82
+ .update(JSON.stringify([...paths].sort()))
83
+ .digest("hex")}`;
84
+ }
85
+
86
+ function productionFiles(relative, extensions) {
87
+ const absolute = path.join(root, relative);
88
+ if (!fs.existsSync(absolute)) return [];
89
+ const entries = fs.readdirSync(absolute, { withFileTypes: true });
90
+ return entries.flatMap((entry) => {
91
+ const child = path.posix.join(relative, entry.name);
92
+ if (
93
+ entry.isDirectory() &&
94
+ !["dist", "node_modules", ".git"].includes(entry.name)
95
+ )
96
+ return productionFiles(child, extensions);
97
+ if (
98
+ entry.isFile() &&
99
+ extensions.some((extension) => entry.name.endsWith(extension))
100
+ )
101
+ return [child];
102
+ return [];
103
+ });
104
+ }
105
+
106
+ function matchingProductionFiles(roots, extensions, pattern) {
107
+ return roots
108
+ .flatMap((relative) => productionFiles(relative, extensions))
109
+ .filter((relative) => relative !== "scripts/check-v4-release-topology.mjs")
110
+ .filter((relative) => pattern.test(read(relative)))
111
+ .sort();
112
+ }
113
+
114
+ export function discoverV4ReleaseAuthorityClosure() {
115
+ const providerPlane = matchingProductionFiles(
116
+ ["actions", "packages/core"],
117
+ [".js", ".mjs", ".cjs"],
118
+ /(?:release-tail-provider-(?:adapters|plane)|create(?:GitHubReleaseAssets|SignedStaticChannel|SiteReleaseActivation|ReleasedEvidence)Adapter)/u,
119
+ );
120
+ const runtimeSelectors = matchingProductionFiles(
121
+ [".github/workflows", "scripts", "packages/core"],
122
+ [".yml", ".yaml", ".js", ".mjs", ".cjs"],
123
+ /(?:promotion-runtime-sha|resume-buildchain-runtime-sha|BUILDCHAIN_(?:CURRENT_RUNTIME_SHA|RUNTIME_REF|RESUME_CANDIDATE_RUN_ID)|authorizeV4RuntimeSelection|scanV4RuntimeSelectorPersistence|v4-release-candidate-adapter)/u,
124
+ );
125
+ const terminalProjections = matchingProductionFiles(
126
+ [".github/workflows", "actions", "packages/core", "scripts"],
127
+ [".yml", ".yaml", ".js", ".mjs", ".cjs"],
128
+ /(?:createV4ReleaseReceipt|release-receipt\.json|V4_RELEASE_RECEIPT_CONTRACT)/u,
129
+ );
130
+ const privilegedModules = discoverStaticModuleClosure(PRIVILEGED_ENTRYPOINTS);
131
+ const legacyEngineModules = productionFiles(
132
+ "actions/promote-buildchain-ref",
133
+ [".js", ".mjs", ".cjs"],
134
+ )
135
+ .filter((relative) =>
136
+ /(?:^|\/)(?:lib|promote-(?:alpha|release|major)-channel|durable-transaction-operations)\.js$/u.test(
137
+ relative,
138
+ ),
139
+ )
140
+ .sort();
141
+ return {
142
+ providerAdapters: [
143
+ ...new Set([
144
+ ...providerPlane,
145
+ "packages/core/release-tail-provider-plane.js",
146
+ ]),
147
+ ].sort(),
148
+ runtimeSelectors,
149
+ runtimeEngines: ["actions/v4-release-candidate-promote/index.js"],
150
+ terminalProjections,
151
+ privilegedExecutableClosure: {
152
+ entrypoints: PRIVILEGED_ENTRYPOINTS,
153
+ modules: privilegedModules,
154
+ root: rootedPathSet(privilegedModules),
155
+ },
156
+ legacyEngineModules,
157
+ };
158
+ }
159
+
160
+ function jobBlock(source, jobId) {
161
+ const escaped = jobId.replace(/[.*+?^${}()|[\]\\]/gu, "\\$&");
162
+ return (
163
+ source.match(
164
+ new RegExp(
165
+ `^ ${escaped}:\\n([\\s\\S]*?)(?=^ [A-Za-z0-9_.-]+:|(?![\\s\\S]))`,
166
+ "mu",
167
+ ),
168
+ )?.[1] || ""
169
+ );
170
+ }
171
+
172
+ function permission(block, name) {
173
+ return (
174
+ new RegExp(`^ ${name}:\\s*([^#\\n]+)`, "mu")
175
+ .exec(block)?.[1]
176
+ ?.trim() || null
177
+ );
178
+ }
179
+
180
+ function workflowSnapshot(relative) {
181
+ const source = read(relative);
182
+ const document = parseWorkflowDocument(source);
183
+ const jobs = document.jobs
184
+ .filter((job) => job.id !== "universal-bootstrap")
185
+ .map((job) => {
186
+ const block = jobBlock(source, job.id);
187
+ const uses = job.uses || null;
188
+ return {
189
+ id: job.id,
190
+ kind: uses ? "reusable-call" : "runner",
191
+ uses,
192
+ permissions: {
193
+ contents: permission(block, "contents"),
194
+ idToken: permission(block, "id-token"),
195
+ },
196
+ carriers: {
197
+ artifactDownload: /uses:\s+actions\/download-artifact@/u.test(block),
198
+ artifactUpload: /uses:\s+actions\/upload-artifact@/u.test(block),
199
+ jobOutput: /GITHUB_OUTPUT/u.test(block),
200
+ },
201
+ mutationSignals: [
202
+ /contents:\s*write/u.test(block) && "contents-write",
203
+ /id-token:\s*write/u.test(block) && "oidc-write",
204
+ /(?:promote-buildchain-ref|v4-release-candidate-promote)/u.test(
205
+ block,
206
+ ) && "promotion-runtime",
207
+ /(?:git push|npm publish|gh release (?:create|upload))/u.test(block) &&
208
+ "direct-publication-command",
209
+ ].filter(Boolean),
210
+ };
211
+ });
212
+ return {
213
+ path: relative,
214
+ triggers: document.triggers,
215
+ jobs,
216
+ reusableEdges: parseYamlUses(source)
217
+ .map(({ value }) => value)
218
+ .filter((value) => /\.github\/workflows\//u.test(value))
219
+ .filter((value) => !/\/bootstrap\.yml(?:@v4)?$/u.test(value))
220
+ .sort(),
221
+ };
222
+ }
223
+
224
+ export function discoverV4ReleaseTopology(
225
+ workflowPaths,
226
+ semanticWorkflowPaths = workflowPaths,
227
+ ) {
228
+ const workflows = workflowPaths.map(workflowSnapshot);
229
+ const jobs = workflows.flatMap((workflow) => workflow.jobs);
230
+ const mutationJobs = jobs.filter((job) => job.mutationSignals.length > 0);
231
+ const semanticPaths = new Set(semanticWorkflowPaths);
232
+ const semanticJobs = workflows
233
+ .filter((workflow) => semanticPaths.has(workflow.path))
234
+ .flatMap((workflow) => workflow.jobs);
235
+ const semanticMutationJobs = semanticJobs.filter(
236
+ (job) => job.kind === "runner" && job.mutationSignals.length > 0,
237
+ );
238
+ return {
239
+ jobRecordFields: [
240
+ "id",
241
+ "kind",
242
+ "uses",
243
+ "contentsPermission",
244
+ "oidcPermission",
245
+ "carriers",
246
+ "mutationSignals",
247
+ ],
248
+ workflows: workflows
249
+ .filter((workflow) => semanticPaths.has(workflow.path))
250
+ .map((workflow) => ({
251
+ path: workflow.path,
252
+ triggers: workflow.triggers,
253
+ jobs: workflow.jobs.map((job) =>
254
+ [
255
+ job.id,
256
+ job.kind,
257
+ job.uses || "-",
258
+ job.permissions.contents || "-",
259
+ job.permissions.idToken || "-",
260
+ Object.entries(job.carriers)
261
+ .filter(([, present]) => present)
262
+ .map(([name]) => name)
263
+ .join(",") || "-",
264
+ job.mutationSignals.join(",") || "-",
265
+ ].join("|"),
266
+ ),
267
+ reusableEdges: workflow.reusableEdges,
268
+ })),
269
+ metrics: {
270
+ workflowCount: workflows.length,
271
+ jobCount: jobs.length,
272
+ reusableEdgeCount: workflows.reduce(
273
+ (count, workflow) => count + workflow.reusableEdges.length,
274
+ 0,
275
+ ),
276
+ mutationRelevantNodeCount: jobs.filter(
277
+ (job) =>
278
+ job.kind === "reusable-call" ||
279
+ job.mutationSignals.length > 0 ||
280
+ job.carriers.artifactDownload ||
281
+ job.carriers.artifactUpload,
282
+ ).length,
283
+ contentsWriteJobCount: mutationJobs.filter((job) =>
284
+ job.mutationSignals.includes("contents-write"),
285
+ ).length,
286
+ oidcWriteJobCount: mutationJobs.filter((job) =>
287
+ job.mutationSignals.includes("oidc-write"),
288
+ ).length,
289
+ },
290
+ semanticMetrics: {
291
+ workflowCount: semanticPaths.size,
292
+ mutationRelevantNodeCount: semanticJobs.filter(
293
+ (job) =>
294
+ job.kind === "reusable-call" ||
295
+ job.mutationSignals.length > 0 ||
296
+ job.carriers.artifactDownload ||
297
+ job.carriers.artifactUpload,
298
+ ).length,
299
+ contentsWriteJobCount: semanticMutationJobs.filter((job) =>
300
+ job.mutationSignals.includes("contents-write"),
301
+ ).length,
302
+ oidcWriteJobCount: semanticMutationJobs.filter((job) =>
303
+ job.mutationSignals.includes("oidc-write"),
304
+ ).length,
305
+ },
306
+ };
307
+ }
308
+
309
+ export function findUnknownV4ReleaseTopology(
310
+ workflowPaths,
311
+ allWorkflowPaths = fs
312
+ .readdirSync(path.join(root, ".github/workflows"))
313
+ .filter((name) => /\.ya?ml$/u.test(name))
314
+ .map((name) => `.github/workflows/${name}`),
315
+ readWorkflow = read,
316
+ ) {
317
+ const declared = new Set(workflowPaths);
318
+ return allWorkflowPaths
319
+ .filter((relative) => !declared.has(relative))
320
+ .filter((relative) => {
321
+ const source = readWorkflow(relative);
322
+ const usesReleaseAuthority = parseYamlUses(source).some(({ value }) =>
323
+ /(?:release-candidate-promote|promote-buildchain-ref|v4-release-candidate-promote|release-tail)/u.test(
324
+ value,
325
+ ),
326
+ );
327
+ const hasReleaseLanguage =
328
+ /(?:^|[-_ ])(?:release|publish|promotion|distribution|tag)(?:$|[-_ :])/imu.test(
329
+ source,
330
+ );
331
+ const hasMutationAuthority =
332
+ /(?:contents|id-token):\s*write/u.test(source) ||
333
+ /(?:git push|npm publish|gh release (?:create|upload)|createRef|updateRef)/u.test(
334
+ source,
335
+ );
336
+ return (
337
+ usesReleaseAuthority || (hasReleaseLanguage && hasMutationAuthority)
338
+ );
339
+ })
340
+ .sort();
341
+ }
342
+
343
+ function assertClosedWorld(workflowPaths) {
344
+ const unknown = findUnknownV4ReleaseTopology(workflowPaths);
345
+ assert.deepEqual(
346
+ unknown,
347
+ [],
348
+ `unknown v4 release topology workflows: ${unknown.join(", ")}`,
349
+ );
350
+ }
351
+
352
+ function assertAuthorityClosure(ledger) {
353
+ const closure = ledger.authorityClosure;
354
+ assert.ok(
355
+ closure && typeof closure === "object",
356
+ "authority closure missing",
357
+ );
358
+ for (const className of [
359
+ "providerAdapters",
360
+ "runtimeSelectors",
361
+ "runtimeEngines",
362
+ "terminalProjections",
363
+ "legacyEngineModules",
364
+ ]) {
365
+ assert.ok(
366
+ Array.isArray(closure[className]) && closure[className].length > 0,
367
+ `authority closure class ${className} is empty`,
368
+ );
369
+ for (const relative of closure[className])
370
+ assert.ok(
371
+ fs.statSync(path.join(root, relative)).isFile(),
372
+ `authority closure path is not a file: ${relative}`,
373
+ );
374
+ }
375
+ const discovered = discoverV4ReleaseAuthorityClosure();
376
+ for (const className of Object.keys(discovered))
377
+ assert.deepEqual(
378
+ closure[className],
379
+ discovered[className],
380
+ `authority closure class drifted: ${className}`,
381
+ );
382
+ assert.deepEqual(
383
+ closure.privilegedExecutableClosure,
384
+ discovered.privilegedExecutableClosure,
385
+ "privileged executable transitive closure drifted",
386
+ );
387
+ assert.match(
388
+ closure.privilegedExecutableClosure.root,
389
+ /^sha256:[0-9a-f]{64}$/u,
390
+ );
391
+ const reachableLegacyEngines = closure.legacyEngineModules.filter(
392
+ (relative) =>
393
+ closure.privilegedExecutableClosure.modules.includes(relative),
394
+ );
395
+ assert.deepEqual(
396
+ reachableLegacyEngines,
397
+ [],
398
+ `legacy release engines remain reachable from APPLY: ${reachableLegacyEngines.join(", ")}`,
399
+ );
400
+ assert.deepEqual(closure.runtimeEngines, [
401
+ "actions/v4-release-candidate-promote/index.js",
402
+ ]);
403
+ assert.equal(
404
+ closure.freshEntry,
405
+ ".github/workflows/release-candidate-promote.yml",
406
+ );
407
+ assert.equal(
408
+ closure.recoveryEntry,
409
+ ".github/workflows/buildchain-ref-promotion-recovery.yml",
410
+ );
411
+ const engineSurface = [
412
+ ".github/workflows/.release-candidate-promote.yml",
413
+ ...closure.privilegedExecutableClosure.modules,
414
+ ]
415
+ .map(read)
416
+ .join("\n");
417
+ for (const pattern of closure.forbiddenLegacyEnginePatterns)
418
+ assert.doesNotMatch(
419
+ engineSurface,
420
+ new RegExp(pattern, "u"),
421
+ `legacy release engine remains reachable: ${pattern}`,
422
+ );
423
+ const canonicalWorkflow = read(
424
+ ".github/workflows/.release-candidate-promote.yml",
425
+ );
426
+ assert.match(
427
+ canonicalWorkflow,
428
+ /scripts\/v4-release-candidate-adapter\.mjs/u,
429
+ );
430
+ assert.match(
431
+ canonicalWorkflow,
432
+ /release-invocation\.json[\s\S]*release-transaction\.json[\s\S]*release-receipt\.json/u,
433
+ );
434
+ }
435
+
436
+ export function checkV4ReleaseTopology() {
437
+ const ledger = JSON.parse(fs.readFileSync(ledgerPath, "utf8"));
438
+ assert.equal(ledger.contract, "kungfu-buildchain-v4-release-topology/v1");
439
+ assertClosedWorld(ledger.closedWorld.workflowPaths);
440
+ assertAuthorityClosure(ledger);
441
+ const actual = discoverV4ReleaseTopology(
442
+ ledger.closedWorld.workflowPaths,
443
+ ledger.semanticScope.workflowPaths,
444
+ );
445
+ assert.deepEqual(actual, ledger.observedTopology);
446
+ assert.equal(
447
+ ledger.targetBudgets.maximumMutationRelevantNodeCount,
448
+ Math.floor(ledger.baselineMetrics.semanticMutationRelevantNodeCount / 2),
449
+ );
450
+ if (ledger.enforcement === "converged") {
451
+ assert.ok(
452
+ actual.semanticMetrics.mutationRelevantNodeCount <=
453
+ ledger.targetBudgets.maximumMutationRelevantNodeCount,
454
+ );
455
+ assert.equal(actual.semanticMetrics.contentsWriteJobCount, 1);
456
+ assert.equal(actual.semanticMetrics.oidcWriteJobCount, 1);
457
+ const publisher = actual.workflows.find(
458
+ ({ path: workflowPath }) =>
459
+ workflowPath === ".github/workflows/.release-candidate-promote.yml",
460
+ );
461
+ assert.deepEqual(
462
+ publisher.jobs.map((job) => job.split("|", 1)[0]),
463
+ ["apply", "qualify", "settle"],
464
+ );
465
+ }
466
+ return actual;
467
+ }
468
+
469
+ if (
470
+ process.argv[1] &&
471
+ import.meta.url === pathToFileURL(process.argv[1]).href
472
+ ) {
473
+ if (process.argv.includes("--print-closure")) {
474
+ process.stdout.write(
475
+ `${JSON.stringify(discoverV4ReleaseAuthorityClosure(), null, 2)}\n`,
476
+ );
477
+ } else if (process.argv.includes("--print")) {
478
+ const ledger = JSON.parse(fs.readFileSync(ledgerPath, "utf8"));
479
+ process.stdout.write(
480
+ `${JSON.stringify(
481
+ discoverV4ReleaseTopology(
482
+ ledger.closedWorld.workflowPaths,
483
+ ledger.semanticScope.workflowPaths,
484
+ ),
485
+ null,
486
+ 2,
487
+ )}\n`,
488
+ );
489
+ } else {
490
+ checkV4ReleaseTopology();
491
+ process.stdout.write("v4 release topology: ok\n");
492
+ }
493
+ }