@patronage/factory-ci 1.0.0-alpha.41 → 1.0.0-alpha.43
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 +4 -4
- package/dist/.build-fingerprint.json +1 -1
- package/dist/alchemy/index.d.ts +1 -1
- package/dist/alchemy/index.js +2 -2
- package/dist/{execute-alchemy-entry-B0lBN-YZ.js → execute-alchemy-entry-C2ZhsNTN.js} +1 -1
- package/dist/index.d.ts +4 -2
- package/dist/index.js +222 -59
- package/package.json +2 -2
- package/src/alchemy/plan-effects.ts +1 -1
- package/src/alchemy-baseline.ts +1 -1
- package/src/proof-reuse-gate.ts +219 -58
package/README.md
CHANGED
|
@@ -407,7 +407,7 @@ The **proof-reuse gate** decides whether a hosted job may reuse the local verifi
|
|
|
407
407
|
|
|
408
408
|
There is no mode to choose. The emitted condition is a trust predicate, so the package owns it: the merge-target opt-out and its push-event merge fallback (#611) are deleted, and no consumer option can reuse proof outside a pull request.
|
|
409
409
|
|
|
410
|
-
A proof is reusable only when the complete Checks API result (`filter=all`, every page) establishes one unambiguous newest generation
|
|
410
|
+
A proof is reusable only when the complete Checks API result (`filter=all`, every page) establishes one unambiguous newest generation, produced by the pinned App for the exact repository and head, completed successfully with `outcome: passed`, whose verification started after every other run at that head was posted, and covering every command identity the guarded surface requires. A pass is ordered at its typed proof's start, never later than its own `started_at`, and every other run at its `started_at`; the doc comment above `GATE_JQ` in `src/proof-reuse-gate.ts` states the full rule (#1490, #1506). Coverage is the union of `executedCommands` and commands released by `notRequiredCommands` only after the gate validates each release against that same proof binding's command-to-target map and identity-bound impact stamp. Missing, malformed, duplicated, affected, unknown, or differently bound release data refuses reuse and runs the hosted surface. `mode` is reported as diagnostic metadata, never authorized on: a reduced-mode proof whose executed and stamp-authorized released commands cover a surface is reusable.
|
|
411
411
|
|
|
412
412
|
The only thing a consumer chooses is **what its surface requires**, expressed as the plain profile command objects that surface selects — a repository with distinct core and docs jobs selects distinct sets and gets distinct required coverage. `proofReuseRequiredCommands()` is the single derivation both the gate and the assertion go through. Identities are baked into the emitted script, so they are held to a plain `[A-Za-z0-9_][\w.:@/-]*` allow-list and shell-quoted at the interpolation site; a selection carrying anything else is unusable and degrades to a gate that always refuses.
|
|
413
413
|
|
|
@@ -752,7 +752,7 @@ const graph = await evaluateStack({
|
|
|
752
752
|
|
|
753
753
|
`evaluateStack` runs a stack program at one stage and returns the graph Alchemy would plan, with no state store and no network. It wraps Alchemy's `Plan.make`: the program registers its resources under a `Stack` service, then the plan builds under `inMemoryState()` at the requested `Stage`. Every provider answers its `read` and `list` probes with "absent", so the cold-adoption probe `Plan.make` makes for a resource with resolved props and no prior state never leaves the process. A stage the program returns from early (paitronage's `placeholder` stage) evaluates to an empty graph.
|
|
754
754
|
|
|
755
|
-
`program` is the effect the consumer hands `Alchemy.Stack`, not the `Alchemy.Stack(...)` value. The value captures the consumer's real `providers` and `state` layers, and at Alchemy 2.0.0-beta.
|
|
755
|
+
`program` is the effect the consumer hands `Alchemy.Stack`, not the `Alchemy.Stack(...)` value. The value captures the consumer's real `providers` and `state` layers, and at Alchemy 2.0.0-beta.83 building `Cloudflare.providers()` is not inert (`ProfileStoreLive` inside `CloudflareApiLive` writes `~/.alchemy/profiles/default`, and the layer needs the `AuthProviders` service), so evaluating the value cannot stay free of side effects. Export the program next to the stack:
|
|
756
756
|
|
|
757
757
|
```ts
|
|
758
758
|
export const program = Effect.gen(function* () {
|
|
@@ -763,7 +763,7 @@ export default Alchemy.Stack("hq", { providers, state }, program);
|
|
|
763
763
|
|
|
764
764
|
Pass `providers` when the program depends on hand-written provider layers. Every provider that layer registers keeps its identity (`stables`, `aliases`, `diff`) and loses its probes; an unregistered resource type still evaluates. Each graph resource carries the `LogicalId`, `Type`, and raw `Props` of its plan node, so a prop may hold an unresolved Alchemy output. `upstreamByProp` names, per top-level prop, the logical ids that prop's value references, which is the only way to read a cross-resource reference out of raw props: an output is a function, so the prop that holds it says nothing on its own. A prop that references nothing carries no key. The references are kept per prop and never pooled into one list, so a caller asking which resources one prop names is never answered with an id a different prop mentioned. Each binding row comes from Alchemy's Worker binding channel: `worker` is the host's logical id, `name` and `type` are the strings Alchemy emits (`d1`, `kv_namespace`, `secrets_store_secret`, and so on), and `target` is the logical id of the resource the row references, when it references one.
|
|
765
765
|
|
|
766
|
-
The caller's `providers` layer is **built** before its probes are stubbed: `evaluateStack` wraps that layer, and Alchemy's own lookup resolves each provider out of it before `read` and `list` are replaced. So any side effect a layer performs at construction — a credential read, a network call, a file write — is the caller's, and happens. This is why `Cloudflare.providers()` must not be passed: at beta.
|
|
766
|
+
The caller's `providers` layer is **built** before its probes are stubbed: `evaluateStack` wraps that layer, and Alchemy's own lookup resolves each provider out of it before `read` and `list` are replaced. So any side effect a layer performs at construction — a credential read, a network call, a file write — is the caller's, and happens. This is why `Cloudflare.providers()` must not be passed: at beta.83 its `CloudflareApiLive` still creates `~/.alchemy/profiles/default` and requires `AuthProviders` when it builds, before there is anything to stub. Beta.77 also resolved credentials there (`Credentials.fromAuthProvider`); beta.81 deferred that to first use and beta.83 still does. The no-network guarantee covers evaluation, not layer construction: pass only layers whose construction is inert.
|
|
767
767
|
|
|
768
768
|
The helper decides nothing about the graph. Invariants over it are separate exports; `assertUrlImpliesAuth` below is the first.
|
|
769
769
|
|
|
@@ -799,7 +799,7 @@ The factory's own security review prompt carries the same rule in prose, so a re
|
|
|
799
799
|
import { ALCHEMY_BASELINE, assertAlchemyBaseline } from "@patronage/factory-ci";
|
|
800
800
|
```
|
|
801
801
|
|
|
802
|
-
`ALCHEMY_BASELINE` is the exact `alchemy` and `effect` pair the fleet moves together on: `{ alchemy: "2.0.0-beta.
|
|
802
|
+
`ALCHEMY_BASELINE` is the exact `alchemy` and `effect` pair the fleet moves together on: `{ alchemy: "2.0.0-beta.83", effect: "4.0.1" }`. It is a plain constant on the root entry — it imports neither package — so any consumer can read it without installing the `./alchemy` subpath's peers.
|
|
803
803
|
|
|
804
804
|
`assertAlchemyBaseline({ packageJson })` is a consumer contract helper: it fails when the consumer's own `dependencies` or `devDependencies` pin `alchemy` or `effect` to anything other than the baseline, and it fails when only one of the pair is present. Alchemy peers on Effect, so an unpinned auto-installed Effect can drift outside the baseline while a lone `alchemy` pin would otherwise pass. Both packages remaining absent is not drift — they are optional peers of the subpath, so a consumer that never imports it, such as this package's own CLI, carries neither and passes. The pin is exact, not a range: the fleet is pre-1.0 and moves together, so a range would let one project drift silently ahead of or behind the rest. `assertAlchemyBaseline` reads only the object it is handed; it never walks the filesystem or reads a lockfile. Call it from a consumer's own contract test, passing that consumer's parsed `package.json`.
|
|
805
805
|
|
package/dist/alchemy/index.d.ts
CHANGED
|
@@ -744,7 +744,7 @@ declare const isAlchemyLifecycleError: (error: unknown) => error is AlchemyLifec
|
|
|
744
744
|
* The renderer logs every line through Effect's pretty console logger, so a
|
|
745
745
|
* line arrives as `[HH:MM:SS.mmm] INFO (#1): <line>`, and coloured when the
|
|
746
746
|
* child inherits `FORCE_COLOR`. Both wrappers are stripped before a line is
|
|
747
|
-
* read. The captured output under `tests/fixtures/plan-output/beta-
|
|
747
|
+
* read. The captured output under `tests/fixtures/plan-output/beta-83/` is
|
|
748
748
|
* the evidence for every shape this file reads.
|
|
749
749
|
*
|
|
750
750
|
* The adapter fails on anything it does not recognise: no summary, two
|
package/dist/alchemy/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { i as isLocalPreviewStage, n as executeAlchemyEntry, r as resolveAlchemyChildCwd, s as ALCHEMY_BASELINE } from "../execute-alchemy-entry-
|
|
1
|
+
import { i as isLocalPreviewStage, n as executeAlchemyEntry, r as resolveAlchemyChildCwd, s as ALCHEMY_BASELINE } from "../execute-alchemy-entry-C2ZhsNTN.js";
|
|
2
2
|
import { createRequire } from "node:module";
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { createHash } from "node:crypto";
|
|
@@ -585,7 +585,7 @@ const assertDestroyLeftNothing = async ({ stack, stage, stateReader }) => {
|
|
|
585
585
|
* The renderer logs every line through Effect's pretty console logger, so a
|
|
586
586
|
* line arrives as `[HH:MM:SS.mmm] INFO (#1): <line>`, and coloured when the
|
|
587
587
|
* child inherits `FORCE_COLOR`. Both wrappers are stripped before a line is
|
|
588
|
-
* read. The captured output under `tests/fixtures/plan-output/beta-
|
|
588
|
+
* read. The captured output under `tests/fixtures/plan-output/beta-83/` is
|
|
589
589
|
* the evidence for every shape this file reads.
|
|
590
590
|
*
|
|
591
591
|
* The adapter fails on anything it does not recognise: no summary, two
|
|
@@ -12,7 +12,7 @@ import { spawnSync } from "node:child_process";
|
|
|
12
12
|
* `effect`, so it ships from the root entry, not the `./alchemy` subpath.
|
|
13
13
|
*/
|
|
14
14
|
const ALCHEMY_BASELINE = {
|
|
15
|
-
alchemy: "2.0.0-beta.
|
|
15
|
+
alchemy: "2.0.0-beta.83",
|
|
16
16
|
effect: "4.0.1"
|
|
17
17
|
};
|
|
18
18
|
const BASELINE_PACKAGE_NAMES = Object.keys(ALCHEMY_BASELINE);
|
package/dist/index.d.ts
CHANGED
|
@@ -12,7 +12,7 @@ import { StdioOptions } from "node:child_process";
|
|
|
12
12
|
* `effect`, so it ships from the root entry, not the `./alchemy` subpath.
|
|
13
13
|
*/
|
|
14
14
|
declare const ALCHEMY_BASELINE: {
|
|
15
|
-
readonly alchemy: "2.0.0-beta.
|
|
15
|
+
readonly alchemy: "2.0.0-beta.83";
|
|
16
16
|
readonly effect: "4.0.1";
|
|
17
17
|
};
|
|
18
18
|
/**
|
|
@@ -750,7 +750,9 @@ declare const FACTORY_PROOF_GATE_IF = "github.event_name == 'pull_request'";
|
|
|
750
750
|
* cover every required command
|
|
751
751
|
* - `ambiguous` two different generations share the newest instant, the
|
|
752
752
|
* newest repeats another run's verdict with no proof time to
|
|
753
|
-
* tell them apart,
|
|
753
|
+
* tell them apart, a run's start time cannot be ranked, or the
|
|
754
|
+
* newest pass started before another run at this head was
|
|
755
|
+
* posted
|
|
754
756
|
* - `error` the gate could not reach a decision (fail open)
|
|
755
757
|
*
|
|
756
758
|
* There is no `reduced`: mode stopped being an authorization condition in
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as bundleAlchemyEntry } from "./bundle-alchemy-entry-CT5hCphA.js";
|
|
2
|
-
import { a as localPreviewStage, c as assertAlchemyBaseline, i as isLocalPreviewStage, n as executeAlchemyEntry, o as parseLocalPreviewStage, s as ALCHEMY_BASELINE, t as EXECUTE_ALCHEMY_ENTRY_MAX_BUFFER } from "./execute-alchemy-entry-
|
|
2
|
+
import { a as localPreviewStage, c as assertAlchemyBaseline, i as isLocalPreviewStage, n as executeAlchemyEntry, o as parseLocalPreviewStage, s as ALCHEMY_BASELINE, t as EXECUTE_ALCHEMY_ENTRY_MAX_BUFFER } from "./execute-alchemy-entry-C2ZhsNTN.js";
|
|
3
3
|
import { createRequire } from "node:module";
|
|
4
4
|
import { mkdir, readFile, rename, writeFile } from "node:fs/promises";
|
|
5
5
|
import path from "node:path";
|
|
@@ -534,7 +534,9 @@ const FACTORY_PROOF_GATE_IF = "github.event_name == 'pull_request'";
|
|
|
534
534
|
* cover every required command
|
|
535
535
|
* - `ambiguous` two different generations share the newest instant, the
|
|
536
536
|
* newest repeats another run's verdict with no proof time to
|
|
537
|
-
* tell them apart,
|
|
537
|
+
* tell them apart, a run's start time cannot be ranked, or the
|
|
538
|
+
* newest pass started before another run at this head was
|
|
539
|
+
* posted
|
|
538
540
|
* - `error` the gate could not reach a decision (fail open)
|
|
539
541
|
*
|
|
540
542
|
* There is no `reduced`: mode stopped being an authorization condition in
|
|
@@ -574,6 +576,24 @@ const COMMAND_IDENTITY_MAX_LENGTH = 120;
|
|
|
574
576
|
* lockstep with the proof/check-payload producer.
|
|
575
577
|
*/
|
|
576
578
|
const TRUSTED_IMPACT_STAMP_VERSION = 4;
|
|
579
|
+
/**
|
|
580
|
+
* The verify modes the CLI reads a payload under (`isResolvedPrVerifyMode` in
|
|
581
|
+
* `software-factory/src/pr-verify-mode.ts`). factory-ci cannot import it, so
|
|
582
|
+
* the list is repeated here, and the software-factory differential suite pins
|
|
583
|
+
* the two lists together (#1510).
|
|
584
|
+
*/
|
|
585
|
+
const RESOLVED_VERIFY_MODES = [
|
|
586
|
+
"docs-only",
|
|
587
|
+
"trivial",
|
|
588
|
+
"full"
|
|
589
|
+
];
|
|
590
|
+
/**
|
|
591
|
+
* The check-text size over which the CLI drops a transported typed proof
|
|
592
|
+
* (`readTransportedVerifyProof` in
|
|
593
|
+
* `software-factory/src/pr-verify-check-payload.ts`), in UTF-8 bytes of the
|
|
594
|
+
* raw text it parsed, fence included (#1510).
|
|
595
|
+
*/
|
|
596
|
+
const TRANSPORT_CAP_BYTES = 6e4;
|
|
577
597
|
const isProofReuseCommand = (value) => {
|
|
578
598
|
if (!(value && typeof value === "object")) return false;
|
|
579
599
|
const entry = value;
|
|
@@ -658,64 +678,168 @@ const resolveProofReuseCommands = (catalog, names, selectionLabel) => names.map(
|
|
|
658
678
|
* document. Anything unparseable degrades to `null`, and therefore to a
|
|
659
679
|
* refusal.
|
|
660
680
|
*
|
|
661
|
-
* This is the *second* parser of that payload
|
|
681
|
+
* This is the *second* parser of that payload, and it does not reimplement
|
|
682
|
+
* the first: `parsePrVerifyCheckPayload`
|
|
662
683
|
* (`software-factory/src/pr-verify-check-payload.ts`) regex-extracts the fenced
|
|
663
|
-
* block
|
|
664
|
-
*
|
|
665
|
-
*
|
|
666
|
-
*
|
|
667
|
-
*
|
|
668
|
-
*
|
|
684
|
+
* block up to the next line that starts with a fence and `JSON.parse`s it,
|
|
685
|
+
* while this one strips every such line and `fromjson`s what remains. The
|
|
686
|
+
* writer renders JSON, whose strings hold no raw line feed, between one
|
|
687
|
+
* opening and one closing fence line, so on its text the two read the same
|
|
688
|
+
* JSON, three backticks inside a string included. On other text they can
|
|
689
|
+
* differ in either direction. Prose around the fence parses there and refuses
|
|
690
|
+
* here; the test suite asserts that the exact shape the renderer emits is
|
|
691
|
+
* proven here and that the prose-wrapped shape refuses. Text that parses here
|
|
692
|
+
* and not there is part of the trust boundary below.
|
|
669
693
|
*
|
|
670
|
-
*
|
|
671
|
-
*
|
|
694
|
+
* Once parsed, a payload is read by the CLI's readability rules (#1510).
|
|
695
|
+
* `bound` requires the binding's
|
|
696
|
+
* `kind`, `schemaVersion` 1, this head, this repository and a resolved verify
|
|
697
|
+
* mode (`resolvedMode`, the CLI's `isResolvedPrVerifyMode`), and the verdict
|
|
698
|
+
* stage refuses a run that is not `bound` as `unreadable`; an `outcome` other
|
|
699
|
+
* than `passed` is never a pass. `binding` drops a transported typed proof
|
|
700
|
+
* (`verificationProof`) when the text it parsed, fence included, is over
|
|
701
|
+
* 60,000 UTF-8 bytes, as `readTransportedVerifyProof` does, so the run is a
|
|
702
|
+
* pass with no typed proof to both readers. On text the writer never emits,
|
|
703
|
+
* this reader can still read a payload differently; see the trust boundary
|
|
704
|
+
* below.
|
|
705
|
+
*
|
|
706
|
+
* A passing generation is ordered by when its verification started, never
|
|
707
|
+
* later than when its run reached GitHub and never by when its verification
|
|
708
|
+
* ended (#1409, #1490). Every other run is ordered by when it reached GitHub
|
|
709
|
+
* (#1506). It is the rule `fetchPrVerifyProofBinding` applies
|
|
672
710
|
* (`software-factory/src/github-check-runs.ts`), mirrored here because this
|
|
673
711
|
* reader is jq in generated CI and cannot import it:
|
|
674
712
|
*
|
|
675
|
-
* - A run
|
|
676
|
-
*
|
|
677
|
-
*
|
|
678
|
-
*
|
|
679
|
-
*
|
|
680
|
-
* and
|
|
681
|
-
*
|
|
682
|
-
*
|
|
683
|
-
*
|
|
684
|
-
*
|
|
685
|
-
* -
|
|
686
|
-
*
|
|
687
|
-
*
|
|
688
|
-
*
|
|
689
|
-
*
|
|
690
|
-
*
|
|
713
|
+
* - A passing run (`passing`) is completed with conclusion `success`, and its
|
|
714
|
+
* binding is bound to this head and repository with outcome `passed`. When it
|
|
715
|
+
* transports a typed proof (`verificationProof`) whose start is computable
|
|
716
|
+
* (`proofStart`: its `endedAt` minus its `durationMs`), it is ordered at that
|
|
717
|
+
* start, or at its own `started_at` when that is earlier. Such runs with the
|
|
718
|
+
* same binding, status and conclusion are one generation posted more than
|
|
719
|
+
* once (`pr:verify` posts, `pr:publish` re-posts), ordered at the earliest of
|
|
720
|
+
* its members' instants, whatever order GitHub serves them in. A re-post does
|
|
721
|
+
* not move the proof's start, so a re-post of an older pass never outranks a
|
|
722
|
+
* newer failure, and a post plus its re-post is no tie.
|
|
723
|
+
* - Any other run is its own generation at its `started_at`: one still
|
|
724
|
+
* running, a failure or cancellation whether or not it carries a proof, an
|
|
725
|
+
* unbound one, or a pass with no usable typed proof (over the text cap,
|
|
726
|
+
* written before proofs travelled, or with no computable start). A run is
|
|
727
|
+
* created no earlier than its verification began, so `started_at` is an
|
|
728
|
+
* upper bound on that start. Ranking there can only make such a run newer
|
|
729
|
+
* than it is, so it vetoes more, never less.
|
|
730
|
+
* - Neither `endedAt` nor a passing run's `started_at` is its start. The
|
|
731
|
+
* factory posts a `pr-verify` run only once verification has finished, so
|
|
732
|
+
* both say when it ended, and an older pass ordered there would hide a run
|
|
733
|
+
* that started after the pass began: still running, or failed (#1490). A
|
|
734
|
+
* pass's `started_at` only caps its proof's start. A failure's `started_at`
|
|
735
|
+
* is when it was posted, not when it started, and that is deliberate: a
|
|
736
|
+
* veto's instant only has to be no earlier than its start.
|
|
737
|
+
* - Only a pass is ordered by its proof because this reader cannot run the
|
|
738
|
+
* proof schema (#1506). The CLI drops a payload whose proof fails that
|
|
739
|
+
* schema and orders the run at its `started_at`; ordered by its proof's
|
|
740
|
+
* claimed start, a failure carrying a malformed proof ranked under an older
|
|
741
|
+
* pass here, and the gate returned `proven` where the CLI refused. For an
|
|
742
|
+
* honest proof, `started_at` is no earlier than `endedAt`, which is no
|
|
743
|
+
* earlier than the start, so the cap changes nothing for a valid pass.
|
|
744
|
+
* - A pass is reused only when its verification started strictly after every
|
|
745
|
+
* other run at this head was posted (#1506). Its start is its instant: its
|
|
746
|
+
* proof's start, capped as above, or its `started_at` when it is ordered
|
|
747
|
+
* there. Every other run's post is its `started_at`, rounded down to the
|
|
748
|
+
* whole second. Only the pass's own generation is left out: its re-post
|
|
749
|
+
* group, or, for a pass with no typed proof, that run alone
|
|
750
|
+
* (`ownGeneration`). At most one generation can satisfy this, and that one
|
|
751
|
+
* is the newest, so the gate selects the newest generation and, when it is
|
|
752
|
+
* a pass (`passing`), refuses it as `ambiguous` unless every other run was
|
|
753
|
+
* posted before its instant. When the newest generation is not a pass, the
|
|
754
|
+
* verdict is a refusal anyway, so its reason (`failed`, `pending`, ...)
|
|
755
|
+
* stands and the check does not run.
|
|
756
|
+
* - The check exists because any other run may be ordered earlier than its
|
|
757
|
+
* post by a proof this reader cannot validate: a pass that only claims
|
|
758
|
+
* `passed` looks to jq exactly like one the CLI validates. Without it, a
|
|
759
|
+
* successful run whose malformed proof claimed an early start ranked under
|
|
760
|
+
* an older pass, whether that pass was ordered by its proof or at its
|
|
761
|
+
* `started_at`, and the gate reused the older pass where the CLI, which
|
|
762
|
+
* drops that payload and ranks the run at its `started_at`, refused. With
|
|
763
|
+
* it, whether a pass may be reused never consults another run's proof
|
|
764
|
+
* fields, only when each other run was posted, which GitHub records. Those
|
|
765
|
+
* fields can only cause a refusal; they never hide a veto. The pass's own
|
|
766
|
+
* clock is capped at its post, so it can only count against that pass.
|
|
767
|
+
* - Two changes on valid input follow, and both only add refusals, each
|
|
768
|
+
* costing one hosted run in a rare case. A failure carrying a proof is
|
|
769
|
+
* ordered when it was posted instead of when it started, so an older failure
|
|
770
|
+
* that finished after a newer pass began now refuses reuse. Two pass
|
|
771
|
+
* generations whose verifications overlapped now refuse, as does an older
|
|
772
|
+
* pass re-posted after a newer pass started. Passes that ran one after the
|
|
773
|
+
* other, and a pass with its own re-posts, are reused as before.
|
|
774
|
+
* - The hosted gate's trust boundary is a class. This reader does not
|
|
775
|
+
* reimplement the CLI's payload parser. On payloads the factory's writer
|
|
776
|
+
* emits, both readers select the same pass or both refuse: the differential
|
|
777
|
+
* suite, `software-factory/src/pr-verify-reuse-differential.test.ts`,
|
|
778
|
+
* asserts it over 9,653 generated run sets. On App-signed text the writer
|
|
779
|
+
* never emits, the two can differ in either direction. The known instances
|
|
780
|
+
* where this gate reuses and the CLI refuses are: (a) a reused run whose
|
|
781
|
+
* typed proof fails `validatePrVerifyProof`; (b) a newest pass that repeats
|
|
782
|
+
* another run's verdict only once the CLI normalizes that run's payload, say
|
|
783
|
+
* by dropping a key, since the CLI compares normalized payloads and this
|
|
784
|
+
* reader raw ones; (c) a payload in `output.summary` beside a text payload
|
|
785
|
+
* the CLI cannot read, which the CLI reads from the summary and this reader
|
|
786
|
+
* from the text; (d) text that this reader's strip-and-`fromjson` reads and
|
|
787
|
+
* the CLI's fence match or `JSON.parse` refuses, such as a closing fence
|
|
788
|
+
* with no opening one, a doubled opening fence, a fence line inside the
|
|
789
|
+
* JSON, a payload split across two fenced blocks, or a number literal such
|
|
790
|
+
* as `NaN` where the jq in use accepts it (jq 1.8 does). Mirroring any of it
|
|
791
|
+
* would turn this reader into a parser. Only the factory App can post the
|
|
792
|
+
* run, and that identity bounds the whole class (#1511).
|
|
793
|
+
* - A run not ordered by a typed proof carries no generation identity, so it
|
|
794
|
+
* is never grouped. Two separate executions with the same command names and
|
|
795
|
+
* verdict post the same compact binding, and so does a re-post. When the
|
|
796
|
+
* newest generation is one of these and repeats another run's verdict
|
|
797
|
+
* (binding, status and conclusion), it could be a re-post of an older
|
|
798
|
+
* verdict or a new one, so it is `ambiguous`. Proofs that size are rare;
|
|
799
|
+
* refusing costs a hosted run.
|
|
691
800
|
*
|
|
692
801
|
* Two different generations that share the newest instant are `ambiguous`
|
|
693
802
|
* rather than arbitrarily resolved: the gate cannot tell which one describes
|
|
694
803
|
* the tree, and silently picking either is exactly the kind of coin-flip
|
|
695
|
-
* authorization this whole mechanism exists to remove.
|
|
696
|
-
*
|
|
697
|
-
*
|
|
698
|
-
*
|
|
804
|
+
* authorization this whole mechanism exists to remove.
|
|
805
|
+
*
|
|
806
|
+
* Every instant is a whole epoch second, rounded down. A `started_at` keeps
|
|
807
|
+
* its whole second, so `…:00Z` and `…:00.500Z` compare equal. A proof's start
|
|
808
|
+
* is `floor((endedAt - durationMs) / 1000)` with `endedAt` in epoch
|
|
809
|
+
* milliseconds, its fraction read to the millisecond the way `Date.parse`
|
|
810
|
+
* reads it. Rounding down is monotonic, so it can merge two instants into a
|
|
811
|
+
* tie, which is `ambiguous`, but never invert them. It also fails closed: a
|
|
812
|
+
* proof's start never moves later, so it never outranks an unbound run in the
|
|
813
|
+
* same second. The TypeScript reader rounds the same way, so the two agree on
|
|
814
|
+
* every canonical instant. Two genuine verification generations within the
|
|
815
|
+
* same second at the same head is not a real state.
|
|
699
816
|
*
|
|
700
|
-
*
|
|
701
|
-
*
|
|
702
|
-
*
|
|
703
|
-
*
|
|
704
|
-
*
|
|
705
|
-
*
|
|
706
|
-
*
|
|
707
|
-
*
|
|
708
|
-
* authorize the wrong one.
|
|
817
|
+
* `fromdateiso8601` reads only canonical UTC, and the gate never asks it to
|
|
818
|
+
* read anything else. Every candidate must carry a canonical UTC
|
|
819
|
+
* `started_at`, and one that does not makes the newest generation
|
|
820
|
+
* unestablishable, which is `ambiguous`. A typed proof whose `endedAt` is not
|
|
821
|
+
* canonical UTC, or whose `durationMs` is missing or not a finite non-negative
|
|
822
|
+
* number, records no start, and its run falls back to `started_at` like any
|
|
823
|
+
* other run without a typed proof. Refusing costs a hosted run; ranking an
|
|
824
|
+
* unorderable set could authorize the wrong one.
|
|
709
825
|
*/
|
|
710
826
|
const GATE_JQ = String.raw`
|
|
711
827
|
def binding:
|
|
712
828
|
[ .output.text, .output.summary ]
|
|
713
829
|
| map(select(type == "string"))
|
|
714
|
-
| map(
|
|
715
|
-
|
|
716
|
-
|
|
830
|
+
| map(. as $text
|
|
831
|
+
| (split("\n") | map(select(startswith("${"```"}") | not)) | join("\n")
|
|
832
|
+
| try fromjson catch null)
|
|
833
|
+
| select(type == "object")
|
|
834
|
+
| if ($text | utf8bytelength) > ${TRANSPORT_CAP_BYTES}
|
|
835
|
+
then del(.verificationProof)
|
|
836
|
+
else .
|
|
837
|
+
end)
|
|
717
838
|
| .[0];
|
|
718
839
|
|
|
840
|
+
def resolvedMode:
|
|
841
|
+
IN(${RESOLVED_VERIFY_MODES.map((mode) => JSON.stringify(mode)).join(", ")});
|
|
842
|
+
|
|
719
843
|
def startedAt: (.started_at // "") | tostring;
|
|
720
844
|
|
|
721
845
|
def rankable:
|
|
@@ -723,17 +847,45 @@ def rankable:
|
|
|
723
847
|
|
|
724
848
|
def wholeSecond: sub("\\.[0-9]+Z$"; "Z");
|
|
725
849
|
|
|
850
|
+
def epochSecond:
|
|
851
|
+
if type == "string" and rankable
|
|
852
|
+
then (try (wholeSecond | fromdateiso8601) catch null)
|
|
853
|
+
else null
|
|
854
|
+
end;
|
|
855
|
+
|
|
856
|
+
def millisecondPart:
|
|
857
|
+
((capture("\\.(?<digits>[0-9]+)Z$") | .digits) // "") + "000"
|
|
858
|
+
| .[0:3]
|
|
859
|
+
| tonumber;
|
|
860
|
+
|
|
726
861
|
def bound:
|
|
727
862
|
(.binding | type) == "object"
|
|
728
863
|
and .binding.kind == "pr-verify-proof-binding"
|
|
729
864
|
and .binding.schemaVersion == 1
|
|
730
865
|
and .binding.headSha == $sha
|
|
731
|
-
and .binding.repository == $repository
|
|
866
|
+
and .binding.repository == $repository
|
|
867
|
+
and (.binding.mode | resolvedMode);
|
|
868
|
+
|
|
869
|
+
def passing:
|
|
870
|
+
.status == "completed"
|
|
871
|
+
and .conclusion == "success"
|
|
872
|
+
and bound
|
|
873
|
+
and .binding.outcome == "passed";
|
|
732
874
|
|
|
733
|
-
def
|
|
734
|
-
if bound then
|
|
735
|
-
|
|
736
|
-
|
|
|
875
|
+
def proofStart:
|
|
876
|
+
if bound and (.binding.verificationProof | type) == "object" then
|
|
877
|
+
.binding.verificationProof as $proof
|
|
878
|
+
| ($proof.endedAt | epochSecond) as $ended
|
|
879
|
+
| $proof.durationMs as $duration
|
|
880
|
+
| if $ended != null
|
|
881
|
+
and ($duration | type) == "number"
|
|
882
|
+
and ($duration | isinfinite | not)
|
|
883
|
+
and $duration >= 0
|
|
884
|
+
then ($ended * 1000 + ($proof.endedAt | millisecondPart) - $duration)
|
|
885
|
+
/ 1000
|
|
886
|
+
| floor
|
|
887
|
+
else null
|
|
888
|
+
end
|
|
737
889
|
else null
|
|
738
890
|
end;
|
|
739
891
|
|
|
@@ -743,6 +895,12 @@ def sameVerdict($other):
|
|
|
743
895
|
and .conclusion == $other.conclusion
|
|
744
896
|
and .binding == $other.binding;
|
|
745
897
|
|
|
898
|
+
def ownGeneration($generation):
|
|
899
|
+
if $generation.recorded
|
|
900
|
+
then .recorded and sameVerdict($generation)
|
|
901
|
+
else .index == $generation.index
|
|
902
|
+
end;
|
|
903
|
+
|
|
746
904
|
def nonemptyString:
|
|
747
905
|
type == "string" and length > 0;
|
|
748
906
|
|
|
@@ -767,15 +925,19 @@ def releaseAuthorized($release; $commands; $stamp):
|
|
|
767
925
|
url: ((.html_url // "") | tostring),
|
|
768
926
|
binding: binding }
|
|
769
927
|
] as $runs
|
|
770
|
-
| ($runs | map(.started |
|
|
771
|
-
| [ $runs
|
|
772
|
-
|
|
|
773
|
-
|
|
|
928
|
+
| ($runs | map(.started | epochSecond != null) | all) as $orderable
|
|
929
|
+
| [ range(0; $runs | length) as $index
|
|
930
|
+
| $runs[$index]
|
|
931
|
+
| (.started | epochSecond) as $posted
|
|
932
|
+
| (if passing then proofStart else null end) as $start
|
|
933
|
+
| . + { at: ([$start, $posted] | map(select(. != null)) | min),
|
|
934
|
+
index: $index,
|
|
935
|
+
recorded: ($start != null) }
|
|
774
936
|
] as $observed
|
|
775
937
|
| ( [ $observed[] | select(.recorded | not) ]
|
|
776
938
|
+ ( [ $observed[] | select(.recorded) ]
|
|
777
939
|
| group_by([.status, .conclusion, .binding])
|
|
778
|
-
| map(.[0]) ) ) as $generations
|
|
940
|
+
| map(.[0] + { at: (map(.at) | min) }) ) ) as $generations
|
|
779
941
|
| ($generations | map(.at) | max) as $newest
|
|
780
942
|
| [ $generations[] | select(.at == $newest) ] as $generation
|
|
781
943
|
| (if ($runs | length) == 0 then ["none", "", "", ""]
|
|
@@ -785,6 +947,11 @@ def releaseAuthorized($release; $commands; $stamp):
|
|
|
785
947
|
| ($newestRun.recorded | not)
|
|
786
948
|
and ([ $runs[] | select(sameVerdict($newestRun)) ] | length) > 1)
|
|
787
949
|
then ["ambiguous", "", "", ""]
|
|
950
|
+
elif ($generation[0] as $newestRun
|
|
951
|
+
| ($newestRun | passing)
|
|
952
|
+
and any($observed[] | select(ownGeneration($newestRun) | not);
|
|
953
|
+
(.started | epochSecond) >= $newestRun.at))
|
|
954
|
+
then ["ambiguous", "", "", ""]
|
|
788
955
|
else
|
|
789
956
|
$generation[0] as $run
|
|
790
957
|
| (if ($run.binding | type) == "object" then $run.binding else {} end) as $proof
|
|
@@ -834,11 +1001,7 @@ def releaseAuthorized($release; $commands; $stamp):
|
|
|
834
1001
|
| ($required - $executed - $released) as $missing
|
|
835
1002
|
| (if $run.status != "completed" then "pending"
|
|
836
1003
|
elif $run.conclusion != "success" then "failed"
|
|
837
|
-
elif (
|
|
838
|
-
or ($proof.kind != "pr-verify-proof-binding")
|
|
839
|
-
or ($proof.schemaVersion != 1)
|
|
840
|
-
or ($proof.headSha != $sha)
|
|
841
|
-
or ($proof.repository != $repository) then "unreadable"
|
|
1004
|
+
elif ($run | bound | not) then "unreadable"
|
|
842
1005
|
elif $proof.outcome != "passed" then "failed"
|
|
843
1006
|
elif ($required | length) == 0 then "incomplete"
|
|
844
1007
|
elif ($releasesValid | not) then "incomplete"
|
|
@@ -1039,7 +1202,7 @@ case "$reason" in
|
|
|
1039
1202
|
ambiguous)
|
|
1040
1203
|
say 'Ran the full suite. The newest factory proof for this commit is ambiguous.'
|
|
1041
1204
|
say ''
|
|
1042
|
-
say "Two different \`$CHECK_NAME\` proofs at head \`$HEAD_SHA\` share the newest generation, the newest repeats an earlier run's verdict with no proof time to tell them apart,
|
|
1205
|
+
say "Two different \`$CHECK_NAME\` proofs at head \`$HEAD_SHA\` share the newest generation, the newest repeats an earlier run's verdict with no proof time to tell them apart, a run's start time cannot be ranked, or the newest pass started before another run at this head was posted, so there is no single newest generation to trust. The gate refuses rather than picking one."
|
|
1043
1206
|
say ''
|
|
1044
1207
|
say '${CORRECTIVE_LINE}'
|
|
1045
1208
|
;;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@patronage/factory-ci",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.43",
|
|
4
4
|
"description": "Deep CI and deploy building blocks for Patronage factory projects: workflow source artifacts, hosted diff classification, Alchemy entry execution, and disposable-stage semantics",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"alchemy",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@types/node": "24.13.3",
|
|
42
42
|
"@vitest/coverage-v8": "4.1.10",
|
|
43
|
-
"alchemy": "2.0.0-beta.
|
|
43
|
+
"alchemy": "2.0.0-beta.83",
|
|
44
44
|
"effect": "4.0.1",
|
|
45
45
|
"knip": "6.27.0",
|
|
46
46
|
"oxfmt": "0.59.0",
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
* The renderer logs every line through Effect's pretty console logger, so a
|
|
16
16
|
* line arrives as `[HH:MM:SS.mmm] INFO (#1): <line>`, and coloured when the
|
|
17
17
|
* child inherits `FORCE_COLOR`. Both wrappers are stripped before a line is
|
|
18
|
-
* read. The captured output under `tests/fixtures/plan-output/beta-
|
|
18
|
+
* read. The captured output under `tests/fixtures/plan-output/beta-83/` is
|
|
19
19
|
* the evidence for every shape this file reads.
|
|
20
20
|
*
|
|
21
21
|
* The adapter fails on anything it does not recognise: no summary, two
|
package/src/alchemy-baseline.ts
CHANGED
package/src/proof-reuse-gate.ts
CHANGED
|
@@ -148,7 +148,9 @@ export const FACTORY_PROOF_GATE_IF = "github.event_name == 'pull_request'";
|
|
|
148
148
|
* cover every required command
|
|
149
149
|
* - `ambiguous` two different generations share the newest instant, the
|
|
150
150
|
* newest repeats another run's verdict with no proof time to
|
|
151
|
-
* tell them apart,
|
|
151
|
+
* tell them apart, a run's start time cannot be ranked, or the
|
|
152
|
+
* newest pass started before another run at this head was
|
|
153
|
+
* posted
|
|
152
154
|
* - `error` the gate could not reach a decision (fail open)
|
|
153
155
|
*
|
|
154
156
|
* There is no `reduced`: mode stopped being an authorization condition in
|
|
@@ -205,6 +207,22 @@ const COMMAND_IDENTITY_MAX_LENGTH = 120;
|
|
|
205
207
|
*/
|
|
206
208
|
const TRUSTED_IMPACT_STAMP_VERSION = 4;
|
|
207
209
|
|
|
210
|
+
/**
|
|
211
|
+
* The verify modes the CLI reads a payload under (`isResolvedPrVerifyMode` in
|
|
212
|
+
* `software-factory/src/pr-verify-mode.ts`). factory-ci cannot import it, so
|
|
213
|
+
* the list is repeated here, and the software-factory differential suite pins
|
|
214
|
+
* the two lists together (#1510).
|
|
215
|
+
*/
|
|
216
|
+
const RESOLVED_VERIFY_MODES = ["docs-only", "trivial", "full"] as const;
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* The check-text size over which the CLI drops a transported typed proof
|
|
220
|
+
* (`readTransportedVerifyProof` in
|
|
221
|
+
* `software-factory/src/pr-verify-check-payload.ts`), in UTF-8 bytes of the
|
|
222
|
+
* raw text it parsed, fence included (#1510).
|
|
223
|
+
*/
|
|
224
|
+
const TRANSPORT_CAP_BYTES = 60_000;
|
|
225
|
+
|
|
208
226
|
const isProofReuseCommand = (value: unknown): value is ProofReuseCommand => {
|
|
209
227
|
if (!(value && typeof value === "object")) {
|
|
210
228
|
return false;
|
|
@@ -314,64 +332,168 @@ export const resolveProofReuseCommands = (
|
|
|
314
332
|
* document. Anything unparseable degrades to `null`, and therefore to a
|
|
315
333
|
* refusal.
|
|
316
334
|
*
|
|
317
|
-
* This is the *second* parser of that payload
|
|
335
|
+
* This is the *second* parser of that payload, and it does not reimplement
|
|
336
|
+
* the first: `parsePrVerifyCheckPayload`
|
|
318
337
|
* (`software-factory/src/pr-verify-check-payload.ts`) regex-extracts the fenced
|
|
319
|
-
* block
|
|
320
|
-
*
|
|
321
|
-
*
|
|
322
|
-
*
|
|
323
|
-
*
|
|
324
|
-
*
|
|
338
|
+
* block up to the next line that starts with a fence and `JSON.parse`s it,
|
|
339
|
+
* while this one strips every such line and `fromjson`s what remains. The
|
|
340
|
+
* writer renders JSON, whose strings hold no raw line feed, between one
|
|
341
|
+
* opening and one closing fence line, so on its text the two read the same
|
|
342
|
+
* JSON, three backticks inside a string included. On other text they can
|
|
343
|
+
* differ in either direction. Prose around the fence parses there and refuses
|
|
344
|
+
* here; the test suite asserts that the exact shape the renderer emits is
|
|
345
|
+
* proven here and that the prose-wrapped shape refuses. Text that parses here
|
|
346
|
+
* and not there is part of the trust boundary below.
|
|
347
|
+
*
|
|
348
|
+
* Once parsed, a payload is read by the CLI's readability rules (#1510).
|
|
349
|
+
* `bound` requires the binding's
|
|
350
|
+
* `kind`, `schemaVersion` 1, this head, this repository and a resolved verify
|
|
351
|
+
* mode (`resolvedMode`, the CLI's `isResolvedPrVerifyMode`), and the verdict
|
|
352
|
+
* stage refuses a run that is not `bound` as `unreadable`; an `outcome` other
|
|
353
|
+
* than `passed` is never a pass. `binding` drops a transported typed proof
|
|
354
|
+
* (`verificationProof`) when the text it parsed, fence included, is over
|
|
355
|
+
* 60,000 UTF-8 bytes, as `readTransportedVerifyProof` does, so the run is a
|
|
356
|
+
* pass with no typed proof to both readers. On text the writer never emits,
|
|
357
|
+
* this reader can still read a payload differently; see the trust boundary
|
|
358
|
+
* below.
|
|
325
359
|
*
|
|
326
|
-
*
|
|
327
|
-
* GitHub
|
|
360
|
+
* A passing generation is ordered by when its verification started, never
|
|
361
|
+
* later than when its run reached GitHub and never by when its verification
|
|
362
|
+
* ended (#1409, #1490). Every other run is ordered by when it reached GitHub
|
|
363
|
+
* (#1506). It is the rule `fetchPrVerifyProofBinding` applies
|
|
328
364
|
* (`software-factory/src/github-check-runs.ts`), mirrored here because this
|
|
329
365
|
* reader is jq in generated CI and cannot import it:
|
|
330
366
|
*
|
|
331
|
-
* - A run
|
|
332
|
-
*
|
|
333
|
-
*
|
|
334
|
-
*
|
|
335
|
-
*
|
|
336
|
-
* and
|
|
337
|
-
*
|
|
338
|
-
*
|
|
339
|
-
*
|
|
340
|
-
*
|
|
341
|
-
* -
|
|
342
|
-
*
|
|
343
|
-
*
|
|
344
|
-
*
|
|
345
|
-
*
|
|
346
|
-
*
|
|
367
|
+
* - A passing run (`passing`) is completed with conclusion `success`, and its
|
|
368
|
+
* binding is bound to this head and repository with outcome `passed`. When it
|
|
369
|
+
* transports a typed proof (`verificationProof`) whose start is computable
|
|
370
|
+
* (`proofStart`: its `endedAt` minus its `durationMs`), it is ordered at that
|
|
371
|
+
* start, or at its own `started_at` when that is earlier. Such runs with the
|
|
372
|
+
* same binding, status and conclusion are one generation posted more than
|
|
373
|
+
* once (`pr:verify` posts, `pr:publish` re-posts), ordered at the earliest of
|
|
374
|
+
* its members' instants, whatever order GitHub serves them in. A re-post does
|
|
375
|
+
* not move the proof's start, so a re-post of an older pass never outranks a
|
|
376
|
+
* newer failure, and a post plus its re-post is no tie.
|
|
377
|
+
* - Any other run is its own generation at its `started_at`: one still
|
|
378
|
+
* running, a failure or cancellation whether or not it carries a proof, an
|
|
379
|
+
* unbound one, or a pass with no usable typed proof (over the text cap,
|
|
380
|
+
* written before proofs travelled, or with no computable start). A run is
|
|
381
|
+
* created no earlier than its verification began, so `started_at` is an
|
|
382
|
+
* upper bound on that start. Ranking there can only make such a run newer
|
|
383
|
+
* than it is, so it vetoes more, never less.
|
|
384
|
+
* - Neither `endedAt` nor a passing run's `started_at` is its start. The
|
|
385
|
+
* factory posts a `pr-verify` run only once verification has finished, so
|
|
386
|
+
* both say when it ended, and an older pass ordered there would hide a run
|
|
387
|
+
* that started after the pass began: still running, or failed (#1490). A
|
|
388
|
+
* pass's `started_at` only caps its proof's start. A failure's `started_at`
|
|
389
|
+
* is when it was posted, not when it started, and that is deliberate: a
|
|
390
|
+
* veto's instant only has to be no earlier than its start.
|
|
391
|
+
* - Only a pass is ordered by its proof because this reader cannot run the
|
|
392
|
+
* proof schema (#1506). The CLI drops a payload whose proof fails that
|
|
393
|
+
* schema and orders the run at its `started_at`; ordered by its proof's
|
|
394
|
+
* claimed start, a failure carrying a malformed proof ranked under an older
|
|
395
|
+
* pass here, and the gate returned `proven` where the CLI refused. For an
|
|
396
|
+
* honest proof, `started_at` is no earlier than `endedAt`, which is no
|
|
397
|
+
* earlier than the start, so the cap changes nothing for a valid pass.
|
|
398
|
+
* - A pass is reused only when its verification started strictly after every
|
|
399
|
+
* other run at this head was posted (#1506). Its start is its instant: its
|
|
400
|
+
* proof's start, capped as above, or its `started_at` when it is ordered
|
|
401
|
+
* there. Every other run's post is its `started_at`, rounded down to the
|
|
402
|
+
* whole second. Only the pass's own generation is left out: its re-post
|
|
403
|
+
* group, or, for a pass with no typed proof, that run alone
|
|
404
|
+
* (`ownGeneration`). At most one generation can satisfy this, and that one
|
|
405
|
+
* is the newest, so the gate selects the newest generation and, when it is
|
|
406
|
+
* a pass (`passing`), refuses it as `ambiguous` unless every other run was
|
|
407
|
+
* posted before its instant. When the newest generation is not a pass, the
|
|
408
|
+
* verdict is a refusal anyway, so its reason (`failed`, `pending`, ...)
|
|
409
|
+
* stands and the check does not run.
|
|
410
|
+
* - The check exists because any other run may be ordered earlier than its
|
|
411
|
+
* post by a proof this reader cannot validate: a pass that only claims
|
|
412
|
+
* `passed` looks to jq exactly like one the CLI validates. Without it, a
|
|
413
|
+
* successful run whose malformed proof claimed an early start ranked under
|
|
414
|
+
* an older pass, whether that pass was ordered by its proof or at its
|
|
415
|
+
* `started_at`, and the gate reused the older pass where the CLI, which
|
|
416
|
+
* drops that payload and ranks the run at its `started_at`, refused. With
|
|
417
|
+
* it, whether a pass may be reused never consults another run's proof
|
|
418
|
+
* fields, only when each other run was posted, which GitHub records. Those
|
|
419
|
+
* fields can only cause a refusal; they never hide a veto. The pass's own
|
|
420
|
+
* clock is capped at its post, so it can only count against that pass.
|
|
421
|
+
* - Two changes on valid input follow, and both only add refusals, each
|
|
422
|
+
* costing one hosted run in a rare case. A failure carrying a proof is
|
|
423
|
+
* ordered when it was posted instead of when it started, so an older failure
|
|
424
|
+
* that finished after a newer pass began now refuses reuse. Two pass
|
|
425
|
+
* generations whose verifications overlapped now refuse, as does an older
|
|
426
|
+
* pass re-posted after a newer pass started. Passes that ran one after the
|
|
427
|
+
* other, and a pass with its own re-posts, are reused as before.
|
|
428
|
+
* - The hosted gate's trust boundary is a class. This reader does not
|
|
429
|
+
* reimplement the CLI's payload parser. On payloads the factory's writer
|
|
430
|
+
* emits, both readers select the same pass or both refuse: the differential
|
|
431
|
+
* suite, `software-factory/src/pr-verify-reuse-differential.test.ts`,
|
|
432
|
+
* asserts it over 9,653 generated run sets. On App-signed text the writer
|
|
433
|
+
* never emits, the two can differ in either direction. The known instances
|
|
434
|
+
* where this gate reuses and the CLI refuses are: (a) a reused run whose
|
|
435
|
+
* typed proof fails `validatePrVerifyProof`; (b) a newest pass that repeats
|
|
436
|
+
* another run's verdict only once the CLI normalizes that run's payload, say
|
|
437
|
+
* by dropping a key, since the CLI compares normalized payloads and this
|
|
438
|
+
* reader raw ones; (c) a payload in `output.summary` beside a text payload
|
|
439
|
+
* the CLI cannot read, which the CLI reads from the summary and this reader
|
|
440
|
+
* from the text; (d) text that this reader's strip-and-`fromjson` reads and
|
|
441
|
+
* the CLI's fence match or `JSON.parse` refuses, such as a closing fence
|
|
442
|
+
* with no opening one, a doubled opening fence, a fence line inside the
|
|
443
|
+
* JSON, a payload split across two fenced blocks, or a number literal such
|
|
444
|
+
* as `NaN` where the jq in use accepts it (jq 1.8 does). Mirroring any of it
|
|
445
|
+
* would turn this reader into a parser. Only the factory App can post the
|
|
446
|
+
* run, and that identity bounds the whole class (#1511).
|
|
447
|
+
* - A run not ordered by a typed proof carries no generation identity, so it
|
|
448
|
+
* is never grouped. Two separate executions with the same command names and
|
|
449
|
+
* verdict post the same compact binding, and so does a re-post. When the
|
|
450
|
+
* newest generation is one of these and repeats another run's verdict
|
|
451
|
+
* (binding, status and conclusion), it could be a re-post of an older
|
|
452
|
+
* verdict or a new one, so it is `ambiguous`. Proofs that size are rare;
|
|
453
|
+
* refusing costs a hosted run.
|
|
347
454
|
*
|
|
348
455
|
* Two different generations that share the newest instant are `ambiguous`
|
|
349
456
|
* rather than arbitrarily resolved: the gate cannot tell which one describes
|
|
350
457
|
* the tree, and silently picking either is exactly the kind of coin-flip
|
|
351
|
-
* authorization this whole mechanism exists to remove.
|
|
352
|
-
* normalized to whole seconds so `…:00Z` and `…:00.000Z` compare equal; two
|
|
353
|
-
* genuine verification generations within the same second at the same head
|
|
354
|
-
* is not a real state, and collapsing them errs toward refusing.
|
|
458
|
+
* authorization this whole mechanism exists to remove.
|
|
355
459
|
*
|
|
356
|
-
*
|
|
357
|
-
*
|
|
358
|
-
*
|
|
359
|
-
*
|
|
360
|
-
*
|
|
361
|
-
*
|
|
362
|
-
*
|
|
363
|
-
*
|
|
364
|
-
*
|
|
460
|
+
* Every instant is a whole epoch second, rounded down. A `started_at` keeps
|
|
461
|
+
* its whole second, so `…:00Z` and `…:00.500Z` compare equal. A proof's start
|
|
462
|
+
* is `floor((endedAt - durationMs) / 1000)` with `endedAt` in epoch
|
|
463
|
+
* milliseconds, its fraction read to the millisecond the way `Date.parse`
|
|
464
|
+
* reads it. Rounding down is monotonic, so it can merge two instants into a
|
|
465
|
+
* tie, which is `ambiguous`, but never invert them. It also fails closed: a
|
|
466
|
+
* proof's start never moves later, so it never outranks an unbound run in the
|
|
467
|
+
* same second. The TypeScript reader rounds the same way, so the two agree on
|
|
468
|
+
* every canonical instant. Two genuine verification generations within the
|
|
469
|
+
* same second at the same head is not a real state.
|
|
470
|
+
*
|
|
471
|
+
* `fromdateiso8601` reads only canonical UTC, and the gate never asks it to
|
|
472
|
+
* read anything else. Every candidate must carry a canonical UTC
|
|
473
|
+
* `started_at`, and one that does not makes the newest generation
|
|
474
|
+
* unestablishable, which is `ambiguous`. A typed proof whose `endedAt` is not
|
|
475
|
+
* canonical UTC, or whose `durationMs` is missing or not a finite non-negative
|
|
476
|
+
* number, records no start, and its run falls back to `started_at` like any
|
|
477
|
+
* other run without a typed proof. Refusing costs a hosted run; ranking an
|
|
478
|
+
* unorderable set could authorize the wrong one.
|
|
365
479
|
*/
|
|
366
480
|
const GATE_JQ = String.raw`
|
|
367
481
|
def binding:
|
|
368
482
|
[ .output.text, .output.summary ]
|
|
369
483
|
| map(select(type == "string"))
|
|
370
|
-
| map(
|
|
371
|
-
|
|
372
|
-
|
|
484
|
+
| map(. as $text
|
|
485
|
+
| (split("\n") | map(select(startswith("${"```"}") | not)) | join("\n")
|
|
486
|
+
| try fromjson catch null)
|
|
487
|
+
| select(type == "object")
|
|
488
|
+
| if ($text | utf8bytelength) > ${TRANSPORT_CAP_BYTES}
|
|
489
|
+
then del(.verificationProof)
|
|
490
|
+
else .
|
|
491
|
+
end)
|
|
373
492
|
| .[0];
|
|
374
493
|
|
|
494
|
+
def resolvedMode:
|
|
495
|
+
IN(${RESOLVED_VERIFY_MODES.map((mode) => JSON.stringify(mode)).join(", ")});
|
|
496
|
+
|
|
375
497
|
def startedAt: (.started_at // "") | tostring;
|
|
376
498
|
|
|
377
499
|
def rankable:
|
|
@@ -379,17 +501,45 @@ def rankable:
|
|
|
379
501
|
|
|
380
502
|
def wholeSecond: sub("\\.[0-9]+Z$"; "Z");
|
|
381
503
|
|
|
504
|
+
def epochSecond:
|
|
505
|
+
if type == "string" and rankable
|
|
506
|
+
then (try (wholeSecond | fromdateiso8601) catch null)
|
|
507
|
+
else null
|
|
508
|
+
end;
|
|
509
|
+
|
|
510
|
+
def millisecondPart:
|
|
511
|
+
((capture("\\.(?<digits>[0-9]+)Z$") | .digits) // "") + "000"
|
|
512
|
+
| .[0:3]
|
|
513
|
+
| tonumber;
|
|
514
|
+
|
|
382
515
|
def bound:
|
|
383
516
|
(.binding | type) == "object"
|
|
384
517
|
and .binding.kind == "pr-verify-proof-binding"
|
|
385
518
|
and .binding.schemaVersion == 1
|
|
386
519
|
and .binding.headSha == $sha
|
|
387
|
-
and .binding.repository == $repository
|
|
520
|
+
and .binding.repository == $repository
|
|
521
|
+
and (.binding.mode | resolvedMode);
|
|
522
|
+
|
|
523
|
+
def passing:
|
|
524
|
+
.status == "completed"
|
|
525
|
+
and .conclusion == "success"
|
|
526
|
+
and bound
|
|
527
|
+
and .binding.outcome == "passed";
|
|
388
528
|
|
|
389
|
-
def
|
|
390
|
-
if bound then
|
|
391
|
-
|
|
392
|
-
|
|
|
529
|
+
def proofStart:
|
|
530
|
+
if bound and (.binding.verificationProof | type) == "object" then
|
|
531
|
+
.binding.verificationProof as $proof
|
|
532
|
+
| ($proof.endedAt | epochSecond) as $ended
|
|
533
|
+
| $proof.durationMs as $duration
|
|
534
|
+
| if $ended != null
|
|
535
|
+
and ($duration | type) == "number"
|
|
536
|
+
and ($duration | isinfinite | not)
|
|
537
|
+
and $duration >= 0
|
|
538
|
+
then ($ended * 1000 + ($proof.endedAt | millisecondPart) - $duration)
|
|
539
|
+
/ 1000
|
|
540
|
+
| floor
|
|
541
|
+
else null
|
|
542
|
+
end
|
|
393
543
|
else null
|
|
394
544
|
end;
|
|
395
545
|
|
|
@@ -399,6 +549,12 @@ def sameVerdict($other):
|
|
|
399
549
|
and .conclusion == $other.conclusion
|
|
400
550
|
and .binding == $other.binding;
|
|
401
551
|
|
|
552
|
+
def ownGeneration($generation):
|
|
553
|
+
if $generation.recorded
|
|
554
|
+
then .recorded and sameVerdict($generation)
|
|
555
|
+
else .index == $generation.index
|
|
556
|
+
end;
|
|
557
|
+
|
|
402
558
|
def nonemptyString:
|
|
403
559
|
type == "string" and length > 0;
|
|
404
560
|
|
|
@@ -423,15 +579,19 @@ def releaseAuthorized($release; $commands; $stamp):
|
|
|
423
579
|
url: ((.html_url // "") | tostring),
|
|
424
580
|
binding: binding }
|
|
425
581
|
] as $runs
|
|
426
|
-
| ($runs | map(.started |
|
|
427
|
-
| [ $runs
|
|
428
|
-
|
|
|
429
|
-
|
|
|
582
|
+
| ($runs | map(.started | epochSecond != null) | all) as $orderable
|
|
583
|
+
| [ range(0; $runs | length) as $index
|
|
584
|
+
| $runs[$index]
|
|
585
|
+
| (.started | epochSecond) as $posted
|
|
586
|
+
| (if passing then proofStart else null end) as $start
|
|
587
|
+
| . + { at: ([$start, $posted] | map(select(. != null)) | min),
|
|
588
|
+
index: $index,
|
|
589
|
+
recorded: ($start != null) }
|
|
430
590
|
] as $observed
|
|
431
591
|
| ( [ $observed[] | select(.recorded | not) ]
|
|
432
592
|
+ ( [ $observed[] | select(.recorded) ]
|
|
433
593
|
| group_by([.status, .conclusion, .binding])
|
|
434
|
-
| map(.[0]) ) ) as $generations
|
|
594
|
+
| map(.[0] + { at: (map(.at) | min) }) ) ) as $generations
|
|
435
595
|
| ($generations | map(.at) | max) as $newest
|
|
436
596
|
| [ $generations[] | select(.at == $newest) ] as $generation
|
|
437
597
|
| (if ($runs | length) == 0 then ["none", "", "", ""]
|
|
@@ -441,6 +601,11 @@ def releaseAuthorized($release; $commands; $stamp):
|
|
|
441
601
|
| ($newestRun.recorded | not)
|
|
442
602
|
and ([ $runs[] | select(sameVerdict($newestRun)) ] | length) > 1)
|
|
443
603
|
then ["ambiguous", "", "", ""]
|
|
604
|
+
elif ($generation[0] as $newestRun
|
|
605
|
+
| ($newestRun | passing)
|
|
606
|
+
and any($observed[] | select(ownGeneration($newestRun) | not);
|
|
607
|
+
(.started | epochSecond) >= $newestRun.at))
|
|
608
|
+
then ["ambiguous", "", "", ""]
|
|
444
609
|
else
|
|
445
610
|
$generation[0] as $run
|
|
446
611
|
| (if ($run.binding | type) == "object" then $run.binding else {} end) as $proof
|
|
@@ -490,11 +655,7 @@ def releaseAuthorized($release; $commands; $stamp):
|
|
|
490
655
|
| ($required - $executed - $released) as $missing
|
|
491
656
|
| (if $run.status != "completed" then "pending"
|
|
492
657
|
elif $run.conclusion != "success" then "failed"
|
|
493
|
-
elif (
|
|
494
|
-
or ($proof.kind != "pr-verify-proof-binding")
|
|
495
|
-
or ($proof.schemaVersion != 1)
|
|
496
|
-
or ($proof.headSha != $sha)
|
|
497
|
-
or ($proof.repository != $repository) then "unreadable"
|
|
658
|
+
elif ($run | bound | not) then "unreadable"
|
|
498
659
|
elif $proof.outcome != "passed" then "failed"
|
|
499
660
|
elif ($required | length) == 0 then "incomplete"
|
|
500
661
|
elif ($releasesValid | not) then "incomplete"
|
|
@@ -704,7 +865,7 @@ case "$reason" in
|
|
|
704
865
|
ambiguous)
|
|
705
866
|
say 'Ran the full suite. The newest factory proof for this commit is ambiguous.'
|
|
706
867
|
say ''
|
|
707
|
-
say "Two different \`$CHECK_NAME\` proofs at head \`$HEAD_SHA\` share the newest generation, the newest repeats an earlier run's verdict with no proof time to tell them apart,
|
|
868
|
+
say "Two different \`$CHECK_NAME\` proofs at head \`$HEAD_SHA\` share the newest generation, the newest repeats an earlier run's verdict with no proof time to tell them apart, a run's start time cannot be ranked, or the newest pass started before another run at this head was posted, so there is no single newest generation to trust. The gate refuses rather than picking one."
|
|
708
869
|
say ''
|
|
709
870
|
say '${CORRECTIVE_LINE}'
|
|
710
871
|
;;
|