@kungfu-tech/buildchain 4.0.2-alpha.10 → 4.0.2-alpha.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/architecture/agent-change-map.md +40 -0
- package/architecture/ci-lane-change-budget.json +332 -0
- package/architecture/internal-capabilities.json +39 -0
- package/architecture/maintainability-debt.json +11 -9
- package/architecture/maintainability-policy.json +7 -7
- package/architecture/v4-release-topology.json +2 -1
- package/architecture/v4-universal-workflow-bootstrap.json +181 -0
- package/architecture/v4-universal-workflow-fault-campaign.json +72 -0
- package/architecture/v4-universal-workflow-train-admission.json +40 -0
- package/dist/site/buildchain-contract.json +86 -41
- package/dist/site/buildchain-site.json +15 -10
- package/dist/site/capability-registry.json +1 -1
- package/dist/site/controller-registry.json +46 -10
- package/dist/site/kfd-claims.json +154 -68
- package/dist/site/kfd-upstream-aggregate.json +1 -1
- package/dist/site/manual-registry.json +2 -2
- package/dist/site/node-api-registry.json +7 -7
- package/dist/site/page-registry.json +9 -4
- package/dist/site/public-surface-audit.json +158 -66
- package/dist/site/publication-authority-registry.json +67 -1
- package/dist/site/publication-registry.json +4 -4
- package/dist/site/site-manifest.json +6 -6
- package/dist/site/workflow-registry.json +189 -67
- package/docs/node-api-reference.md +9 -9
- package/docs/reusable-build-surface.md +16 -0
- package/package.json +2 -2
- package/packages/core/buildchain-publication-authority.js +3 -0
- package/packages/core/ci-lane-change-budget.js +14 -1
- package/packages/core/release-tail-provider-plane.js +1 -1
- package/packages/core/v4-product-publication.js +1 -1
- package/packages/core/v4-universal-workflow-bootstrap.js +596 -0
- package/scripts/check-maintainability.mjs +16 -113
- package/scripts/check-v4-release-topology.mjs +5 -2
- package/scripts/check-v4-universal-workflow-bootstrap.mjs +257 -0
- package/scripts/generate-channel-build-workflow.mjs +5 -1
- package/scripts/generate-channel-promotion-workflow.mjs +3 -2
- package/scripts/generate-v4-universal-workflow-facades.mjs +415 -0
- package/scripts/maintainability-public-surface.mjs +115 -0
- package/scripts/universal-facade-maintainability.mjs +82 -0
- package/scripts/v4-universal-workflow-backflow.mjs +212 -0
- package/scripts/v4-universal-workflow-engine.mjs +586 -0
- package/scripts/v4-universal-workflow-self-dogfood.mjs +205 -0
- package/templates/universal-buildchain-bootstrap-recovery.yml +282 -0
- package/templates/universal-buildchain-bootstrap.yml +28 -0
|
@@ -0,0 +1,415 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { execFileSync } from "node:child_process";
|
|
5
|
+
import { fileURLToPath } from "node:url";
|
|
6
|
+
const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
|
|
7
|
+
const contractPath = path.join(
|
|
8
|
+
root,
|
|
9
|
+
"architecture/v4-universal-workflow-bootstrap.json",
|
|
10
|
+
);
|
|
11
|
+
const contract = JSON.parse(fs.readFileSync(contractPath, "utf8"));
|
|
12
|
+
const laneBudgetPath = path.join(
|
|
13
|
+
root,
|
|
14
|
+
"architecture/ci-lane-change-budget.json",
|
|
15
|
+
);
|
|
16
|
+
const recoveryTemplatePath = path.join(
|
|
17
|
+
root,
|
|
18
|
+
contract.bootstrap.consumerRecoveryTemplate,
|
|
19
|
+
);
|
|
20
|
+
const recoveryWorkflowPath = path.join(
|
|
21
|
+
root,
|
|
22
|
+
contract.bootstrap.consumerRecoveryWorkflow,
|
|
23
|
+
);
|
|
24
|
+
const universalInput = ` universal-request-json:
|
|
25
|
+
description: "Versioned exact-candidate request envelope; empty preserves the compatibility path"
|
|
26
|
+
default: ""
|
|
27
|
+
required: false
|
|
28
|
+
type: string
|
|
29
|
+
`;
|
|
30
|
+
const bootstrapJob = ` universal-bootstrap:
|
|
31
|
+
name: Universal exact-candidate execution
|
|
32
|
+
if: \${{ inputs.universal-request-json != '' }}
|
|
33
|
+
uses: ./.github/workflows/bootstrap.yml
|
|
34
|
+
with:
|
|
35
|
+
request-json: \${{ inputs.universal-request-json }}
|
|
36
|
+
|
|
37
|
+
`;
|
|
38
|
+
|
|
39
|
+
function fail(message) {
|
|
40
|
+
throw new Error(message);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function activeFacadePaths() {
|
|
44
|
+
const retired = new Set(contract.retiredWorkflowSurfaces || []);
|
|
45
|
+
return contract.inventoryWorkflows.filter(
|
|
46
|
+
(relative) =>
|
|
47
|
+
relative !== contract.bootstrap.publicWorkflow &&
|
|
48
|
+
relative !== contract.bootstrap.consumerRecoveryWorkflow &&
|
|
49
|
+
!retired.has(relative),
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function sourceRevision() {
|
|
54
|
+
const revision = contract.migration.facadeSourceRevision;
|
|
55
|
+
if (!/^[0-9a-f]{40}$/u.test(revision || ""))
|
|
56
|
+
fail("migration.facadeSourceRevision must be an exact commit");
|
|
57
|
+
return revision;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function materializeSourceRevision() {
|
|
61
|
+
const revision = sourceRevision();
|
|
62
|
+
try {
|
|
63
|
+
execFileSync("git", ["cat-file", "-e", `${revision}^{commit}`], {
|
|
64
|
+
cwd: root,
|
|
65
|
+
stdio: "ignore",
|
|
66
|
+
});
|
|
67
|
+
return;
|
|
68
|
+
} catch {}
|
|
69
|
+
try {
|
|
70
|
+
execFileSync(
|
|
71
|
+
"git",
|
|
72
|
+
["fetch", "--no-tags", "--depth=1", "origin", revision],
|
|
73
|
+
{ cwd: root, stdio: "pipe" },
|
|
74
|
+
);
|
|
75
|
+
execFileSync("git", ["cat-file", "-e", `${revision}^{commit}`], {
|
|
76
|
+
cwd: root,
|
|
77
|
+
stdio: "ignore",
|
|
78
|
+
});
|
|
79
|
+
} catch (error) {
|
|
80
|
+
const detail = String(error?.stderr || error?.message || error).trim();
|
|
81
|
+
fail(
|
|
82
|
+
`facade source revision ${revision} is unavailable and could not be hydrated from origin${detail ? `: ${detail}` : ""}`,
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function frozenFacadeSource(relative) {
|
|
88
|
+
return execFileSync("git", ["show", `${sourceRevision()}:${relative}`], {
|
|
89
|
+
cwd: root,
|
|
90
|
+
encoding: "utf8",
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function isChannelGeneratedFacade(relative) {
|
|
95
|
+
return (contract.migration.channelGeneratedFacades || []).includes(relative);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function addUniversalInput(source, relative) {
|
|
99
|
+
if (source.includes(" universal-request-json:\n")) return source;
|
|
100
|
+
const workflowCall = source.match(/^(\s*)workflow_call:\s*$/mu);
|
|
101
|
+
if (!workflowCall) fail(`${relative} has no workflow_call mapping`);
|
|
102
|
+
const callIndent = workflowCall[1];
|
|
103
|
+
const inputHeader = `${callIndent} inputs:\n`;
|
|
104
|
+
const callEnd = workflowCall.index + workflowCall[0].length;
|
|
105
|
+
if (source.slice(callEnd + 1).startsWith(inputHeader)) {
|
|
106
|
+
const insertion = callEnd + 1 + inputHeader.length;
|
|
107
|
+
return `${source.slice(0, insertion)}${universalInput}${source.slice(insertion)}`;
|
|
108
|
+
}
|
|
109
|
+
return `${source.slice(0, callEnd + 1)}\n${inputHeader}${universalInput}${source.slice(callEnd + 1)}`;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function conditionExpression(source, relative, jobId) {
|
|
113
|
+
const child = source.match(/^(\s+)[A-Za-z0-9_-]+:/mu);
|
|
114
|
+
const indent = child?.[1] || " ";
|
|
115
|
+
const match = source.match(new RegExp(`^${indent}if:\\s*(.*)$`, "mu"));
|
|
116
|
+
if (!match)
|
|
117
|
+
return `${indent}if: \${{ inputs.universal-request-json == '' }}\n`;
|
|
118
|
+
const suffix = match[1].trim();
|
|
119
|
+
if (suffix === ">-" || suffix === "|") {
|
|
120
|
+
const start = match.index + match[0].length + 1;
|
|
121
|
+
const tail = source.slice(start);
|
|
122
|
+
const endMatch = tail.match(/^ [A-Za-z0-9_-]+:/mu);
|
|
123
|
+
const end = endMatch ? start + endMatch.index : source.length;
|
|
124
|
+
const raw = source.slice(start, end).trim();
|
|
125
|
+
const inner = raw
|
|
126
|
+
.replace(/^\$\{\{\s*/u, "")
|
|
127
|
+
.replace(/\s*\}\}$/u, "")
|
|
128
|
+
.split("\n")
|
|
129
|
+
.map((line) => line.trim())
|
|
130
|
+
.filter(Boolean)
|
|
131
|
+
.join("\n ");
|
|
132
|
+
if (!inner) fail(`${relative}#${jobId} has an empty multiline if`);
|
|
133
|
+
return {
|
|
134
|
+
start: match.index,
|
|
135
|
+
end,
|
|
136
|
+
value: `${indent}if: >-\n${indent} \${{\n${indent} inputs.universal-request-json == '' &&\n${indent} (\n${indent} ${inner}\n${indent} )\n${indent} }}\n`,
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
const inner = suffix.startsWith("${{")
|
|
140
|
+
? suffix.replace(/^\$\{\{\s*/u, "").replace(/\s*\}\}$/u, "")
|
|
141
|
+
: suffix;
|
|
142
|
+
return {
|
|
143
|
+
start: match.index,
|
|
144
|
+
end:
|
|
145
|
+
match.index +
|
|
146
|
+
match[0].length +
|
|
147
|
+
(source[match.index + match[0].length] === "\n" ? 1 : 0),
|
|
148
|
+
value: `${indent}if: \${{ inputs.universal-request-json == '' && (${inner}) }}\n`,
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
function guardCompatibilityJobs(source, relative) {
|
|
153
|
+
const jobs = source.match(/^jobs:\s*$/mu);
|
|
154
|
+
if (!jobs) fail(`${relative} has no jobs mapping`);
|
|
155
|
+
const bodyStart = jobs.index + jobs[0].length + 1;
|
|
156
|
+
const body = source.slice(bodyStart);
|
|
157
|
+
const headers = [...body.matchAll(/^ ([A-Za-z0-9_-]+):\s*$/gmu)];
|
|
158
|
+
if (headers.length === 0) fail(`${relative} has no jobs`);
|
|
159
|
+
let rewritten = body;
|
|
160
|
+
for (let index = headers.length - 1; index >= 0; index -= 1) {
|
|
161
|
+
const header = headers[index];
|
|
162
|
+
if (header[1] === "universal-bootstrap") continue;
|
|
163
|
+
const start = header.index + header[0].length + 1;
|
|
164
|
+
const end = headers[index + 1]?.index ?? body.length;
|
|
165
|
+
const job = body.slice(start, end);
|
|
166
|
+
if (job.includes("inputs.universal-request-json == ''")) continue;
|
|
167
|
+
const condition = conditionExpression(job, relative, header[1]);
|
|
168
|
+
if (typeof condition === "string") {
|
|
169
|
+
rewritten = `${rewritten.slice(0, start)}${condition}${rewritten.slice(start)}`;
|
|
170
|
+
} else {
|
|
171
|
+
rewritten = `${rewritten.slice(0, start + condition.start)}${condition.value}${rewritten.slice(start + condition.end)}`;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
const withGuards = `${source.slice(0, bodyStart)}${rewritten}`;
|
|
175
|
+
return withGuards.includes(" universal-bootstrap:\n")
|
|
176
|
+
? withGuards
|
|
177
|
+
: `${withGuards.slice(0, bodyStart)}${bootstrapJob}${withGuards.slice(bodyStart)}`;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
export function migrateV4UniversalWorkflowFacade(source, relative) {
|
|
181
|
+
return guardCompatibilityJobs(addUniversalInput(source, relative), relative);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
function verify(source, relative) {
|
|
185
|
+
for (const snippet of [
|
|
186
|
+
" universal-request-json:\n",
|
|
187
|
+
" universal-bootstrap:\n",
|
|
188
|
+
"uses: ./.github/workflows/bootstrap.yml",
|
|
189
|
+
]) {
|
|
190
|
+
if (!source.includes(snippet))
|
|
191
|
+
fail(`${relative} is missing ${snippet.trim()}`);
|
|
192
|
+
}
|
|
193
|
+
const jobs = source.slice(source.search(/^jobs:\s*$/mu));
|
|
194
|
+
const headers = [...jobs.matchAll(/^ ([A-Za-z0-9_-]+):\s*$/gmu)];
|
|
195
|
+
for (let index = 0; index < headers.length; index += 1) {
|
|
196
|
+
const header = headers[index];
|
|
197
|
+
if (header[1] === "universal-bootstrap") continue;
|
|
198
|
+
const end = headers[index + 1]?.index ?? jobs.length;
|
|
199
|
+
const block = jobs.slice(header.index, end);
|
|
200
|
+
if (!block.includes("inputs.universal-request-json == ''"))
|
|
201
|
+
fail(`${relative}#${header[1]} can overlap universal execution`);
|
|
202
|
+
}
|
|
203
|
+
if (!isChannelGeneratedFacade(relative)) {
|
|
204
|
+
const expected = migrateV4UniversalWorkflowFacade(
|
|
205
|
+
frozenFacadeSource(relative),
|
|
206
|
+
relative,
|
|
207
|
+
);
|
|
208
|
+
if (source !== expected)
|
|
209
|
+
fail(
|
|
210
|
+
`${relative} differs from the exact generated facade rooted at ${sourceRevision()}`,
|
|
211
|
+
);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
function laneBudget({ laneId, authorityClass, triggerClass, minutes, metric }) {
|
|
216
|
+
return {
|
|
217
|
+
laneId,
|
|
218
|
+
authorityClass,
|
|
219
|
+
triggerClass,
|
|
220
|
+
concurrencyPolicy: { mode: "none", cancelInProgress: false },
|
|
221
|
+
expectedRunnerMinutes: minutes,
|
|
222
|
+
cancellationBehavior: "finish-started",
|
|
223
|
+
sloImpact: {
|
|
224
|
+
mergeCritical: false,
|
|
225
|
+
metric,
|
|
226
|
+
expectedContributionSeconds: 0,
|
|
227
|
+
rationale:
|
|
228
|
+
"The opt-in universal path preserves the default compatibility lane and executes only an exact admitted runtime.",
|
|
229
|
+
},
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
function updateLaneBudgets() {
|
|
234
|
+
const policy = JSON.parse(fs.readFileSync(laneBudgetPath, "utf8"));
|
|
235
|
+
const mixed = new Set([
|
|
236
|
+
".github/workflows/release-governance-reconcile.yml",
|
|
237
|
+
".github/workflows/v4-adopter-delivery.yml",
|
|
238
|
+
]);
|
|
239
|
+
const facadeLanes = activeFacadePaths().map(
|
|
240
|
+
(relative) => `${relative}#universal-bootstrap`,
|
|
241
|
+
);
|
|
242
|
+
policy.declarationFamilies = [
|
|
243
|
+
{
|
|
244
|
+
...laneBudget({
|
|
245
|
+
laneId: "",
|
|
246
|
+
authorityClass: "governed-delegation",
|
|
247
|
+
triggerClass: "reusable",
|
|
248
|
+
minutes: 60,
|
|
249
|
+
metric: "opt-in exact-candidate execution latency",
|
|
250
|
+
}),
|
|
251
|
+
laneIds: facadeLanes.filter(
|
|
252
|
+
(laneId) => !mixed.has(laneId.split("#", 1)[0]),
|
|
253
|
+
),
|
|
254
|
+
},
|
|
255
|
+
{
|
|
256
|
+
...laneBudget({
|
|
257
|
+
laneId: "",
|
|
258
|
+
authorityClass: "governed-delegation",
|
|
259
|
+
triggerClass: "mixed",
|
|
260
|
+
minutes: 60,
|
|
261
|
+
metric: "mixed-trigger exact-candidate execution latency",
|
|
262
|
+
}),
|
|
263
|
+
laneIds: facadeLanes.filter((laneId) =>
|
|
264
|
+
mixed.has(laneId.split("#", 1)[0]),
|
|
265
|
+
),
|
|
266
|
+
},
|
|
267
|
+
].map(({ laneId: _laneId, ...family }) => family);
|
|
268
|
+
const universalLaneIds = new Set([
|
|
269
|
+
".github/workflows/bootstrap.yml#admit",
|
|
270
|
+
".github/workflows/bootstrap.yml#execute",
|
|
271
|
+
".github/workflows/bootstrap.yml#settle",
|
|
272
|
+
".github/workflows/universal-bootstrap-recovery.yml#recovery-admit",
|
|
273
|
+
".github/workflows/universal-bootstrap-recovery.yml#recovery-execute",
|
|
274
|
+
".github/workflows/universal-bootstrap-recovery.yml#recovery-settle",
|
|
275
|
+
".github/workflows/universal-bootstrap-dogfood.yml#public-bootstrap",
|
|
276
|
+
".github/workflows/universal-bootstrap-dogfood.yml#prepare",
|
|
277
|
+
".github/workflows/universal-bootstrap-dogfood.yml#primary-conformance",
|
|
278
|
+
".github/workflows/universal-bootstrap-dogfood.yml#recovery-conformance",
|
|
279
|
+
".github/workflows/universal-bootstrap-dogfood.yml#primary-alpha",
|
|
280
|
+
".github/workflows/universal-bootstrap-dogfood.yml#recovery-alpha",
|
|
281
|
+
".github/workflows/universal-bootstrap-dogfood.yml#primary-stable",
|
|
282
|
+
".github/workflows/universal-bootstrap-dogfood.yml#recovery-stable",
|
|
283
|
+
".github/workflows/universal-bootstrap-dogfood.yml#reconcile",
|
|
284
|
+
]);
|
|
285
|
+
policy.declarations = policy.declarations.filter(
|
|
286
|
+
({ laneId }) => !universalLaneIds.has(laneId),
|
|
287
|
+
);
|
|
288
|
+
policy.declarations.push(
|
|
289
|
+
laneBudget({
|
|
290
|
+
laneId: ".github/workflows/bootstrap.yml#admit",
|
|
291
|
+
authorityClass: "evidence",
|
|
292
|
+
triggerClass: "reusable",
|
|
293
|
+
minutes: 10,
|
|
294
|
+
metric: "exact-candidate admission latency",
|
|
295
|
+
}),
|
|
296
|
+
laneBudget({
|
|
297
|
+
laneId: ".github/workflows/bootstrap.yml#execute",
|
|
298
|
+
authorityClass: "governed-delegation",
|
|
299
|
+
triggerClass: "reusable",
|
|
300
|
+
minutes: 60,
|
|
301
|
+
metric: "exact-candidate execution latency",
|
|
302
|
+
}),
|
|
303
|
+
laneBudget({
|
|
304
|
+
laneId: ".github/workflows/bootstrap.yml#settle",
|
|
305
|
+
authorityClass: "evidence",
|
|
306
|
+
triggerClass: "reusable",
|
|
307
|
+
minutes: 10,
|
|
308
|
+
metric: "universal terminal settlement latency",
|
|
309
|
+
}),
|
|
310
|
+
laneBudget({
|
|
311
|
+
laneId:
|
|
312
|
+
".github/workflows/universal-bootstrap-recovery.yml#recovery-admit",
|
|
313
|
+
authorityClass: "evidence",
|
|
314
|
+
triggerClass: "reusable",
|
|
315
|
+
minutes: 10,
|
|
316
|
+
metric: "consumer-owned exact-candidate admission latency",
|
|
317
|
+
}),
|
|
318
|
+
laneBudget({
|
|
319
|
+
laneId:
|
|
320
|
+
".github/workflows/universal-bootstrap-recovery.yml#recovery-execute",
|
|
321
|
+
authorityClass: "governed-delegation",
|
|
322
|
+
triggerClass: "reusable",
|
|
323
|
+
minutes: 60,
|
|
324
|
+
metric: "consumer-owned exact-candidate execution latency",
|
|
325
|
+
}),
|
|
326
|
+
laneBudget({
|
|
327
|
+
laneId:
|
|
328
|
+
".github/workflows/universal-bootstrap-recovery.yml#recovery-settle",
|
|
329
|
+
authorityClass: "evidence",
|
|
330
|
+
triggerClass: "reusable",
|
|
331
|
+
minutes: 10,
|
|
332
|
+
metric: "consumer-owned terminal settlement latency",
|
|
333
|
+
}),
|
|
334
|
+
laneBudget({
|
|
335
|
+
laneId: ".github/workflows/universal-bootstrap-dogfood.yml#prepare",
|
|
336
|
+
authorityClass: "evidence",
|
|
337
|
+
triggerClass: "mixed",
|
|
338
|
+
minutes: 10,
|
|
339
|
+
metric: "Train-first self-dogfood admission latency",
|
|
340
|
+
}),
|
|
341
|
+
...[
|
|
342
|
+
"primary-conformance",
|
|
343
|
+
"recovery-conformance",
|
|
344
|
+
"primary-alpha",
|
|
345
|
+
"recovery-alpha",
|
|
346
|
+
"primary-stable",
|
|
347
|
+
"recovery-stable",
|
|
348
|
+
].map((job) =>
|
|
349
|
+
laneBudget({
|
|
350
|
+
laneId: `.github/workflows/universal-bootstrap-dogfood.yml#${job}`,
|
|
351
|
+
authorityClass: "governed-delegation",
|
|
352
|
+
triggerClass: "mixed",
|
|
353
|
+
minutes: 60,
|
|
354
|
+
metric: "Train-first exact-candidate self-dogfood latency",
|
|
355
|
+
}),
|
|
356
|
+
),
|
|
357
|
+
laneBudget({
|
|
358
|
+
laneId: ".github/workflows/universal-bootstrap-dogfood.yml#reconcile",
|
|
359
|
+
authorityClass: "evidence",
|
|
360
|
+
triggerClass: "mixed",
|
|
361
|
+
minutes: 10,
|
|
362
|
+
metric: "primary and recovery equivalence latency",
|
|
363
|
+
}),
|
|
364
|
+
);
|
|
365
|
+
fs.writeFileSync(laneBudgetPath, `${JSON.stringify(policy, null, 2)}\n`);
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
function main() {
|
|
369
|
+
const check = process.argv.includes("--check");
|
|
370
|
+
const fresh = process.argv.includes("--fresh");
|
|
371
|
+
materializeSourceRevision();
|
|
372
|
+
if (check) {
|
|
373
|
+
if (
|
|
374
|
+
fs.readFileSync(recoveryWorkflowPath, "utf8") !==
|
|
375
|
+
fs.readFileSync(recoveryTemplatePath, "utf8")
|
|
376
|
+
)
|
|
377
|
+
fail(
|
|
378
|
+
"consumer recovery workflow differs from its pre-positioned template",
|
|
379
|
+
);
|
|
380
|
+
} else {
|
|
381
|
+
fs.writeFileSync(
|
|
382
|
+
recoveryWorkflowPath,
|
|
383
|
+
fs.readFileSync(recoveryTemplatePath, "utf8"),
|
|
384
|
+
);
|
|
385
|
+
}
|
|
386
|
+
for (const relative of activeFacadePaths()) {
|
|
387
|
+
const target = path.join(root, relative);
|
|
388
|
+
const source = fresh
|
|
389
|
+
? frozenFacadeSource(relative)
|
|
390
|
+
: fs.readFileSync(target, "utf8");
|
|
391
|
+
if (check) verify(source, relative);
|
|
392
|
+
else
|
|
393
|
+
fs.writeFileSync(
|
|
394
|
+
target,
|
|
395
|
+
migrateV4UniversalWorkflowFacade(source, relative),
|
|
396
|
+
);
|
|
397
|
+
}
|
|
398
|
+
if (!check) {
|
|
399
|
+
contract.bootstrapGovernedWorkflows = [
|
|
400
|
+
contract.bootstrap.publicWorkflow,
|
|
401
|
+
...activeFacadePaths(),
|
|
402
|
+
].sort();
|
|
403
|
+
contract.migration.compatibilityFacades = "generated-dual-path";
|
|
404
|
+
fs.writeFileSync(contractPath, `${JSON.stringify(contract, null, 2)}\n`);
|
|
405
|
+
updateLaneBudgets();
|
|
406
|
+
process.stdout.write(
|
|
407
|
+
`${JSON.stringify({ migrated: activeFacadePaths().length })}\n`,
|
|
408
|
+
);
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
const isMain =
|
|
413
|
+
process.argv[1] &&
|
|
414
|
+
path.resolve(process.argv[1]) === fileURLToPath(import.meta.url);
|
|
415
|
+
if (isMain) main();
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { execFileSync } from "node:child_process";
|
|
4
|
+
import {
|
|
5
|
+
isGeneratedFacadePublicTransition,
|
|
6
|
+
loadUniversalFacadeMigration,
|
|
7
|
+
} from "./universal-facade-maintainability.mjs";
|
|
8
|
+
|
|
9
|
+
function readJson(root, file) {
|
|
10
|
+
return JSON.parse(fs.readFileSync(path.join(root, file), "utf8"));
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function readJsonAtRevision(root, revision, file) {
|
|
14
|
+
return JSON.parse(
|
|
15
|
+
execFileSync("git", ["show", `${revision}:${file}`], {
|
|
16
|
+
cwd: root,
|
|
17
|
+
encoding: "utf8",
|
|
18
|
+
}),
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function publicSurfaceContract(entry, kind) {
|
|
23
|
+
if (kind === "cli") return { id: entry.id, usage: entry.usage };
|
|
24
|
+
if (kind === "node")
|
|
25
|
+
return {
|
|
26
|
+
export: entry.export,
|
|
27
|
+
specifier: entry.specifier,
|
|
28
|
+
target: entry.target,
|
|
29
|
+
};
|
|
30
|
+
return {
|
|
31
|
+
id: entry.id,
|
|
32
|
+
path: entry.path,
|
|
33
|
+
reusable: entry.reusable,
|
|
34
|
+
inputs: entry.inputs || [],
|
|
35
|
+
secrets: entry.secrets || [],
|
|
36
|
+
outputs: entry.outputs || [],
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function evaluatePublicSurface({
|
|
41
|
+
root,
|
|
42
|
+
revision,
|
|
43
|
+
policy,
|
|
44
|
+
migration = loadUniversalFacadeMigration(root),
|
|
45
|
+
}) {
|
|
46
|
+
const issues = [];
|
|
47
|
+
const capabilityGroups = new Set(
|
|
48
|
+
readJson(root, "dist/site/capability-registry.json").groups.map(
|
|
49
|
+
(entry) => entry.id,
|
|
50
|
+
),
|
|
51
|
+
);
|
|
52
|
+
const definitions = [
|
|
53
|
+
["dist/site/cli-registry.json", "commands", "cli", "id"],
|
|
54
|
+
["dist/site/node-api-registry.json", "exports", "node", "export"],
|
|
55
|
+
["dist/site/workflow-registry.json", "workflows", "workflow", "id"],
|
|
56
|
+
["dist/site/workflow-registry.json", "actions", "action", "id"],
|
|
57
|
+
];
|
|
58
|
+
for (const [file, collection, kind, key] of definitions) {
|
|
59
|
+
const current = readJson(root, file)[collection] || [];
|
|
60
|
+
const baseline = readJsonAtRevision(root, revision, file)[collection] || [];
|
|
61
|
+
const previousByKey = new Map(baseline.map((entry) => [entry[key], entry]));
|
|
62
|
+
for (const entry of current) {
|
|
63
|
+
const label = `${kind}:${entry[key]}`;
|
|
64
|
+
for (const field of policy.publicSurfacePolicy.requiredLifecycleFields) {
|
|
65
|
+
if (
|
|
66
|
+
!Object.prototype.hasOwnProperty.call(entry, field) ||
|
|
67
|
+
typeof entry[field] !== "string"
|
|
68
|
+
)
|
|
69
|
+
issues.push(`${label}: lifecycle field ${field} is missing`);
|
|
70
|
+
}
|
|
71
|
+
if (!capabilityGroups.has(entry.capabilityGroup))
|
|
72
|
+
issues.push(
|
|
73
|
+
`${label}: capability group ${entry.capabilityGroup || "<empty>"} is not registered`,
|
|
74
|
+
);
|
|
75
|
+
const previous = previousByKey.get(entry[key]);
|
|
76
|
+
const currentContract = publicSurfaceContract(entry, kind);
|
|
77
|
+
if (
|
|
78
|
+
previous &&
|
|
79
|
+
JSON.stringify(currentContract) !==
|
|
80
|
+
JSON.stringify(publicSurfaceContract(previous, kind))
|
|
81
|
+
) {
|
|
82
|
+
const approval = policy.approvedPublicSurfaceTransitions?.[label];
|
|
83
|
+
const approvedContract =
|
|
84
|
+
approval?.fromRevision === revision &&
|
|
85
|
+
String(approval?.rationale || "").trim()
|
|
86
|
+
? approval.contract
|
|
87
|
+
: null;
|
|
88
|
+
const generated = isGeneratedFacadePublicTransition({
|
|
89
|
+
entry,
|
|
90
|
+
kind,
|
|
91
|
+
migration,
|
|
92
|
+
baseContract:
|
|
93
|
+
approvedContract || publicSurfaceContract(previous, kind),
|
|
94
|
+
currentContract,
|
|
95
|
+
});
|
|
96
|
+
if (
|
|
97
|
+
!generated &&
|
|
98
|
+
(!approvedContract ||
|
|
99
|
+
JSON.stringify(approvedContract) !==
|
|
100
|
+
JSON.stringify(currentContract))
|
|
101
|
+
)
|
|
102
|
+
issues.push(
|
|
103
|
+
`${label}: existing public contract drifted from ${revision}`,
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
if (!previous && !entry.nonDuplicationRationale)
|
|
107
|
+
issues.push(
|
|
108
|
+
`${label}: new public surface requires a non-duplication rationale`,
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return issues;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export { evaluatePublicSurface, publicSurfaceContract };
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { execFileSync } from "node:child_process";
|
|
4
|
+
|
|
5
|
+
function loadUniversalFacadeMigration(root) {
|
|
6
|
+
const contract = JSON.parse(
|
|
7
|
+
fs.readFileSync(
|
|
8
|
+
path.join(root, "architecture/v4-universal-workflow-bootstrap.json"),
|
|
9
|
+
"utf8",
|
|
10
|
+
),
|
|
11
|
+
);
|
|
12
|
+
const retired = new Set(contract.retiredWorkflowSurfaces || []);
|
|
13
|
+
const paths = (contract.bootstrapGovernedWorkflows || []).filter(
|
|
14
|
+
(entry) =>
|
|
15
|
+
entry !== contract.bootstrap?.publicWorkflow && !retired.has(entry),
|
|
16
|
+
);
|
|
17
|
+
const sourceRevision = contract.migration?.facadeSourceRevision || "";
|
|
18
|
+
if (!/^[0-9a-f]{40}$/u.test(sourceRevision)) {
|
|
19
|
+
throw new Error(
|
|
20
|
+
"universal facade migration requires an exact facadeSourceRevision",
|
|
21
|
+
);
|
|
22
|
+
}
|
|
23
|
+
return { paths: new Set(paths), sourceRevision };
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function verifyUniversalFacadeMigration(root) {
|
|
27
|
+
execFileSync(
|
|
28
|
+
process.execPath,
|
|
29
|
+
["scripts/generate-v4-universal-workflow-facades.mjs", "--check"],
|
|
30
|
+
{ cwd: root, stdio: "pipe" },
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function governUniversalFacadeWorkflowMetrics({
|
|
35
|
+
root,
|
|
36
|
+
current,
|
|
37
|
+
workflowMetricsAtRevision,
|
|
38
|
+
}) {
|
|
39
|
+
const migration = loadUniversalFacadeMigration(root);
|
|
40
|
+
verifyUniversalFacadeMigration(root);
|
|
41
|
+
const frozen = workflowMetricsAtRevision(root, migration.sourceRevision);
|
|
42
|
+
const governed = { ...current, workflows: { ...current.workflows } };
|
|
43
|
+
for (const file of migration.paths) {
|
|
44
|
+
if (!frozen[file])
|
|
45
|
+
throw new Error(`frozen universal facade source is missing ${file}`);
|
|
46
|
+
governed.workflows[file] = frozen[file];
|
|
47
|
+
}
|
|
48
|
+
return { governed, migration };
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function isGeneratedFacadePublicTransition({
|
|
52
|
+
entry,
|
|
53
|
+
kind,
|
|
54
|
+
migration,
|
|
55
|
+
baseContract,
|
|
56
|
+
currentContract,
|
|
57
|
+
}) {
|
|
58
|
+
if (kind !== "workflow" || !migration?.paths.has(entry.path) || !baseContract)
|
|
59
|
+
return false;
|
|
60
|
+
const { inputs: currentInputs, ...currentRest } = currentContract;
|
|
61
|
+
const { inputs: previousInputs, ...previousRest } = baseContract;
|
|
62
|
+
if (JSON.stringify(currentRest) !== JSON.stringify(previousRest))
|
|
63
|
+
return false;
|
|
64
|
+
const added = currentInputs.filter(
|
|
65
|
+
(input) => !previousInputs.includes(input),
|
|
66
|
+
);
|
|
67
|
+
const removed = previousInputs.filter(
|
|
68
|
+
(input) => !currentInputs.includes(input),
|
|
69
|
+
);
|
|
70
|
+
return (
|
|
71
|
+
removed.length === 0 &&
|
|
72
|
+
added.length === 1 &&
|
|
73
|
+
added[0] === "universal-request-json"
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export {
|
|
78
|
+
governUniversalFacadeWorkflowMetrics,
|
|
79
|
+
isGeneratedFacadePublicTransition,
|
|
80
|
+
loadUniversalFacadeMigration,
|
|
81
|
+
verifyUniversalFacadeMigration,
|
|
82
|
+
};
|