@patronage/factory-ci 1.0.0-alpha.43 → 1.0.0-alpha.45

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.
@@ -5,11 +5,7 @@
5
5
  * reuse the local verification the factory already published for *this exact
6
6
  * head*? It asks that only on a pull request, so every default-branch push
7
7
  * executes the full hosted suite (#863). Refusing runs hosted CI; it never
8
- * fails the candidate. Three
9
- * repositories had independently grown their own answer to that question and
10
- * had already drifted apart, so the answer lives here once, with the App
11
- * identity, check name, step identity, output names, guard, and every trust
12
- * predicate fixed rather than consumer-configurable.
8
+ * fails the candidate.
13
9
  *
14
10
  * What a consumer chooses is only *what its guarded surface requires*: the
15
11
  * plain profile command objects that surface selects. Everything else below is
@@ -136,8 +132,8 @@ export const FACTORY_PROOF_GATE_GUARD = `steps.${FACTORY_PROOF_GATE_STEP_ID}.out
136
132
  export const FACTORY_PROOF_GATE_IF = "github.event_name == 'pull_request'";
137
133
 
138
134
  /**
139
- * The complete refusal vocabulary. Deliberately few, because these are the
140
- * only distinctions the gate can honestly make from its Checks API reads.
135
+ * The complete refusal vocabulary: the only distinctions the gate can make
136
+ * from its Checks API reads.
141
137
  *
142
138
  * - `proven` a covering, passing, unambiguous proof for this exact head
143
139
  * - `none` no App-verified factory check run at this commit
@@ -148,14 +144,11 @@ export const FACTORY_PROOF_GATE_IF = "github.event_name == 'pull_request'";
148
144
  * cover every required command
149
145
  * - `ambiguous` two different generations share the newest instant, the
150
146
  * newest repeats another run's verdict with no proof time to
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
147
+ * tell them apart, a run's start time cannot be ranked, the
148
+ * newest pass records no verification start beside another run
149
+ * at this head (#1514), or the newest pass started before
150
+ * another run at this head was posted
154
151
  * - `error` the gate could not reach a decision (fail open)
155
- *
156
- * There is no `reduced`: mode stopped being an authorization condition in
157
- * ADR 0022, so a narrower run that still executed every required command is
158
- * indistinguishable from a full one *for this surface*, which is the point.
159
152
  */
160
153
  export const FACTORY_PROOF_GATE_REASONS = [
161
154
  "proven",
@@ -269,31 +262,12 @@ export const proofReuseRequiredCommands = (
269
262
  };
270
263
 
271
264
  /**
272
- * Resolve command *identities* to their `ProofReuseCommand` objects (ADR
273
- * 0021).
274
- *
275
- * Selection by name is deliberately a consumer decision (proof-surfaces.ts in
276
- * software-factory-hq, the `paitronage:verify` filter in paitronage's
277
- * `verify.ts`): only the consumer knows which named commands a guarded
278
- * surface requires. What both of those implementations independently
279
- * hand-rolled is the same lookup — find each name in the profile's command
280
- * catalog, and refuse to silently shrink the required set when a name has no
281
- * entry. That lookup is what this function is: the mechanic, not the
282
- * selection.
283
- *
284
- * Throwing at generation time (rather than returning `undefined` or an empty
285
- * array) is deliberate: a name with no catalog entry is a mistake in the
286
- * generator source, not a runtime condition a consumer should have to check
287
- * for, and a required set that quietly loses an entry is exactly what makes a
288
- * passing proof trivially "covering".
289
- *
290
- * `selectionLabel` names the failure, nothing else: it is not part of the
291
- * selection this function resolves, only prose a consumer supplies for its
292
- * own thrown error (e.g. HQ's surface name, "core" or "docs"). The message
293
- * deliberately says "the profile's command catalog" rather than naming
294
- * `software-factory.profile.json`: a fleet-generic library must not assume
295
- * every consumer's catalog is that exact file, so this wording differs
296
- * on purpose from the HQ-local message it replaced.
265
+ * Resolve command identities to their `ProofReuseCommand` objects (ADR 0021).
266
+ * Which names a surface requires is the consumer's choice; this is only the
267
+ * lookup. A name with no catalog entry throws at generation time, because a
268
+ * required set that quietly loses an entry makes any passing proof covering.
269
+ * The message says "the profile's command catalog" rather than a file name,
270
+ * since not every consumer's catalog is `software-factory.profile.json`.
297
271
  */
298
272
  export const resolveProofReuseCommands = (
299
273
  catalog: readonly ProofReuseCommand[],
@@ -381,6 +355,14 @@ export const resolveProofReuseCommands = (
381
355
  * created no earlier than its verification began, so `started_at` is an
382
356
  * upper bound on that start. Ranking there can only make such a run newer
383
357
  * than it is, so it vetoes more, never less.
358
+ * - A pass with no usable typed proof is reused only when it is the only run
359
+ * at this head (#1514). Its verification started at some unknown instant
360
+ * no later than its `started_at`, so another run posted before that
361
+ * `started_at` may still have been posted after the pass began: a pass
362
+ * verified before a failure but posted after it would otherwise outrank
363
+ * the failure. Ranked at its post, such a pass can only veto more as an
364
+ * older run; as the newest it is `ambiguous` beside any other run. Proofs
365
+ * over the text cap are rare, so refusing costs a hosted run.
384
366
  * - Neither `endedAt` nor a passing run's `started_at` is its start. The
385
367
  * factory posts a `pr-verify` run only once verification has finished, so
386
368
  * both say when it ended, and an older pass ordered there would hide a run
@@ -429,7 +411,7 @@ export const resolveProofReuseCommands = (
429
411
  * reimplement the CLI's payload parser. On payloads the factory's writer
430
412
  * emits, both readers select the same pass or both refuse: the differential
431
413
  * 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
414
+ * asserts it over 10,561 generated run sets. On App-signed text the writer
433
415
  * never emits, the two can differ in either direction. The known instances
434
416
  * where this gate reuses and the CLI refuses are: (a) a reused run whose
435
417
  * typed proof fails `validatePrVerifyProof`; (b) a newest pass that repeats
@@ -601,6 +583,11 @@ def releaseAuthorized($release; $commands; $stamp):
601
583
  | ($newestRun.recorded | not)
602
584
  and ([ $runs[] | select(sameVerdict($newestRun)) ] | length) > 1)
603
585
  then ["ambiguous", "", "", ""]
586
+ elif ($generation[0] as $newestRun
587
+ | ($newestRun | passing)
588
+ and ($newestRun.recorded | not)
589
+ and ($runs | length) > 1)
590
+ then ["ambiguous", "", "", ""]
604
591
  elif ($generation[0] as $newestRun
605
592
  | ($newestRun | passing)
606
593
  and any($observed[] | select(ownGeneration($newestRun) | not);
@@ -668,15 +655,8 @@ def releaseAuthorized($release; $commands; $stamp):
668
655
  | join("\n")
669
656
  `.trim();
670
657
 
671
- /**
672
- * Every refusal ends on the same line. `pr:verify` is the command that
673
- * produces the proof this job looks for, so it is the corrective action
674
- * whatever the refusal was.
675
- *
676
- * It is phrased as an option, not a reprimand. A pull request opened by hand
677
- * has no factory proof and never will; the full suite running for it is the
678
- * designed behavior, not a mistake to report.
679
- */
658
+ // Phrased as an option, not a reprimand: a hand-opened pull request has no
659
+ // factory proof, and the full suite running for it is the designed behavior.
680
660
  const CORRECTIVE_LINE =
681
661
  "Run `psf pr:verify` before publishing to reuse local proof and avoid a duplicate server run.";
682
662
 
@@ -739,13 +719,15 @@ gate_lookup() {
739
719
  lookup_detail="checks API unreadable: $lookup_response"
740
720
  return 0
741
721
  fi
742
- if ! lookup_finding=$(printf '%s' "$lookup_response" | jq -r -s \
722
+ # A herestring, not printf piped into jq: the lookup starts jq alone,
723
+ # with no pipeline around it (#1096).
724
+ if ! lookup_finding=$(jq -r -s \
743
725
  --arg name "$CHECK_NAME" \
744
726
  --arg app "$FACTORY_APP_ID" \
745
727
  --arg sha "$1" \
746
728
  --arg repository "$GITHUB_REPOSITORY" \
747
729
  --argjson required "$REQUIRED_COMMANDS" \
748
- '${GATE_JQ}' 2>&1); then
730
+ '${GATE_JQ}' 2>&1 <<< "$lookup_response"); then
749
731
  lookup_detail="unreadable proof binding: $lookup_finding"
750
732
  return 0
751
733
  fi
@@ -801,9 +783,14 @@ if [ "$reason" = 'proven' ]; then
801
783
  fi
802
784
 
803
785
  # detail can carry arbitrary gh or jq error text. Collapse it to one bounded
804
- # line so it cannot restructure the summary it is written into.
805
- detail=$(printf '%s' "$detail" | tr '\n\r\t' ' ' | cut -c1-240)
806
- missing=$(printf '%s' "$missing" | tr '\n\r\t' ' ' | cut -c1-240)
786
+ # line so it cannot restructure the summary it is written into. Builtin
787
+ # expansions, not printf | tr | cut: each process the script starts waits for
788
+ # a CPU on a loaded machine, and these two pipelines were most of the
789
+ # processes every gate run started (#1096).
790
+ detail=${shellExpansion(String.raw`detail//[$'\n\r\t']/ `)}
791
+ detail=${shellExpansion("detail:0:240")}
792
+ missing=${shellExpansion(String.raw`missing//[$'\n\r\t']/ `)}
793
+ missing=${shellExpansion("missing:0:240")}
807
794
  if ! [[ "$source_url" =~ ^https://github\.com/[A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+/runs/[0-9]+$ ]]; then
808
795
  source_url=''
809
796
  fi
@@ -865,7 +852,7 @@ case "$reason" in
865
852
  ambiguous)
866
853
  say 'Ran the full suite. The newest factory proof for this commit is ambiguous.'
867
854
  say ''
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."
855
+ 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, the newest pass records no verification start beside another run at this head, 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."
869
856
  say ''
870
857
  say '${CORRECTIVE_LINE}'
871
858
  ;;
@@ -960,9 +947,7 @@ export const factoryProofGateStep = (
960
947
  continueOnError: true as const,
961
948
  env: Object.freeze({
962
949
  GH_TOKEN: githubExpression("secrets.GITHUB_TOKEN"),
963
- // On a pull request the verified head is the PR branch tip. The step
964
- // never runs on a push, so no reachable path reads the `github.sha`
965
- // half.
950
+ // The step never runs on a push, so the `github.sha` half is unreachable.
966
951
  HEAD_SHA: githubExpression(
967
952
  "github.event.pull_request.head.sha || github.sha"
968
953
  ),
@@ -60,9 +60,6 @@ say '## ${label} timing'
60
60
  say ''
61
61
 
62
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
63
  say '- Path: full execution, no proof consulted'
67
64
  say '- Proof-reuse gate: did not run on this ref; the full suite ran.'
68
65
  say "- Verified head: \`${shellExpansion("GITHUB_SHA:-unknown")}\`"
@@ -12,11 +12,7 @@ const UPLOAD_ARTIFACT_REPOSITORY = UPLOAD_ARTIFACT.uses.slice(
12
12
  );
13
13
 
14
14
  export const FACTORY_PUSH_IDENTITY_SCHEMA_VERSION = 1;
15
- /**
16
- * The artifact prefix and the five step IDs are module-private. Alpha.13
17
- * removed them from the public surface (#719). A caller reads a step ID from
18
- * the builder's returned `steps` (`step.id`) or from `artifactName`.
19
- */
15
+
20
16
  const FACTORY_PUSH_IDENTITY_ARTIFACT_PREFIX = "factory-push-identity";
21
17
  const FACTORY_PUSH_IDENTITY_RECORD_STEP_ID = "factory_push_identity_record";
22
18
  const FACTORY_PUSH_IDENTITY_LOOKUP_STEP_ID = "factory_push_identity_lookup";