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

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/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
- import { t as bundleAlchemyEntry } from "./bundle-alchemy-entry-BuMrl5fR.js";
2
- import { a as localPreviewStage, c as assertAlchemyBaseline, i as isLocalPreviewStage, n as executeAlchemyEntry, o as parseLocalPreviewStage, s as ALCHEMY_BASELINE, t as EXECUTE_ALCHEMY_ENTRY_MAX_BUFFER } from "./execute-alchemy-entry-CDMdbXIi.js";
1
+ import { t as bundleAlchemyEntry } from "./bundle-alchemy-entry-Ba1Ebp91.js";
2
+ import { a as localPreviewStage, c as assertAlchemyBaseline, i as isLocalPreviewStage, n as executeAlchemyEntry, o as parseLocalPreviewStage, s as ALCHEMY_BASELINE, t as EXECUTE_ALCHEMY_ENTRY_MAX_BUFFER } from "./execute-alchemy-entry-CxQrjSg8.js";
3
3
  import { createRequire } from "node:module";
4
4
  import { mkdir, readFile, rename, writeFile } from "node:fs/promises";
5
5
  import path from "node:path";
@@ -10,7 +10,7 @@ import { execFileSync, spawn } from "node:child_process";
10
10
  import { once } from "node:events";
11
11
  import { arch, availableParallelism, cpus, platform, release, totalmem } from "node:os";
12
12
  import { performance } from "node:perf_hooks";
13
- //#region src/actions.ts
13
+ // src/actions.ts
14
14
  /**
15
15
  * The canonical Node 24 family shared by factory-project workflows.
16
16
  *
@@ -45,8 +45,7 @@ const UPLOAD_ARTIFACT = {
45
45
  tag: "v4.6.2",
46
46
  uses: "actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02"
47
47
  };
48
- //#endregion
49
- //#region src/candidate-lifecycle.ts
48
+ // src/candidate-lifecycle.ts
50
49
  /**
51
50
  * Pull-request events that can create or refresh a Factory candidate run.
52
51
  *
@@ -71,8 +70,7 @@ const factoryCandidateOrPushCondition = (candidateCondition) => {
71
70
  ...candidateCondition ? [candidateCondition] : []
72
71
  ].join(" && ")})`].join(" || ");
73
72
  };
74
- //#endregion
75
- //#region src/preview-proof-lifecycle.ts
73
+ // src/preview-proof-lifecycle.ts
76
74
  const EMPTY_STATE = Object.freeze({ registrations: Object.freeze([]) });
77
75
  const DETACHED_PROOF_BRANCH = "(detached)";
78
76
  /**
@@ -174,8 +172,7 @@ const previewProofLifecycle = {
174
172
  resolve,
175
173
  transition
176
174
  };
177
- //#endregion
178
- //#region src/github-transport.ts
175
+ // src/github-transport.ts
179
176
  /**
180
177
  * One GitHub JSON request with bounded transport retries (#830, #923).
181
178
  *
@@ -285,8 +282,7 @@ const githubJson$1 = async (options, errors) => {
285
282
  if (outcome.ok) return outcome.value;
286
283
  throw errors.transport(outcome, attempts);
287
284
  };
288
- //#endregion
289
- //#region src/github-app-token.ts
285
+ // src/github-app-token.ts
290
286
  /**
291
287
  * Minting a GitHub App installation token: the RS256 app JWT, the optional
292
288
  * installation lookup, and the token exchange (#617).
@@ -382,7 +378,8 @@ const mintInstallationToken = async (input, options = {}) => {
382
378
  if (typeof installation.id !== "number") throw new TypeError("GitHub App installation response omitted id");
383
379
  installationId = installation.id;
384
380
  } else {
385
- const accountLogin = installationAccountLogin(await githubAppJson(request, `https://api.github.com/app/installations/${installationId}`, jwt, "GET", budget));
381
+ const pinned = await githubAppJson(request, `https://api.github.com/app/installations/${installationId}`, jwt, "GET", budget);
382
+ const accountLogin = installationAccountLogin(pinned);
386
383
  if (accountLogin === void 0) throw new TypeError("GitHub App installation response omitted account login");
387
384
  if (accountLogin.toLowerCase() !== input.owner.toLowerCase()) throw new Error(`GitHub App installation ${installationId} belongs to ${accountLogin}, not ${input.owner}; refusing to mint a token for ${input.owner}/${input.repo}`);
388
385
  }
@@ -397,8 +394,7 @@ const mintInstallationToken = async (input, options = {}) => {
397
394
  if (typeof minted.token !== "string") throw new TypeError("GitHub App token response omitted token");
398
395
  return minted.token;
399
396
  };
400
- //#endregion
401
- //#region src/proof-reuse-gate.ts
397
+ // src/proof-reuse-gate.ts
402
398
  /**
403
399
  * The GitHub-side **proof-reuse gate** (ADR 0022, #309, #317).
404
400
  *
@@ -1281,8 +1277,7 @@ const assertProofReuseCoverage = (input) => {
1281
1277
  const problem = report.requiredCommands.length === 0 ? "selects no usable profile commands, so any passing proof would trivially cover it" : `skips work no selected profile command runs: ${report.uncovered.join(", ")}`;
1282
1278
  throw new Error(`Proof-reuse coverage failed: the ${surface} surface ${problem}. Add the command to software-factory.profile.json (and to this surface's selection), or stop skipping it.`);
1283
1279
  };
1284
- //#endregion
1285
- //#region src/preview-proof-inventory.ts
1280
+ // src/preview-proof-inventory.ts
1286
1281
  /**
1287
1282
  * Hosted preview-proof inventory (#639): persist and list Factory-App
1288
1283
  * registrations, and record cleanup outcomes, without PR comments.
@@ -1678,10 +1673,12 @@ const githubStore = (transport) => {
1678
1673
  const { token } = transport;
1679
1674
  return {
1680
1675
  list: async (input) => {
1681
- return takeNewestRegistrations(await mapPool(await listCommitShasForPull(request, token, timeoutMs, input.owner, input.repo, input.pr), 8, async (sha) => ({
1676
+ const shas = await listCommitShasForPull(request, token, timeoutMs, input.owner, input.repo, input.pr);
1677
+ const runsBySha = await mapPool(shas, 8, async (sha) => ({
1682
1678
  runs: await listCheckRunsOnSha(request, token, timeoutMs, input.owner, input.repo, sha),
1683
1679
  sha
1684
- })), input.pr);
1680
+ }));
1681
+ return takeNewestRegistrations(runsBySha, input.pr);
1685
1682
  },
1686
1683
  put: async (input) => {
1687
1684
  const registration = assertPersistableRegistration(input.registration);
@@ -1771,8 +1768,7 @@ const previewProofInventory = {
1771
1768
  persist,
1772
1769
  recordCleanup
1773
1770
  };
1774
- //#endregion
1775
- //#region src/pinned-action.ts
1771
+ // src/pinned-action.ts
1776
1772
  const PINNED_ACTION_PATTERN = /^[\w.-]+\/[\w.-]+@[0-9a-f]{40}$/u;
1777
1773
  const ACTION_TAG_PATTERN = /^v\d+(?:\.\d+){0,2}$/u;
1778
1774
  const actionRepository = (action) => action.uses.slice(0, action.uses.indexOf("@"));
@@ -1782,9 +1778,8 @@ const assertPinnedAction = (name, action, expectedRepository) => {
1782
1778
  if (expectedRepository && actionRepository(action) !== expectedRepository) throw new Error(`${name} must pin ${expectedRepository}, got ${actionRepository(action)}.`);
1783
1779
  if (!ACTION_TAG_PATTERN.test(action.tag)) throw new Error(`${name} tag must be vN, vN.N, or vN.N.N, got "${action.tag}".`);
1784
1780
  };
1785
- //#endregion
1786
- //#region src/factory-workflow.ts
1787
- const RESERVED_ACTION_NAMES = new Set([
1781
+ // src/factory-workflow.ts
1782
+ const RESERVED_ACTION_NAMES = /* @__PURE__ */ new Set([
1788
1783
  "checkout",
1789
1784
  "setupNode",
1790
1785
  "setupPnpm"
@@ -1897,8 +1892,7 @@ const factoryWorkflow = (options) => {
1897
1892
  })
1898
1893
  });
1899
1894
  };
1900
- //#endregion
1901
- //#region src/cursor-oidc.ts
1895
+ // src/cursor-oidc.ts
1902
1896
  /**
1903
1897
  * Pinned Cursor OIDC trust predicates for the Factory App broker (#949).
1904
1898
  *
@@ -1926,8 +1920,7 @@ const FACTORY_CURSOR_OIDC_MANAGED_RUNTIME = "managed";
1926
1920
  const FACTORY_APP_BROKER_PATH = "/api/factory-app/installation-token";
1927
1921
  /** Production broker origin. The CLI pins this; it is not profile-declared. */
1928
1922
  const FACTORY_APP_BROKER_ORIGIN = "https://hq.patronage.com";
1929
- //#endregion
1930
- //#region src/proof-reuse-presentation.ts
1923
+ // src/proof-reuse-presentation.ts
1931
1924
  /** Generic timing and presentation steps around the proof-reuse gate (#652). */
1932
1925
  const githubExpression = (expression) => `\${{ ${expression} }}`;
1933
1926
  const shellExpansion = (expression) => `\${${expression}}`;
@@ -1997,8 +1990,7 @@ const factoryProofReuseSummaryStep = (options) => Object.freeze({
1997
1990
  name: FACTORY_PROOF_TIMING_SUMMARY_STEP_NAME,
1998
1991
  run: factoryProofReuseSummaryScript(options)
1999
1992
  });
2000
- //#endregion
2001
- //#region src/impact-demand-condition.ts
1993
+ // src/impact-demand-condition.ts
2002
1994
  const impactDemandConditions = (options) => {
2003
1995
  const targetOutput = (targetName) => {
2004
1996
  const output = options.targetOutputs[targetName];
@@ -2015,8 +2007,7 @@ const impactDemandConditions = (options) => {
2015
2007
  demandedIfAtStep: (targetName) => condition(`steps.${options.stepId}`, "outcome", targetOutput(targetName))
2016
2008
  });
2017
2009
  };
2018
- //#endregion
2019
- //#region src/runnable-cli.ts
2010
+ // src/runnable-cli.ts
2020
2011
  /**
2021
2012
  * `@patronage/software-factory` publishes two dist entries. `dist/index.js` is
2022
2013
  * the package export: consumers import it, so it runs no command. `dist/cli.js`
@@ -2033,8 +2024,7 @@ const INERT_ENTRY_PATTERN = /(?:^|[/\\])dist[/\\]index\.js(?:["'\s]|$)/u;
2033
2024
  const assertRunnableCli = (name, cli) => {
2034
2025
  if (INERT_ENTRY_PATTERN.test(cli)) throw new Error(`${name} must invoke the software-factory bin, not the package entry dist/index.js, which imports as a library and exits 0 without running the command. Use the bin name (for example "pnpm exec psf") or dist/cli.js. Got "${cli}".`);
2035
2026
  };
2036
- //#endregion
2037
- //#region src/production-impact-workflow.ts
2027
+ // src/production-impact-workflow.ts
2038
2028
  const FACTORY_PRODUCTION_IMPACT_STEP_ID = "production_impact";
2039
2029
  const FACTORY_PRODUCTION_IMPACT_DECISION_OUTPUT = "decision";
2040
2030
  const FACTORY_PRODUCTION_IMPACT_BASIS_OUTPUT = "basis";
@@ -2130,8 +2120,7 @@ const factoryProductionImpactWorkflow = (options) => {
2130
2120
  targetOutputs: Object.freeze(targetOutputs)
2131
2121
  });
2132
2122
  };
2133
- //#endregion
2134
- //#region src/candidate-impact-workflow.ts
2123
+ // src/candidate-impact-workflow.ts
2135
2124
  const FACTORY_CANDIDATE_IMPACT_STEP_ID = "candidate_impact";
2136
2125
  const FACTORY_CANDIDATE_IMPACT_DECISION_OUTPUT = "decision";
2137
2126
  const FACTORY_CANDIDATE_IMPACT_BASIS_OUTPUT = "basis";
@@ -2190,8 +2179,7 @@ const factoryCandidateImpactWorkflow = (options) => {
2190
2179
  targetOutputs: Object.freeze(targetOutputs)
2191
2180
  });
2192
2181
  };
2193
- //#endregion
2194
- //#region src/lifecycle-contract-lane.ts
2182
+ // src/lifecycle-contract-lane.ts
2195
2183
  const FACTORY_LIFECYCLE_CONTRACT_JOB_ID = "factory-contracts";
2196
2184
  const FACTORY_LIFECYCLE_CONTRACT_JOB_NAME = "Factory / Alchemy Contracts";
2197
2185
  const JOB_ID_PATTERN$1 = /^[A-Za-z_][A-Za-z0-9_-]*$/u;
@@ -2257,8 +2245,7 @@ const factoryLifecycleContractLane = (declaration) => {
2257
2245
  steps: Object.freeze([runStep, summaryStep])
2258
2246
  });
2259
2247
  };
2260
- //#endregion
2261
- //#region src/merge-freeze-job.ts
2248
+ // src/merge-freeze-job.ts
2262
2249
  /**
2263
2250
  * The merge-freeze writer job (#356, ADR 0016; #429 for the
2264
2251
  * merge-target namespace; #872 for this package).
@@ -2433,7 +2420,7 @@ const factoryMergeFreezeJob = (options) => {
2433
2420
  env: Object.freeze({
2434
2421
  GH_TOKEN: `\${{ steps.${FACTORY_MERGE_FREEZE_APP_TOKEN_STEP_ID}.outputs.token }}`,
2435
2422
  VERIFY_JOBS: `\${{ toJSON(needs) }}`,
2436
- VERIFY_RESULT: options.verifyResultExpression ?? FACTORY_MERGE_FREEZE_VERIFY_RESULT_EXPRESSION
2423
+ VERIFY_RESULT: options.verifyResultExpression ?? "${{ (contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled')) && 'failure' || 'success' }}"
2437
2424
  }),
2438
2425
  name: "Complete the merge-freeze generation",
2439
2426
  run: factoryMergeFreezeScript()
@@ -2447,8 +2434,7 @@ const factoryMergeFreezeJob = (options) => {
2447
2434
  steps: Object.freeze([mintStep, reportStep])
2448
2435
  });
2449
2436
  };
2450
- //#endregion
2451
- //#region src/pr-status-hud-workflow.ts
2437
+ // src/pr-status-hud-workflow.ts
2452
2438
  const FACTORY_PR_STATUS_HUD_JOB_ID = "status-hud";
2453
2439
  const FACTORY_PR_STATUS_HUD_JOB_NAME = "Present PR status HUD";
2454
2440
  const FACTORY_PR_STATUS_HUD_APP_TOKEN_STEP_ID = "factory-app-token";
@@ -2504,8 +2490,7 @@ const factoryPrStatusHudWorkflow = (options) => {
2504
2490
  presentSteps: Object.freeze([mintStep, presentStep])
2505
2491
  });
2506
2492
  };
2507
- //#endregion
2508
- //#region src/preview-cleanup-topology.ts
2493
+ // src/preview-cleanup-topology.ts
2509
2494
  const FACTORY_PREVIEW_CLEANUP_AUDIT_JOB_ID = "stage-residue-audit";
2510
2495
  const FACTORY_PREVIEW_CLEANUP_AUDIT_JOB_NAME = "Stage residue audit";
2511
2496
  const JOB_ID_PATTERN = /^[A-Za-z_][A-Za-z0-9_-]*$/u;
@@ -2557,8 +2542,7 @@ const factoryPreviewCleanupTopology = (options) => {
2557
2542
  destroyJobs: Object.freeze(destroyJobs)
2558
2543
  });
2559
2544
  };
2560
- //#endregion
2561
- //#region src/preview-cleanup.ts
2545
+ // src/preview-cleanup.ts
2562
2546
  const DEFAULT_SWEEP_MAX_TARGETS = 50;
2563
2547
  /** GitHub refuses a matrix with more than 256 entries. */
2564
2548
  const MATRIX_ENTRY_LIMIT$1 = 256;
@@ -2852,8 +2836,7 @@ const readPullRequestStates = async (input, access) => {
2852
2836
  }
2853
2837
  return states;
2854
2838
  };
2855
- //#endregion
2856
- //#region src/preview-cleanup-workflow.ts
2839
+ // src/preview-cleanup-workflow.ts
2857
2840
  const FACTORY_PREVIEW_CLEANUP_DISCOVER_JOB_ID = "discover";
2858
2841
  const FACTORY_PREVIEW_CLEANUP_DISCOVER_JOB_NAME = "Discover preview cleanup targets";
2859
2842
  const FACTORY_PREVIEW_CLEANUP_DISCOVER_STEP_ID = "targets";
@@ -3079,8 +3062,7 @@ const factoryPreviewCleanupWorkflow = (options) => {
3079
3062
  permissions: Object.freeze({ contents: "read" })
3080
3063
  });
3081
3064
  };
3082
- //#endregion
3083
- //#region src/preview-receipt-workflow.ts
3065
+ // src/preview-receipt-workflow.ts
3084
3066
  /** Receipt transport only. The consumer owns selection, lifecycle, smoke, and freshness. */
3085
3067
  const factoryPreviewReceiptWorkflow = (options) => {
3086
3068
  if (!/^preview:[a-z][a-z0-9-]*$/u.test(options.target)) throw new Error("Preview receipts require a declared preview target name.");
@@ -3140,8 +3122,7 @@ const factoryPreviewReceiptWorkflow = (options) => {
3140
3122
  })
3141
3123
  });
3142
3124
  };
3143
- //#endregion
3144
- //#region src/push-identity-workflow.ts
3125
+ // src/push-identity-workflow.ts
3145
3126
  /** `owner/repo` slice of the catalog's `UPLOAD_ARTIFACT` pin, derived rather
3146
3127
  * than repeated as a literal, so a repository rename here cannot drift from
3147
3128
  * the pin it validates against. */
@@ -3511,8 +3492,7 @@ const factoryPushIdentityConsumer = (options) => {
3511
3492
  usableIf: `steps.${FACTORY_PUSH_IDENTITY_VALIDATE_STEP_ID}.outputs.disposition == 'usable'`
3512
3493
  });
3513
3494
  };
3514
- //#endregion
3515
- //#region src/vitest-profile.ts
3495
+ // src/vitest-profile.ts
3516
3496
  /**
3517
3497
  * Vitest suite profiling — the measurement mechanics behind a CI runner
3518
3498
  * comparison (#640, #647).
@@ -3533,7 +3513,7 @@ const factoryPushIdentityConsumer = (options) => {
3533
3513
  const VITEST_PROFILE_SCHEMA_VERSION = 1;
3534
3514
  /** `tool` discriminator every emitted profile carries. */
3535
3515
  const VITEST_PROFILE_TOOL = "factory-ci-vitest-profile";
3536
- const RUN_TIMEOUT_MS = 15 * 6e4;
3516
+ const RUN_TIMEOUT_MS = 9e5;
3537
3517
  const TERMINATION_GRACE_MS = 5e3;
3538
3518
  /**
3539
3519
  * A sample failed. The partial profile is already on disk; `exitCode` is the
@@ -3833,8 +3813,7 @@ const runVitestProfile = async (options, dependencies = {}) => {
3833
3813
  }
3834
3814
  return profile;
3835
3815
  };
3836
- //#endregion
3837
- //#region src/vitest-profile-reader.ts
3816
+ // src/vitest-profile-reader.ts
3838
3817
  const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
3839
3818
  const isFiniteNumber = (value) => typeof value === "number" && Number.isFinite(value);
3840
3819
  const durationSummaryFailure = (value, where) => {
@@ -3947,8 +3926,7 @@ const readVitestProfileDocument = (value) => {
3947
3926
  profile: value
3948
3927
  };
3949
3928
  };
3950
- //#endregion
3951
- //#region src/verify-runner-policy.ts
3929
+ // src/verify-runner-policy.ts
3952
3930
  const DEPOT_LABEL = "depot-ubuntu-24.04";
3953
3931
  const HOSTED_LABEL = "ubuntu-latest";
3954
3932
  const isOverride = (decision) => typeof decision === "object";
@@ -4064,8 +4042,7 @@ const assertVerifyRunnerPolicy = (yaml, input) => {
4064
4042
  if (report.forbiddenKinds.length > 0) details.push(`deploy-credentials is illegal inside Verify: ${report.forbiddenKinds.join(", ")}`);
4065
4043
  throw new Error(`${input.source} Verify runner policy failed:\n${details.map((detail) => ` - ${detail}`).join("\n")}`);
4066
4044
  };
4067
- //#endregion
4068
- //#region src/workflow-shell-lint.ts
4045
+ // src/workflow-shell-lint.ts
4069
4046
  const RUN_KEY = /^(?<indent>\s*)(?:-\s+)?run:(?<inline>.*)$/u;
4070
4047
  /**
4071
4048
  * GitHub evaluates `${{ }}` before bash ever sees the script, and what it
@@ -4100,8 +4077,10 @@ const neutralizeExpressions = (script) => {
4100
4077
  end = scan + 2;
4101
4078
  break;
4102
4079
  }
4103
- } else if (char === quote) if (script[scan + 1] === quote) scan += 1;
4104
- else quote = void 0;
4080
+ } else if (char === quote) {
4081
+ if (script[scan + 1] === quote) scan += 1;
4082
+ else quote = void 0;
4083
+ }
4105
4084
  scan += 1;
4106
4085
  }
4107
4086
  if (end === -1) {
@@ -4252,7 +4231,7 @@ const ASSIGNMENT = /^[A-Za-z_]\w*=/u;
4252
4231
  * Named rather than inferred, so an unfamiliar command fails loudly instead of
4253
4232
  * being skipped as though it had been considered.
4254
4233
  */
4255
- const NON_SHELL_INTERPRETERS = new Set([
4234
+ const NON_SHELL_INTERPRETERS = /* @__PURE__ */ new Set([
4256
4235
  "cmd",
4257
4236
  "powershell",
4258
4237
  "pwsh",
@@ -4328,5 +4307,4 @@ const assertWorkflowShellParses = (yaml, options) => {
4328
4307
  const detail = failures.map((failure) => ` - ${failure.step ?? "unnamed step"}: ${failure.stderr.replaceAll("\n", "\n ")}`).join("\n");
4329
4308
  throw new Error(`${options.source} emits shell bash cannot parse; the runner would treat it as a no-op:\n${detail}`);
4330
4309
  };
4331
- //#endregion
4332
4310
  export { ALCHEMY_BASELINE, EXECUTE_ALCHEMY_ENTRY_MAX_BUFFER, 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_APP_TOKEN_STEP_ID, FACTORY_PREVIEW_CLEANUP_AUDIT_JOB_ID, FACTORY_PREVIEW_CLEANUP_AUDIT_JOB_NAME, FACTORY_PREVIEW_CLEANUP_CHECKOUT_REF, FACTORY_PREVIEW_CLEANUP_DEFAULT_SWEEP_CRON, FACTORY_PREVIEW_CLEANUP_DESTROY_STEP_ID, FACTORY_PREVIEW_CLEANUP_DISCOVER_JOB_ID, FACTORY_PREVIEW_CLEANUP_DISCOVER_JOB_NAME, FACTORY_PREVIEW_CLEANUP_DISCOVER_STEP_ID, FACTORY_PREVIEW_CLEANUP_PR_CLOSED_CONDITION, FACTORY_PREVIEW_CLEANUP_SWEEP_CONDITION, 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, GitHubApiError, GitHubAppTokenTransportError, NODE_PNPM_ACTION_FAMILY_NODE24, PREVIEW_PROOF_INVENTORY_CHECK_NAME, PREVIEW_PROOF_INVENTORY_LIST_PERMISSIONS, PreviewProofTransportError, SETUP_STEP_ROLES, UPLOAD_ARTIFACT, VITEST_PROFILE_SCHEMA_VERSION, VITEST_PROFILE_TOOL, VitestProfileError, assertAlchemyBaseline, assertPreviewCleanupStackPolicy, assertPreviewCleanupTargetsAbsent, assertProofReuseCoverage, assertVerifyRunnerPolicy, assertWorkflowShellParses, bundleAlchemyEntry, captureVitestProfileEnvironment, discoverOrphanedPreviewCleanupTargets, discoverPreviewCleanupTargets, executeAlchemyEntry, factoryCandidateImpactWorkflow, factoryCandidateOrPushCondition, factoryLifecycleContractLane, factoryMergeFreezeJob, factoryMergeFreezeScript, factoryPrStatusHudWorkflow, factoryPreviewCleanupTopology, factoryPreviewCleanupWorkflow, factoryPreviewReceiptWorkflow, factoryProductionImpactWorkflow, factoryProofGateScript, factoryProofGateStep, factoryProofReuseSummaryStep, factoryProofTimingStartStep, factoryPushIdentityConsumer, factoryPushIdentityProducer, factoryVerifyRunner, factoryWorkflow, githubAppJwt, isLocalPreviewStage, localPreviewStage, mintInstallationToken, normalizeVitestProfileSample, parseHostedPreviewStage, parseLocalPreviewStage, parsePreviewCleanupResidue, parsePreviewCleanupTargets, previewCleanupDestroyJobId, previewCleanupGithubOutput, previewCleanupResiduePullRequests, previewCleanupStackOutputKey, previewProofInventory, previewProofLifecycle, productionImpactTargetOutput, proofReuseCoverage, proofReuseRequiredCommands, readPullRequestStates, readVitestProfileDocument, recordPreviewCleanupOutcome, resolveProofReuseCommands, runVitestProfile, setupStepsForRoles, verifyRunnerPolicy, workflowRunBlocks, workflowShellParseFailures, writeVitestProfile };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@patronage/factory-ci",
3
- "version": "1.0.0-alpha.45",
3
+ "version": "1.0.0-alpha.47",
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",
@@ -35,22 +35,22 @@
35
35
  "tag": "next"
36
36
  },
37
37
  "dependencies": {
38
- "esbuild": "0.28.1"
38
+ "esbuild": "0.28.2"
39
39
  },
40
40
  "devDependencies": {
41
41
  "@alchemy.run/cloudflare": "2.0.0-beta.84",
42
- "@types/node": "24.13.3",
43
- "@vitest/coverage-v8": "4.1.10",
42
+ "@patronage/alchemy-d1-state": "0.4.0",
43
+ "@types/node": "24.19.2",
44
+ "@vitest/coverage-v8": "5.0.5",
44
45
  "alchemy": "2.0.0-beta.84",
45
46
  "effect": "4.0.6",
46
- "knip": "6.27.0",
47
- "oxfmt": "0.59.0",
48
- "oxlint": "1.76.0",
49
- "tsdown": "0.21.10",
50
- "typescript": "5.9.3",
51
- "ultracite": "7.10.5",
52
- "vitest": "4.1.10",
53
- "@patronage/alchemy-d1-state": "0.4.0"
47
+ "knip": "6.43.0",
48
+ "oxfmt": "0.75.0",
49
+ "oxlint": "1.90.0",
50
+ "tsdown": "0.23.2",
51
+ "typescript": "7.1.0-beta",
52
+ "ultracite": "8.1.0",
53
+ "vitest": "5.0.5"
54
54
  },
55
55
  "peerDependencies": {
56
56
  "alchemy": ">=2.0.0-beta.63 <3",
@@ -19,6 +19,7 @@
19
19
  import { readFileSync } from "node:fs";
20
20
  import { createRequire } from "node:module";
21
21
  import path from "node:path";
22
+ import { setTimeout as wait } from "node:timers/promises";
22
23
  import { isDeepStrictEqual } from "node:util";
23
24
 
24
25
  import * as Effect from "effect/Effect";
@@ -187,8 +188,48 @@ export interface AlchemyLifecyclePolicy {
187
188
  * not converged whatever this list names.
188
189
  */
189
190
  readonly nonConvergentResources?: readonly string[];
191
+ /**
192
+ * Bounded read-only re-plans after the apply (#1349). A provider can
193
+ * report a resource as still changing for a short while after a successful
194
+ * apply. Set, a post-deploy plan that is only `NOT_CONVERGED` waits
195
+ * `delayMillis` and re-plans, up to `attempts` more times, under the same
196
+ * lease. The apply never repeats, and every other check (the state read on
197
+ * both sides of each plan, retained identities, created resources, the
198
+ * lease) runs on every attempt and stops the deploy at once. Exhausted, the
199
+ * deploy is still `NOT_CONVERGED`. Omitted, there is no retry. `attempts`
200
+ * is 1 to 10 and `delayMillis` 0 to 60 000, and below an explicit
201
+ * `ownershipTtlMillis`. That bound is a floor: the lease is renewed after
202
+ * each dry-run, so the delay plus one re-plan must fit inside the lease;
203
+ * keep the delay well under it.
204
+ */
205
+ readonly convergenceRetries?: {
206
+ readonly attempts: number;
207
+ readonly delayMillis: number;
208
+ };
190
209
  }
191
210
 
211
+ const MAX_CONVERGENCE_ATTEMPTS = 10;
212
+ const MAX_CONVERGENCE_DELAY_MILLIS = 60_000;
213
+
214
+ /**
215
+ * A delay at or above an explicit lease TTL lapses the lease mid-wait, which
216
+ * would surface late as `OWNERSHIP_LOST`; refuse it up front. This is a floor,
217
+ * not a guarantee: the re-plan after the wait also runs before the renewal.
218
+ */
219
+ const validConvergenceRetries = ({
220
+ convergenceRetries: retries,
221
+ ownershipTtlMillis,
222
+ }: AlchemyLifecyclePolicy): boolean =>
223
+ retries === undefined ||
224
+ (Number.isInteger(retries.attempts) &&
225
+ retries.attempts >= 1 &&
226
+ retries.attempts <= MAX_CONVERGENCE_ATTEMPTS &&
227
+ Number.isInteger(retries.delayMillis) &&
228
+ retries.delayMillis >= 0 &&
229
+ retries.delayMillis <= MAX_CONVERGENCE_DELAY_MILLIS &&
230
+ (ownershipTtlMillis === undefined ||
231
+ retries.delayMillis < ownershipTtlMillis));
232
+
192
233
  type DistributiveOmit<T, K extends PropertyKey> = T extends unknown
193
234
  ? Omit<T, K>
194
235
  : never;
@@ -483,7 +524,8 @@ class LifecycleRun {
483
524
  }
484
525
  if (
485
526
  typeof this.policy.holder !== "string" ||
486
- this.policy.holder.trim() === ""
527
+ this.policy.holder.trim() === "" ||
528
+ !validConvergenceRetries(this.policy)
487
529
  ) {
488
530
  throw this.fail("INVALID_POLICY", "request");
489
531
  }
@@ -1163,26 +1205,53 @@ class LifecycleRun {
1163
1205
  // The convergence dry-run is the same read-only plan as admission's:
1164
1206
  // the state read before it is the post-apply state the
1165
1207
  // postconditions are checked against, and the read after it refuses
1166
- // a child that wrote.
1167
- const post = await this.readOnlyPlan(
1168
- this.planArgs(false),
1169
- lease,
1170
- accept,
1171
- "postcondition"
1172
- );
1173
- const after = post.before;
1174
- if (after.resources.length === 0) {
1175
- throw this.fail("DEPLOY_INCOMPLETE", "postcondition");
1176
- }
1177
- const createdNow = this.createdFqns(plan.before, after, plan.effects);
1178
- if (isProtected && !admittedFirstDeploy) {
1179
- this.assertRetained(
1180
- persistedToSnapshot(this.target, after),
1181
- persistedToSnapshot(this.target, plan.before),
1208
+ // a child that wrote. Every check runs again on each bounded re-plan
1209
+ // (#1349); only a plan that is not converged waits for another.
1210
+ const converge = async (
1211
+ retriesLeft: number
1212
+ ): Promise<{
1213
+ readonly createdNow: readonly string[];
1214
+ readonly post: {
1215
+ readonly before: PersistedState;
1216
+ readonly effects: PlanEffects;
1217
+ };
1218
+ }> => {
1219
+ const post = await this.readOnlyPlan(
1220
+ this.planArgs(false),
1221
+ lease,
1222
+ accept,
1182
1223
  "postcondition"
1183
1224
  );
1184
- }
1185
- this.assertConverged(post.effects, after);
1225
+ const after = post.before;
1226
+ if (after.resources.length === 0) {
1227
+ throw this.fail("DEPLOY_INCOMPLETE", "postcondition");
1228
+ }
1229
+ const createdNow = this.createdFqns(plan.before, after, plan.effects);
1230
+ if (isProtected && !admittedFirstDeploy) {
1231
+ this.assertRetained(
1232
+ persistedToSnapshot(this.target, after),
1233
+ persistedToSnapshot(this.target, plan.before),
1234
+ "postcondition"
1235
+ );
1236
+ }
1237
+ try {
1238
+ this.assertConverged(post.effects, after);
1239
+ } catch (error) {
1240
+ if (
1241
+ retriesLeft === 0 ||
1242
+ !(error instanceof AlchemyLifecycleError) ||
1243
+ error.code !== "NOT_CONVERGED"
1244
+ ) {
1245
+ throw error;
1246
+ }
1247
+ await wait(this.policy.convergenceRetries?.delayMillis ?? 0);
1248
+ return await converge(retriesLeft - 1);
1249
+ }
1250
+ return { createdNow, post };
1251
+ };
1252
+ const { createdNow, post } = await converge(
1253
+ this.policy.convergenceRetries?.attempts ?? 0
1254
+ );
1186
1255
  return {
1187
1256
  convergence: post.effects,
1188
1257
  created: createdNow,
@@ -4,11 +4,21 @@ import path from "node:path";
4
4
  import { build } from "esbuild";
5
5
 
6
6
  /**
7
- * Alchemy and Effect must resolve from the *consumer's* node_modules at run
8
- * time, never from the bundle: Alchemy's resource registry and Effect's
9
- * service tags are identity-sensitive, and a second copy silently breaks both.
7
+ * Alchemy, its `@alchemy.run/*` provider packages and Effect must resolve from
8
+ * the *consumer's* node_modules at run time, never from the bundle: Alchemy's
9
+ * resource registry and Effect's service tags are identity-sensitive, and a
10
+ * second copy silently breaks both. Since 2.0.0-beta.84 the providers
11
+ * (`@alchemy.run/cloudflare` and the rest) ship outside core, and they import
12
+ * runtime-only specifiers such as `cloudflare:workers` that no Node bundle can
13
+ * resolve.
10
14
  */
11
- const ALCHEMY_EXTERNALS = ["alchemy", "alchemy/*", "effect", "effect/*"];
15
+ const ALCHEMY_EXTERNALS = [
16
+ "alchemy",
17
+ "alchemy/*",
18
+ "@alchemy.run/*",
19
+ "effect",
20
+ "effect/*",
21
+ ];
12
22
 
13
23
  /**
14
24
  * The package names behind `ALCHEMY_EXTERNALS`, derived rather than restated so
@@ -97,7 +107,8 @@ export interface BundleAlchemyEntryOptions {
97
107
  * `packages: "external"`. Values are resolved the way esbuild resolves any
98
108
  * import, so give absolute paths or package names — which aliases a repo
99
109
  * needs is the consumer's policy and this package bakes in none. A key on
100
- * `alchemy`, `effect`, or a subpath of either is rejected outright, and the
110
+ * `alchemy`, an `@alchemy.run/*` provider, `effect`, or a subpath of any of
111
+ * them is rejected outright, and the
101
112
  * finished bundle is checked for files from those packages however they were
102
113
  * reached.
103
114
  */
@@ -119,11 +130,11 @@ export interface BundleAlchemyEntryOptions {
119
130
  }
120
131
 
121
132
  /**
122
- * Pre-bundle an Alchemy entry to a single ESM file, keeping `alchemy` and
123
- * `effect` external (#268).
133
+ * Pre-bundle an Alchemy entry to a single ESM file, keeping `alchemy`, its
134
+ * `@alchemy.run/*` providers and `effect` external (#268).
124
135
  *
125
136
  * 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
137
+ * has to be flattened first, and the flattening must not swallow the
127
138
  * packages whose identity matters.
128
139
  *
129
140
  * Returns the absolute path of the file written.
@@ -964,11 +964,6 @@ export const factoryProofGateStep = (
964
964
  export interface ProofReuseCoverageInput {
965
965
  /** The same selection handed to the gate for this surface. */
966
966
  readonly commands: readonly ProofReuseCommand[];
967
- /**
968
- * @deprecated Ignored. Consumer prose cannot authorize executable coverage;
969
- * retained only so the 0.2.1 security patch remains source-compatible.
970
- */
971
- readonly equivalents?: Readonly<Record<string, string>>;
972
967
  /**
973
968
  * The command strings the consumer's workflow would skip when the gate says
974
969
  * `true`, already resolved to the leaves that actually run. Extracting them