@kungfu-tech/buildchain 4.1.3-alpha.0 → 4.1.3-alpha.2
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/action-taxonomy.json +16 -0
- package/architecture/agent-change-map.md +245 -4
- package/architecture/ci-lane-change-budget.json +289 -0
- package/architecture/decisions/0005-minimal-consumer-contract.md +122 -0
- package/architecture/decisions/0006-business-attempt-journal.md +89 -0
- package/architecture/decisions/0007-hosted-pipeline-controller.md +106 -0
- package/architecture/decisions/0008-pipeline-product-publication.md +99 -0
- package/architecture/internal-capabilities.json +340 -4
- package/architecture/maintainability-debt.json +3 -1
- package/architecture/maintainability-policy.json +8 -8
- package/architecture/minimal-consumer-migration.json +7558 -0
- package/architecture/release-topology.json +248 -11
- package/architecture/universal-workflow-bootstrap.json +10 -0
- package/architecture/universal-workflow-capability-policy.json +6 -6
- package/architecture/workflow-taxonomy.json +55 -0
- package/contracts/release-discussion-v1.schema.json +3 -0
- package/dist/readers/business-attempt.cjs +805 -0
- package/dist/readers/release-discussion.cjs +4 -0
- package/dist/site/buildchain-contract.json +7 -5
- package/dist/site/buildchain-site.json +25 -15
- package/dist/site/capability-registry.json +3 -3
- package/dist/site/kfd-claims.json +311 -10
- package/dist/site/kfd-upstream-aggregate.json +1 -1
- package/dist/site/manual-registry.json +1 -1
- package/dist/site/node-api-registry.json +9 -9
- package/dist/site/page-registry.json +20 -10
- package/dist/site/public-surface-audit.json +201 -7
- package/dist/site/publication-authority-registry.json +121 -1
- package/dist/site/publication-registry.json +4 -4
- package/dist/site/site-manifest.json +5 -5
- package/dist/site/workflow-registry.json +416 -7
- package/docs/node-api-reference.md +12 -12
- package/docs/release-discussions.md +44 -5
- package/docs/runtime-entry.md +45 -5
- package/docs/workflow-catalog.md +5 -0
- package/package.json +4 -3
- package/packages/core/consumer/contract/entries.js +85 -0
- package/packages/core/consumer/contract/examples.js +96 -0
- package/packages/core/consumer/contract/identity.js +65 -0
- package/packages/core/consumer/contract/inspection.js +45 -0
- package/packages/core/consumer/contract/plan.js +99 -0
- package/packages/core/consumer/contract/products.js +101 -0
- package/packages/core/consumer/contract/shape.js +46 -0
- package/packages/core/dev-delivery/candidate/admission.js +9 -5
- package/packages/core/dev-delivery/candidate/reservation.js +11 -0
- package/packages/core/dev-delivery/candidate/source-paths.js +12 -4
- package/packages/core/dev-delivery/native/actions.js +7 -1
- package/packages/core/dev-delivery/native/heartbeat-action.js +16 -0
- package/packages/core/dev-delivery/native/heartbeat.js +6 -4
- package/packages/core/dev-delivery/queue/landing-action.js +5 -0
- package/packages/core/governance/buildchain-publication-authority.js +5 -0
- package/packages/core/paper/operations/bootstrap.js +2 -0
- package/packages/core/paper/paper-npm-bootstrap.js +2 -2
- package/packages/core/providers/github/attempt-index.js +60 -0
- package/packages/core/providers/github/attempt-journal.js +154 -0
- package/packages/core/providers/github/discussions/materials.js +23 -7
- package/packages/core/providers/github/discussions/transport.js +16 -5
- package/packages/core/providers/github/pipeline-checkout.js +49 -0
- package/packages/core/providers/github/pipeline-events.js +52 -0
- package/packages/core/providers/github/pipeline-integration.js +95 -0
- package/packages/core/providers/github/pipeline-policy.js +213 -0
- package/packages/core/providers/github/pipeline-product-payload.js +50 -0
- package/packages/core/providers/github/pipeline-product-release.js +191 -0
- package/packages/core/providers/github/pipeline-publication-artifacts.js +153 -0
- package/packages/core/providers/github/pipeline-run-entry.js +86 -0
- package/packages/core/providers/github/pipeline-runs.js +132 -0
- package/packages/core/providers/github/pipeline-source.js +178 -0
- package/packages/core/providers/github/pipeline-version.js +201 -0
- package/packages/core/providers/github/pipeline-worker.js +108 -0
- package/packages/core/publication/candidate/registry-hydration.js +2 -2
- package/packages/core/publication/npm/pack-preview.js +2 -2
- package/packages/core/publication/npm/pack-result.js +31 -0
- package/packages/core/publication/npm/package.js +3 -6
- package/packages/core/publication/npm/pipeline-channel.js +87 -0
- package/packages/core/publication/npm/pipeline-provider.js +109 -0
- package/packages/core/publication/npm/registry.js +12 -9
- package/packages/core/publication/pipeline/actions.js +100 -0
- package/packages/core/publication/pipeline/apply.js +182 -0
- package/packages/core/publication/pipeline/build-segments.js +107 -0
- package/packages/core/publication/pipeline/capsules.js +89 -0
- package/packages/core/publication/pipeline/context.js +39 -0
- package/packages/core/publication/pipeline/development-anchor.js +91 -0
- package/packages/core/publication/pipeline/development-current.js +63 -0
- package/packages/core/publication/pipeline/development-pr.js +85 -0
- package/packages/core/publication/pipeline/development-proof.js +76 -0
- package/packages/core/publication/pipeline/development-transition.js +112 -0
- package/packages/core/publication/pipeline/distribution.js +124 -0
- package/packages/core/publication/pipeline/documents.js +156 -0
- package/packages/core/publication/pipeline/effects.js +162 -0
- package/packages/core/publication/pipeline/files.js +66 -0
- package/packages/core/publication/pipeline/imported-materials.js +32 -0
- package/packages/core/publication/pipeline/journal.js +110 -0
- package/packages/core/publication/pipeline/next-development.js +116 -0
- package/packages/core/publication/pipeline/pack.js +151 -0
- package/packages/core/publication/pipeline/package-policy.js +22 -0
- package/packages/core/publication/pipeline/plan.js +114 -0
- package/packages/core/publication/pipeline/prepare.js +151 -0
- package/packages/core/publication/pipeline/qualification.js +170 -0
- package/packages/core/publication/pipeline/qualify.js +104 -0
- package/packages/core/publication/pipeline/recovery-admission.js +122 -0
- package/packages/core/publication/pipeline/recovery-build-download.js +80 -0
- package/packages/core/publication/pipeline/recovery-build-plan.js +122 -0
- package/packages/core/publication/pipeline/recovery-build-readback.js +68 -0
- package/packages/core/publication/pipeline/recovery-capsules.js +54 -0
- package/packages/core/publication/pipeline/recovery-import.js +80 -0
- package/packages/core/publication/pipeline/recovery-inspection.js +218 -0
- package/packages/core/publication/pipeline/recovery-materials.js +104 -0
- package/packages/core/publication/pipeline/recovery-plan.js +46 -0
- package/packages/core/publication/pipeline/recovery-prepare.js +73 -0
- package/packages/core/publication/pipeline/recovery-qualification.js +128 -0
- package/packages/core/publication/pipeline/recovery-readback.js +56 -0
- package/packages/core/publication/pipeline/recovery-signing.js +58 -0
- package/packages/core/publication/pipeline/sealed-products.js +79 -0
- package/packages/core/publication/pipeline/settle.js +43 -0
- package/packages/core/publication/pipeline/signing.js +140 -0
- package/packages/core/publication/pipeline/source-plan.js +83 -0
- package/packages/core/publication/pipeline/version.js +81 -0
- package/packages/core/publication/publication-reproducibility.js +2 -2
- package/packages/core/release/discussion/binary.js +11 -0
- package/packages/core/release/discussion/checkpoints.js +45 -4
- package/packages/core/release/discussion/envelope.js +1 -0
- package/packages/core/release/discussion/evidence.js +51 -0
- package/packages/core/release/discussion/presentation.js +92 -0
- package/packages/core/release/discussion/publication.js +3 -1
- package/packages/core/release/discussion/qualification.js +1 -0
- package/packages/core/release/discussion/reader.js +9 -0
- package/packages/core/release/discussion/session.js +2 -0
- package/packages/core/release/discussion/store.js +28 -31
- package/packages/core/release/discussion/threads.js +83 -0
- package/packages/core/release/promote-candidate/product-provider-adapters.js +4 -3
- package/packages/core/release/promote-ref/internal/npm-existing-evidence.js +2 -1
- package/packages/core/release/promote-ref/internal/publish-command.js +16 -5
- package/packages/core/runtime/buildchain-domain.wasm +0 -0
- package/packages/core/runtime/domain-wasm-artifact.js +2 -2
- package/packages/core/runtime/entry/actions.js +27 -25
- package/packages/core/runtime/entry/attempt.js +25 -0
- package/packages/core/runtime/entry/selection.js +14 -0
- package/packages/core/runtime/entry/source.js +62 -0
- package/packages/core/workflow/attempt/identity.js +165 -0
- package/packages/core/workflow/attempt/journal.js +87 -0
- package/packages/core/workflow/attempt/materials.js +72 -0
- package/packages/core/workflow/attempt/reader-entry.js +12 -0
- package/packages/core/workflow/attempt/reader.js +149 -0
- package/packages/core/workflow/attempt/records.js +153 -0
- package/packages/core/workflow/attempt/store.js +75 -0
- package/packages/core/workflow/commands/pipeline-build.mjs +23 -0
- package/packages/core/workflow/pipeline/action-output.js +11 -0
- package/packages/core/workflow/pipeline/actions.js +62 -0
- package/packages/core/workflow/pipeline/build-control.js +140 -0
- package/packages/core/workflow/pipeline/build-evidence.js +92 -0
- package/packages/core/workflow/pipeline/build-qualification.js +145 -0
- package/packages/core/workflow/pipeline/build-result.js +69 -0
- package/packages/core/workflow/pipeline/build.js +95 -0
- package/packages/core/workflow/pipeline/cancellation.js +169 -0
- package/packages/core/workflow/pipeline/channel-control.js +127 -0
- package/packages/core/workflow/pipeline/controller.js +133 -0
- package/packages/core/workflow/pipeline/delivery-control.js +204 -0
- package/packages/core/workflow/pipeline/delivery-observation.js +118 -0
- package/packages/core/workflow/pipeline/delivery-request.js +198 -0
- package/packages/core/workflow/pipeline/events.js +84 -0
- package/packages/core/workflow/pipeline/fence.js +42 -0
- package/packages/core/workflow/pipeline/group-control.js +56 -0
- package/packages/core/workflow/pipeline/guard-build.js +37 -0
- package/packages/core/workflow/pipeline/guard.js +156 -0
- package/packages/core/workflow/pipeline/host.js +114 -0
- package/packages/core/workflow/pipeline/materials.js +58 -0
- package/packages/core/workflow/pipeline/notifications.js +36 -0
- package/packages/core/workflow/pipeline/parent-notification.js +27 -0
- package/packages/core/workflow/pipeline/platforms.js +21 -0
- package/packages/core/workflow/pipeline/progress.js +108 -0
- package/packages/core/workflow/pipeline/projection.js +20 -0
- package/packages/core/workflow/pipeline/reconcile.js +194 -0
- package/packages/core/workflow/pipeline/recovery-action.js +30 -0
- package/packages/core/workflow/pipeline/recovery-admission.js +122 -0
- package/packages/core/workflow/pipeline/recovery-build-control.js +95 -0
- package/packages/core/workflow/pipeline/recovery-build-evidence.js +71 -0
- package/packages/core/workflow/pipeline/recovery-build.js +121 -0
- package/packages/core/workflow/pipeline/recovery-controller.js +91 -0
- package/packages/core/workflow/pipeline/recovery-integration.js +66 -0
- package/packages/core/workflow/pipeline/recovery-merge-proof.js +90 -0
- package/packages/core/workflow/pipeline/recovery-ownership-settlement.js +150 -0
- package/packages/core/workflow/pipeline/recovery-ownership.js +91 -0
- package/packages/core/workflow/pipeline/recovery-plan.js +126 -0
- package/packages/core/workflow/pipeline/recovery-runtime.js +68 -0
- package/packages/core/workflow/pipeline/recovery-session.js +129 -0
- package/packages/core/workflow/pipeline/recovery-transition.js +135 -0
- package/packages/core/workflow/pipeline/recovery-unrecorded-build.js +74 -0
- package/packages/core/workflow/pipeline/runtime-source.js +111 -0
- package/packages/core/workflow/pipeline/selection.js +106 -0
- package/packages/core/workflow/pipeline/session.js +72 -0
- package/packages/core/workflow/pipeline/settlement.js +137 -0
- package/packages/core/workflow/pipeline/wake.js +38 -0
- package/packages/core/workflow/pipeline/web-status.js +108 -0
- package/scripts/build-release-discussion-reader.mjs +11 -7
- package/scripts/check-pipeline-publication-topology.mjs +36 -0
- package/scripts/check-release-topology.mjs +6 -1
- package/scripts/generate-minimal-consumer-contract.mjs +155 -0
- package/scripts/verify-golden-path.mjs +5 -1
- package/templates/minimal-consumer/binary/.buildchain/buildchain.toml +45 -0
- package/templates/minimal-consumer/binary/.github/workflows/buildchain-recover.yml +30 -0
- package/templates/minimal-consumer/binary/.github/workflows/buildchain.yml +28 -0
- package/templates/minimal-consumer/binary/package.json +6 -0
- package/templates/minimal-consumer/binary/src/build.mjs +5 -0
- package/templates/minimal-consumer/binary/src/hello.c +2 -0
- package/templates/minimal-consumer/binary/src/verify.mjs +3 -0
- package/templates/minimal-consumer/npm/.buildchain/buildchain.toml +46 -0
- package/templates/minimal-consumer/npm/.github/workflows/buildchain-recover.yml +30 -0
- package/templates/minimal-consumer/npm/.github/workflows/buildchain.yml +28 -0
- package/templates/minimal-consumer/npm/package.json +6 -0
- package/templates/minimal-consumer/npm/src/build.mjs +5 -0
- package/templates/minimal-consumer/npm/src/verify.mjs +3 -0
- package/templates/minimal-consumer/paper/.buildchain/buildchain.toml +45 -0
- package/templates/minimal-consumer/paper/.github/workflows/buildchain-recover.yml +30 -0
- package/templates/minimal-consumer/paper/.github/workflows/buildchain.yml +28 -0
- package/templates/minimal-consumer/paper/package.json +6 -0
- package/templates/minimal-consumer/paper/src/build.mjs +12 -0
- package/templates/minimal-consumer/paper/src/verify.mjs +3 -0
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import { recordDigest } from "../../release/discussion/envelope.js";
|
|
2
|
+
|
|
3
|
+
const TERMINAL = new Set([
|
|
4
|
+
"merged",
|
|
5
|
+
"terminal-failure",
|
|
6
|
+
"dequeued",
|
|
7
|
+
"cancelled",
|
|
8
|
+
]);
|
|
9
|
+
const wait = (reason) => ({ operation: "wait", reason });
|
|
10
|
+
|
|
11
|
+
export function terminalPipelineCandidate(candidate) {
|
|
12
|
+
return Boolean(candidate && TERMINAL.has(candidate.status));
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function pipelineCandidateRoot(current) {
|
|
16
|
+
if (
|
|
17
|
+
!current.identity?.id ||
|
|
18
|
+
current.identity.generation !== current.generation.id
|
|
19
|
+
)
|
|
20
|
+
throw new Error(
|
|
21
|
+
"Pipeline candidate requires its exact business attempt identity",
|
|
22
|
+
);
|
|
23
|
+
return recordDigest({
|
|
24
|
+
schema: "buildchain.pipeline-candidate-source/v1",
|
|
25
|
+
intent: current.intent,
|
|
26
|
+
attempt: current.identity,
|
|
27
|
+
generation: current.generation,
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function pipelineCandidate(queue, current) {
|
|
32
|
+
const source = current.generation.source;
|
|
33
|
+
const number = current.intent.source.pullRequest;
|
|
34
|
+
const matches = queue.candidates.filter(
|
|
35
|
+
(candidate) =>
|
|
36
|
+
candidate.pullRequestNumber === number &&
|
|
37
|
+
candidate.sourceHead === source.commit &&
|
|
38
|
+
candidate.sourceRoot === pipelineCandidateRoot(current),
|
|
39
|
+
);
|
|
40
|
+
const active = matches.find(
|
|
41
|
+
(candidate) => candidate.candidateId === queue.activeWarrant?.candidateId,
|
|
42
|
+
);
|
|
43
|
+
return active || matches.at(-1) || null;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function cancellation({
|
|
47
|
+
candidate,
|
|
48
|
+
queue,
|
|
49
|
+
worker,
|
|
50
|
+
reason,
|
|
51
|
+
observedSourceHead,
|
|
52
|
+
}) {
|
|
53
|
+
if (candidate && ["cancelled", "dequeued"].includes(candidate.status))
|
|
54
|
+
return {
|
|
55
|
+
operation: "record-cancellation",
|
|
56
|
+
reason,
|
|
57
|
+
candidateId: candidate.candidateId,
|
|
58
|
+
};
|
|
59
|
+
if (!candidate || TERMINAL.has(candidate.status))
|
|
60
|
+
return { operation: "supersede", reason };
|
|
61
|
+
if (candidate.candidateId !== queue.activeWarrant?.candidateId) {
|
|
62
|
+
if (candidate.status !== "queued") return wait("unfenced-candidate-state");
|
|
63
|
+
return {
|
|
64
|
+
operation: "cancel-queued",
|
|
65
|
+
reason,
|
|
66
|
+
candidateId: candidate.candidateId,
|
|
67
|
+
expectedSourceHead: candidate.sourceHead,
|
|
68
|
+
observedSourceHead,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
// Expiration is not evidence that the old native worker stopped. Never
|
|
72
|
+
// release or transfer an active Warrant until the provider proves terminality.
|
|
73
|
+
if (!worker || worker.status !== "completed")
|
|
74
|
+
return {
|
|
75
|
+
operation: "stop-worker",
|
|
76
|
+
reason: "active-worker-not-terminal",
|
|
77
|
+
candidateId: candidate.candidateId,
|
|
78
|
+
};
|
|
79
|
+
return {
|
|
80
|
+
operation: "settle-cancelled",
|
|
81
|
+
reason,
|
|
82
|
+
candidateId: candidate.candidateId,
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function sameSource(current, live) {
|
|
87
|
+
if (!live.source) return false;
|
|
88
|
+
return recordDigest(current.generation.source) === recordDigest(live.source);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function mergedDelivery(candidate, live, evidence) {
|
|
92
|
+
if (!candidate) return wait("merged-candidate-authority-required");
|
|
93
|
+
if (
|
|
94
|
+
!evidence.integration ||
|
|
95
|
+
evidence.integration.sourceHead !== live.source.commit
|
|
96
|
+
)
|
|
97
|
+
return wait("exact-protected-integration-proof-required");
|
|
98
|
+
if (candidate.status !== "merged")
|
|
99
|
+
return { operation: "settle-merged", reason: "protected-merge-observed" };
|
|
100
|
+
if (
|
|
101
|
+
!evidence.settlement ||
|
|
102
|
+
evidence.settlement.candidateId !== candidate.candidateId
|
|
103
|
+
)
|
|
104
|
+
return wait("terminal-settlement-readback-required");
|
|
105
|
+
return { operation: "wake-publication", reason: "delivery-terminal" };
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// This pure planner selects the next domain transaction. Its booleans are
|
|
109
|
+
// authenticated provider readbacks at the adapter boundary, never workflow inputs.
|
|
110
|
+
// A selected operation is not a receipt or permission to skip that domain's gates.
|
|
111
|
+
export function reconcilePipeline({ current, live, queue, worker, evidence }) {
|
|
112
|
+
if (
|
|
113
|
+
queue.repository !== current.intent.repository ||
|
|
114
|
+
queue.protectedBase !== current.intent.source.targetBranch ||
|
|
115
|
+
live.pullRequest !== current.intent.source.pullRequest
|
|
116
|
+
)
|
|
117
|
+
throw new Error("Pipeline observation belongs to another intent");
|
|
118
|
+
const candidate = pipelineCandidate(queue, current);
|
|
119
|
+
const cancellationInput = {
|
|
120
|
+
candidate,
|
|
121
|
+
queue,
|
|
122
|
+
worker,
|
|
123
|
+
observedSourceHead: live.observedHead || live.source?.commit,
|
|
124
|
+
};
|
|
125
|
+
if (live.state === "closed" && !live.merged)
|
|
126
|
+
return cancellation({
|
|
127
|
+
...cancellationInput,
|
|
128
|
+
reason: "pull-request-closed",
|
|
129
|
+
});
|
|
130
|
+
if (
|
|
131
|
+
live.targetBranch &&
|
|
132
|
+
live.targetBranch !== current.intent.source.targetBranch
|
|
133
|
+
)
|
|
134
|
+
return cancellation({
|
|
135
|
+
...cancellationInput,
|
|
136
|
+
reason: "target-branch-changed",
|
|
137
|
+
});
|
|
138
|
+
if (live.routeEnabled === false)
|
|
139
|
+
return cancellation({
|
|
140
|
+
...cancellationInput,
|
|
141
|
+
reason: "channel-policy-changed",
|
|
142
|
+
});
|
|
143
|
+
if (!sameSource(current, live))
|
|
144
|
+
return cancellation({
|
|
145
|
+
...cancellationInput,
|
|
146
|
+
reason: "source-generation-changed",
|
|
147
|
+
});
|
|
148
|
+
if (live.merged) return mergedDelivery(candidate, live, evidence);
|
|
149
|
+
if (current.generation.baseCommit !== live.baseCommit)
|
|
150
|
+
return cancellation({
|
|
151
|
+
...cancellationInput,
|
|
152
|
+
reason: "protected-base-advanced",
|
|
153
|
+
});
|
|
154
|
+
if (live.dequeued === true)
|
|
155
|
+
return cancellation({
|
|
156
|
+
...cancellationInput,
|
|
157
|
+
reason: "pull-request-dequeued",
|
|
158
|
+
});
|
|
159
|
+
return openDelivery({ candidate, live, queue, worker, evidence });
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
function openDelivery({ candidate, live, queue, worker, evidence }) {
|
|
163
|
+
if (live.state !== "open") return wait("unknown-provider-state");
|
|
164
|
+
if (live.terminalOnly) return wait("terminal-event-cannot-start-execution");
|
|
165
|
+
if (candidate && TERMINAL.has(candidate.status))
|
|
166
|
+
return wait("successor-attempt-required");
|
|
167
|
+
if (!evidence.build)
|
|
168
|
+
return { operation: "build", reason: "source-needs-qualification" };
|
|
169
|
+
if (evidence.build.sourceHead !== live.source.commit)
|
|
170
|
+
throw new Error("Build evidence belongs to another source");
|
|
171
|
+
if (evidence.build.outcome !== "success") {
|
|
172
|
+
if (candidate && candidate.candidateId === queue.activeWarrant?.candidateId)
|
|
173
|
+
return worker?.status === "completed"
|
|
174
|
+
? { operation: "settle-failure", reason: "native-execution-failed" }
|
|
175
|
+
: { operation: "stop-worker", reason: "failed-worker-not-terminal" };
|
|
176
|
+
return wait("build-failed");
|
|
177
|
+
}
|
|
178
|
+
if (!live.ready || live.draft) return wait("ready-review-required");
|
|
179
|
+
if (!evidence.review) return wait("independent-protected-review-required");
|
|
180
|
+
if (!evidence.checks) return wait("exact-required-checks-pending");
|
|
181
|
+
if (!candidate) return { operation: "reserve", reason: "source-admitted" };
|
|
182
|
+
if (candidate.candidateId !== queue.activeWarrant?.candidateId)
|
|
183
|
+
return queue.activeWarrant
|
|
184
|
+
? wait("another-candidate-active")
|
|
185
|
+
: { operation: "select", reason: "candidate-queued" };
|
|
186
|
+
if (queue.activeWarrant.phase === "provisional")
|
|
187
|
+
return {
|
|
188
|
+
operation: "qualify-native",
|
|
189
|
+
reason: "independent-native-proof-required",
|
|
190
|
+
};
|
|
191
|
+
if (!evidence.qualification)
|
|
192
|
+
return wait("qualified-warrant-readback-required");
|
|
193
|
+
return { operation: "land", reason: "protected-queue-admission" };
|
|
194
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { recoveryInputs } from "../../consumer/contract/entries.js";
|
|
2
|
+
import { pipelineHost } from "./host.js";
|
|
3
|
+
import { controlPipelineRecovery } from "./recovery-controller.js";
|
|
4
|
+
import { pipelineActionOutputs } from "./action-output.js";
|
|
5
|
+
import { resumePipelineSession } from "./session.js";
|
|
6
|
+
|
|
7
|
+
export async function recoverPipelineAction(core, env) {
|
|
8
|
+
const { attempt } = recoveryInputs({
|
|
9
|
+
attempt: core.getInput("attempt", { required: true }),
|
|
10
|
+
});
|
|
11
|
+
const host = await pipelineHost(core, env, "Buildchain recovery controller");
|
|
12
|
+
try {
|
|
13
|
+
const result = await controlPipelineRecovery(
|
|
14
|
+
attempt,
|
|
15
|
+
core.getInput("definition-sha", { required: true }),
|
|
16
|
+
host,
|
|
17
|
+
);
|
|
18
|
+
pipelineActionOutputs(core, result);
|
|
19
|
+
} catch (error) {
|
|
20
|
+
try {
|
|
21
|
+
const session = await resumePipelineSession({ ...host, attempt }, host);
|
|
22
|
+
await host.project(session);
|
|
23
|
+
} catch {
|
|
24
|
+
core.warning(
|
|
25
|
+
"Recovery status projection is unavailable; the canonical attempt remains authoritative.",
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
throw error;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { recordDigest } from "../../release/discussion/envelope.js";
|
|
2
|
+
import { readPipelineCaller } from "../../providers/github/pipeline-run-entry.js";
|
|
3
|
+
import { RECOVERY_ENTRY } from "../../consumer/contract/entries.js";
|
|
4
|
+
|
|
5
|
+
export async function recoveryExecution(host, definitionSha) {
|
|
6
|
+
const { run } = await host.runs.read(host.runId, host.runAttempt);
|
|
7
|
+
const definitions = (run.referenced_workflows || []).filter((item) =>
|
|
8
|
+
item.path?.startsWith(`kungfu-systems/buildchain/${RECOVERY_ENTRY}@`),
|
|
9
|
+
);
|
|
10
|
+
if (
|
|
11
|
+
run.event !== "workflow_dispatch" ||
|
|
12
|
+
run.status !== "in_progress" ||
|
|
13
|
+
run.repository?.full_name !== host.repository ||
|
|
14
|
+
run.head_repository?.full_name !== host.repository ||
|
|
15
|
+
run.path?.split("@")[0] !== ".github/workflows/buildchain-recover.yml" ||
|
|
16
|
+
definitions.length !== 1 ||
|
|
17
|
+
definitions[0].sha !== definitionSha ||
|
|
18
|
+
!/^[0-9a-f]{40}$/u.test(definitionSha || "")
|
|
19
|
+
)
|
|
20
|
+
throw new Error(
|
|
21
|
+
"Recovery must execute the exact canonical entry from the same consumer repository",
|
|
22
|
+
);
|
|
23
|
+
const channel = definitions[0].path
|
|
24
|
+
.split("@")
|
|
25
|
+
.at(-1)
|
|
26
|
+
.replace(/^refs\/tags\//u, "");
|
|
27
|
+
if (!["v4", "v4-alpha"].includes(channel))
|
|
28
|
+
throw new Error("Recovery entry must be a published floating channel");
|
|
29
|
+
return {
|
|
30
|
+
run,
|
|
31
|
+
channel,
|
|
32
|
+
entry: {
|
|
33
|
+
repository: "kungfu-systems/buildchain",
|
|
34
|
+
workflow: RECOVERY_ENTRY,
|
|
35
|
+
sha: definitionSha,
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export async function admitRecoverySource(session, execution, host) {
|
|
41
|
+
const current = session.observed.history.at(-1);
|
|
42
|
+
const original = current.generation.source;
|
|
43
|
+
const source = await host.source.source(original.commit, original.configPath);
|
|
44
|
+
if (
|
|
45
|
+
recordDigest(source.identity) !== recordDigest(original) ||
|
|
46
|
+
host.selection.source?.sha !== original.commit ||
|
|
47
|
+
host.selection.source?.repository !== host.repository
|
|
48
|
+
)
|
|
49
|
+
throw new Error(
|
|
50
|
+
"Recovery source, config or selected runtime source changed",
|
|
51
|
+
);
|
|
52
|
+
const caller = await readPipelineCaller(
|
|
53
|
+
execution.run,
|
|
54
|
+
original.configPath,
|
|
55
|
+
host.request,
|
|
56
|
+
host.repository,
|
|
57
|
+
);
|
|
58
|
+
const admission = await host.source.observeIntent(
|
|
59
|
+
session.intent,
|
|
60
|
+
current.generation,
|
|
61
|
+
{ "config-path": original.configPath },
|
|
62
|
+
);
|
|
63
|
+
if (
|
|
64
|
+
!admission.live.source ||
|
|
65
|
+
recordDigest(admission.live.source) !== recordDigest(original) ||
|
|
66
|
+
admission.live.targetBranch !== session.intent.source.targetBranch ||
|
|
67
|
+
(!admission.live.merged &&
|
|
68
|
+
(admission.live.state !== "open" ||
|
|
69
|
+
admission.live.routeEnabled === false ||
|
|
70
|
+
admission.live.baseCommit !== current.generation.baseCommit))
|
|
71
|
+
)
|
|
72
|
+
throw new Error(
|
|
73
|
+
"Selected source was closed, superseded or rebased; use its current admitted attempt",
|
|
74
|
+
);
|
|
75
|
+
return {
|
|
76
|
+
source,
|
|
77
|
+
admission,
|
|
78
|
+
caller,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export async function recoveryPredecessorRuns(session, host) {
|
|
83
|
+
const current = session.observed.history.at(-1);
|
|
84
|
+
const keys = [
|
|
85
|
+
...new Map(
|
|
86
|
+
current.runs.map((writer) => [
|
|
87
|
+
`${writer.runId}:${writer.runAttempt}`,
|
|
88
|
+
writer,
|
|
89
|
+
]),
|
|
90
|
+
).values(),
|
|
91
|
+
];
|
|
92
|
+
if (keys.length > 100)
|
|
93
|
+
throw new Error("Recovery predecessor run inventory exceeds its bound");
|
|
94
|
+
const observations = [];
|
|
95
|
+
for (const writer of keys) {
|
|
96
|
+
if (
|
|
97
|
+
Number(writer.runId) === host.runId &&
|
|
98
|
+
Number(writer.runAttempt) === host.runAttempt
|
|
99
|
+
)
|
|
100
|
+
throw new Error("Recovery cannot replace its own live execution");
|
|
101
|
+
const { run } = await host.runs.read(
|
|
102
|
+
Number(writer.runId),
|
|
103
|
+
Number(writer.runAttempt),
|
|
104
|
+
);
|
|
105
|
+
if (
|
|
106
|
+
run.repository?.full_name !== host.repository ||
|
|
107
|
+
run.head_repository?.full_name !== host.repository
|
|
108
|
+
)
|
|
109
|
+
throw new Error(
|
|
110
|
+
"Recovery predecessor execution crossed a repository or fork boundary",
|
|
111
|
+
);
|
|
112
|
+
observations.push(run);
|
|
113
|
+
}
|
|
114
|
+
return {
|
|
115
|
+
schema: "buildchain.pipeline-recovery-executions/v1",
|
|
116
|
+
predecessor: current.identity.id,
|
|
117
|
+
runs: observations,
|
|
118
|
+
terminal: observations.every(
|
|
119
|
+
(run) => run.status === "completed" && run.conclusion,
|
|
120
|
+
),
|
|
121
|
+
};
|
|
122
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { object } from "../../consumer/contract/shape.js";
|
|
2
|
+
import { recordDigest } from "../../release/discussion/envelope.js";
|
|
3
|
+
import { resumePipelineSession } from "./session.js";
|
|
4
|
+
import { recoveryBuildEvidence } from "./recovery-build-evidence.js";
|
|
5
|
+
import { qualifyPipelineBuild } from "./build-qualification.js";
|
|
6
|
+
import { retainPipelineBuildResult } from "./build-result.js";
|
|
7
|
+
|
|
8
|
+
export const RECOVERY_BUILD_CONTEXT =
|
|
9
|
+
"buildchain.pipeline-recovery-build-context/v1";
|
|
10
|
+
|
|
11
|
+
export async function beginRecoveryBuild(session, host) {
|
|
12
|
+
session.observed = await session.journal.read();
|
|
13
|
+
const { plan, build } = await recoveryBuildEvidence(session, host);
|
|
14
|
+
const observed = session.observed;
|
|
15
|
+
const previous = observed.phases.build;
|
|
16
|
+
if (
|
|
17
|
+
previous &&
|
|
18
|
+
(previous.payload.writer.runId !== String(host.runId) ||
|
|
19
|
+
previous.payload.writer.runAttempt !== String(host.runAttempt))
|
|
20
|
+
)
|
|
21
|
+
return null;
|
|
22
|
+
await session.progress.progress({
|
|
23
|
+
attempt: observed.attempt,
|
|
24
|
+
phase: "build",
|
|
25
|
+
state: "running",
|
|
26
|
+
eventKey: `build-start:${host.runId}:${host.runAttempt}`,
|
|
27
|
+
expectedHead: observed.head,
|
|
28
|
+
reason: build.reason,
|
|
29
|
+
});
|
|
30
|
+
return {
|
|
31
|
+
schema: RECOVERY_BUILD_CONTEXT,
|
|
32
|
+
attempt: observed.attempt,
|
|
33
|
+
generation: observed.generation,
|
|
34
|
+
source: build.source,
|
|
35
|
+
runId: host.runId,
|
|
36
|
+
runAttempt: host.runAttempt,
|
|
37
|
+
platforms: build.scheduled,
|
|
38
|
+
recoveryPlanRoot: plan.root,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export async function recordRecoveryBuild(context, host) {
|
|
43
|
+
object(context, [
|
|
44
|
+
"schema",
|
|
45
|
+
"attempt",
|
|
46
|
+
"generation",
|
|
47
|
+
"source",
|
|
48
|
+
"runId",
|
|
49
|
+
"runAttempt",
|
|
50
|
+
"platforms",
|
|
51
|
+
"recoveryPlanRoot",
|
|
52
|
+
]);
|
|
53
|
+
if (
|
|
54
|
+
context.schema !== RECOVERY_BUILD_CONTEXT ||
|
|
55
|
+
context.runId !== host.runId ||
|
|
56
|
+
context.runAttempt !== host.runAttempt
|
|
57
|
+
)
|
|
58
|
+
throw new Error("Recovery build callback belongs to another execution");
|
|
59
|
+
const session = await resumePipelineSession(
|
|
60
|
+
{ ...host, attempt: context.attempt },
|
|
61
|
+
host,
|
|
62
|
+
);
|
|
63
|
+
const { plan, build } = await recoveryBuildEvidence(session, host);
|
|
64
|
+
const writer = session.observed.phases.build?.payload.writer;
|
|
65
|
+
if (
|
|
66
|
+
context.generation !== session.observed.generation ||
|
|
67
|
+
context.recoveryPlanRoot !== plan.root ||
|
|
68
|
+
recordDigest(context.source) !== recordDigest(build.source) ||
|
|
69
|
+
recordDigest(context.platforms) !== recordDigest(build.scheduled) ||
|
|
70
|
+
writer?.runId !== String(host.runId) ||
|
|
71
|
+
writer?.runAttempt !== String(host.runAttempt)
|
|
72
|
+
)
|
|
73
|
+
throw new Error(
|
|
74
|
+
"Recovery build callback changed its reserved work or admission",
|
|
75
|
+
);
|
|
76
|
+
const segments = structuredClone(build.segments);
|
|
77
|
+
if (build.scheduled.length) {
|
|
78
|
+
const platforms = build.scheduled.map((item) => item.platform);
|
|
79
|
+
const readback = await host.runs.build(
|
|
80
|
+
host.runId,
|
|
81
|
+
host.runAttempt,
|
|
82
|
+
build.source,
|
|
83
|
+
platforms,
|
|
84
|
+
);
|
|
85
|
+
segments.push({ readback, platforms, runtime: host.runtime });
|
|
86
|
+
}
|
|
87
|
+
const result = qualifyPipelineBuild({
|
|
88
|
+
source: build.source,
|
|
89
|
+
platforms: build.platforms.map((item) => item.platform),
|
|
90
|
+
segments,
|
|
91
|
+
runId: host.runId,
|
|
92
|
+
runAttempt: host.runAttempt,
|
|
93
|
+
});
|
|
94
|
+
return retainPipelineBuildResult(context, result, session, host);
|
|
95
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { recordDigest } from "../../release/discussion/envelope.js";
|
|
2
|
+
import { retainedRecoveryEvidence } from "./recovery-session.js";
|
|
3
|
+
import { pipelinePlatforms } from "./platforms.js";
|
|
4
|
+
import { buildReadbackPlatforms } from "./build-qualification.js";
|
|
5
|
+
import { qualifyRecoveryRuntime } from "./recovery-runtime.js";
|
|
6
|
+
|
|
7
|
+
export async function recoveryBuildEvidence(session, host) {
|
|
8
|
+
const { plan, evidence } = await retainedRecoveryEvidence(session, host);
|
|
9
|
+
const build = evidence.build;
|
|
10
|
+
if (!build) throw new Error("Recovery admission has no qualified build plan");
|
|
11
|
+
const { root, ...body } = build;
|
|
12
|
+
const current = session.observed.history.at(-1);
|
|
13
|
+
const source = await host.source.source(
|
|
14
|
+
current.generation.source.commit,
|
|
15
|
+
current.generation.source.configPath,
|
|
16
|
+
);
|
|
17
|
+
if (
|
|
18
|
+
root !== recordDigest(body) ||
|
|
19
|
+
body.schema !== "buildchain.pipeline-recovery-build/v1" ||
|
|
20
|
+
body.predecessor !== plan.predecessor ||
|
|
21
|
+
recordDigest(body.source) !== recordDigest(current.generation.source) ||
|
|
22
|
+
recordDigest(source.identity) !== recordDigest(body.source) ||
|
|
23
|
+
recordDigest(pipelinePlatforms(source.plan)) !==
|
|
24
|
+
recordDigest(body.platforms) ||
|
|
25
|
+
recordDigest(host.runtime) !== recordDigest(plan.runtime)
|
|
26
|
+
)
|
|
27
|
+
throw new Error(
|
|
28
|
+
"Recovery build plan changed its source, platform inventory or executor",
|
|
29
|
+
);
|
|
30
|
+
const selected = new Set();
|
|
31
|
+
for (const segment of build.segments) {
|
|
32
|
+
const old = segment.readback;
|
|
33
|
+
const inventory = buildReadbackPlatforms(old);
|
|
34
|
+
const fresh = await host.runs.build(
|
|
35
|
+
old.runId,
|
|
36
|
+
old.runAttempt,
|
|
37
|
+
build.source,
|
|
38
|
+
inventory,
|
|
39
|
+
);
|
|
40
|
+
const runtime = await qualifyRecoveryRuntime(
|
|
41
|
+
segment.runtime,
|
|
42
|
+
host.runtime,
|
|
43
|
+
"build",
|
|
44
|
+
host.request,
|
|
45
|
+
);
|
|
46
|
+
if (recordDigest(fresh) !== recordDigest(old) || !runtime.compatible)
|
|
47
|
+
throw new Error(
|
|
48
|
+
"Recovered platform changed during execution requalification",
|
|
49
|
+
);
|
|
50
|
+
for (const platform of segment.platforms) {
|
|
51
|
+
const job = old.jobs[inventory.indexOf(platform)];
|
|
52
|
+
if (
|
|
53
|
+
selected.has(platform) ||
|
|
54
|
+
job?.status !== "completed" ||
|
|
55
|
+
job.conclusion !== "success"
|
|
56
|
+
)
|
|
57
|
+
throw new Error(
|
|
58
|
+
"Recovery cannot reuse duplicate or unsuccessful platform results",
|
|
59
|
+
);
|
|
60
|
+
selected.add(platform);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
if (
|
|
64
|
+
recordDigest(build.scheduled) !==
|
|
65
|
+
recordDigest(build.platforms.filter((item) => !selected.has(item.platform)))
|
|
66
|
+
)
|
|
67
|
+
throw new Error(
|
|
68
|
+
"Recovery scheduling differs from the qualified remaining platform set",
|
|
69
|
+
);
|
|
70
|
+
return { plan, build };
|
|
71
|
+
}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { recordDigest } from "../../release/discussion/envelope.js";
|
|
2
|
+
import { pipelinePlatforms } from "./platforms.js";
|
|
3
|
+
import { qualifyRecoveryRuntime } from "./recovery-runtime.js";
|
|
4
|
+
import { unrecordedRecoveryBuild } from "./recovery-unrecorded-build.js";
|
|
5
|
+
import {
|
|
6
|
+
PIPELINE_BUILD_QUALIFICATION,
|
|
7
|
+
buildReadbackPlatforms,
|
|
8
|
+
verifyPipelineBuildQualification,
|
|
9
|
+
qualifyPipelineBuild,
|
|
10
|
+
} from "./build-qualification.js";
|
|
11
|
+
|
|
12
|
+
async function retainedSegments(session, source, platforms, host) {
|
|
13
|
+
const phase = session.observed.history.at(-1).phases.build;
|
|
14
|
+
const references = (phase?.payload.materials || []).filter(
|
|
15
|
+
(item) =>
|
|
16
|
+
item.id.startsWith("build/provider-") ||
|
|
17
|
+
item.id.startsWith("build/qualified-"),
|
|
18
|
+
);
|
|
19
|
+
if (!references.length && phase?.payload.state !== "success")
|
|
20
|
+
return unrecordedRecoveryBuild(session, source, platforms, host);
|
|
21
|
+
if (references.length !== 1)
|
|
22
|
+
throw new Error(
|
|
23
|
+
"Recovery cannot qualify the unique retained build receipt",
|
|
24
|
+
);
|
|
25
|
+
const value = await host.materialStore(session).read(references[0]);
|
|
26
|
+
if (value.schema === PIPELINE_BUILD_QUALIFICATION) {
|
|
27
|
+
await verifyPipelineBuildQualification(value, source, platforms, host.runs);
|
|
28
|
+
return value.segments;
|
|
29
|
+
}
|
|
30
|
+
const inventory = buildReadbackPlatforms(value);
|
|
31
|
+
if (
|
|
32
|
+
recordDigest(value.source) !== recordDigest(source) ||
|
|
33
|
+
recordDigest([...inventory].sort()) !== recordDigest([...platforms].sort())
|
|
34
|
+
)
|
|
35
|
+
throw new Error(
|
|
36
|
+
"Recovery build receipt changed its original platform inventory",
|
|
37
|
+
);
|
|
38
|
+
const fresh = await host.runs.build(
|
|
39
|
+
value.runId,
|
|
40
|
+
value.runAttempt,
|
|
41
|
+
source,
|
|
42
|
+
inventory,
|
|
43
|
+
);
|
|
44
|
+
if (recordDigest(fresh) !== recordDigest(value))
|
|
45
|
+
throw new Error("Recovery build receipt changed during provider readback");
|
|
46
|
+
const segments = [{ readback: value, platforms, runtime: phase.runtime }];
|
|
47
|
+
qualifyPipelineBuild({
|
|
48
|
+
source,
|
|
49
|
+
platforms,
|
|
50
|
+
segments,
|
|
51
|
+
runId: value.runId,
|
|
52
|
+
runAttempt: value.runAttempt,
|
|
53
|
+
});
|
|
54
|
+
return segments;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// Every retained segment is independently observed, even when its old overall
|
|
58
|
+
// workflow failed elsewhere. Only successful jobs with an unchanged execution
|
|
59
|
+
// implementation qualify for reuse. Missing evidence is not invented.
|
|
60
|
+
export async function qualifyRecoveryBuild(session, admission, host) {
|
|
61
|
+
const source = session.observed.history.at(-1).generation.source;
|
|
62
|
+
if (recordDigest(admission.identity) !== recordDigest(source))
|
|
63
|
+
throw new Error("Recovery build admission changed its exact source");
|
|
64
|
+
const platforms = pipelinePlatforms(admission.plan);
|
|
65
|
+
const prior = await retainedSegments(
|
|
66
|
+
session,
|
|
67
|
+
source,
|
|
68
|
+
platforms.map((item) => item.platform),
|
|
69
|
+
host,
|
|
70
|
+
);
|
|
71
|
+
const segments = [],
|
|
72
|
+
runtimes = [],
|
|
73
|
+
selected = new Set();
|
|
74
|
+
for (const segment of prior) {
|
|
75
|
+
const runtime = await qualifyRecoveryRuntime(
|
|
76
|
+
segment.runtime,
|
|
77
|
+
host.runtime,
|
|
78
|
+
"build",
|
|
79
|
+
host.request,
|
|
80
|
+
);
|
|
81
|
+
runtimes.push(runtime);
|
|
82
|
+
const inventory = buildReadbackPlatforms(segment.readback);
|
|
83
|
+
const reusable = segment.platforms.filter((platform) => {
|
|
84
|
+
const job = segment.readback.jobs[inventory.indexOf(platform)];
|
|
85
|
+
return (
|
|
86
|
+
runtime.compatible &&
|
|
87
|
+
job.status === "completed" &&
|
|
88
|
+
job.conclusion === "success"
|
|
89
|
+
);
|
|
90
|
+
});
|
|
91
|
+
if (reusable.length) {
|
|
92
|
+
for (const platform of reusable) {
|
|
93
|
+
if (
|
|
94
|
+
selected.has(platform) ||
|
|
95
|
+
!platforms.some((item) => item.platform === platform)
|
|
96
|
+
)
|
|
97
|
+
throw new Error(
|
|
98
|
+
"Recovery build has duplicate or undeclared retained platforms",
|
|
99
|
+
);
|
|
100
|
+
selected.add(platform);
|
|
101
|
+
}
|
|
102
|
+
segments.push({ ...segment, platforms: reusable });
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
const body = {
|
|
106
|
+
schema: "buildchain.pipeline-recovery-build/v1",
|
|
107
|
+
predecessor: session.observed.attempt,
|
|
108
|
+
predecessorHead: session.observed.head,
|
|
109
|
+
source,
|
|
110
|
+
platforms,
|
|
111
|
+
scheduled: platforms.filter((item) => !selected.has(item.platform)),
|
|
112
|
+
segments,
|
|
113
|
+
runtimes,
|
|
114
|
+
reason: !prior.length
|
|
115
|
+
? "No retained product result; execute declared platforms"
|
|
116
|
+
: runtimes.some((item) => !item.compatible)
|
|
117
|
+
? "Changed stage implementation requires affected platform execution"
|
|
118
|
+
: "Reuse independently verified successful platforms; execute only missing results",
|
|
119
|
+
};
|
|
120
|
+
return { ...body, root: recordDigest(body) };
|
|
121
|
+
}
|