@patronage/factory-ci 1.0.0-alpha.4 → 1.0.0-alpha.40
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/README.md +712 -10
- package/dist/.build-fingerprint.json +3 -0
- package/dist/alchemy/index.d.ts +1174 -0
- package/dist/alchemy/index.js +2142 -0
- package/dist/bundle-alchemy-entry-CT5hCphA.js +112 -0
- package/dist/execute-alchemy-entry-B397GSk5.d.ts +134 -0
- package/dist/execute-alchemy-entry-CZ7Knz4q.js +160 -0
- package/dist/index.d.ts +1205 -87
- package/dist/index.js +2752 -317
- package/package.json +28 -10
- package/src/actions.ts +13 -0
- package/src/alchemy/child-diagnostics.ts +148 -0
- package/src/alchemy/credential-preflight.ts +428 -0
- package/src/alchemy/destroy-postcondition.ts +103 -0
- package/src/alchemy/evaluate-stack.ts +153 -0
- package/src/alchemy/first-deploy-authorization.ts +194 -0
- package/src/alchemy/index.ts +144 -0
- package/src/alchemy/lifecycle-failure.ts +174 -0
- package/src/alchemy/lifecycle.ts +1330 -0
- package/src/alchemy/local-emulation.ts +89 -0
- package/src/alchemy/plan-effects.ts +510 -0
- package/src/alchemy/retained-identity.ts +248 -0
- package/src/alchemy/secret-name-policy.ts +96 -0
- package/src/alchemy/stage-policy.ts +269 -0
- package/src/alchemy/state-tree.ts +168 -0
- package/src/alchemy/url-implies-auth.ts +264 -0
- package/src/alchemy-baseline.ts +75 -0
- package/src/bundle-alchemy-entry.ts +5 -0
- package/src/candidate-impact-workflow.ts +110 -0
- package/src/candidate-lifecycle.ts +29 -0
- package/src/cursor-oidc.ts +33 -0
- package/src/execute-alchemy-entry.ts +128 -8
- package/src/factory-workflow.ts +83 -40
- package/src/github-app-token.ts +92 -18
- package/src/github-transport.ts +186 -0
- package/src/impact-demand-condition.ts +67 -0
- package/src/index.ts +174 -0
- package/src/lifecycle-contract-lane.ts +113 -0
- package/src/merge-freeze-job.ts +253 -0
- package/src/pinned-action.ts +30 -0
- package/src/pr-status-hud-workflow.ts +96 -0
- package/src/preview-cleanup-topology.ts +115 -0
- package/src/preview-proof-inventory.ts +1092 -0
- package/src/preview-proof-lifecycle.ts +328 -0
- package/src/preview-receipt-workflow.ts +83 -0
- package/src/production-impact-workflow.ts +181 -0
- package/src/proof-reuse-gate.ts +223 -48
- package/src/proof-reuse-presentation.ts +131 -0
- package/src/push-identity-workflow.ts +463 -0
- package/src/runnable-cli.ts +27 -0
- package/src/verify-runner-policy.ts +290 -0
- package/src/vitest-profile-reader.test.ts +208 -0
- package/src/vitest-profile-reader.ts +225 -0
- package/src/vitest-profile.ts +631 -0
package/src/proof-reuse-gate.ts
CHANGED
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
*
|
|
4
4
|
* It answers one question, before checkout and before install: may this job
|
|
5
5
|
* reuse the local verification the factory already published for *this exact
|
|
6
|
-
* head*?
|
|
6
|
+
* head*? It asks that only on a pull request, so every default-branch push
|
|
7
|
+
* executes the full hosted suite (#863). Refusing runs hosted CI; it never
|
|
8
|
+
* fails the candidate. Three
|
|
7
9
|
* repositories had independently grown their own answer to that question and
|
|
8
10
|
* had already drifted apart, so the answer lives here once, with the App
|
|
9
11
|
* identity, check name, step identity, output names, guard, and every trust
|
|
@@ -57,6 +59,15 @@ export const FACTORY_PROOF_GATE_APP_ID = "4314840";
|
|
|
57
59
|
/** Step id the guard condition refers to. */
|
|
58
60
|
export const FACTORY_PROOF_GATE_STEP_ID = "factory-proof";
|
|
59
61
|
|
|
62
|
+
/**
|
|
63
|
+
* Human-visible name of the gate step as the Actions jobs API serves it. A
|
|
64
|
+
* read-only run analyzer (`psf ci:analyze`, #647) matches on this name to
|
|
65
|
+
* classify a run as proof-reuse versus full fallback, so it is exported from
|
|
66
|
+
* exactly the module that writes it — matching on a re-typed copy would drift.
|
|
67
|
+
*/
|
|
68
|
+
export const FACTORY_PROOF_GATE_STEP_NAME =
|
|
69
|
+
"Check for factory proof of this head";
|
|
70
|
+
|
|
60
71
|
/**
|
|
61
72
|
* The shell the gate runs under, and it is a correctness requirement rather
|
|
62
73
|
* than a preference.
|
|
@@ -98,6 +109,9 @@ export const FACTORY_PROOF_GATE_REASON_OUTPUT = "reason";
|
|
|
98
109
|
*/
|
|
99
110
|
export const FACTORY_PROOF_GATE_MODE_OUTPUT = "mode";
|
|
100
111
|
|
|
112
|
+
/** Exact Checks API URL of the proof generation selected by the gate. */
|
|
113
|
+
export const FACTORY_PROOF_GATE_SOURCE_URL_OUTPUT = "source-check-url";
|
|
114
|
+
|
|
101
115
|
/**
|
|
102
116
|
* Guard for every step the gate protects. Deliberately `!= 'true'` and not
|
|
103
117
|
* `== 'false'`: an unset, empty, or garbled output must run the suite.
|
|
@@ -105,22 +119,33 @@ export const FACTORY_PROOF_GATE_MODE_OUTPUT = "mode";
|
|
|
105
119
|
export const FACTORY_PROOF_GATE_GUARD = `steps.${FACTORY_PROOF_GATE_STEP_ID}.outputs.${FACTORY_PROOF_GATE_OUTPUT} != 'true'`;
|
|
106
120
|
|
|
107
121
|
/**
|
|
108
|
-
* Pull requests only
|
|
109
|
-
*
|
|
110
|
-
*
|
|
122
|
+
* Pull requests only — the gate's single condition (#873, default since #863,
|
|
123
|
+
* the only mode since the merge-target opt-out was deleted).
|
|
124
|
+
*
|
|
125
|
+
* A merge target's guarantee is about the whole tree, not the diff. A
|
|
126
|
+
* candidate proof only ever binds the diff the candidate was scoped to, so
|
|
127
|
+
* reusing it on the merged commit proves less than the merge target needs.
|
|
128
|
+
* #931 is that defect observed — a `main` push reused a candidate proof,
|
|
129
|
+
* executed no command, and left a red package unnoticed for three days. Every
|
|
130
|
+
* default-branch push therefore executes the full hosted suite, whatever
|
|
131
|
+
* proof exists.
|
|
132
|
+
*
|
|
133
|
+
* Which branches trigger the workflow at all stays repository-owned. This
|
|
134
|
+
* condition only keeps the gate from consulting proof outside a pull request.
|
|
111
135
|
*/
|
|
112
136
|
export const FACTORY_PROOF_GATE_IF = "github.event_name == 'pull_request'";
|
|
113
137
|
|
|
114
138
|
/**
|
|
115
139
|
* The complete refusal vocabulary. Deliberately few, because these are the
|
|
116
|
-
* only distinctions the gate can honestly make from
|
|
140
|
+
* only distinctions the gate can honestly make from its Checks API reads.
|
|
117
141
|
*
|
|
118
142
|
* - `proven` a covering, passing, unambiguous proof for this exact head
|
|
119
143
|
* - `none` no App-verified factory check run at this commit
|
|
120
144
|
* - `pending` the newest generation had not completed when this job read it
|
|
121
145
|
* - `failed` the newest generation records no pass
|
|
122
146
|
* - `unreadable` it passed but carries no binding for this repository and head
|
|
123
|
-
* - `incomplete`
|
|
147
|
+
* - `incomplete` its executed plus stamp-authorized released commands do not
|
|
148
|
+
* cover every required command
|
|
124
149
|
* - `ambiguous` two newest generations share the greatest start time
|
|
125
150
|
* - `error` the gate could not reach a decision (fail open)
|
|
126
151
|
*
|
|
@@ -170,6 +195,14 @@ export interface ProofReuseCommand {
|
|
|
170
195
|
const COMMAND_IDENTITY = /^\w[\w.:@/-]*$/u;
|
|
171
196
|
const COMMAND_IDENTITY_MAX_LENGTH = 120;
|
|
172
197
|
|
|
198
|
+
/**
|
|
199
|
+
* The impact-stamp interpretation the paired factory packages currently
|
|
200
|
+
* share. A release recorded under any other version is an unmodelled input and
|
|
201
|
+
* cannot subtract hosted work. This is intentionally fail-closed and moves in
|
|
202
|
+
* lockstep with the proof/check-payload producer.
|
|
203
|
+
*/
|
|
204
|
+
const TRUSTED_IMPACT_STAMP_VERSION = 4;
|
|
205
|
+
|
|
173
206
|
const isProofReuseCommand = (value: unknown): value is ProofReuseCommand => {
|
|
174
207
|
if (!(value && typeof value === "object")) {
|
|
175
208
|
return false;
|
|
@@ -216,8 +249,53 @@ export const proofReuseRequiredCommands = (
|
|
|
216
249
|
};
|
|
217
250
|
|
|
218
251
|
/**
|
|
219
|
-
*
|
|
220
|
-
*
|
|
252
|
+
* Resolve command *identities* to their `ProofReuseCommand` objects (ADR
|
|
253
|
+
* 0021).
|
|
254
|
+
*
|
|
255
|
+
* Selection by name is deliberately a consumer decision (proof-surfaces.ts in
|
|
256
|
+
* software-factory-hq, the `paitronage:verify` filter in paitronage's
|
|
257
|
+
* `verify.ts`): only the consumer knows which named commands a guarded
|
|
258
|
+
* surface requires. What both of those implementations independently
|
|
259
|
+
* hand-rolled is the same lookup — find each name in the profile's command
|
|
260
|
+
* catalog, and refuse to silently shrink the required set when a name has no
|
|
261
|
+
* entry. That lookup is what this function is: the mechanic, not the
|
|
262
|
+
* selection.
|
|
263
|
+
*
|
|
264
|
+
* Throwing at generation time (rather than returning `undefined` or an empty
|
|
265
|
+
* array) is deliberate: a name with no catalog entry is a mistake in the
|
|
266
|
+
* generator source, not a runtime condition a consumer should have to check
|
|
267
|
+
* for, and a required set that quietly loses an entry is exactly what makes a
|
|
268
|
+
* passing proof trivially "covering".
|
|
269
|
+
*
|
|
270
|
+
* `selectionLabel` names the failure, nothing else: it is not part of the
|
|
271
|
+
* selection this function resolves, only prose a consumer supplies for its
|
|
272
|
+
* own thrown error (e.g. HQ's surface name, "core" or "docs"). The message
|
|
273
|
+
* deliberately says "the profile's command catalog" rather than naming
|
|
274
|
+
* `software-factory.profile.json`: a fleet-generic library must not assume
|
|
275
|
+
* every consumer's catalog is that exact file, so this wording differs
|
|
276
|
+
* on purpose from the HQ-local message it replaced.
|
|
277
|
+
*/
|
|
278
|
+
export const resolveProofReuseCommands = (
|
|
279
|
+
catalog: readonly ProofReuseCommand[],
|
|
280
|
+
names: readonly string[],
|
|
281
|
+
selectionLabel?: string
|
|
282
|
+
): readonly ProofReuseCommand[] =>
|
|
283
|
+
names.map((name) => {
|
|
284
|
+
const command = catalog.find((entry) => entry.name === name);
|
|
285
|
+
if (!command) {
|
|
286
|
+
const location = selectionLabel
|
|
287
|
+
? `Proof-reuse selection for the ${selectionLabel} surface names`
|
|
288
|
+
: "Proof-reuse selection names";
|
|
289
|
+
throw new Error(
|
|
290
|
+
`${location} "${name}", which the profile's command catalog does not define.`
|
|
291
|
+
);
|
|
292
|
+
}
|
|
293
|
+
return { command: command.command, name: command.name };
|
|
294
|
+
});
|
|
295
|
+
|
|
296
|
+
/**
|
|
297
|
+
* jq program: every page of the Checks API result in, four sanitized lines
|
|
298
|
+
* (`reason`, `mode`, uncovered commands, source URL) out.
|
|
221
299
|
*
|
|
222
300
|
* The input is what `gh api --paginate` actually writes: the pages
|
|
223
301
|
* *concatenated* as a stream of top-level response objects, not merged into
|
|
@@ -274,6 +352,20 @@ def startedAt: (.started_at // "") | tostring;
|
|
|
274
352
|
def rankable:
|
|
275
353
|
test("^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}(\\.[0-9]+)?Z$");
|
|
276
354
|
|
|
355
|
+
def nonemptyString:
|
|
356
|
+
type == "string" and length > 0;
|
|
357
|
+
|
|
358
|
+
def distinctNames:
|
|
359
|
+
(map(.name) | length) == (map(.name) | unique | length);
|
|
360
|
+
|
|
361
|
+
def releaseAuthorized($release; $commands; $stamp):
|
|
362
|
+
([ $commands[] | select(.name == $release.name) ]) as $commandRows
|
|
363
|
+
| ([ $stamp.targets[] | select(.name == $release.impactTarget) ]) as $targetRows
|
|
364
|
+
| ($commandRows | length) == 1
|
|
365
|
+
and $commandRows[0].impactTarget == $release.impactTarget
|
|
366
|
+
and ($targetRows | length) == 1
|
|
367
|
+
and $targetRows[0].impact == "not-affected";
|
|
368
|
+
|
|
277
369
|
[ .[]
|
|
278
370
|
| (.check_runs // [])[]
|
|
279
371
|
| select(.name == $name)
|
|
@@ -281,20 +373,62 @@ def rankable:
|
|
|
281
373
|
| { started: startedAt,
|
|
282
374
|
status: (.status // ""),
|
|
283
375
|
conclusion: (.conclusion // ""),
|
|
376
|
+
url: ((.html_url // "") | tostring),
|
|
284
377
|
binding: binding }
|
|
285
378
|
] as $runs
|
|
286
379
|
| ($runs | map(.started | rankable) | all) as $orderable
|
|
287
380
|
| ($runs | map(.started | sub("\\.[0-9]+Z$"; "Z")) | max) as $newest
|
|
288
381
|
| [ $runs[] | select((.started | sub("\\.[0-9]+Z$"; "Z")) == $newest) ] as $generation
|
|
289
|
-
| (if ($runs | length) == 0 then ["none", "", ""]
|
|
290
|
-
elif ($orderable | not) then ["ambiguous", "", ""]
|
|
291
|
-
elif ($generation | length) != 1 then ["ambiguous", "", ""]
|
|
382
|
+
| (if ($runs | length) == 0 then ["none", "", "", ""]
|
|
383
|
+
elif ($orderable | not) then ["ambiguous", "", "", ""]
|
|
384
|
+
elif ($generation | length) != 1 then ["ambiguous", "", "", ""]
|
|
292
385
|
else
|
|
293
386
|
$generation[0] as $run
|
|
294
387
|
| (if ($run.binding | type) == "object" then $run.binding else {} end) as $proof
|
|
295
388
|
| (($proof.mode // "") | tostring) as $mode
|
|
296
389
|
| (($proof.executedCommands // []) | map(select(type == "string"))) as $executed
|
|
297
|
-
| ($
|
|
390
|
+
| ($proof | has("notRequiredCommands")) as $hasReleases
|
|
391
|
+
| (if $hasReleases then $proof.notRequiredCommands else [] end) as $releases
|
|
392
|
+
| ($proof.verificationCommands // null) as $commands
|
|
393
|
+
| ($proof.impactStamp // null) as $stamp
|
|
394
|
+
| (if ($hasReleases | not) then true
|
|
395
|
+
else
|
|
396
|
+
($proof.proofSchemaVersion == 4)
|
|
397
|
+
and ($releases | type) == "array"
|
|
398
|
+
and ($releases | length) > 0
|
|
399
|
+
and ($releases | all(.[];
|
|
400
|
+
type == "object"
|
|
401
|
+
and (.name | nonemptyString)
|
|
402
|
+
and (.impactTarget | nonemptyString)
|
|
403
|
+
and (.basis | nonemptyString)))
|
|
404
|
+
and ($releases | distinctNames)
|
|
405
|
+
and ($commands | type) == "array"
|
|
406
|
+
and ($commands | all(.[];
|
|
407
|
+
type == "object"
|
|
408
|
+
and (.name | nonemptyString)
|
|
409
|
+
and ((has("impactTarget") | not) or (.impactTarget | nonemptyString))))
|
|
410
|
+
and ($commands | distinctNames)
|
|
411
|
+
and ($stamp | type) == "object"
|
|
412
|
+
and ($stamp.stampVersion == ${TRUSTED_IMPACT_STAMP_VERSION})
|
|
413
|
+
and ($stamp.basis == "target-scoped")
|
|
414
|
+
and (($stamp.reasons | type) == "array")
|
|
415
|
+
and ($stamp.reasons | all(.[]; type == "string"))
|
|
416
|
+
and (($stamp.unsubscribedPaths | type) == "array")
|
|
417
|
+
and ($stamp.unsubscribedPaths | all(.[]; type == "string"))
|
|
418
|
+
and (($stamp.targets | type) == "array")
|
|
419
|
+
and ($stamp.targets | all(.[];
|
|
420
|
+
type == "object"
|
|
421
|
+
and (.name | nonemptyString)
|
|
422
|
+
and (.basis | nonemptyString)
|
|
423
|
+
and ((.impact == "affected") or (.impact == "not-affected"))
|
|
424
|
+
and ((.subscribedPaths | type) == "array")
|
|
425
|
+
and (.subscribedPaths | all(.[]; type == "string"))))
|
|
426
|
+
and ($stamp.targets | distinctNames)
|
|
427
|
+
and (([$releases[].name] - $executed | length) == ($releases | length))
|
|
428
|
+
and ($releases | all(.[]; releaseAuthorized(.; $commands; $stamp)))
|
|
429
|
+
end) as $releasesValid
|
|
430
|
+
| (if $releasesValid then [$releases[].name] else [] end) as $released
|
|
431
|
+
| ($required - $executed - $released) as $missing
|
|
298
432
|
| (if $run.status != "completed" then "pending"
|
|
299
433
|
elif $run.conclusion != "success" then "failed"
|
|
300
434
|
elif (($run.binding | type) != "object")
|
|
@@ -304,10 +438,11 @@ def rankable:
|
|
|
304
438
|
or ($proof.repository != $repository) then "unreadable"
|
|
305
439
|
elif $proof.outcome != "passed" then "failed"
|
|
306
440
|
elif ($required | length) == 0 then "incomplete"
|
|
441
|
+
elif ($releasesValid | not) then "incomplete"
|
|
307
442
|
elif ($missing | length) != 0 then "incomplete"
|
|
308
443
|
else "proven"
|
|
309
444
|
end) as $reason
|
|
310
|
-
| [$reason, $mode, ($missing | join(", "))]
|
|
445
|
+
| [$reason, $mode, ($missing | join(", ")), $run.url]
|
|
311
446
|
end)
|
|
312
447
|
| map(gsub("[\\r\\n\\t]"; " "))
|
|
313
448
|
| join("\n")
|
|
@@ -359,31 +494,42 @@ reason=error
|
|
|
359
494
|
detail=''
|
|
360
495
|
mode=''
|
|
361
496
|
missing=''
|
|
497
|
+
source_url=''
|
|
362
498
|
|
|
499
|
+
# One proof lookup at one commit. Sets lookup_reason / lookup_mode /
|
|
500
|
+
# lookup_missing / lookup_url, or lookup_detail when the read itself
|
|
501
|
+
# failed. Always returns 0: every caller must reach the single
|
|
502
|
+
# GITHUB_OUTPUT write below whatever this function meets.
|
|
503
|
+
#
|
|
363
504
|
# filter=all with full pagination is load-bearing (ADR 0022). GitHub's
|
|
364
505
|
# default "latest" filter is ordered by completion, so a newer generation
|
|
365
506
|
# that is still running can be hidden behind an older completed one — the
|
|
366
507
|
# gate would then read a stale pass as current.
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
508
|
+
gate_lookup() {
|
|
509
|
+
lookup_reason=error
|
|
510
|
+
lookup_mode=''
|
|
511
|
+
lookup_missing=''
|
|
512
|
+
lookup_url=''
|
|
513
|
+
lookup_detail=''
|
|
514
|
+
if ! lookup_response=$(gh api --method GET --paginate \
|
|
515
|
+
"repos/$GITHUB_REPOSITORY/commits/$1/check-runs" \
|
|
516
|
+
-f "check_name=$CHECK_NAME" \
|
|
517
|
+
-f filter=all \
|
|
518
|
+
-f per_page=100 2>&1); then
|
|
519
|
+
lookup_detail="checks API unreadable: $lookup_response"
|
|
520
|
+
return 0
|
|
521
|
+
fi
|
|
522
|
+
if ! lookup_finding=$(printf '%s' "$lookup_response" | jq -r -s \
|
|
523
|
+
--arg name "$CHECK_NAME" \
|
|
524
|
+
--arg app "$FACTORY_APP_ID" \
|
|
525
|
+
--arg sha "$1" \
|
|
526
|
+
--arg repository "$GITHUB_REPOSITORY" \
|
|
527
|
+
--argjson required "$REQUIRED_COMMANDS" \
|
|
528
|
+
'${GATE_JQ}' 2>&1); then
|
|
529
|
+
lookup_detail="unreadable proof binding: $lookup_finding"
|
|
530
|
+
return 0
|
|
531
|
+
fi
|
|
532
|
+
# Four separate reads, not one IFS split: tab is IFS whitespace, so a
|
|
387
533
|
# split would collapse the empty fields the vocabulary relies on.
|
|
388
534
|
#
|
|
389
535
|
# The trailing "|| :" on each read is load-bearing. "missing" is empty for
|
|
@@ -394,17 +540,32 @@ else
|
|
|
394
540
|
# GITHUB_OUTPUT write below, which is exactly how this gate failed in
|
|
395
541
|
# hosted CI on every decidable verdict while every test passed (#319).
|
|
396
542
|
{
|
|
397
|
-
IFS= read -r
|
|
398
|
-
IFS= read -r
|
|
399
|
-
IFS= read -r
|
|
400
|
-
|
|
401
|
-
|
|
543
|
+
IFS= read -r lookup_reason || :
|
|
544
|
+
IFS= read -r lookup_mode || :
|
|
545
|
+
IFS= read -r lookup_missing || :
|
|
546
|
+
IFS= read -r lookup_url || :
|
|
547
|
+
} <<< "$lookup_finding"
|
|
548
|
+
case "$lookup_reason" in
|
|
402
549
|
proven | none | pending | failed | unreadable | incomplete | ambiguous) ;;
|
|
403
550
|
*)
|
|
404
|
-
|
|
405
|
-
|
|
551
|
+
lookup_detail="unexpected gate result: $lookup_reason"
|
|
552
|
+
lookup_reason=error
|
|
406
553
|
;;
|
|
407
554
|
esac
|
|
555
|
+
return 0
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
if [ -z "${shellExpansion("HEAD_SHA:-")}" ]; then
|
|
559
|
+
detail='no verification head SHA'
|
|
560
|
+
elif [ -z "${shellExpansion("GITHUB_REPOSITORY:-")}" ]; then
|
|
561
|
+
detail='no repository name'
|
|
562
|
+
else
|
|
563
|
+
gate_lookup "$HEAD_SHA"
|
|
564
|
+
reason="$lookup_reason"
|
|
565
|
+
detail="$lookup_detail"
|
|
566
|
+
mode="$lookup_mode"
|
|
567
|
+
missing="$lookup_missing"
|
|
568
|
+
source_url="$lookup_url"
|
|
408
569
|
fi
|
|
409
570
|
|
|
410
571
|
# The binding is App-verified, but it still reaches markdown. Only a plain
|
|
@@ -423,6 +584,9 @@ fi
|
|
|
423
584
|
# line so it cannot restructure the summary it is written into.
|
|
424
585
|
detail=$(printf '%s' "$detail" | tr '\n\r\t' ' ' | cut -c1-240)
|
|
425
586
|
missing=$(printf '%s' "$missing" | tr '\n\r\t' ' ' | cut -c1-240)
|
|
587
|
+
if ! [[ "$source_url" =~ ^https://github\.com/[A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+/runs/[0-9]+$ ]]; then
|
|
588
|
+
source_url=''
|
|
589
|
+
fi
|
|
426
590
|
|
|
427
591
|
SUMMARY="${shellExpansion("GITHUB_STEP_SUMMARY:-/dev/null")}"
|
|
428
592
|
say() { printf '%s\n' "$1" >> "$SUMMARY"; }
|
|
@@ -433,9 +597,13 @@ say ''
|
|
|
433
597
|
case "$reason" in
|
|
434
598
|
proven)
|
|
435
599
|
echo "Factory proof: reusing local verification of $HEAD_SHA; skipping the $SURFACE suite."
|
|
436
|
-
say "Skipped. The factory already verified this exact
|
|
600
|
+
say "Skipped. The factory already verified this exact content, so this job did not run the $SURFACE suite a second time."
|
|
437
601
|
say ''
|
|
438
|
-
|
|
602
|
+
if [ -n "$source_url" ]; then
|
|
603
|
+
say "- Reused proof: [\`$CHECK_NAME\`]($source_url), published by the pinned factory GitHub App."
|
|
604
|
+
else
|
|
605
|
+
say "- Reused proof: the \`$CHECK_NAME\` check run published by the pinned factory GitHub App."
|
|
606
|
+
fi
|
|
439
607
|
say "- Covers head: \`$HEAD_SHA\`"
|
|
440
608
|
say "- Recorded mode: \`$mode\` (diagnostic only), outcome \`passed\`."
|
|
441
609
|
;;
|
|
@@ -470,7 +638,7 @@ case "$reason" in
|
|
|
470
638
|
incomplete)
|
|
471
639
|
say "Ran the full suite. The factory proof for this commit does not cover every command the $SURFACE surface requires."
|
|
472
640
|
say ''
|
|
473
|
-
say "The newest \`$CHECK_NAME\` check run at head \`$HEAD_SHA\` passed, but its \`
|
|
641
|
+
say "The newest \`$CHECK_NAME\` check run at head \`$HEAD_SHA\` passed, but its executed commands plus stamp-authorized \`notRequiredCommands\` do not cover this surface. Missing: \`$missing\`"
|
|
474
642
|
say ''
|
|
475
643
|
say '${CORRECTIVE_LINE}'
|
|
476
644
|
;;
|
|
@@ -501,6 +669,7 @@ fi
|
|
|
501
669
|
printf '${FACTORY_PROOF_GATE_OUTPUT}=%s\n' "$verdict"
|
|
502
670
|
printf '${FACTORY_PROOF_GATE_REASON_OUTPUT}=%s\n' "$reason"
|
|
503
671
|
printf '${FACTORY_PROOF_GATE_MODE_OUTPUT}=%s\n' "$mode"
|
|
672
|
+
printf '${FACTORY_PROOF_GATE_SOURCE_URL_OUTPUT}=%s\n' "$source_url"
|
|
504
673
|
} >> "${shellExpansion("GITHUB_OUTPUT:-/dev/null")}"
|
|
505
674
|
`.trim();
|
|
506
675
|
|
|
@@ -552,9 +721,10 @@ export interface FactoryProofGateStep {
|
|
|
552
721
|
|
|
553
722
|
/**
|
|
554
723
|
* The step itself, structurally accepted by gagen's `step()` without adding a
|
|
555
|
-
* gagen runtime dependency. It belongs first in the job it guards:
|
|
556
|
-
*
|
|
557
|
-
*
|
|
724
|
+
* gagen runtime dependency. It belongs first in the job it guards: a few API
|
|
725
|
+
* reads with the default `GITHUB_TOKEN`, no checkout, no install, so a proven
|
|
726
|
+
* head costs a runner nothing beyond job startup. The step runs on pull
|
|
727
|
+
* requests only, so it needs only `checks: read` (#873, #863).
|
|
558
728
|
*
|
|
559
729
|
* A **step, not a job**, and that is not a style preference. A separate gate
|
|
560
730
|
* job that errored would leave the guarded job `skipped`, and a summary job
|
|
@@ -570,11 +740,16 @@ export const factoryProofGateStep = (
|
|
|
570
740
|
continueOnError: true as const,
|
|
571
741
|
env: Object.freeze({
|
|
572
742
|
GH_TOKEN: githubExpression("secrets.GITHUB_TOKEN"),
|
|
573
|
-
|
|
743
|
+
// On a pull request the verified head is the PR branch tip. The step
|
|
744
|
+
// never runs on a push, so no reachable path reads the `github.sha`
|
|
745
|
+
// half.
|
|
746
|
+
HEAD_SHA: githubExpression(
|
|
747
|
+
"github.event.pull_request.head.sha || github.sha"
|
|
748
|
+
),
|
|
574
749
|
}),
|
|
575
750
|
id: FACTORY_PROOF_GATE_STEP_ID,
|
|
576
751
|
if: FACTORY_PROOF_GATE_IF,
|
|
577
|
-
name:
|
|
752
|
+
name: FACTORY_PROOF_GATE_STEP_NAME,
|
|
578
753
|
run: factoryProofGateScript(options),
|
|
579
754
|
// Never omit: the runner's default `run:` shell supplies `-e`, which
|
|
580
755
|
// voids the fail-open design. See FACTORY_PROOF_GATE_SHELL.
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
/** Generic timing and presentation steps around the proof-reuse gate (#652). */
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
FACTORY_PROOF_GATE_MODE_OUTPUT,
|
|
5
|
+
FACTORY_PROOF_GATE_OUTPUT,
|
|
6
|
+
FACTORY_PROOF_GATE_REASON_OUTPUT,
|
|
7
|
+
FACTORY_PROOF_GATE_SOURCE_URL_OUTPUT,
|
|
8
|
+
FACTORY_PROOF_GATE_STEP_ID,
|
|
9
|
+
} from "./proof-reuse-gate.ts";
|
|
10
|
+
|
|
11
|
+
const githubExpression = (expression: string): string =>
|
|
12
|
+
`\${{ ${expression} }}`;
|
|
13
|
+
|
|
14
|
+
const shellExpansion = (expression: string): string => `\${${expression}}`;
|
|
15
|
+
|
|
16
|
+
const safeLabel = (surface: string): string => {
|
|
17
|
+
const cleaned = (typeof surface === "string" ? surface : "")
|
|
18
|
+
.replaceAll(/[^\w -]/gu, "")
|
|
19
|
+
.trim()
|
|
20
|
+
.slice(0, 60);
|
|
21
|
+
return cleaned.length > 0 ? cleaned : "verification";
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const FACTORY_PROOF_TIMING_STEP_ID = "ci-timing";
|
|
25
|
+
const FACTORY_PROOF_TIMING_START_STEP_NAME = "Start CI timing";
|
|
26
|
+
const FACTORY_PROOF_TIMING_SUMMARY_STEP_NAME = "Record proof-reuse timing";
|
|
27
|
+
|
|
28
|
+
export interface FactoryProofReusePresentationOptions {
|
|
29
|
+
/** Human-readable name of the guarded suite. */
|
|
30
|
+
readonly surface: string;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface FactoryProofTimingStartStep {
|
|
34
|
+
readonly continueOnError: true;
|
|
35
|
+
readonly id: typeof FACTORY_PROOF_TIMING_STEP_ID;
|
|
36
|
+
readonly name: typeof FACTORY_PROOF_TIMING_START_STEP_NAME;
|
|
37
|
+
readonly run: string;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export const factoryProofTimingStartStep = (): FactoryProofTimingStartStep =>
|
|
41
|
+
Object.freeze({
|
|
42
|
+
continueOnError: true as const,
|
|
43
|
+
id: FACTORY_PROOF_TIMING_STEP_ID,
|
|
44
|
+
name: FACTORY_PROOF_TIMING_START_STEP_NAME,
|
|
45
|
+
run: String.raw`started_ms="$(node -e 'process.stdout.write(String(Date.now()))')"
|
|
46
|
+
printf 'started_ms=%s\n' "$started_ms" >> "$GITHUB_OUTPUT"`,
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
const factoryProofReuseSummaryScript = ({
|
|
50
|
+
surface,
|
|
51
|
+
}: FactoryProofReusePresentationOptions): string => {
|
|
52
|
+
const label = safeLabel(surface);
|
|
53
|
+
return String.raw`now_ms="$(node -e 'process.stdout.write(String(Date.now()))')"
|
|
54
|
+
ci_started_ms="${shellExpansion("CI_STARTED_MS:-")}"
|
|
55
|
+
|
|
56
|
+
SUMMARY="${shellExpansion("GITHUB_STEP_SUMMARY:-/dev/null")}"
|
|
57
|
+
say() { printf '%s\n' "$1" >> "$SUMMARY"; }
|
|
58
|
+
|
|
59
|
+
say '## ${label} timing'
|
|
60
|
+
say ''
|
|
61
|
+
|
|
62
|
+
if [ "${shellExpansion("GITHUB_EVENT_NAME:-")}" = 'push' ] && [ -z "${shellExpansion("PROOF_REASON:-")}" ]; then
|
|
63
|
+
# A push run with no recorded reason is one where the gate step's condition
|
|
64
|
+
# kept it off entirely, so the full suite ran with no reuse decision. The
|
|
65
|
+
# gate runs on pull requests only (#863), so that is every push.
|
|
66
|
+
say '- Path: full execution, no proof consulted'
|
|
67
|
+
say '- Proof-reuse gate: did not run on this ref; the full suite ran.'
|
|
68
|
+
say "- Verified head: \`${shellExpansion("GITHUB_SHA:-unknown")}\`"
|
|
69
|
+
echo "::notice title=Factory proof reuse::The proof-reuse gate did not run on this ref; the full ${label} suite executed."
|
|
70
|
+
elif [ "${shellExpansion("PROOF_REUSED:-")}" = 'true' ]; then
|
|
71
|
+
say '- Path: trusted local proof reused'
|
|
72
|
+
if [ -n "${shellExpansion("PROOF_SOURCE_URL:-")}" ]; then
|
|
73
|
+
say "- Reused proof: [exact source check](${shellExpansion("PROOF_SOURCE_URL")})"
|
|
74
|
+
fi
|
|
75
|
+
say "- Bound head: \`${shellExpansion("PROOF_HEAD_SHA:-unknown")}\`"
|
|
76
|
+
say "- Factory verification mode: ${shellExpansion("PROOF_MODE:-unavailable")} (diagnostic only)"
|
|
77
|
+
echo "::notice title=Factory proof reuse::Reused trusted local proof for ${label} at ${shellExpansion("PROOF_HEAD_SHA:-unknown")}."
|
|
78
|
+
else
|
|
79
|
+
say "- Path: full GitHub CI fallback (${shellExpansion("PROOF_REASON:-error")})"
|
|
80
|
+
say "- Bound head: \`${shellExpansion("PROOF_HEAD_SHA:-unknown")}\`"
|
|
81
|
+
say "- Factory verification mode: ${shellExpansion("PROOF_MODE:-unavailable")} (diagnostic only)"
|
|
82
|
+
echo "::notice title=Factory proof reuse::No reusable proof for ${label}; the full hosted suite executed (${shellExpansion("PROOF_REASON:-error")})."
|
|
83
|
+
fi
|
|
84
|
+
|
|
85
|
+
if [[ "$ci_started_ms" =~ ^[0-9]+$ ]]; then
|
|
86
|
+
say "- GitHub workflow execution after the proof gate: $((now_ms - ci_started_ms)) ms"
|
|
87
|
+
else
|
|
88
|
+
say '- GitHub workflow execution after the proof gate: unavailable'
|
|
89
|
+
fi
|
|
90
|
+
say ''`;
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
export interface FactoryProofReuseSummaryStep {
|
|
94
|
+
readonly continueOnError: true;
|
|
95
|
+
readonly env: Readonly<Record<string, string>>;
|
|
96
|
+
readonly if: "always()";
|
|
97
|
+
readonly name: typeof FACTORY_PROOF_TIMING_SUMMARY_STEP_NAME;
|
|
98
|
+
readonly run: string;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export const factoryProofReuseSummaryStep = (
|
|
102
|
+
options: FactoryProofReusePresentationOptions
|
|
103
|
+
): FactoryProofReuseSummaryStep =>
|
|
104
|
+
Object.freeze({
|
|
105
|
+
continueOnError: true as const,
|
|
106
|
+
env: Object.freeze({
|
|
107
|
+
CI_STARTED_MS: githubExpression(
|
|
108
|
+
`steps.${FACTORY_PROOF_TIMING_STEP_ID}.outputs.started_ms`
|
|
109
|
+
),
|
|
110
|
+
// PR runs bind to the PR branch tip; push runs to the pushed head. No
|
|
111
|
+
// push run records a reason, and this value only labels the summary.
|
|
112
|
+
PROOF_HEAD_SHA: githubExpression(
|
|
113
|
+
"github.event.pull_request.head.sha || github.sha"
|
|
114
|
+
),
|
|
115
|
+
PROOF_MODE: githubExpression(
|
|
116
|
+
`steps.${FACTORY_PROOF_GATE_STEP_ID}.outputs.${FACTORY_PROOF_GATE_MODE_OUTPUT}`
|
|
117
|
+
),
|
|
118
|
+
PROOF_REASON: githubExpression(
|
|
119
|
+
`steps.${FACTORY_PROOF_GATE_STEP_ID}.outputs.${FACTORY_PROOF_GATE_REASON_OUTPUT}`
|
|
120
|
+
),
|
|
121
|
+
PROOF_REUSED: githubExpression(
|
|
122
|
+
`steps.${FACTORY_PROOF_GATE_STEP_ID}.outputs.${FACTORY_PROOF_GATE_OUTPUT}`
|
|
123
|
+
),
|
|
124
|
+
PROOF_SOURCE_URL: githubExpression(
|
|
125
|
+
`steps.${FACTORY_PROOF_GATE_STEP_ID}.outputs.${FACTORY_PROOF_GATE_SOURCE_URL_OUTPUT}`
|
|
126
|
+
),
|
|
127
|
+
}),
|
|
128
|
+
if: "always()" as const,
|
|
129
|
+
name: FACTORY_PROOF_TIMING_SUMMARY_STEP_NAME,
|
|
130
|
+
run: factoryProofReuseSummaryScript(options),
|
|
131
|
+
});
|