@patronage/factory-ci 1.0.0-alpha.4 → 1.0.0-alpha.41

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.
Files changed (54) hide show
  1. package/README.md +713 -11
  2. package/dist/.build-fingerprint.json +3 -0
  3. package/dist/alchemy/index.d.ts +1174 -0
  4. package/dist/alchemy/index.js +2142 -0
  5. package/dist/bundle-alchemy-entry-CT5hCphA.js +112 -0
  6. package/dist/execute-alchemy-entry-B0lBN-YZ.js +160 -0
  7. package/dist/execute-alchemy-entry-B397GSk5.d.ts +134 -0
  8. package/dist/index.d.ts +1218 -93
  9. package/dist/index.js +2841 -333
  10. package/package.json +28 -10
  11. package/src/actions.ts +13 -0
  12. package/src/alchemy/child-diagnostics.ts +148 -0
  13. package/src/alchemy/credential-preflight.ts +428 -0
  14. package/src/alchemy/destroy-postcondition.ts +103 -0
  15. package/src/alchemy/evaluate-stack.ts +153 -0
  16. package/src/alchemy/first-deploy-authorization.ts +194 -0
  17. package/src/alchemy/index.ts +144 -0
  18. package/src/alchemy/lifecycle-failure.ts +174 -0
  19. package/src/alchemy/lifecycle.ts +1330 -0
  20. package/src/alchemy/local-emulation.ts +89 -0
  21. package/src/alchemy/plan-effects.ts +510 -0
  22. package/src/alchemy/retained-identity.ts +248 -0
  23. package/src/alchemy/secret-name-policy.ts +96 -0
  24. package/src/alchemy/stage-policy.ts +269 -0
  25. package/src/alchemy/state-tree.ts +168 -0
  26. package/src/alchemy/url-implies-auth.ts +264 -0
  27. package/src/alchemy-baseline.ts +75 -0
  28. package/src/bundle-alchemy-entry.ts +5 -0
  29. package/src/candidate-impact-workflow.ts +110 -0
  30. package/src/candidate-lifecycle.ts +29 -0
  31. package/src/cursor-oidc.ts +33 -0
  32. package/src/execute-alchemy-entry.ts +128 -8
  33. package/src/factory-workflow.ts +83 -40
  34. package/src/github-app-token.ts +131 -22
  35. package/src/github-transport.ts +186 -0
  36. package/src/impact-demand-condition.ts +67 -0
  37. package/src/index.ts +174 -0
  38. package/src/lifecycle-contract-lane.ts +113 -0
  39. package/src/merge-freeze-job.ts +253 -0
  40. package/src/pinned-action.ts +30 -0
  41. package/src/pr-status-hud-workflow.ts +96 -0
  42. package/src/preview-cleanup-topology.ts +115 -0
  43. package/src/preview-proof-inventory.ts +1092 -0
  44. package/src/preview-proof-lifecycle.ts +328 -0
  45. package/src/preview-receipt-workflow.ts +83 -0
  46. package/src/production-impact-workflow.ts +181 -0
  47. package/src/proof-reuse-gate.ts +297 -63
  48. package/src/proof-reuse-presentation.ts +131 -0
  49. package/src/push-identity-workflow.ts +463 -0
  50. package/src/runnable-cli.ts +27 -0
  51. package/src/verify-runner-policy.ts +290 -0
  52. package/src/vitest-profile-reader.test.ts +208 -0
  53. package/src/vitest-profile-reader.ts +225 -0
  54. package/src/vitest-profile.ts +631 -0
package/dist/index.d.ts CHANGED
@@ -1,3 +1,49 @@
1
+ import { a as BundleAlchemyEntryOptions, i as executeAlchemyEntry, n as ExecuteAlchemyEntryOptions, o as bundleAlchemyEntry, r as ExecuteAlchemyEntryResult, t as EXECUTE_ALCHEMY_ENTRY_MAX_BUFFER } from "./execute-alchemy-entry-B397GSk5.js";
2
+ import { StdioOptions } from "node:child_process";
3
+
4
+ //#region src/alchemy-baseline.d.ts
5
+ /**
6
+ * The Alchemy fleet baseline (#985, #993). Every factory project that
7
+ * imports `@patronage/factory-ci/alchemy` pins `alchemy` and `effect` to
8
+ * these exact versions. The pair moves together, in the same lockstep
9
+ * release that bumps this constant.
10
+ *
11
+ * This module is a plain constant: it imports neither `alchemy` nor
12
+ * `effect`, so it ships from the root entry, not the `./alchemy` subpath.
13
+ */
14
+ declare const ALCHEMY_BASELINE: {
15
+ readonly alchemy: "2.0.0-beta.81";
16
+ readonly effect: "4.0.1";
17
+ };
18
+ /**
19
+ * The slice of a consumer's `package.json` that carries the pins this
20
+ * baseline checks. Only `dependencies` and `devDependencies` are read —
21
+ * `peerDependencies` is deliberately a range, not a pin (ADR 0031), so it is
22
+ * never compared against the exact baseline.
23
+ */
24
+ interface AlchemyBaselinePackageJson {
25
+ readonly dependencies?: Record<string, string>;
26
+ readonly devDependencies?: Record<string, string>;
27
+ }
28
+ interface AssertAlchemyBaselineInput {
29
+ readonly packageJson: AlchemyBaselinePackageJson;
30
+ }
31
+ /**
32
+ * Fails when the consumer's `alchemy` or `effect` pin differs from
33
+ * {@link ALCHEMY_BASELINE}, or when only one of the pair is present.
34
+ * Alchemy peers on Effect, so an unpinned auto-installed Effect can drift
35
+ * outside the baseline while a lone `alchemy` pin would otherwise pass.
36
+ * Both packages remaining absent is not drift — they are optional peers of
37
+ * the `./alchemy` subpath, so a consumer that never touches it carries
38
+ * neither.
39
+ *
40
+ * Reads only the `packageJson` object it is handed; it never walks the
41
+ * filesystem.
42
+ */
43
+ declare const assertAlchemyBaseline: ({
44
+ packageJson
45
+ }: AssertAlchemyBaselineInput) => void;
46
+ //#endregion
1
47
  //#region src/actions.d.ts
2
48
  /**
3
49
  * The GitHub Actions this family's workflow generators use, pinned to full
@@ -51,56 +97,33 @@ declare const NODE_PNPM_ACTION_FAMILY_NODE24: {
51
97
  readonly uses: "pnpm/action-setup@0ebf47130e4866e96fce0953f49152a61190b271";
52
98
  };
53
99
  };
100
+ /**
101
+ * The one `actions/upload-artifact` pin every workflow generator shares
102
+ * (#887). Two callers pinned two different commits of the same tag family;
103
+ * naming the pin here makes that drift impossible the same way the Node/pnpm
104
+ * family does. A caller passes this through `factoryWorkflow`'s
105
+ * `additionalActions.uploadArtifact` explicitly — the catalog names the pin,
106
+ * it does not inject the upload step.
107
+ */
108
+ declare const UPLOAD_ARTIFACT: {
109
+ readonly tag: "v4.6.2";
110
+ readonly uses: "actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02";
111
+ };
54
112
  //#endregion
55
- //#region src/bundle-alchemy-entry.d.ts
56
- interface BundleAlchemyEntryOptions {
57
- /** The Alchemy entry to bundle, e.g. `alchemy.run.ts`. */
58
- readonly entry: string;
59
- /** Where to write the bundled ESM file, e.g. `.alchemy/deploy-entry.mjs`. */
60
- readonly outfile: string;
61
- /** esbuild's working directory; also the base for relative paths. */
62
- readonly absWorkingDir?: string;
63
- /**
64
- * Import specifiers to rewrite before resolution, passed straight to
65
- * esbuild's `alias`. Substitution happens before the `packages` and
66
- * `external` decisions, so an aliased bare specifier is inlined even under
67
- * `packages: "external"`. Values are resolved the way esbuild resolves any
68
- * import, so give absolute paths or package names — which aliases a repo
69
- * needs is the consumer's policy and this package bakes in none. A key on
70
- * `alchemy`, `effect`, or a subpath of either is rejected outright, and the
71
- * finished bundle is checked for files from those packages however they were
72
- * reached.
73
- */
74
- readonly alias?: Readonly<Record<string, string>>;
75
- /**
76
- * `"external"` (default) leaves every bare import outside the entry's own
77
- * source graph to Node's resolver at run time — the entry's TypeScript is
78
- * still inlined, which is the whole point. `"bundle"` inlines dependencies
79
- * too, minus the Alchemy/Effect externals, for a runner without the
80
- * consumer's node_modules.
81
- */
82
- readonly packages?: "bundle" | "external";
83
- /** Emit a sourcemap next to the outfile. Default `false`. */
84
- readonly sourcemap?: boolean;
85
- /** esbuild target. Default `node24`. */
86
- readonly target?: string;
87
- /** tsconfig to apply to the entry's sources. */
88
- readonly tsconfig?: string;
89
- }
113
+ //#region src/candidate-lifecycle.d.ts
90
114
  /**
91
- * Pre-bundle an Alchemy entry to a single ESM file, keeping `alchemy` and
92
- * `effect` external (#268).
115
+ * Pull-request events that can create or refresh a Factory candidate run.
93
116
  *
94
- * Both repos that deploy through Alchemy wrote this: the Alchemy CLI runs a
95
- * JavaScript entry, so a TypeScript `alchemy.run.ts` has to be flattened
96
- * first, and the flattening must not swallow the two packages whose identity
97
- * matters. Firedup additionally resolved esbuild *through vite* because it had
98
- * no direct dependency on it; here esbuild is a plain dependency of this
99
- * package and that hack can be deleted.
100
- *
101
- * Returns the absolute path of the file written.
117
+ * GitHub's draft boolean remains the lifecycle authority: these triggers make
118
+ * a run visible, while `factoryCandidateOrPushCondition` keeps substantive
119
+ * jobs idle until the pull request is a candidate.
102
120
  */
103
- declare const bundleAlchemyEntry: (options: BundleAlchemyEntryOptions) => Promise<string>;
121
+ declare const FACTORY_CANDIDATE_PULL_REQUEST_TYPES: readonly ["opened", "synchronize", "reopened", "ready_for_review"];
122
+ /**
123
+ * Build a GitHub Actions job condition for candidate PRs and merge-target
124
+ * pushes. The caller owns triggers, jobs, runners, permissions, and topology.
125
+ */
126
+ declare const factoryCandidateOrPushCondition: (candidateCondition?: string) => string;
104
127
  //#endregion
105
128
  //#region src/disposable-stage.d.ts
106
129
  declare const localPreviewStageBrand: unique symbol;
@@ -144,14 +167,260 @@ interface LocalPreviewStageOptions {
144
167
  */
145
168
  declare const localPreviewStage: (options: LocalPreviewStageOptions) => LocalPreviewStage;
146
169
  //#endregion
170
+ //#region src/preview-proof-lifecycle.d.ts
171
+ /**
172
+ * Preview-proof lifecycle: admit a disposable preview, register envelope-bound
173
+ * proof at head, and record cleanup. One `transition` path owns those state
174
+ * changes. Recovery (#766) re-enters cleanup through the same event. Hosted
175
+ * inventory listing and cleanup-outcome persistence live in
176
+ * `previewProofInventory`, which sits on the registration read model `resolve`
177
+ * already returns.
178
+ *
179
+ * Proof sits entirely on one side of GitHub's draft/ready boundary
180
+ * (paitronage#1089): a draft candidate cannot begin or register. Machine
181
+ * evidence is the envelope at head (#355), never a PR comment. The SHA and
182
+ * repository bind that proof (#1312): a detached HEAD or a branch name that
183
+ * differs from the PR head is the same commit, and the registration records
184
+ * `branch: "(detached)"`.
185
+ */
186
+ type PreviewProofCleanupStatus = "failed" | "passed" | "pending";
187
+ interface PreviewProofCandidate {
188
+ readonly branch: string;
189
+ readonly dirty: boolean;
190
+ readonly headSha: string;
191
+ readonly isDraft: boolean;
192
+ readonly pr: number;
193
+ readonly prHeadRef: string;
194
+ readonly prHeadSha: string;
195
+ readonly prRepository: string;
196
+ readonly prState: "CLOSED" | "MERGED" | "OPEN";
197
+ readonly repository: string;
198
+ }
199
+ interface PreviewProofEnvelopeEvidence {
200
+ readonly check: string;
201
+ readonly headSha: string;
202
+ readonly mergeBaseSha: string;
203
+ readonly outcome: "fail" | "pass";
204
+ readonly patchId: string;
205
+ }
206
+ interface PreviewProofCleanupOutcome {
207
+ readonly evidence: readonly string[];
208
+ readonly outcome: Exclude<PreviewProofCleanupStatus, "pending">;
209
+ readonly runUrl?: string;
210
+ }
211
+ interface PreviewProofRegistration {
212
+ /**
213
+ * Present only when the checkout is detached or its branch name is not the
214
+ * PR head. The `(detached)` sentinel is on the lifecycle registration
215
+ * `transition` returns, and `previewProofInventory` does not persist it.
216
+ * It is not a branch to check out.
217
+ */
218
+ readonly branch?: "(detached)";
219
+ readonly cleanup: {
220
+ readonly evidence: readonly string[];
221
+ readonly outcome: PreviewProofCleanupStatus;
222
+ readonly runUrl?: string;
223
+ };
224
+ readonly convergence: {
225
+ readonly detail: string;
226
+ readonly status: "passed";
227
+ };
228
+ readonly headSha: string;
229
+ readonly pr: number;
230
+ readonly proof: {
231
+ readonly check: string;
232
+ readonly headSha: string;
233
+ readonly mergeBaseSha: string;
234
+ readonly patchId: string;
235
+ };
236
+ readonly smoke: {
237
+ readonly detail: string;
238
+ readonly outcome: "passed";
239
+ };
240
+ readonly source: "local-self-certified";
241
+ readonly stack: string;
242
+ readonly stage: LocalPreviewStage;
243
+ readonly url: string;
244
+ }
245
+ interface PreviewProofLifecycleState {
246
+ readonly registrations: readonly PreviewProofRegistration[];
247
+ }
248
+ type PreviewProofLifecycleEvent = {
249
+ readonly candidate: PreviewProofCandidate;
250
+ readonly stage: string;
251
+ readonly type: "begin";
252
+ } | {
253
+ readonly candidate: PreviewProofCandidate;
254
+ readonly convergence: {
255
+ readonly detail: string;
256
+ readonly status: "failed" | "passed";
257
+ };
258
+ readonly evidence: PreviewProofEnvelopeEvidence;
259
+ readonly smoke: {
260
+ readonly detail: string;
261
+ readonly outcome: "failed" | "passed";
262
+ };
263
+ readonly stack: string;
264
+ readonly stage: string;
265
+ readonly type: "register";
266
+ readonly url: string;
267
+ } | {
268
+ readonly evidence: readonly string[];
269
+ readonly outcome: Exclude<PreviewProofCleanupStatus, "pending">;
270
+ readonly pr: number;
271
+ readonly runUrl?: string;
272
+ readonly stack: string;
273
+ readonly stage: string;
274
+ readonly type: "cleanup";
275
+ };
276
+ interface PreviewProofResolveQuery {
277
+ readonly pr?: number;
278
+ readonly stack?: string;
279
+ readonly stage?: string;
280
+ }
281
+ declare const previewProofLifecycle: {
282
+ readonly empty: () => PreviewProofLifecycleState;
283
+ readonly recover: (state: PreviewProofLifecycleState, event: Extract<PreviewProofLifecycleEvent, {
284
+ type: "cleanup";
285
+ }>) => PreviewProofLifecycleState;
286
+ readonly resolve: (state: PreviewProofLifecycleState, query?: PreviewProofResolveQuery) => readonly PreviewProofRegistration[];
287
+ readonly transition: (state: PreviewProofLifecycleState, event: PreviewProofLifecycleEvent) => PreviewProofLifecycleState;
288
+ };
289
+ //#endregion
290
+ //#region src/preview-proof-inventory.d.ts
291
+ /**
292
+ * Hosted preview-proof inventory (#639): persist and list Factory-App
293
+ * registrations, and record cleanup outcomes, without PR comments.
294
+ *
295
+ * `list` is a read over App-owned commit check-runs and works with a workflow
296
+ * `GITHUB_TOKEN`. `persist` and `recordCleanup` write those check-runs, which
297
+ * GitHub only allows the producing App to update. Pass an installation token
298
+ * the caller minted; this package does not read operator config or hold
299
+ * secrets. Cleanup writes go through `previewProofLifecycle.transition` with
300
+ * `{ type: "cleanup" }`. Outcomes are never inferred from whether a stage
301
+ * still exists.
302
+ *
303
+ * Transient transport failures are retried with bounded backoff and then
304
+ * surface as `PreviewProofTransportError` (#830). A failure from `persist` or
305
+ * `recordCleanup` is an evidence-registration failure, never a failed
306
+ * deployment: the caller retains the healthy disposable stage, records its own
307
+ * proof BLOCKED (never PASS), and re-runs registration at the same head —
308
+ * writes are keyed by stack and stage, so resuming needs no redeploy.
309
+ * Admission stays fail-closed on its own: an unregistered proof never
310
+ * satisfies the preview demand.
311
+ */
312
+ /** Check-run name that carries one registration JSON payload. Not a gate. */
313
+ declare const PREVIEW_PROOF_INVENTORY_CHECK_NAME = "patronage-factory/preview-proof";
314
+ /**
315
+ * Least privilege for a job whose `GITHUB_TOKEN` calls `list`. A
316
+ * `permissions` block zeroes every unlisted scope, and `list` reads five
317
+ * endpoints: `pulls/{pr}`, `pulls/{pr}/commits`, and the GraphQL force-push
318
+ * timeline (`pull-requests`), `compare` (`contents`), and
319
+ * `commits/{sha}/check-runs` (`checks`). A job
320
+ * that omits `pull-requests: read` fails with 403 on a same-repository PR
321
+ * and skips every destroy matrix (#859). Give the discovery job this object.
322
+ */
323
+ declare const PREVIEW_PROOF_INVENTORY_LIST_PERMISSIONS: Readonly<{
324
+ readonly checks: "read";
325
+ readonly contents: "read";
326
+ readonly "pull-requests": "read";
327
+ }>;
328
+ interface PreviewProofInventoryStore {
329
+ list: (input: {
330
+ owner: string;
331
+ pr: number;
332
+ repo: string;
333
+ }) => Promise<readonly PreviewProofRegistration[]>;
334
+ put: (input: {
335
+ owner: string;
336
+ registration: PreviewProofRegistration;
337
+ repo: string;
338
+ }) => Promise<void>;
339
+ }
340
+ interface PreviewProofInventoryTransport {
341
+ /** Injectable `fetch` (tests, or a caller with its own instrumented one). */
342
+ fetch?: typeof fetch;
343
+ /** Per-request timeout; defaults to five seconds. */
344
+ timeoutMs?: number;
345
+ /**
346
+ * Bearer token. `list` accepts a workflow `GITHUB_TOKEN` (read) and needs
347
+ * commit (contents) read for the force-push timeline; the contents-less
348
+ * Factory App token cannot serve it (#825). `persist` and `recordCleanup`
349
+ * must use a Factory App installation token: GitHub refuses GITHUB_TOKEN
350
+ * writes to App-owned check-runs.
351
+ */
352
+ token: string;
353
+ }
354
+ interface PreviewProofInventoryAccess {
355
+ fetch?: typeof fetch;
356
+ store?: PreviewProofInventoryStore;
357
+ timeoutMs?: number;
358
+ token?: string;
359
+ }
360
+ interface PreviewProofInventoryListInput {
361
+ owner: string;
362
+ pr: number;
363
+ repo: string;
364
+ stack?: string;
365
+ stage?: string;
366
+ }
367
+ interface PreviewProofInventoryPersistInput {
368
+ owner: string;
369
+ registration: PreviewProofRegistration;
370
+ repo: string;
371
+ }
372
+ interface PreviewProofInventoryCleanupInput {
373
+ evidence: readonly string[];
374
+ headSha?: string;
375
+ outcome: Exclude<PreviewProofCleanupStatus, "pending">;
376
+ owner: string;
377
+ pr: number;
378
+ repo: string;
379
+ runUrl?: string;
380
+ stack: string;
381
+ stage: string;
382
+ }
383
+ /**
384
+ * The transport gave out — a network-level rejection (EPIPE, DNS, an aborted
385
+ * or timed-out request) or a transient HTTP status — and bounded retries did
386
+ * not recover it. GitHub never judged the content, so this is never a
387
+ * validation verdict and never a deployment failure. Only a bounded reason
388
+ * string is retained: the raw transport error can hold the request and its
389
+ * `Authorization` header, so it is deliberately discarded.
390
+ */
391
+ declare class PreviewProofTransportError extends Error {
392
+ /** How many transport attempts were made before giving up. */
393
+ readonly attempts: number;
394
+ /** The last transient HTTP status, when the server answered at all. */
395
+ readonly status?: number;
396
+ constructor(reason: string, attempts: number, status?: number);
397
+ }
398
+ declare const previewProofInventory: {
399
+ readonly githubStore: (transport: PreviewProofInventoryTransport) => PreviewProofInventoryStore;
400
+ readonly list: (input: PreviewProofInventoryListInput, access: PreviewProofInventoryAccess) => Promise<readonly PreviewProofRegistration[]>;
401
+ readonly listPermissions: Readonly<{
402
+ readonly checks: "read";
403
+ readonly contents: "read";
404
+ readonly "pull-requests": "read";
405
+ }>;
406
+ readonly memoryStore: () => PreviewProofInventoryStore;
407
+ readonly persist: (input: PreviewProofInventoryPersistInput, access: PreviewProofInventoryAccess) => Promise<void>;
408
+ readonly recordCleanup: (input: PreviewProofInventoryCleanupInput, access: PreviewProofInventoryAccess) => Promise<PreviewProofRegistration>;
409
+ };
410
+ //#endregion
147
411
  //#region src/factory-workflow.d.ts
148
412
  interface WorkflowStep {
413
+ readonly continueOnError?: boolean;
414
+ readonly env?: Readonly<Record<string, string>>;
415
+ readonly id?: string;
416
+ readonly if?: string;
149
417
  readonly name: string;
150
418
  readonly uses?: string;
151
419
  readonly with?: Readonly<Record<string, string>>;
152
420
  readonly run?: string;
153
421
  }
154
422
  interface CheckoutStepOptions {
423
+ readonly fetchDepth?: number;
155
424
  readonly name?: string;
156
425
  readonly ref?: string;
157
426
  }
@@ -168,6 +437,14 @@ interface FactoryWorkflowSetupOptions {
168
437
  readonly install?: InstallStepOptions;
169
438
  readonly setupNode?: SetupNodeStepOptions;
170
439
  }
440
+ /**
441
+ * Stable identifiers for the setup steps a generated workflow always emits,
442
+ * in emission order. A consumer selects steps by role instead of locating
443
+ * them by display name or by array position/length, so renaming a step or
444
+ * adding a new supported role never breaks role-based composition (#1076).
445
+ */
446
+ declare const SETUP_STEP_ROLES: readonly ["checkout", "setupPnpm", "setupNode", "install"];
447
+ type SetupStepRole = (typeof SETUP_STEP_ROLES)[number];
171
448
  interface FactoryWorkflowOptions<Additional extends Readonly<Record<string, PinnedAction>>> {
172
449
  /**
173
450
  * Required complete family. There is no default, so adopting this package
@@ -188,6 +465,13 @@ interface FactoryWorkflowArtifact<Additional extends Readonly<Record<string, Pin
188
465
  readonly actions: Readonly<FamilyActions & Additional>;
189
466
  /** Checkout → pnpm → Node → install, customized by named role. */
190
467
  readonly setupSteps: readonly WorkflowStep[];
468
+ /**
469
+ * The same steps as `setupSteps`, keyed by stable role instead of position.
470
+ * A consumer that needs a subset or a differently-ordered composition (for
471
+ * example, a custom checkout followed by the shared install steps) selects
472
+ * by role here and never destructures `setupSteps` by array shape.
473
+ */
474
+ readonly setupStepsByRole: Readonly<Record<SetupStepRole, WorkflowStep>>;
191
475
  /**
192
476
  * Structurally accepted by gagen's `writeOrLint`; this package deliberately
193
477
  * has no gagen dependency.
@@ -197,6 +481,18 @@ interface FactoryWorkflowArtifact<Additional extends Readonly<Record<string, Pin
197
481
  readonly pinDeps: false;
198
482
  };
199
483
  }
484
+ /**
485
+ * Select setup steps by stable role, in the order the roles are given.
486
+ *
487
+ * This is the supported alternative to destructuring `setupSteps` by array
488
+ * position or asserting its length: a caller names exactly the roles it
489
+ * needs (for example, every role but `checkout`, to follow its own
490
+ * head-pinned checkout with the shared pnpm/Node/install sequence), and that
491
+ * selection survives a renamed step or an added role.
492
+ */
493
+ declare const setupStepsForRoles: (artifact: {
494
+ readonly setupStepsByRole: Readonly<Record<SetupStepRole, WorkflowStep>>;
495
+ }, roles: readonly SetupStepRole[]) => readonly WorkflowStep[];
200
496
  /**
201
497
  * Own one generated workflow source's action pins, setup block, provenance
202
498
  * banner, and gagen pinning policy as a single artifact.
@@ -206,15 +502,59 @@ interface FactoryWorkflowArtifact<Additional extends Readonly<Record<string, Pin
206
502
  */
207
503
  declare const factoryWorkflow: <const Additional extends Readonly<Record<string, PinnedAction>> = Record<never, never>>(options: FactoryWorkflowOptions<Additional>) => FactoryWorkflowArtifact<Additional>;
208
504
  //#endregion
505
+ //#region src/cursor-oidc.d.ts
506
+ /**
507
+ * Pinned Cursor OIDC trust predicates for the Factory App broker (#949).
508
+ *
509
+ * The broker verifies a Cursor-managed Cloud Agent JWT and mints a
510
+ * repo-scoped Factory App installation token. Audience, issuer, and JWKS are
511
+ * not consumer settings: a knob that pointed them elsewhere would be the
512
+ * whole mechanism undone, the same reason {@link FACTORY_PROOF_GATE_APP_ID}
513
+ * is pinned.
514
+ */
515
+ /** Cursor's OIDC issuer. Tokens minted on the agent VM carry this `iss`. */
516
+ declare const FACTORY_CURSOR_OIDC_ISSUER = "https://api.cursor.com";
517
+ /** JWKS the broker uses to verify RS256 signatures. */
518
+ declare const FACTORY_CURSOR_OIDC_JWKS_URL = "https://api.cursor.com/keys";
519
+ /**
520
+ * Audience a Cursor-managed VM must mint with. The CLI and the broker share
521
+ * this string; Cursor does not allowlist audiences.
522
+ */
523
+ declare const FACTORY_CURSOR_OIDC_AUDIENCE = "Factory";
524
+ /**
525
+ * Runtime claim a Cursor-managed Cloud Agent VM always presents. Self-hosted
526
+ * workers are not this broker's callers.
527
+ */
528
+ declare const FACTORY_CURSOR_OIDC_MANAGED_RUNTIME = "managed";
529
+ /** HQ route that exchanges a verified Cursor OIDC JWT for an App token. */
530
+ declare const FACTORY_APP_BROKER_PATH = "/api/factory-app/installation-token";
531
+ /** Production broker origin. The CLI pins this; it is not profile-declared. */
532
+ declare const FACTORY_APP_BROKER_ORIGIN = "https://hq.patronage.com";
533
+ //#endregion
534
+ //#region src/github-transport.d.ts
535
+ /**
536
+ * Bounded transport retries could not reach the GitHub App endpoint (#923).
537
+ * The reason is credential-free, so it is safe to log. Re-exported from
538
+ * `github-app-token.ts`, which owns the mint surface.
539
+ */
540
+ declare class GitHubAppTokenTransportError extends Error {
541
+ /** How many transport attempts were made before giving up. */
542
+ readonly attempts: number;
543
+ /** The last transient HTTP status, when the server answered at all. */
544
+ readonly status?: number;
545
+ constructor(reason: string, attempts: number, status?: number);
546
+ }
547
+ //#endregion
209
548
  //#region src/github-app-token.d.ts
210
549
  /**
211
550
  * What a consumer must know to mint: the app id, where the private key is, and
212
551
  * — when it has been recorded — which installation to mint against.
213
552
  *
214
553
  * `installationId` is optional because the installation is discoverable from
215
- * the repository. `privateKeyPath` is a path rather than key material so no
216
- * consumer has to hold a secret in memory to call this, and so the key-path
217
- * convention stays the consumer's.
554
+ * the repository. When it is set, the mint still looks it up to confirm its
555
+ * account owns the repository. `privateKeyPath` is a path rather than key
556
+ * material so no consumer has to hold a secret in memory to call this, and so
557
+ * the key-path convention stays the consumer's.
218
558
  */
219
559
  interface GithubAppCredentials {
220
560
  appId: number | string;
@@ -226,6 +566,18 @@ declare class GitHubApiError extends Error {
226
566
  readonly status: number;
227
567
  constructor(status: number, statusText: string);
228
568
  }
569
+ /**
570
+ * Installation-token permission subset. GitHub only grants permissions the
571
+ * App already has; a caller that wants least privilege names the subset here
572
+ * rather than taking the App's full installation grant (#949).
573
+ */
574
+ interface GithubAppInstallationPermissions {
575
+ checks?: "read" | "write";
576
+ }
577
+ /** The Factory App broker's token: repo-scoped Checks write, nothing else. */
578
+ declare const FACTORY_APP_BROKER_TOKEN_PERMISSIONS: {
579
+ readonly checks: "write";
580
+ };
229
581
  interface GithubAppTokenOptions {
230
582
  /** Injectable `fetch` (tests, or a caller with its own instrumented one). */
231
583
  fetch?: typeof fetch;
@@ -235,6 +587,15 @@ interface GithubAppTokenOptions {
235
587
  readPrivateKey?: (privateKeyPath: string) => Buffer | string;
236
588
  /** Per-request timeout; defaults to five seconds. */
237
589
  timeoutMs?: number;
590
+ /**
591
+ * Total transport attempts per request, the first one included. Defaults to
592
+ * three: a mint that must survive a stale keep-alive socket (#923). A caller
593
+ * whose mint is best-effort and already has a fallback passes 1, because
594
+ * retrying against a deliberately short timeout only delays that fallback
595
+ * (#938). The backoff between attempts is fixed and does not scale with
596
+ * `timeoutMs`; the two dials are unrelated.
597
+ */
598
+ transportAttempts?: number;
238
599
  }
239
600
  /**
240
601
  * The signed app JWT GitHub accepts as `Authorization: Bearer` for the App
@@ -250,45 +611,30 @@ declare const githubAppJwt: (credentials: GithubAppCredentials, options?: Pick<G
250
611
  *
251
612
  * When the credentials omit `installationId`, the installation is discovered
252
613
  * from the repository first — the same call every consumer had written for
253
- * itself. Nothing is cached: the token is returned to the caller and this
254
- * module keeps no copy.
614
+ * itself. A pinned `installationId` is looked up instead, and the mint is
615
+ * refused unless that installation's account is the repository owner (GitHub
616
+ * logins compare case-insensitively): a `repositories` restriction names
617
+ * repositories without an owner, so a pin for one account must not mint for
618
+ * a same-named repository under another (#1428). Nothing is cached: the token
619
+ * is returned to the caller and this module keeps no copy.
255
620
  */
256
621
  declare const mintInstallationToken: (input: {
257
622
  credentials: GithubAppCredentials;
258
623
  owner: string;
259
- repo: string;
260
- }, options?: GithubAppTokenOptions) => Promise<string>;
261
- //#endregion
262
- //#region src/execute-alchemy-entry.d.ts
263
- interface ExecuteAlchemyEntryOptions {
264
624
  /**
265
- * CLI arguments before the bundled entry. The absolute entry path is always
266
- * appended as the final argument.
625
+ * Installation permission subset. Omitted, GitHub grants the App's full
626
+ * installation permissions. The Factory App broker passes
627
+ * {@link FACTORY_APP_BROKER_TOKEN_PERMISSIONS}.
628
+ */
629
+ permissions?: GithubAppInstallationPermissions;
630
+ /**
631
+ * Repository names (not `owner/repo`) to bind the token to. Omitted, the
632
+ * token covers every repository the installation can reach. The broker
633
+ * always names the one repository the Cursor OIDC claim authenticated.
267
634
  */
268
- readonly args: readonly string[];
269
- readonly bundle: BundleAlchemyEntryOptions;
270
- /** Child working directory. Defaults to the bundle root, then process.cwd. */
271
- readonly cwd?: string;
272
- /** Child environment. Defaults to process.env. */
273
- readonly env?: NodeJS.ProcessEnv;
274
- /** Consumer module context; normally the caller's import.meta.url. */
275
- readonly from: string | URL;
276
- /** Child stdio. Default "inherit". */
277
- readonly stdio?: "inherit" | "pipe";
278
- }
279
- interface ExecuteAlchemyEntryResult {
280
- readonly bundledEntry: string;
281
- readonly stderr: string | null;
282
- readonly stdout: string | null;
283
- }
284
- /**
285
- * Bundle a consumer-owned Alchemy entry, resolve that consumer's Alchemy CLI,
286
- * run it under the current Node binary, and return only on a successful exit.
287
- *
288
- * Deploy/destroy/plan selection, stage admission, credentials, and every
289
- * convergence or destructive-change policy remain the caller's responsibility.
290
- */
291
- declare const executeAlchemyEntry: (options: ExecuteAlchemyEntryOptions) => Promise<ExecuteAlchemyEntryResult>;
635
+ repositories?: readonly string[];
636
+ repo: string;
637
+ }, options?: GithubAppTokenOptions) => Promise<string>;
292
638
  //#endregion
293
639
  //#region src/proof-reuse-gate.d.ts
294
640
  /**
@@ -296,7 +642,9 @@ declare const executeAlchemyEntry: (options: ExecuteAlchemyEntryOptions) => Prom
296
642
  *
297
643
  * It answers one question, before checkout and before install: may this job
298
644
  * reuse the local verification the factory already published for *this exact
299
- * head*? Refusing runs hosted CI; it never fails the candidate. Three
645
+ * head*? It asks that only on a pull request, so every default-branch push
646
+ * executes the full hosted suite (#863). Refusing runs hosted CI; it never
647
+ * fails the candidate. Three
300
648
  * repositories had independently grown their own answer to that question and
301
649
  * had already drifted apart, so the answer lives here once, with the App
302
650
  * identity, check name, step identity, output names, guard, and every trust
@@ -322,6 +670,13 @@ declare const FACTORY_PROOF_GATE_CHECK_NAME = "patronage-factory/pr-verify";
322
670
  declare const FACTORY_PROOF_GATE_APP_ID = "4314840";
323
671
  /** Step id the guard condition refers to. */
324
672
  declare const FACTORY_PROOF_GATE_STEP_ID = "factory-proof";
673
+ /**
674
+ * Human-visible name of the gate step as the Actions jobs API serves it. A
675
+ * read-only run analyzer (`psf ci:analyze`, #647) matches on this name to
676
+ * classify a run as proof-reuse versus full fallback, so it is exported from
677
+ * exactly the module that writes it — matching on a re-typed copy would drift.
678
+ */
679
+ declare const FACTORY_PROOF_GATE_STEP_NAME = "Check for factory proof of this head";
325
680
  /**
326
681
  * The shell the gate runs under, and it is a correctness requirement rather
327
682
  * than a preference.
@@ -359,28 +714,43 @@ declare const FACTORY_PROOF_GATE_REASON_OUTPUT = "reason";
359
714
  * proof that executed every command the surface requires is reusable.
360
715
  */
361
716
  declare const FACTORY_PROOF_GATE_MODE_OUTPUT = "mode";
717
+ /** Exact Checks API URL of the proof generation selected by the gate. */
718
+ declare const FACTORY_PROOF_GATE_SOURCE_URL_OUTPUT = "source-check-url";
362
719
  /**
363
720
  * Guard for every step the gate protects. Deliberately `!= 'true'` and not
364
721
  * `== 'false'`: an unset, empty, or garbled output must run the suite.
365
722
  */
366
723
  declare const FACTORY_PROOF_GATE_GUARD = "steps.factory-proof.outputs.reuse-proof != 'true'";
367
724
  /**
368
- * Pull requests only. A push to a protected branch must never skip: deploy
369
- * gates wait for a green required check at the *merged* SHA, and no local
370
- * proof was ever written for that tree.
725
+ * Pull requests only — the gate's single condition (#873, default since #863,
726
+ * the only mode since the merge-target opt-out was deleted).
727
+ *
728
+ * A merge target's guarantee is about the whole tree, not the diff. A
729
+ * candidate proof only ever binds the diff the candidate was scoped to, so
730
+ * reusing it on the merged commit proves less than the merge target needs.
731
+ * #931 is that defect observed — a `main` push reused a candidate proof,
732
+ * executed no command, and left a red package unnoticed for three days. Every
733
+ * default-branch push therefore executes the full hosted suite, whatever
734
+ * proof exists.
735
+ *
736
+ * Which branches trigger the workflow at all stays repository-owned. This
737
+ * condition only keeps the gate from consulting proof outside a pull request.
371
738
  */
372
739
  declare const FACTORY_PROOF_GATE_IF = "github.event_name == 'pull_request'";
373
740
  /**
374
741
  * The complete refusal vocabulary. Deliberately few, because these are the
375
- * only distinctions the gate can honestly make from one Checks API read.
742
+ * only distinctions the gate can honestly make from its Checks API reads.
376
743
  *
377
744
  * - `proven` a covering, passing, unambiguous proof for this exact head
378
745
  * - `none` no App-verified factory check run at this commit
379
746
  * - `pending` the newest generation had not completed when this job read it
380
747
  * - `failed` the newest generation records no pass
381
748
  * - `unreadable` it passed but carries no binding for this repository and head
382
- * - `incomplete` it passed but did not execute every required command
383
- * - `ambiguous` two newest generations share the greatest start time
749
+ * - `incomplete` its executed plus stamp-authorized released commands do not
750
+ * cover every required command
751
+ * - `ambiguous` two different generations share the newest instant, the
752
+ * newest repeats another run's verdict with no proof time to
753
+ * tell them apart, or a run's start time cannot be ranked
384
754
  * - `error` the gate could not reach a decision (fail open)
385
755
  *
386
756
  * There is no `reduced`: mode stopped being an authorization condition in
@@ -415,6 +785,34 @@ interface ProofReuseCommand {
415
785
  * must refuse instead.
416
786
  */
417
787
  declare const proofReuseRequiredCommands: (commands: readonly ProofReuseCommand[]) => readonly string[] | undefined;
788
+ /**
789
+ * Resolve command *identities* to their `ProofReuseCommand` objects (ADR
790
+ * 0021).
791
+ *
792
+ * Selection by name is deliberately a consumer decision (proof-surfaces.ts in
793
+ * software-factory-hq, the `paitronage:verify` filter in paitronage's
794
+ * `verify.ts`): only the consumer knows which named commands a guarded
795
+ * surface requires. What both of those implementations independently
796
+ * hand-rolled is the same lookup — find each name in the profile's command
797
+ * catalog, and refuse to silently shrink the required set when a name has no
798
+ * entry. That lookup is what this function is: the mechanic, not the
799
+ * selection.
800
+ *
801
+ * Throwing at generation time (rather than returning `undefined` or an empty
802
+ * array) is deliberate: a name with no catalog entry is a mistake in the
803
+ * generator source, not a runtime condition a consumer should have to check
804
+ * for, and a required set that quietly loses an entry is exactly what makes a
805
+ * passing proof trivially "covering".
806
+ *
807
+ * `selectionLabel` names the failure, nothing else: it is not part of the
808
+ * selection this function resolves, only prose a consumer supplies for its
809
+ * own thrown error (e.g. HQ's surface name, "core" or "docs"). The message
810
+ * deliberately says "the profile's command catalog" rather than naming
811
+ * `software-factory.profile.json`: a fleet-generic library must not assume
812
+ * every consumer's catalog is that exact file, so this wording differs
813
+ * on purpose from the HQ-local message it replaced.
814
+ */
815
+ declare const resolveProofReuseCommands: (catalog: readonly ProofReuseCommand[], names: readonly string[], selectionLabel?: string) => readonly ProofReuseCommand[];
418
816
  interface FactoryProofGateOptions {
419
817
  /**
420
818
  * The profile command objects this guarded surface selected. A consumer with
@@ -455,9 +853,10 @@ interface FactoryProofGateStep {
455
853
  }
456
854
  /**
457
855
  * The step itself, structurally accepted by gagen's `step()` without adding a
458
- * gagen runtime dependency. It belongs first in the job it guards: one Checks
459
- * API read with the default `GITHUB_TOKEN` (`checks: read`), no checkout, no
460
- * install, so a proven head costs a runner nothing beyond job startup.
856
+ * gagen runtime dependency. It belongs first in the job it guards: a few API
857
+ * reads with the default `GITHUB_TOKEN`, no checkout, no install, so a proven
858
+ * head costs a runner nothing beyond job startup. The step runs on pull
859
+ * requests only, so it needs only `checks: read` (#873, #863).
461
860
  *
462
861
  * A **step, not a job**, and that is not a style preference. A separate gate
463
862
  * job that errored would leave the guarded job `skipped`, and a summary job
@@ -510,6 +909,732 @@ declare const proofReuseCoverage: ({
510
909
  /** `proofReuseCoverage`, as a build failure. */
511
910
  declare const assertProofReuseCoverage: (input: ProofReuseCoverageInput) => ProofReuseCoverageReport;
512
911
  //#endregion
912
+ //#region src/proof-reuse-presentation.d.ts
913
+ /** Generic timing and presentation steps around the proof-reuse gate (#652). */
914
+ declare const FACTORY_PROOF_TIMING_STEP_ID = "ci-timing";
915
+ declare const FACTORY_PROOF_TIMING_START_STEP_NAME = "Start CI timing";
916
+ declare const FACTORY_PROOF_TIMING_SUMMARY_STEP_NAME = "Record proof-reuse timing";
917
+ interface FactoryProofReusePresentationOptions {
918
+ /** Human-readable name of the guarded suite. */
919
+ readonly surface: string;
920
+ }
921
+ interface FactoryProofTimingStartStep {
922
+ readonly continueOnError: true;
923
+ readonly id: typeof FACTORY_PROOF_TIMING_STEP_ID;
924
+ readonly name: typeof FACTORY_PROOF_TIMING_START_STEP_NAME;
925
+ readonly run: string;
926
+ }
927
+ declare const factoryProofTimingStartStep: () => FactoryProofTimingStartStep;
928
+ interface FactoryProofReuseSummaryStep {
929
+ readonly continueOnError: true;
930
+ readonly env: Readonly<Record<string, string>>;
931
+ readonly if: "always()";
932
+ readonly name: typeof FACTORY_PROOF_TIMING_SUMMARY_STEP_NAME;
933
+ readonly run: string;
934
+ }
935
+ declare const factoryProofReuseSummaryStep: (options: FactoryProofReusePresentationOptions) => FactoryProofReuseSummaryStep;
936
+ //#endregion
937
+ //#region src/candidate-impact-workflow.d.ts
938
+ declare const FACTORY_CANDIDATE_IMPACT_STEP_ID = "candidate_impact";
939
+ declare const FACTORY_CANDIDATE_IMPACT_DECISION_OUTPUT = "decision";
940
+ declare const FACTORY_CANDIDATE_IMPACT_BASIS_OUTPUT = "basis";
941
+ declare const FACTORY_CANDIDATE_IMPACT_INERT_OUTPUT = "inert_paths";
942
+ declare const FACTORY_CANDIDATE_IMPACT_UNSUBSCRIBED_OUTPUT = "unsubscribed_paths";
943
+ interface FactoryCandidateImpactWorkflowOptions {
944
+ readonly base?: string;
945
+ readonly cli?: string;
946
+ readonly head?: string;
947
+ readonly profilePath?: string;
948
+ readonly targets: readonly string[];
949
+ }
950
+ interface FactoryCandidateImpactWorkflow {
951
+ /** Outputs for a caller-owned decision job that subsequent jobs may consume. */
952
+ readonly decisionJobOutputs: Readonly<Record<string, string>>;
953
+ readonly decisionStep: WorkflowStep;
954
+ /**
955
+ * A fail-open cross-job condition: only an explicit usable withdrawal skips
956
+ * work. The decision job id is required.
957
+ */
958
+ readonly demandedIf: (targetName: string, decisionJob: string) => string;
959
+ /** The same fail-open condition for a step in the decision job. */
960
+ readonly demandedIfAtStep: (targetName: string) => string;
961
+ readonly targetOutputs: Readonly<Record<string, string>>;
962
+ }
963
+ /**
964
+ * Generate the factory-owned candidate routing seam for a consumer
965
+ * pull-request workflow (#741). The decision step calls
966
+ * `psf candidate:impact` with the pull request's exact base/head commits, so
967
+ * the canonical profile impact declarations and dependency graph route the
968
+ * run — never a second path matcher. Consumers retain jobs, surface names,
969
+ * runners, commands, and credentials; this artifact supplies only the
970
+ * decision step and per-target withdrawal conditions. Target output keys are
971
+ * the same stable contract the production decision seam writes.
972
+ *
973
+ * The decision checkout must have the exact head commit checked out and the
974
+ * base commit reachable (`fetchDepth: 0`, `ref` = the head SHA); anything
975
+ * else refuses withdrawal and keeps every target demanded.
976
+ */
977
+ declare const factoryCandidateImpactWorkflow: (options: FactoryCandidateImpactWorkflowOptions) => FactoryCandidateImpactWorkflow;
978
+ //#endregion
979
+ //#region src/lifecycle-contract-lane.d.ts
980
+ declare const FACTORY_LIFECYCLE_CONTRACT_JOB_ID = "factory-contracts";
981
+ declare const FACTORY_LIFECYCLE_CONTRACT_JOB_NAME = "Factory / Alchemy Contracts";
982
+ interface FactoryLifecycleContractLaneOptions {
983
+ readonly command: string;
984
+ readonly jobId?: string;
985
+ readonly jobName?: string;
986
+ }
987
+ interface FactoryLifecycleContractLane {
988
+ readonly jobId: string;
989
+ readonly jobName: string;
990
+ readonly steps: readonly WorkflowStep[];
991
+ }
992
+ /**
993
+ * Generate the factory-owned non-credentialed lifecycle-contract lane
994
+ * (#765). Consumers declare the package-script command in
995
+ * `software-factory.profile.json`; this helper never loads that profile.
996
+ * Callers pass the parsed declaration (or omit it) and include or skip the
997
+ * returned job. Setup, runners, topology, and credentials stay with the
998
+ * caller — and this lane must never receive credentials.
999
+ *
1000
+ * The generated steps run only the declared package script and write an
1001
+ * always() evidence summary of what the lane proves and does not prove.
1002
+ * The command must be a package-script invocation: `run <script>`, or a
1003
+ * shorthand whose script name contains `:` (`pnpm test:factory`). Optional
1004
+ * pnpm `--filter <pkg>` may precede either form. Shell operators, credential
1005
+ * env, extra flags, and direct Vitest are refused.
1006
+ */
1007
+ declare const factoryLifecycleContractLane: (declaration?: FactoryLifecycleContractLaneOptions) => FactoryLifecycleContractLane | undefined;
1008
+ //#endregion
1009
+ //#region src/merge-freeze-job.d.ts
1010
+ /**
1011
+ * The merge-freeze writer job (#356, ADR 0016; #429 for the
1012
+ * merge-target namespace; #872 for this package).
1013
+ *
1014
+ * A consumer's generated merge-target-push Verify workflow is the ONLY
1015
+ * producer of `patronage-factory/merge-freeze` generations: a red
1016
+ * push-triggered Verify completes a generation active, a green one completes
1017
+ * it inactive, and no command, scheduled job, or second workflow writes this
1018
+ * check run. The operator override (`demand:waive --demand merge-freeze`)
1019
+ * waives the demand for one candidate during a fix-forward; it never writes
1020
+ * here.
1021
+ *
1022
+ * The write mirrors what the factory package's merge-freeze reader parses:
1023
+ * create the run `in_progress` with no `started_at` (GitHub stamps the
1024
+ * generation clock — the ordering rule itself is owned by the reader), then
1025
+ * PATCH it completed with the reader-shaped state payload in `output.text`.
1026
+ * The consumer's workflow test executes this exact script against a stubbed
1027
+ * `gh` and parses the emitted payload with `validateMergeFreezeState`, so
1028
+ * writer and reader cannot drift silently.
1029
+ *
1030
+ * Those two API calls are what the reader's two settling phases observe
1031
+ * (#890). Before the POST the merge target carries no generation at all, which
1032
+ * a reader reports as `awaiting-generation` while the pushed hosted verify run
1033
+ * is still pending. Between the POST and the PATCH the generation exists with
1034
+ * no `output.text`, which a reader reports as `running-generation`. Only the
1035
+ * PATCH writes a verdict, so neither phase is one.
1036
+ *
1037
+ * Failure posture is deliberately fail-closed and the opposite of the
1038
+ * proof-reuse gate's fail-open shell: this step runs under the runner's
1039
+ * default `bash -e {0}`, so any API refusal aborts the step, the generation
1040
+ * stays absent or `in_progress`, and every `pr:ready` arming-time read of
1041
+ * that tip (#477) refuses until a later push writes a green generation.
1042
+ *
1043
+ * **Ownership line.** This package owns the check name, the App identity, the
1044
+ * `create-github-app-token` inputs, the result fold, the merge-target `if`,
1045
+ * and the job's `permissions`. The caller owns the runner, the `needs` list
1046
+ * of every authoritative verification leaf, the timeout, and any extra env.
1047
+ */
1048
+ /** The one check-run name every merge-freeze reader pins. */
1049
+ declare const FACTORY_MERGE_FREEZE_CHECK_NAME = "patronage-factory/merge-freeze";
1050
+ declare const FACTORY_MERGE_FREEZE_JOB_ID = "freeze";
1051
+ declare const FACTORY_MERGE_FREEZE_JOB_NAME = "Report the merge freeze";
1052
+ /** Step id the token step exposes its installation token under. */
1053
+ declare const FACTORY_MERGE_FREEZE_APP_TOKEN_STEP_ID = "factory-app-token";
1054
+ /**
1055
+ * The GitHub Actions expression that folds the needed jobs' results into the
1056
+ * one word the script branches on. It mirrors the `verify` summary job's
1057
+ * failure condition exactly: any failed or cancelled needed job is a red
1058
+ * merge target.
1059
+ */
1060
+ declare const FACTORY_MERGE_FREEZE_VERIFY_RESULT_EXPRESSION = "${{ (contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled')) && 'failure' || 'success' }}";
1061
+ /**
1062
+ * The literal factory merge-target namespace, as a `github.ref` predicate
1063
+ * (#429).
1064
+ *
1065
+ * `main` plus the repository-owned `epic/**` integration branches, and
1066
+ * nothing else. Deliberately literal rather than profile-declared: one
1067
+ * implementation per contract, no configuration machinery for a two-element
1068
+ * namespace whose second element is a namespace prefix the repository itself
1069
+ * owns. `epic/` needs the trailing slash — `startsWith` would otherwise admit
1070
+ * `epicness/…`, which is not a merge target.
1071
+ *
1072
+ * A caller's `push` trigger branch list names the same namespace. That list
1073
+ * decides which events produce a run at all; this predicate decides which of
1074
+ * those runs may write a generation.
1075
+ */
1076
+ declare const FACTORY_MERGE_TARGET_REF_CONDITION: string;
1077
+ /**
1078
+ * `always()` is load-bearing: the red path is the whole point, so the job must
1079
+ * run when a needed verification job failed. `github.event_name == 'push'` is
1080
+ * load-bearing twice over: a `pull_request` run must never write a generation
1081
+ * (its `github.sha` is a synthetic merge commit that no base tip is ever read
1082
+ * at), and a `pull_request` trigger with an `epic/**` base list would
1083
+ * otherwise reach this job.
1084
+ */
1085
+ declare const FACTORY_MERGE_FREEZE_IF: string;
1086
+ /**
1087
+ * Least privilege for the writer job: no `GITHUB_TOKEN` scope at all.
1088
+ *
1089
+ * Both Checks API calls run under the App installation token minted in the
1090
+ * first step (`GH_TOKEN: steps.factory-app-token.outputs.token`), and the job
1091
+ * never checks out the repository. So the job uses no `GITHUB_TOKEN` scope,
1092
+ * and an empty block is the honest declaration. A `checks: write` here would
1093
+ * hand every adopter an unused write scope (#884).
1094
+ */
1095
+ declare const FACTORY_MERGE_FREEZE_PERMISSIONS: Readonly<{}>;
1096
+ /**
1097
+ * The script the freeze step runs. Environment contract:
1098
+ * - `GH_TOKEN`: an installation token for the pinned Patronage Factory App —
1099
+ * the check run must carry that App's identity or every reader rejects it.
1100
+ * - `VERIFY_RESULT`: `success` or `failure` (see the fold expression above).
1101
+ * - `VERIFY_JOBS`: JSON `needs` context; only job results are retained.
1102
+ * - `GITHUB_SHA` / `GITHUB_REPOSITORY` / `GITHUB_SERVER_URL` /
1103
+ * `GITHUB_RUN_ID` / `GITHUB_RUN_ATTEMPT` / `GITHUB_REF_NAME`: runner-provided.
1104
+ *
1105
+ * `GITHUB_REF_NAME` is the merge target this run pushed to — `main` or an
1106
+ * `epic/**` integration branch (#429). The job is gated to `push` events on
1107
+ * exactly those refs, so the branch name is always the short name of a
1108
+ * repository-owned merge target and never a pull-request merge ref. It
1109
+ * appears in recovery guidance because a reader of an epic-targeting
1110
+ * candidate must be told which branch owns the generation. A later green
1111
+ * generation on that branch's current tip clears it, including a rerun.
1112
+ */
1113
+ declare const factoryMergeFreezeScript: () => string;
1114
+ interface FactoryMergeFreezeJobOptions<TNeed> {
1115
+ /** The pinned `actions/create-github-app-token` the caller declared. */
1116
+ readonly createGithubAppToken: PinnedAction;
1117
+ /**
1118
+ * Every authoritative verification leaf this generation folds. The elements
1119
+ * are whatever the caller's workflow generator uses for `needs:`; they are
1120
+ * returned unchanged.
1121
+ */
1122
+ readonly needs: readonly TNeed[];
1123
+ /**
1124
+ * Override the result fold. Defaults to
1125
+ * `FACTORY_MERGE_FREEZE_VERIFY_RESULT_EXPRESSION`, which is what a caller
1126
+ * whose summary job folds `needs.*.result` wants. Supply one only when the
1127
+ * caller's red condition is genuinely different.
1128
+ */
1129
+ readonly verifyResultExpression?: string;
1130
+ }
1131
+ interface FactoryMergeFreezeJob<TNeed> {
1132
+ readonly if: typeof FACTORY_MERGE_FREEZE_IF;
1133
+ readonly jobId: typeof FACTORY_MERGE_FREEZE_JOB_ID;
1134
+ readonly jobName: typeof FACTORY_MERGE_FREEZE_JOB_NAME;
1135
+ readonly needs: readonly TNeed[];
1136
+ readonly permissions: typeof FACTORY_MERGE_FREEZE_PERMISSIONS;
1137
+ readonly steps: readonly WorkflowStep[];
1138
+ }
1139
+ /**
1140
+ * Build the merge-freeze writer job.
1141
+ *
1142
+ * An empty `needs` list is refused: a fold over no verification leaf is
1143
+ * always `success`, so such a job would write a green generation for a merge
1144
+ * target nothing verified — the exact failure the freeze exists to prevent.
1145
+ */
1146
+ declare const factoryMergeFreezeJob: <TNeed>(options: FactoryMergeFreezeJobOptions<TNeed>) => FactoryMergeFreezeJob<TNeed>;
1147
+ //#endregion
1148
+ //#region src/pr-status-hud-workflow.d.ts
1149
+ declare const FACTORY_PR_STATUS_HUD_JOB_ID = "status-hud";
1150
+ declare const FACTORY_PR_STATUS_HUD_JOB_NAME = "Present PR status HUD";
1151
+ declare const FACTORY_PR_STATUS_HUD_APP_TOKEN_STEP_ID = "factory-app-token";
1152
+ declare const FACTORY_PR_STATUS_HUD_PLAN_PATH = ".factory-memory/preview-plan.json";
1153
+ /**
1154
+ * Presentation is independent of deploy demand. Callers who `needs` the jobs
1155
+ * that settle HUD sources (verify, deploy) must keep this `always()` so a
1156
+ * skipped or withdrawn deploy still publishes Skipped rows.
1157
+ */
1158
+ declare const FACTORY_PR_STATUS_HUD_IF = "always() && github.event_name == 'pull_request' && github.event.pull_request.draft != true";
1159
+ interface FactoryPrStatusHudWorkflowOptions {
1160
+ readonly cli?: string;
1161
+ readonly createGithubAppToken: PinnedAction;
1162
+ }
1163
+ /**
1164
+ * Least privilege for the job that runs the present step. The present step
1165
+ * is an inventory `list`, so the job needs exactly the inventory's read
1166
+ * permissions (#825, #859).
1167
+ */
1168
+ declare const FACTORY_PR_STATUS_HUD_PERMISSIONS: Readonly<{
1169
+ readonly checks: "read";
1170
+ readonly contents: "read";
1171
+ readonly "pull-requests": "read";
1172
+ }>;
1173
+ declare const FACTORY_PR_STATUS_HUD_CONCURRENCY: Readonly<{
1174
+ cancelInProgress: false;
1175
+ group: "status-hud-${{ github.repository }}-${{ github.event.pull_request.number }}";
1176
+ }>;
1177
+ interface FactoryPrStatusHudWorkflow {
1178
+ readonly concurrency: typeof FACTORY_PR_STATUS_HUD_CONCURRENCY;
1179
+ readonly if: typeof FACTORY_PR_STATUS_HUD_IF;
1180
+ readonly jobId: typeof FACTORY_PR_STATUS_HUD_JOB_ID;
1181
+ readonly jobName: typeof FACTORY_PR_STATUS_HUD_JOB_NAME;
1182
+ readonly permissions: typeof FACTORY_PR_STATUS_HUD_PERMISSIONS;
1183
+ readonly presentSteps: readonly WorkflowStep[];
1184
+ }
1185
+ declare const factoryPrStatusHudWorkflow: (options: FactoryPrStatusHudWorkflowOptions) => FactoryPrStatusHudWorkflow;
1186
+ //#endregion
1187
+ //#region src/preview-cleanup-topology.d.ts
1188
+ declare const FACTORY_PREVIEW_CLEANUP_AUDIT_JOB_ID = "stage-residue-audit";
1189
+ declare const FACTORY_PREVIEW_CLEANUP_AUDIT_JOB_NAME = "Stage residue audit";
1190
+ interface FactoryPreviewCleanupTopologyOptions {
1191
+ readonly audit: {
1192
+ readonly command: string;
1193
+ readonly jobId?: string;
1194
+ readonly jobName?: string;
1195
+ };
1196
+ readonly stacks: readonly string[];
1197
+ }
1198
+ interface FactoryPreviewCleanupDestroyJob {
1199
+ readonly jobId: string;
1200
+ readonly stack: string;
1201
+ }
1202
+ interface FactoryPreviewCleanupAuditJob {
1203
+ readonly if: "always()";
1204
+ readonly jobId: string;
1205
+ readonly jobName: string;
1206
+ readonly needs: readonly string[];
1207
+ readonly steps: readonly WorkflowStep[];
1208
+ }
1209
+ interface FactoryPreviewCleanupTopology {
1210
+ readonly auditJob: FactoryPreviewCleanupAuditJob;
1211
+ readonly destroyJobs: readonly FactoryPreviewCleanupDestroyJob[];
1212
+ }
1213
+ declare const previewCleanupDestroyJobId: (stack: string) => string;
1214
+ /**
1215
+ * Generate the factory-owned preview-cleanup topology (#764): one destroy
1216
+ * job identity per stack, then exactly one stage-wide residue-audit job
1217
+ * that `needs` every destroy. The audit is whole-stage — this helper never
1218
+ * threads a stack name or path filter into it. Callers own destroy steps,
1219
+ * what counts as residue, credentials, and runners.
1220
+ */
1221
+ declare const factoryPreviewCleanupTopology: (options: FactoryPreviewCleanupTopologyOptions) => FactoryPreviewCleanupTopology;
1222
+ //#endregion
1223
+ //#region src/preview-receipt-workflow.d.ts
1224
+ interface FactoryPreviewReceiptWorkflowOptions {
1225
+ readonly target: string;
1226
+ readonly cli?: string;
1227
+ /** Caller-owned PR number expression, passed through the environment. */
1228
+ readonly pr?: string;
1229
+ }
1230
+ interface FactoryPreviewReceiptWorkflow {
1231
+ /** Place before the selected target's first mutation, under its selection guard. */
1232
+ readonly beginStep: WorkflowStep;
1233
+ /** Append after consumer deploy and required smoke steps. Never rename the bind step. */
1234
+ readonly completionSteps: readonly WorkflowStep[];
1235
+ /** Place before cleanup, including cleanup of a failed/unregistered deployment. */
1236
+ readonly invalidateStep: WorkflowStep;
1237
+ readonly permissions: Readonly<{
1238
+ actions: "read";
1239
+ contents: "read";
1240
+ deployments: "write";
1241
+ "pull-requests": "read";
1242
+ }>;
1243
+ }
1244
+ /** Receipt transport only. The consumer owns selection, lifecycle, smoke, and freshness. */
1245
+ declare const factoryPreviewReceiptWorkflow: (options: FactoryPreviewReceiptWorkflowOptions) => FactoryPreviewReceiptWorkflow;
1246
+ //#endregion
1247
+ //#region src/production-impact-workflow.d.ts
1248
+ declare const FACTORY_PRODUCTION_IMPACT_STEP_ID = "production_impact";
1249
+ declare const FACTORY_PRODUCTION_IMPACT_DECISION_OUTPUT = "decision";
1250
+ declare const FACTORY_PRODUCTION_IMPACT_BASIS_OUTPUT = "basis";
1251
+ declare const FACTORY_PRODUCTION_IMPACT_UNSUBSCRIBED_OUTPUT = "unsubscribed_paths";
1252
+ /** Stable GitHub-output key for one declared target. */
1253
+ declare const productionImpactTargetOutput: (targetName: string) => string;
1254
+ interface FactoryProductionImpactWorkflowOptions {
1255
+ /** The checked-out candidate commit. Defaults to `github.sha`. */
1256
+ readonly candidate?: string;
1257
+ readonly cli?: string;
1258
+ readonly profilePath?: string;
1259
+ /** Deployment stage the receipts are bound to, when the consumer has one. */
1260
+ readonly stage?: string;
1261
+ readonly targets: readonly string[];
1262
+ }
1263
+ interface FactoryProductionImpactWorkflow {
1264
+ /** Outputs for a caller-owned decision job that subsequent jobs may consume. */
1265
+ readonly decisionJobOutputs: Readonly<Record<string, string>>;
1266
+ readonly decisionStep: WorkflowStep;
1267
+ /**
1268
+ * A fail-open cross-job condition: only an explicit usable withdrawal skips
1269
+ * work. The decision job id is required.
1270
+ */
1271
+ readonly demandedIf: (targetName: string, decisionJob: string) => string;
1272
+ /** The same fail-open condition for a step in the decision job. */
1273
+ readonly demandedIfAtStep: (targetName: string) => string;
1274
+ /** Permissions every job that runs the decision step or a receipt step declares for `github.token`. */
1275
+ readonly permissions: Readonly<{
1276
+ actions: "read";
1277
+ contents: "read";
1278
+ deployments: "write";
1279
+ }>;
1280
+ /**
1281
+ * The receipt steps a deploy job appends after its deploy and health steps,
1282
+ * in order: a success receipt that runs when every earlier step succeeded
1283
+ * and outputs the new deployment id; a bind step whose name carries that id
1284
+ * and whose presence in GitHub's job record is the reader's proof that this
1285
+ * run created that record; and a failure receipt that runs when a step
1286
+ * failed. Only a bound success receipt advances the target's baseline. Do
1287
+ * not rename or reorder them.
1288
+ */
1289
+ readonly receiptSteps: (targetName: string) => readonly WorkflowStep[];
1290
+ readonly targetOutputs: Readonly<Record<string, string>>;
1291
+ }
1292
+ /**
1293
+ * Generate the small factory-owned decision seam for a consumer production
1294
+ * workflow. Consumers retain jobs, deploy commands, credentials, topology,
1295
+ * health checks, and convergence checks; this artifact supplies the decision
1296
+ * step, per-target withdrawal conditions, and the receipt steps that record
1297
+ * what each deploy job did.
1298
+ *
1299
+ * The decision step resolves each target's demand from its last trusted
1300
+ * successful deployment receipt, never from the push's before commit. The
1301
+ * decision checkout needs full history (`fetchDepth: 0`) so the baseline
1302
+ * commit is reachable; a shallow checkout keeps every target demanded.
1303
+ */
1304
+ declare const factoryProductionImpactWorkflow: (options: FactoryProductionImpactWorkflowOptions) => FactoryProductionImpactWorkflow;
1305
+ //#endregion
1306
+ //#region src/push-identity-workflow.d.ts
1307
+ declare const FACTORY_PUSH_IDENTITY_SCHEMA_VERSION = 1;
1308
+ /** Versioned document uploaded by a push-triggered verification run. */
1309
+ interface FactoryPushIdentityEnvelope {
1310
+ readonly after: string;
1311
+ readonly before: string;
1312
+ readonly repository: string;
1313
+ readonly runId: string;
1314
+ readonly schemaVersion: typeof FACTORY_PUSH_IDENTITY_SCHEMA_VERSION;
1315
+ }
1316
+ type FactoryPushIdentityDisposition = "refused" | "usable";
1317
+ interface FactoryPushIdentityProducerOptions {
1318
+ /**
1319
+ * Explicit caller-owned upload-artifact pin from its workflow artifact.
1320
+ * Pass factory-ci's `UPLOAD_ARTIFACT` catalog export (or another
1321
+ * `actions/upload-artifact` pin); the caller wires the step, the catalog
1322
+ * only names the pin.
1323
+ */
1324
+ readonly uploadArtifact: PinnedAction;
1325
+ /** Optional consumer trigger policy combined with the required push event. */
1326
+ readonly if?: string;
1327
+ }
1328
+ interface FactoryPushIdentityProducer {
1329
+ readonly artifactName: string;
1330
+ readonly steps: readonly WorkflowStep[];
1331
+ }
1332
+ /**
1333
+ * Record and upload the exact push-event identity without changing the Verify
1334
+ * result when transport is unavailable. Place these steps after verification.
1335
+ */
1336
+ declare const factoryPushIdentityProducer: (options: FactoryPushIdentityProducerOptions) => FactoryPushIdentityProducer;
1337
+ interface FactoryPushIdentityConsumer {
1338
+ /** Job outputs suitable for a caller-owned decision job and telemetry. */
1339
+ readonly outputs: Readonly<Record<"after" | "before" | "disposition" | "provenance" | "reason", string>>;
1340
+ readonly requiredPermissions: Readonly<{
1341
+ actions: "read";
1342
+ contents: "read";
1343
+ }>;
1344
+ readonly steps: readonly WorkflowStep[];
1345
+ /** Run classification only when exact identity transport is usable. */
1346
+ readonly usableIf: string;
1347
+ }
1348
+ interface FactoryPushIdentityConsumerOptions {
1349
+ /** Explicit caller-owned checkout pin from its action family. */
1350
+ readonly checkout: PinnedAction;
1351
+ /** Explicit caller-owned download-artifact pin from its workflow artifact. */
1352
+ readonly downloadArtifact: PinnedAction;
1353
+ }
1354
+ /**
1355
+ * Download and validate identity from exactly the triggering workflow run in
1356
+ * the current repository. Every failure becomes a typed refusal; consumers
1357
+ * retain deploy policy, credentials, commands, topology, and convergence.
1358
+ */
1359
+ declare const factoryPushIdentityConsumer: (options: FactoryPushIdentityConsumerOptions) => FactoryPushIdentityConsumer;
1360
+ //#endregion
1361
+ //#region src/vitest-profile.d.ts
1362
+ /** Schema version of the emitted profile document. */
1363
+ declare const VITEST_PROFILE_SCHEMA_VERSION = 1;
1364
+ /** `tool` discriminator every emitted profile carries. */
1365
+ declare const VITEST_PROFILE_TOOL = "factory-ci-vitest-profile";
1366
+ /** Per-assertion status as Vitest's JSON reporter spells it. */
1367
+ type VitestTestStatus = "disabled" | "failed" | "passed" | "pending" | "skipped" | "todo";
1368
+ /** The subset of Vitest's `--reporter=json` document this module reads. */
1369
+ interface VitestJsonReport {
1370
+ numFailedTests: number;
1371
+ numPassedTests: number;
1372
+ numPendingTests: number;
1373
+ numTodoTests: number;
1374
+ numTotalTests: number;
1375
+ numTotalTestSuites: number;
1376
+ success: boolean;
1377
+ testResults: {
1378
+ assertionResults: {
1379
+ duration?: number | null;
1380
+ fullName: string;
1381
+ status: VitestTestStatus;
1382
+ }[];
1383
+ endTime: number;
1384
+ name: string;
1385
+ startTime: number;
1386
+ status: "failed" | "passed";
1387
+ }[];
1388
+ }
1389
+ /** Duration statistics over one population of samples, in milliseconds. */
1390
+ interface VitestProfileDurationSummary {
1391
+ maximum: number;
1392
+ mean: number;
1393
+ median: number;
1394
+ minimum: number;
1395
+ }
1396
+ /**
1397
+ * The machine a sample ran on, plus the commit it measured. `cpuModel` is the
1398
+ * field that makes two runs comparable at all: hosted runner pools mix silicon
1399
+ * behind one label.
1400
+ */
1401
+ interface VitestProfileEnvironment {
1402
+ arch: string;
1403
+ availableParallelism: number;
1404
+ cpuCount: number;
1405
+ cpuModel: string | null;
1406
+ gitDirty: boolean | null;
1407
+ gitHead: string | null;
1408
+ node: string;
1409
+ osRelease: string;
1410
+ platform: string;
1411
+ totalMemoryBytes: number;
1412
+ vitest: string;
1413
+ }
1414
+ /** One complete Vitest run inside a profile. */
1415
+ interface VitestProfileSample {
1416
+ counts: {
1417
+ failed: number;
1418
+ passed: number;
1419
+ pending: number;
1420
+ suites: number;
1421
+ tests: number;
1422
+ todo: number;
1423
+ } | null;
1424
+ durationMs: number;
1425
+ endedAt: string;
1426
+ exitCode: number;
1427
+ failure: string | null;
1428
+ files: {
1429
+ durationMs: number;
1430
+ path: string;
1431
+ status: "failed" | "passed";
1432
+ }[];
1433
+ reportAvailable: boolean;
1434
+ sample: number;
1435
+ startedAt: string;
1436
+ tests: {
1437
+ durationMs: number;
1438
+ file: string;
1439
+ name: string;
1440
+ status: VitestTestStatus;
1441
+ }[];
1442
+ }
1443
+ /** The emitted profile document. */
1444
+ interface VitestProfile {
1445
+ command: string[];
1446
+ endedAt: string;
1447
+ environment: VitestProfileEnvironment;
1448
+ options: {
1449
+ maxWorkers: number;
1450
+ samples: number;
1451
+ slowLimit: number;
1452
+ };
1453
+ rawReportDirectory: string;
1454
+ runs: VitestProfileSample[];
1455
+ schemaVersion: typeof VITEST_PROFILE_SCHEMA_VERSION;
1456
+ startedAt: string;
1457
+ summary: {
1458
+ durationMs: VitestProfileDurationSummary;
1459
+ slowFiles: {
1460
+ durationMs: VitestProfileDurationSummary;
1461
+ path: string;
1462
+ samples: number;
1463
+ }[];
1464
+ slowTests: {
1465
+ durationMs: VitestProfileDurationSummary;
1466
+ file: string;
1467
+ name: string;
1468
+ samples: number;
1469
+ }[];
1470
+ };
1471
+ tool: typeof VITEST_PROFILE_TOOL;
1472
+ }
1473
+ /** What a caller must decide before a profile can run. */
1474
+ interface VitestProfileOptions {
1475
+ /** Directory Vitest runs in; file paths are recorded relative to it. */
1476
+ cwd: string;
1477
+ /** Directory whose Git state is recorded. Defaults to `cwd`. */
1478
+ gitDirectory?: string;
1479
+ /** Vitest `--maxWorkers` for every sample. */
1480
+ maxWorkers: number;
1481
+ /** Absolute path of the profile document to write. */
1482
+ outputPath: string;
1483
+ /** Called before each sample starts. */
1484
+ onSampleStart?: (input: {
1485
+ maxWorkers: number;
1486
+ sample: number;
1487
+ samples: number;
1488
+ }) => void;
1489
+ /** Called after each sample is normalized and persisted. */
1490
+ onSampleComplete?: (input: {
1491
+ result: VitestProfileSample;
1492
+ sample: number;
1493
+ samples: number;
1494
+ }) => void;
1495
+ /** How many serial runs to take. */
1496
+ samples: number;
1497
+ /** How many slow files and slow tests to keep in the summary. */
1498
+ slowLimit: number;
1499
+ /**
1500
+ * `stdio` for the Vitest child. Defaults to `"inherit"`, which is what a
1501
+ * caller printing progress to a terminal wants; a caller whose own stdout is
1502
+ * structured passes `"ignore"` to silence the run.
1503
+ */
1504
+ stdio?: StdioOptions;
1505
+ }
1506
+ /** Outcome of one Vitest invocation, as `runSample` reports it. */
1507
+ interface VitestProfileSampleExecution {
1508
+ durationMs: number;
1509
+ exitCode: number;
1510
+ failure?: string | null;
1511
+ report: VitestJsonReport | null;
1512
+ }
1513
+ /** Injectable seams; production passes none of them. */
1514
+ interface VitestProfileDependencies {
1515
+ now?: () => Date;
1516
+ runSample?: (input: {
1517
+ cwd: string;
1518
+ maxWorkers: number;
1519
+ reportPath: string;
1520
+ sample: number;
1521
+ stdio: StdioOptions;
1522
+ }) => Promise<VitestProfileSampleExecution>;
1523
+ writeResult?: (outputPath: string, profile: VitestProfile) => Promise<void>;
1524
+ }
1525
+ /**
1526
+ * A sample failed. The partial profile is already on disk; `exitCode` is the
1527
+ * status a caller should exit with.
1528
+ */
1529
+ declare class VitestProfileError extends Error {
1530
+ readonly exitCode: number;
1531
+ constructor(message: string, exitCode: number);
1532
+ }
1533
+ /**
1534
+ * Fold one Vitest JSON report into a profile sample: file and test timings,
1535
+ * both sorted slowest first, plus the run's counts. A missing report (crash,
1536
+ * timeout, unwritable output) yields a sample with `reportAvailable: false`
1537
+ * rather than nothing at all.
1538
+ */
1539
+ declare const normalizeVitestProfileSample: (report: VitestJsonReport | null, input: {
1540
+ cwd: string;
1541
+ durationMs: number;
1542
+ endedAt: Date;
1543
+ exitCode: number;
1544
+ failure?: string | null;
1545
+ sample: number;
1546
+ startedAt: Date;
1547
+ }) => VitestProfileSample;
1548
+ /**
1549
+ * Record the machine and commit a profile was taken on. Vitest's version is
1550
+ * resolved from `cwd`, so it is the consumer's Vitest and not this package's.
1551
+ * Git failures degrade to `null` — an artifact from a tarball checkout is still
1552
+ * a usable measurement.
1553
+ */
1554
+ declare const captureVitestProfileEnvironment: (options: {
1555
+ cwd: string;
1556
+ gitDirectory?: string;
1557
+ }) => Promise<VitestProfileEnvironment>;
1558
+ /**
1559
+ * Write a profile document atomically: a partial file must never be readable
1560
+ * as a complete measurement, and the profile is rewritten after every sample.
1561
+ */
1562
+ declare const writeVitestProfile: (outputPath: string, profile: VitestProfile) => Promise<void>;
1563
+ /**
1564
+ * Take `samples` serial Vitest runs at one worker count and persist the profile
1565
+ * after each one. Samples never overlap: concurrent runs would measure CPU and
1566
+ * I/O contention instead of the worker count under test. A failing sample
1567
+ * throws `VitestProfileError` with the partial profile already written.
1568
+ */
1569
+ declare const runVitestProfile: (options: VitestProfileOptions, dependencies?: VitestProfileDependencies) => Promise<VitestProfile>;
1570
+ //#endregion
1571
+ //#region src/vitest-profile-reader.d.ts
1572
+ /**
1573
+ * Outcome of reading one candidate document. `unrecognized` carries the first
1574
+ * reason the document failed — an analyzer reports it verbatim rather than
1575
+ * treating an unreadable profile as an empty one.
1576
+ */
1577
+ type VitestProfileReadResult = {
1578
+ kind: "profile";
1579
+ profile: VitestProfile;
1580
+ } | {
1581
+ kind: "unrecognized";
1582
+ reason: string;
1583
+ };
1584
+ /**
1585
+ * Check one parsed JSON document against the profile contract the writer
1586
+ * emits. Returns the typed profile on success and the first mismatch reason
1587
+ * otherwise — never a partially-usable value.
1588
+ */
1589
+ declare const readVitestProfileDocument: (value: unknown) => VitestProfileReadResult;
1590
+ //#endregion
1591
+ //#region src/verify-runner-policy.d.ts
1592
+ declare const DEPOT_LABEL = "depot-ubuntu-24.04";
1593
+ declare const HOSTED_LABEL = "ubuntu-latest";
1594
+ /**
1595
+ * Why a job runs where it does. The two Depot kinds share a label. They stay
1596
+ * distinct so billed-rounding jobs and long compute jobs cannot be confused
1597
+ * in the declaration table.
1598
+ *
1599
+ * `deploy-credentials` is legal to construct (HQ deploy).
1600
+ * `assertVerifyRunnerPolicy` refuses it, because a Verify workflow has no
1601
+ * Cloudflare production secret.
1602
+ */
1603
+ type FactoryRunnerKind = "sustained-compute" | "rounding-tax" | "app-token" | "deploy-credentials";
1604
+ type FactoryRunnerHome = "depot" | "hosted";
1605
+ interface FactoryRunnerOverride {
1606
+ readonly kind: "override";
1607
+ readonly home: FactoryRunnerHome;
1608
+ readonly why: string;
1609
+ }
1610
+ type FactoryRunnerDecision = FactoryRunnerKind | FactoryRunnerOverride;
1611
+ interface FactoryVerifyRunner {
1612
+ readonly decision: FactoryRunnerDecision;
1613
+ readonly home: FactoryRunnerHome;
1614
+ readonly label: typeof DEPOT_LABEL | typeof HOSTED_LABEL;
1615
+ readonly why?: string;
1616
+ }
1617
+ type FactoryVerifyRunnerTable = Readonly<Record<string, FactoryVerifyRunner>>;
1618
+ interface FactoryVerifyRunnerPolicyInput {
1619
+ readonly source: string;
1620
+ readonly jobs: FactoryVerifyRunnerTable;
1621
+ }
1622
+ interface FactoryVerifyRunnerMismatch {
1623
+ readonly jobId: string;
1624
+ readonly expected: string;
1625
+ readonly actual: string;
1626
+ }
1627
+ interface FactoryVerifyRunnerPolicyReport {
1628
+ readonly ok: boolean;
1629
+ readonly undeclared: readonly string[];
1630
+ readonly missing: readonly string[];
1631
+ readonly mismatches: readonly FactoryVerifyRunnerMismatch[];
1632
+ readonly forbiddenKinds: readonly string[];
1633
+ }
1634
+ declare const factoryVerifyRunner: (decision: FactoryRunnerDecision) => FactoryVerifyRunner;
1635
+ declare const verifyRunnerPolicy: (yaml: string, input: FactoryVerifyRunnerPolicyInput) => FactoryVerifyRunnerPolicyReport;
1636
+ declare const assertVerifyRunnerPolicy: (yaml: string, input: FactoryVerifyRunnerPolicyInput) => FactoryVerifyRunnerPolicyReport;
1637
+ //#endregion
513
1638
  //#region src/workflow-shell-lint.d.ts
514
1639
  /**
515
1640
  * Parse-check the shell embedded in generated workflow YAML (#376).
@@ -561,4 +1686,4 @@ declare const assertWorkflowShellParses: (yaml: string, options: {
561
1686
  readonly source: string;
562
1687
  }) => void;
563
1688
  //#endregion
564
- export { type BundleAlchemyEntryOptions, type CheckoutStepOptions, type ExecuteAlchemyEntryOptions, type ExecuteAlchemyEntryResult, FACTORY_PROOF_GATE_APP_ID, FACTORY_PROOF_GATE_CHECK_NAME, FACTORY_PROOF_GATE_GUARD, FACTORY_PROOF_GATE_IF, FACTORY_PROOF_GATE_MODE_OUTPUT, FACTORY_PROOF_GATE_OUTPUT, FACTORY_PROOF_GATE_REASONS, FACTORY_PROOF_GATE_REASON_OUTPUT, FACTORY_PROOF_GATE_SHELL, FACTORY_PROOF_GATE_STEP_ID, type FactoryProofGateOptions, type FactoryProofGateReason, type FactoryProofGateStep, type FactoryWorkflowArtifact, type FactoryWorkflowOptions, type FactoryWorkflowSetupOptions, GitHubApiError, type GithubAppCredentials, type GithubAppTokenOptions, type InstallStepOptions, type LocalPreviewStage, type LocalPreviewStageOptions, NODE_PNPM_ACTION_FAMILY_NODE24, type NodePnpmActionFamily, type ParseLocalPreviewStageExpected, type ParsedLocalPreviewStage, type PinnedAction, type ProofReuseCommand, type ProofReuseCoverageInput, type ProofReuseCoverageReport, type SetupNodeStepOptions, type WorkflowShellParseFailure, type WorkflowStep, assertProofReuseCoverage, assertWorkflowShellParses, bundleAlchemyEntry, executeAlchemyEntry, factoryProofGateScript, factoryProofGateStep, factoryWorkflow, githubAppJwt, isLocalPreviewStage, localPreviewStage, mintInstallationToken, parseLocalPreviewStage, proofReuseCoverage, proofReuseRequiredCommands, workflowRunBlocks, workflowShellParseFailures };
1689
+ export { ALCHEMY_BASELINE, type AlchemyBaselinePackageJson, type AssertAlchemyBaselineInput, type BundleAlchemyEntryOptions, type CheckoutStepOptions, EXECUTE_ALCHEMY_ENTRY_MAX_BUFFER, type ExecuteAlchemyEntryOptions, type ExecuteAlchemyEntryResult, FACTORY_APP_BROKER_ORIGIN, FACTORY_APP_BROKER_PATH, FACTORY_APP_BROKER_TOKEN_PERMISSIONS, FACTORY_CANDIDATE_IMPACT_BASIS_OUTPUT, FACTORY_CANDIDATE_IMPACT_DECISION_OUTPUT, FACTORY_CANDIDATE_IMPACT_INERT_OUTPUT, FACTORY_CANDIDATE_IMPACT_STEP_ID, FACTORY_CANDIDATE_IMPACT_UNSUBSCRIBED_OUTPUT, FACTORY_CANDIDATE_PULL_REQUEST_TYPES, FACTORY_CURSOR_OIDC_AUDIENCE, FACTORY_CURSOR_OIDC_ISSUER, FACTORY_CURSOR_OIDC_JWKS_URL, FACTORY_CURSOR_OIDC_MANAGED_RUNTIME, FACTORY_LIFECYCLE_CONTRACT_JOB_ID, FACTORY_LIFECYCLE_CONTRACT_JOB_NAME, FACTORY_MERGE_FREEZE_APP_TOKEN_STEP_ID, FACTORY_MERGE_FREEZE_CHECK_NAME, FACTORY_MERGE_FREEZE_IF, FACTORY_MERGE_FREEZE_JOB_ID, FACTORY_MERGE_FREEZE_JOB_NAME, FACTORY_MERGE_FREEZE_PERMISSIONS, FACTORY_MERGE_FREEZE_VERIFY_RESULT_EXPRESSION, FACTORY_MERGE_TARGET_REF_CONDITION, FACTORY_PREVIEW_CLEANUP_AUDIT_JOB_ID, FACTORY_PREVIEW_CLEANUP_AUDIT_JOB_NAME, FACTORY_PRODUCTION_IMPACT_BASIS_OUTPUT, FACTORY_PRODUCTION_IMPACT_DECISION_OUTPUT, FACTORY_PRODUCTION_IMPACT_STEP_ID, FACTORY_PRODUCTION_IMPACT_UNSUBSCRIBED_OUTPUT, FACTORY_PROOF_GATE_APP_ID, FACTORY_PROOF_GATE_CHECK_NAME, FACTORY_PROOF_GATE_GUARD, FACTORY_PROOF_GATE_IF, FACTORY_PROOF_GATE_MODE_OUTPUT, FACTORY_PROOF_GATE_OUTPUT, FACTORY_PROOF_GATE_REASONS, FACTORY_PROOF_GATE_REASON_OUTPUT, FACTORY_PROOF_GATE_SHELL, FACTORY_PROOF_GATE_SOURCE_URL_OUTPUT, FACTORY_PROOF_GATE_STEP_ID, FACTORY_PROOF_GATE_STEP_NAME, FACTORY_PR_STATUS_HUD_APP_TOKEN_STEP_ID, FACTORY_PR_STATUS_HUD_CONCURRENCY, FACTORY_PR_STATUS_HUD_IF, FACTORY_PR_STATUS_HUD_JOB_ID, FACTORY_PR_STATUS_HUD_JOB_NAME, FACTORY_PR_STATUS_HUD_PERMISSIONS, FACTORY_PR_STATUS_HUD_PLAN_PATH, FACTORY_PUSH_IDENTITY_SCHEMA_VERSION, type FactoryCandidateImpactWorkflow, type FactoryCandidateImpactWorkflowOptions, type FactoryLifecycleContractLane, type FactoryLifecycleContractLaneOptions, type FactoryMergeFreezeJob, type FactoryMergeFreezeJobOptions, type FactoryPrStatusHudWorkflow, type FactoryPrStatusHudWorkflowOptions, type FactoryPreviewCleanupAuditJob, type FactoryPreviewCleanupDestroyJob, type FactoryPreviewCleanupTopology, type FactoryPreviewCleanupTopologyOptions, type FactoryPreviewReceiptWorkflow, type FactoryPreviewReceiptWorkflowOptions, type FactoryProductionImpactWorkflow, type FactoryProductionImpactWorkflowOptions, type FactoryProofGateOptions, type FactoryProofGateReason, type FactoryProofGateStep, type FactoryProofReusePresentationOptions, type FactoryProofReuseSummaryStep, type FactoryProofTimingStartStep, type FactoryPushIdentityConsumer, type FactoryPushIdentityConsumerOptions, type FactoryPushIdentityDisposition, type FactoryPushIdentityEnvelope, type FactoryPushIdentityProducer, type FactoryPushIdentityProducerOptions, type FactoryRunnerDecision, type FactoryRunnerHome, type FactoryRunnerKind, type FactoryRunnerOverride, type FactoryVerifyRunner, type FactoryVerifyRunnerMismatch, type FactoryVerifyRunnerPolicyInput, type FactoryVerifyRunnerPolicyReport, type FactoryVerifyRunnerTable, type FactoryWorkflowArtifact, type FactoryWorkflowOptions, type FactoryWorkflowSetupOptions, GitHubApiError, GitHubAppTokenTransportError, type GithubAppCredentials, type GithubAppInstallationPermissions, type GithubAppTokenOptions, type InstallStepOptions, type LocalPreviewStage, type LocalPreviewStageOptions, NODE_PNPM_ACTION_FAMILY_NODE24, type NodePnpmActionFamily, PREVIEW_PROOF_INVENTORY_CHECK_NAME, PREVIEW_PROOF_INVENTORY_LIST_PERMISSIONS, type ParseLocalPreviewStageExpected, type ParsedLocalPreviewStage, type PinnedAction, type PreviewProofCandidate, type PreviewProofCleanupOutcome, type PreviewProofCleanupStatus, type PreviewProofEnvelopeEvidence, type PreviewProofInventoryAccess, type PreviewProofInventoryCleanupInput, type PreviewProofInventoryListInput, type PreviewProofInventoryPersistInput, type PreviewProofInventoryStore, type PreviewProofInventoryTransport, type PreviewProofLifecycleEvent, type PreviewProofLifecycleState, type PreviewProofRegistration, type PreviewProofResolveQuery, PreviewProofTransportError, type ProofReuseCommand, type ProofReuseCoverageInput, type ProofReuseCoverageReport, SETUP_STEP_ROLES, type SetupNodeStepOptions, type SetupStepRole, UPLOAD_ARTIFACT, VITEST_PROFILE_SCHEMA_VERSION, VITEST_PROFILE_TOOL, type VitestJsonReport, type VitestProfile, type VitestProfileDependencies, type VitestProfileDurationSummary, type VitestProfileEnvironment, VitestProfileError, type VitestProfileOptions, type VitestProfileReadResult, type VitestProfileSample, type VitestProfileSampleExecution, type VitestTestStatus, type WorkflowShellParseFailure, type WorkflowStep, assertAlchemyBaseline, assertProofReuseCoverage, assertVerifyRunnerPolicy, assertWorkflowShellParses, bundleAlchemyEntry, captureVitestProfileEnvironment, executeAlchemyEntry, factoryCandidateImpactWorkflow, factoryCandidateOrPushCondition, factoryLifecycleContractLane, factoryMergeFreezeJob, factoryMergeFreezeScript, factoryPrStatusHudWorkflow, factoryPreviewCleanupTopology, factoryPreviewReceiptWorkflow, factoryProductionImpactWorkflow, factoryProofGateScript, factoryProofGateStep, factoryProofReuseSummaryStep, factoryProofTimingStartStep, factoryPushIdentityConsumer, factoryPushIdentityProducer, factoryVerifyRunner, factoryWorkflow, githubAppJwt, isLocalPreviewStage, localPreviewStage, mintInstallationToken, normalizeVitestProfileSample, parseLocalPreviewStage, previewCleanupDestroyJobId, previewProofInventory, previewProofLifecycle, productionImpactTargetOutput, proofReuseCoverage, proofReuseRequiredCommands, readVitestProfileDocument, resolveProofReuseCommands, runVitestProfile, setupStepsForRoles, verifyRunnerPolicy, workflowRunBlocks, workflowShellParseFailures, writeVitestProfile };