@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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@patronage/factory-ci",
3
- "version": "1.0.0-alpha.43",
3
+ "version": "1.0.0-alpha.45",
4
4
  "description": "Deep CI and deploy building blocks for Patronage factory projects: workflow source artifacts, hosted diff classification, Alchemy entry execution, and disposable-stage semantics",
5
5
  "keywords": [
6
6
  "alchemy",
@@ -38,10 +38,11 @@
38
38
  "esbuild": "0.28.1"
39
39
  },
40
40
  "devDependencies": {
41
+ "@alchemy.run/cloudflare": "2.0.0-beta.84",
41
42
  "@types/node": "24.13.3",
42
43
  "@vitest/coverage-v8": "4.1.10",
43
- "alchemy": "2.0.0-beta.83",
44
- "effect": "4.0.1",
44
+ "alchemy": "2.0.0-beta.84",
45
+ "effect": "4.0.6",
45
46
  "knip": "6.27.0",
46
47
  "oxfmt": "0.59.0",
47
48
  "oxlint": "1.76.0",
package/src/actions.ts CHANGED
@@ -2,13 +2,6 @@
2
2
  * The GitHub Actions this family's workflow generators use, pinned to full
3
3
  * commit SHAs in one place (#268).
4
4
  *
5
- * Every repository pinned the same *tags* and got different *commits*: this
6
- * repository's `verify.yml` carried `actions/checkout@11d5960a` while
7
- * `hq-deploy.yml` and all of paitronage carried `34e11487`, because gagen
8
- * resolves a floating `@v4` at generation time and the files were generated
9
- * months apart. Naming the SHA here is what makes that class of drift
10
- * impossible: regenerating a workflow can no longer move a pin.
11
- *
12
5
  * `uses` is a bare `owner/repo@<sha>` string, safe to hand straight to a
13
6
  * gagen step. The tag lives in its own field rather than as a `# v7.0.1`
14
7
  * suffix on `uses`, because a `#` inside a YAML scalar forces quoting and
@@ -5,8 +5,7 @@
5
5
  * else: the child's output is parsed and dropped, so no secret in it can
6
6
  * reach a job log or an evidence file through the operation. That is the
7
7
  * right default and it stays the default. It also leaves an operator with a
8
- * failure code and no record of what failed, which twice cost a paitronage
9
- * investigation its evidence.
8
+ * failure code and no record of what failed.
10
9
  *
11
10
  * This is the opt-in other half: a consumer that names a file gets every
12
11
  * child's streams appended to it, each stream passed whole through the
@@ -1,15 +1,6 @@
1
1
  /**
2
2
  * Cloudflare credential preflight for an Alchemy deploy.
3
3
  *
4
- * Two projects built this twice. Paitronage
5
- * (`scripts/alchemy/credential-preflight.ts` plus
6
- * `scripts/alchemy/cloudflare-token-policy.ts`) and firedup
7
- * (`scripts/alchemy/local-credentials.ts`) both resolve a Cloudflare API
8
- * token, verify it is live, and refuse to deploy unless its permission groups
9
- * match an exact reviewed list. What repeats is the check. What does not
10
- * repeat is the account, the permission list, the resource scope, and where
11
- * the credential comes from, so every one of those is an input.
12
- *
13
4
  * **No credential value is ever printed.** Errors name environment variables and
14
5
  * missing groups from the caller-owned permission requirements. Untrusted API
15
6
  * status, receipt group names, and resource identifiers are never reflected.
@@ -3,11 +3,7 @@
3
3
  *
4
4
  * Alchemy's `destroy` can exit zero while the state store still lists
5
5
  * resources for the stage — a partial destroy, a resource whose delete failed
6
- * quietly, or a state row that was never removed. Paitronage checks the state
7
- * store after the child exits rather than trusting the exit code
8
- * (`runAlchemyLifecycle`, the `"Alchemy destroy left target-stage state
9
- * registered."` branch). Firedup carries no equivalent, which is exactly the
10
- * gap this closes.
6
+ * quietly, or a state row that was never removed.
11
7
  *
12
8
  * Reading the state store is the project's job: only the project knows which
13
9
  * store it configured and how to address a stage in it. This function owns the
@@ -7,10 +7,7 @@ import { canonicalPlan } from "./plan-effects.ts";
7
7
  *
8
8
  * The first deploy of a stack into a stage is the one deploy no earlier state
9
9
  * can constrain: there is nothing to diff against, so the plan is the only
10
- * description of what is about to be created. Paitronage binds that plan to an
11
- * operator decision by hashing it and comparing the hash against a reviewed
12
- * value (`firstDeployPlanSha256` and `assertFirstDeployEntry` in
13
- * `tools/alchemy/src/internal/lifecycle.ts`).
10
+ * description of what is about to be created.
14
11
  *
15
12
  * The generic form keeps the binding and drops the project's stage policy.
16
13
  * Which stages are eligible, and where the authorized hashes are kept, stay
@@ -10,12 +10,6 @@
10
10
  * back a fixed-shape result or an `AlchemyLifecycleError`. It cannot call the
11
11
  * steps in another order, because it does not call the steps.
12
12
  *
13
- * Paitronage and HQ each reconstructed this sequence from the guards in
14
- * `./` and got parts of it wrong in different ways (paitronage#1917): a
15
- * post-child failure reported as not started, an empty-stage cleanup racing
16
- * a concurrent write, a plan whose immutability check ignored stack output.
17
- * The sequence below is the one both were reaching for.
18
- *
19
13
  * What stays with the consumer: the resource graph, the credentials and
20
14
  * environment the child runs with, the stage table, the retained-identity
21
15
  * markers, the first-deploy authorization list, and the state store's own
@@ -474,8 +468,6 @@ class LifecycleRun {
474
468
  return { stack: this.request.stack, stage: this.request.stage };
475
469
  }
476
470
 
477
- // ── request and admission ────────────────────────────────────────────
478
-
479
471
  validateRequest(): void {
480
472
  const { operation, stack, stage } = this.request;
481
473
  if (
@@ -561,8 +553,6 @@ class LifecycleRun {
561
553
  }
562
554
  }
563
555
 
564
- // ── state ────────────────────────────────────────────────────────────
565
-
566
556
  /**
567
557
  * Run `body` under one stage lease. The lease is acquired at
568
558
  * `acquirePhase`, and every child `body` launches carries it, so no other
@@ -714,8 +704,6 @@ class LifecycleRun {
714
704
  return { output: view.output, resources: records };
715
705
  }
716
706
 
717
- // ── execution ────────────────────────────────────────────────────────
718
-
719
707
  private stageArgs(): readonly string[] {
720
708
  return ["--stage", this.request.stage];
721
709
  }
@@ -915,8 +903,6 @@ class LifecycleRun {
915
903
  return { before, effects: this.effectsOf(text, "postcondition"), text };
916
904
  }
917
905
 
918
- // ── operations ───────────────────────────────────────────────────────
919
-
920
906
  private planHashOf(text: string): string | undefined {
921
907
  const { firstDeploy } = this.policy;
922
908
  if (firstDeploy === undefined) {
@@ -28,9 +28,10 @@ const [ACCOUNT_ID_NAME, API_TOKEN_NAME] = HOSTED_CLOUDFLARE_CREDENTIAL_NAMES;
28
28
  * Alchemy validates the value against `/^[0-9a-f]{32}$/i` and rejects
29
29
  * placeholders such as `""` or `dummy` with an authentication error before any
30
30
  * run starts. The check is `validateAccountId`, in
31
- * `alchemy/lib/Cloudflare/Auth/AuthProvider.js` at 2.0.0-beta.76 and in
32
- * `alchemy/lib/Cloudflare/Auth/AuthConfig.js` at 2.0.0-beta.77. The file name
33
- * moves; the pattern is the same in both. Thirty-two zeros pass that shape
31
+ * `alchemy/lib/Cloudflare/Auth/AuthProvider.js` at 2.0.0-beta.76, in
32
+ * `alchemy/lib/Cloudflare/Auth/AuthConfig.js` at 2.0.0-beta.77, and in
33
+ * `@alchemy.run/cloudflare/lib/Auth/AuthConfig.js` from 2.0.0-beta.84. The
34
+ * file moves; the pattern is the same in all three. Thirty-two zeros pass that shape
34
35
  * check and route to nothing.
35
36
  */
36
37
  const SENTINEL_ACCOUNT_ID = "0".repeat(32);
@@ -15,7 +15,7 @@
15
15
  * The renderer logs every line through Effect's pretty console logger, so a
16
16
  * line arrives as `[HH:MM:SS.mmm] INFO (#1): <line>`, and coloured when the
17
17
  * child inherits `FORCE_COLOR`. Both wrappers are stripped before a line is
18
- * read. The captured output under `tests/fixtures/plan-output/beta-83/` is
18
+ * read. The captured output under `tests/fixtures/plan-output/beta-84/` is
19
19
  * the evidence for every shape this file reads.
20
20
  *
21
21
  * The adapter fails on anything it does not recognise: no summary, two
@@ -2,11 +2,9 @@
2
2
  * Stage and stack pairing, and protected-stage policy, from a project-supplied
3
3
  * table (#991).
4
4
  *
5
- * Two projects wrote the same three questions twice — is this stage protected,
6
- * is it disposable, and may this stack run it — and each answered them with its
7
- * own stage names hard-coded into the answer. The names differ; the questions
8
- * do not. This module owns the questions. A project supplies the table and gets
9
- * decisions back, so no project or stack name appears here.
5
+ * This module owns whether a stage is protected, whether it is disposable, and
6
+ * whether a stack may run it. A project supplies the table and gets decisions
7
+ * back, so no project or stack name appears here.
10
8
  *
11
9
  * One stage name does appear: `local`. It names the local emulator rather than
12
10
  * any project's estate, every project spells it the same way, and the question
@@ -2,11 +2,7 @@
2
2
  * The url-implies-auth invariant: a Worker the internet can reach declares how
3
3
  * it is authenticated (#994).
4
4
  *
5
- * A stack reaches production one Worker at a time, and the cheapest way to
6
- * publish an unauthenticated admin surface is to add `workersDev: true`, a
7
- * `domain`, or a route to a Worker that never had one. The Worker still works, nothing
8
- * fails, and the only record of the decision is a diff nobody re-read. This
9
- * check reads the evaluated graph instead and demands that every publicly
5
+ * This check reads the evaluated graph and demands that every publicly
10
6
  * reachable Worker names its guard.
11
7
  *
12
8
  * What counts as a guard is the project's call, not this module's. Patronage
@@ -8,8 +8,8 @@
8
8
  * `effect`, so it ships from the root entry, not the `./alchemy` subpath.
9
9
  */
10
10
  export const ALCHEMY_BASELINE = {
11
- alchemy: "2.0.0-beta.83",
12
- effect: "4.0.1",
11
+ alchemy: "2.0.0-beta.84",
12
+ effect: "4.0.6",
13
13
  } as const;
14
14
 
15
15
  /**
@@ -31,9 +31,17 @@ const BASELINE_PACKAGE_NAMES = Object.keys(
31
31
  ALCHEMY_BASELINE
32
32
  ) as (keyof typeof ALCHEMY_BASELINE)[];
33
33
 
34
+ // From 2.0.0-beta.84 the providers ship as their own packages, each peering
35
+ // on `alchemy` at the exact same version, and pnpm installs a mismatch with
36
+ // only a warning. A consumer that pins one must pin it at the baseline
37
+ // `alchemy` version.
38
+ const ALCHEMY_PROVIDER_PACKAGE_NAMES = ["@alchemy.run/cloudflare"] as const;
39
+
34
40
  /**
35
41
  * Fails when the consumer's `alchemy` or `effect` pin differs from
36
- * {@link ALCHEMY_BASELINE}, or when only one of the pair is present.
42
+ * {@link ALCHEMY_BASELINE}, when the pair is incomplete (a pinned Alchemy
43
+ * provider package such as `@alchemy.run/cloudflare` demands both), or when a
44
+ * pinned provider package is not at the baseline `alchemy` version.
37
45
  * Alchemy peers on Effect, so an unpinned auto-installed Effect can drift
38
46
  * outside the baseline while a lone `alchemy` pin would otherwise pass.
39
47
  * Both packages remaining absent is not drift — they are optional peers of
@@ -47,11 +55,14 @@ export const assertAlchemyBaseline = ({
47
55
  packageJson,
48
56
  }: AssertAlchemyBaselineInput): void => {
49
57
  const drifted: string[] = [];
50
- const pinOf = (name: keyof typeof ALCHEMY_BASELINE): string | undefined =>
58
+ const pinOf = (name: string): string | undefined =>
51
59
  packageJson.dependencies?.[name] ?? packageJson.devDependencies?.[name];
52
- const pairPresent = BASELINE_PACKAGE_NAMES.some(
53
- (name) => pinOf(name) !== undefined
54
- );
60
+ // A provider pin counts too: it peers on `effect` with a range, so a lone
61
+ // provider pin would let an auto-installed Effect drift off the baseline.
62
+ const pairPresent = [
63
+ ...BASELINE_PACKAGE_NAMES,
64
+ ...ALCHEMY_PROVIDER_PACKAGE_NAMES,
65
+ ].some((name) => pinOf(name) !== undefined);
55
66
 
56
67
  for (const name of BASELINE_PACKAGE_NAMES) {
57
68
  const pinned = pinOf(name);
@@ -67,6 +78,15 @@ export const assertAlchemyBaseline = ({
67
78
  }
68
79
  }
69
80
 
81
+ for (const name of ALCHEMY_PROVIDER_PACKAGE_NAMES) {
82
+ const pinned = pinOf(name);
83
+ if (pinned !== undefined && pinned !== ALCHEMY_BASELINE.alchemy) {
84
+ drifted.push(
85
+ `${name}@${pinned} (baseline: ${name}@${ALCHEMY_BASELINE.alchemy})`
86
+ );
87
+ }
88
+ }
89
+
70
90
  if (drifted.length > 0) {
71
91
  throw new Error(
72
92
  `Alchemy fleet baseline drift: ${drifted.join(", ")}. Bump to match ALCHEMY_BASELINE in @patronage/factory-ci, or wait for the next lockstep release.`
@@ -122,12 +122,9 @@ export interface BundleAlchemyEntryOptions {
122
122
  * Pre-bundle an Alchemy entry to a single ESM file, keeping `alchemy` and
123
123
  * `effect` external (#268).
124
124
  *
125
- * Both repos that deploy through Alchemy wrote this: the Alchemy CLI runs a
126
- * JavaScript entry, so a TypeScript `alchemy.run.ts` has to be flattened
127
- * first, and the flattening must not swallow the two packages whose identity
128
- * matters. Firedup additionally resolved esbuild *through vite* because it had
129
- * no direct dependency on it; here esbuild is a plain dependency of this
130
- * package and that hack can be deleted.
125
+ * The Alchemy CLI runs a JavaScript entry, so a TypeScript `alchemy.run.ts`
126
+ * has to be flattened first, and the flattening must not swallow the two
127
+ * packages whose identity matters.
131
128
  *
132
129
  * Returns the absolute path of the file written.
133
130
  */
@@ -2,9 +2,8 @@
2
2
  * The disposable Alchemy stage a local preview deploy runs in:
3
3
  * `local-pr-<pr>-<short sha>` (#268).
4
4
  *
5
- * Two repos invented this grammar independently and then had to agree on it
6
- * anyway, because the same cleanup sweeps delete these stages. A stage that
7
- * does not match is not disposable, and destructive operations must refuse it.
5
+ * A stage that does not match is not disposable, and destructive operations
6
+ * must refuse it.
8
7
  */
9
8
  const LOCAL_PREVIEW_STAGE_PATTERN =
10
9
  /^local-pr-(?<pr>[1-9]\d*)-(?<sha>[0-9a-f]{7,40})$/u;
@@ -7,21 +7,15 @@ import {
7
7
  setGithubTransportWaitForTests,
8
8
  } from "./github-transport.ts";
9
9
 
10
- // The error class lives with the transport primitive because `oxlint`'s
11
- // max-classes-per-file keeps `GitHubApiError` alone in this file. It is
12
- // re-exported here so the mint surface stays one import for consumers.
13
10
  export { GitHubAppTokenTransportError } from "./github-transport.ts";
14
11
 
15
12
  /**
16
13
  * Minting a GitHub App installation token: the RS256 app JWT, the optional
17
14
  * installation lookup, and the token exchange (#617).
18
15
  *
19
- * Two projects had grown the same three steps independently — the factory's
20
- * check-run publisher and paitronage's proof-comment publisher — which is the
21
- * admitted-on-repetition bar. Only the *mechanism* lives here. Where the
22
- * private key comes from, how the app id is configured, and what the token is
23
- * then used for stay with each consumer: this module is handed credentials and
24
- * returns a token.
16
+ * Only the *mechanism* lives here. Where the private key comes from, how the
17
+ * app id is configured, and what the token is then used for stay with each
18
+ * consumer: this module is handed credentials and returns a token.
25
19
  */
26
20
 
27
21
  /** The default request budget, matching the factory's other GitHub writes. */
package/src/index.ts CHANGED
@@ -183,6 +183,50 @@ export {
183
183
  factoryPreviewCleanupTopology,
184
184
  previewCleanupDestroyJobId,
185
185
  } from "./preview-cleanup-topology.ts";
186
+ export {
187
+ assertPreviewCleanupStackPolicy,
188
+ assertPreviewCleanupTargetsAbsent,
189
+ type DiscoverOrphanedPreviewCleanupTargetsInput,
190
+ type DiscoverPreviewCleanupTargetsInput,
191
+ discoverOrphanedPreviewCleanupTargets,
192
+ discoverPreviewCleanupTargets,
193
+ parseHostedPreviewStage,
194
+ parsePreviewCleanupResidue,
195
+ parsePreviewCleanupTargets,
196
+ type PreviewCleanupPullRequestState,
197
+ type PreviewCleanupResidue,
198
+ type PreviewCleanupStackPolicy,
199
+ type PreviewCleanupSweep,
200
+ type PreviewCleanupTarget,
201
+ previewCleanupGithubOutput,
202
+ previewCleanupResiduePullRequests,
203
+ previewCleanupStackOutputKey,
204
+ type ReadPullRequestStatesAccess,
205
+ type ReadPullRequestStatesInput,
206
+ readPullRequestStates,
207
+ type RecordPreviewCleanupOutcomeAccess,
208
+ type RecordPreviewCleanupOutcomeInput,
209
+ type RecordPreviewCleanupOutcomeResult,
210
+ recordPreviewCleanupOutcome,
211
+ } from "./preview-cleanup.ts";
212
+ export {
213
+ FACTORY_PREVIEW_CLEANUP_APP_TOKEN_STEP_ID,
214
+ FACTORY_PREVIEW_CLEANUP_CHECKOUT_REF,
215
+ FACTORY_PREVIEW_CLEANUP_DEFAULT_SWEEP_CRON,
216
+ FACTORY_PREVIEW_CLEANUP_DESTROY_STEP_ID,
217
+ FACTORY_PREVIEW_CLEANUP_DISCOVER_JOB_ID,
218
+ FACTORY_PREVIEW_CLEANUP_DISCOVER_JOB_NAME,
219
+ FACTORY_PREVIEW_CLEANUP_DISCOVER_STEP_ID,
220
+ FACTORY_PREVIEW_CLEANUP_PR_CLOSED_CONDITION,
221
+ FACTORY_PREVIEW_CLEANUP_SWEEP_CONDITION,
222
+ type FactoryPreviewCleanupWorkflow,
223
+ type FactoryPreviewCleanupWorkflowAuditJob,
224
+ type FactoryPreviewCleanupWorkflowDestroyJob,
225
+ type FactoryPreviewCleanupWorkflowDiscoverJob,
226
+ type FactoryPreviewCleanupWorkflowJob,
227
+ type FactoryPreviewCleanupWorkflowOptions,
228
+ factoryPreviewCleanupWorkflow,
229
+ } from "./preview-cleanup-workflow.ts";
186
230
  export {
187
231
  type FactoryPreviewReceiptWorkflow,
188
232
  type FactoryPreviewReceiptWorkflowOptions,