@intentius/chant 0.124.56 → 0.124.57

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 (93) hide show
  1. package/dist/ci-audit/index.d.ts.map +1 -1
  2. package/dist/ci-audit/index.js +1 -2
  3. package/dist/ci-product.d.ts.map +1 -1
  4. package/dist/ci-product.js +4 -5
  5. package/dist/cli/handlers/lifecycle.d.ts.map +1 -1
  6. package/dist/cli/handlers/lifecycle.js +14 -0
  7. package/dist/cli/handlers/pr.d.ts.map +1 -1
  8. package/dist/cli/handlers/pr.js +90 -35
  9. package/dist/components/auto-release.d.ts +5 -2
  10. package/dist/components/auto-release.d.ts.map +1 -1
  11. package/dist/components/auto-release.js +9 -4
  12. package/dist/components/capability.d.ts +10 -0
  13. package/dist/components/capability.d.ts.map +1 -1
  14. package/dist/components/deploy-units.d.ts +12 -0
  15. package/dist/components/deploy-units.d.ts.map +1 -1
  16. package/dist/components/deploy-units.js +20 -1
  17. package/dist/components/pr-pipeline.d.ts +8 -2
  18. package/dist/components/pr-pipeline.d.ts.map +1 -1
  19. package/dist/components/pr-pipeline.js +11 -3
  20. package/dist/components/row-lease.d.ts +22 -1
  21. package/dist/components/row-lease.d.ts.map +1 -1
  22. package/dist/components/row-lease.js +32 -6
  23. package/dist/e2e-harness/index.d.ts.map +1 -1
  24. package/dist/e2e-harness/index.js +1 -2
  25. package/dist/lexicon.d.ts +9 -0
  26. package/dist/lexicon.d.ts.map +1 -1
  27. package/dist/lifecycle/git.d.ts +39 -3
  28. package/dist/lifecycle/git.d.ts.map +1 -1
  29. package/dist/lifecycle/git.js +223 -15
  30. package/dist/lifecycle/lock-rows.d.ts +23 -0
  31. package/dist/lifecycle/lock-rows.d.ts.map +1 -1
  32. package/dist/lifecycle/lock-rows.js +47 -8
  33. package/dist/lifecycle/resource-lock.d.ts +70 -0
  34. package/dist/lifecycle/resource-lock.d.ts.map +1 -1
  35. package/dist/lifecycle/resource-lock.js +241 -5
  36. package/dist/op/gate.js +21 -4
  37. package/dist/op/op-waves-release-port.js +1 -1
  38. package/dist/op/op-waves-release.d.ts +2 -1
  39. package/dist/op/op-waves-release.d.ts.map +1 -1
  40. package/dist/op/op-waves-run.d.ts +8 -0
  41. package/dist/op/op-waves-run.d.ts.map +1 -1
  42. package/dist/op/op-waves-run.js +101 -29
  43. package/dist/op/op-waves.d.ts +18 -0
  44. package/dist/op/op-waves.d.ts.map +1 -1
  45. package/dist/op/op-waves.js +16 -0
  46. package/dist/pr-loop.d.ts.map +1 -1
  47. package/dist/pr-loop.js +1 -2
  48. package/dist/release-floors.d.ts +1 -1
  49. package/dist/release-floors.js +1 -1
  50. package/dist/wave-runtime.mjs +310 -300
  51. package/package.json +1 -1
  52. package/src/ci-audit/index.ts +1 -2
  53. package/src/ci-product.ts +4 -5
  54. package/src/cli/handlers/lifecycle.ts +13 -0
  55. package/src/cli/handlers/pr-before-merge.test.ts +1 -1
  56. package/src/cli/handlers/pr-deploy-inputs.test.ts +1 -1
  57. package/src/cli/handlers/pr-endpoint.test.ts +1 -1
  58. package/src/cli/handlers/pr-green.test.ts +1 -1
  59. package/src/cli/handlers/pr-plan-comment-targets.test.ts +1 -1
  60. package/src/cli/handlers/pr-plan-flags.test.ts +1 -1
  61. package/src/cli/handlers/pr-plan-targets.test.ts +1 -1
  62. package/src/cli/handlers/pr-record.test.ts +34 -2
  63. package/src/cli/handlers/pr-waves-blocked.test.ts +1 -1
  64. package/src/cli/handlers/pr-waves.test.ts +1 -1
  65. package/src/cli/handlers/pr.test.ts +1 -1
  66. package/src/cli/handlers/pr.ts +86 -31
  67. package/src/components/auto-release.test.ts +4 -2
  68. package/src/components/auto-release.ts +9 -5
  69. package/src/components/capability.ts +10 -0
  70. package/src/components/deploy-units.test.ts +18 -1
  71. package/src/components/deploy-units.ts +26 -1
  72. package/src/components/pr-pipeline.ts +12 -3
  73. package/src/components/row-lease.test.ts +61 -1
  74. package/src/components/row-lease.ts +48 -7
  75. package/src/e2e-harness/index.ts +1 -2
  76. package/src/lexicon.ts +9 -0
  77. package/src/lifecycle/git.test.ts +155 -0
  78. package/src/lifecycle/git.ts +213 -17
  79. package/src/lifecycle/lock-rows.test.ts +6 -1
  80. package/src/lifecycle/lock-rows.ts +58 -7
  81. package/src/lifecycle/resource-lock-wait.test.ts +292 -0
  82. package/src/lifecycle/resource-lock.ts +261 -7
  83. package/src/op/gate.test.ts +7 -5
  84. package/src/op/gate.ts +20 -4
  85. package/src/op/op-waves-after-plan.test.ts +1 -2
  86. package/src/op/op-waves-ledger-lock.test.ts +208 -0
  87. package/src/op/op-waves-release-port.ts +1 -1
  88. package/src/op/op-waves-release.ts +1 -1
  89. package/src/op/op-waves-run.ts +104 -29
  90. package/src/op/op-waves.ts +18 -0
  91. package/src/pr-loop-bundle.test.ts +0 -2
  92. package/src/pr-loop.ts +1 -2
  93. package/src/release-floors.ts +1 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@intentius/chant",
3
- "version": "0.124.56",
3
+ "version": "0.124.57",
4
4
  "description": "Declarative infrastructure-as-code toolkit — TypeScript on Node.js",
5
5
  "license": "Apache-2.0",
6
6
  "homepage": "https://intentius.io/chant",
@@ -5,10 +5,9 @@
5
5
  * on `CI_AUDIT_FLOOR`.
6
6
  */
7
7
 
8
- import { NEXT_RELEASE } from "../release-floors";
9
8
 
10
9
  /** The first chant with drift attribution and the unrecorded writer audit in core. */
11
- export const CI_AUDIT_FLOOR = NEXT_RELEASE;
10
+ export const CI_AUDIT_FLOOR = "0.124.56";
12
11
 
13
12
  export * from "./audit-log";
14
13
  export * from "./attribution";
package/src/ci-product.ts CHANGED
@@ -9,7 +9,6 @@
9
9
  * and `assertProductWords` present means the rest is too.
10
10
  */
11
11
 
12
- import { NEXT_RELEASE } from "./release-floors";
13
12
  import type { CiProductWords, CiProductWordsInput } from "./ci-product-words";
14
13
  import type { ProductMcpHook } from "./cli/mcp/product-tools";
15
14
  import type { ProductWaveHook } from "./op/op-waves-after-plan";
@@ -122,7 +121,7 @@ export { upsertPlanNote } from "./pr-post";
122
121
  * open pull request's head. A product feature-detects on
123
122
  * `APPROVAL_STATUS_FLOOR`.
124
123
  */
125
- export const APPROVAL_STATUS_FLOOR = NEXT_RELEASE;
124
+ export const APPROVAL_STATUS_FLOOR = "0.124.56";
126
125
  /**
127
126
  * The approval status for `pull-request` waves too (#4630, 2026-10-28
128
127
  * ruling): the generators add the record-plans and approval-status jobs for
@@ -131,7 +130,7 @@ export const APPROVAL_STATUS_FLOOR = NEXT_RELEASE;
131
130
  * as plywood, whose waves all take `approval: pull-request`, feature-detects
132
131
  * on this floor.
133
132
  */
134
- export const APPROVAL_STATUS_PULL_REQUEST_FLOOR = NEXT_RELEASE;
133
+ export const APPROVAL_STATUS_PULL_REQUEST_FLOOR = "0.124.56";
135
134
  export { opWavesPostsApprovalStatus } from "./op/op-waves";
136
135
  export { approvalStatusOf, headWaveHolds, postApprovalStatus, postOpenApprovalStatuses, type ApprovalStatus, type ApprovalStatusInput } from "./op/approval-status";
137
136
 
@@ -141,7 +140,7 @@ export { approvalStatusOf, headWaveHolds, postApprovalStatus, postOpenApprovalSt
141
140
  * words. `productPipelineJobs(forge, env, { words, respond, decide })` turns
142
141
  * them on and off; a product feature-detects on `CI_RESPOND_FLOOR`.
143
142
  */
144
- export const CI_RESPOND_FLOOR = NEXT_RELEASE;
143
+ export const CI_RESPOND_FLOOR = "0.124.56";
145
144
 
146
145
  /**
147
146
  * `chant build --pr-loop` carries `--merge auto --merge-token-env <VAR>
@@ -150,7 +149,7 @@ export const CI_RESPOND_FLOOR = NEXT_RELEASE;
150
149
  * the build parsed them and wrote jobs without them; a product that writes
151
150
  * its pull request jobs with the build feature-detects on this floor.
152
151
  */
153
- export const PR_LOOP_BUILD_FLAGS_FLOOR = NEXT_RELEASE;
152
+ export const PR_LOOP_BUILD_FLAGS_FLOOR = "0.124.56";
154
153
  export {
155
154
  CI_RESPOND_DEFAULTS,
156
155
  CI_RESPOND_ENV,
@@ -37,6 +37,7 @@ import {
37
37
  } from "../../observation";
38
38
  import { describeIdentities, identityStatusText, type IdentityRow } from "../../identity";
39
39
  import { discoverComponents } from "../../components/discover";
40
+ import { changedFilesBetween, lexiconChangedUnits } from "../../components/changed-files";
40
41
  import { cfnDeployStacks } from "./components";
41
42
  import { affectedStacks } from "../../lifecycle/affected";
42
43
  import { rollbackToRevision } from "../../lifecycle/rollback";
@@ -2131,6 +2132,18 @@ export async function runLifecycleAffected(ctx: CommandContext): Promise<number>
2131
2132
  headRef: args.head,
2132
2133
  includeDependents: args.includeDependents,
2133
2134
  });
2135
+ // Units that are not chant source, a Terraform root or a Pulumi stack, never
2136
+ // show in the artifact diff; the lexicon that owns each answers from the
2137
+ // changed paths (#3183), as `components pr-plan` and `fan-out --base` add them.
2138
+ if (plugins.some((p) => p.changedUnits)) {
2139
+ const root = resolve(".");
2140
+ const units = await lexiconChangedUnits(plugins, {
2141
+ projectRoot: root,
2142
+ config: config as Record<string, unknown>,
2143
+ changedFiles: await changedFilesBetween(root, args.base, args.head ?? "HEAD"),
2144
+ });
2145
+ if (units.length > 0) result = { ...result, changed: [...new Set([...result.changed, ...units])].sort() };
2146
+ }
2134
2147
  } catch (err) {
2135
2148
  console.error(formatError({ message: err instanceof Error ? err.message : String(err) }));
2136
2149
  return 1;
@@ -87,7 +87,7 @@ vi.mock("../../lifecycle/gate-change-set", () => ({
87
87
  }));
88
88
  vi.mock("../../lifecycle/git", async () => {
89
89
  const actual = await vi.importActual<typeof import("../../lifecycle/git")>("../../lifecycle/git");
90
- return { ...actual, pushLifecycleReport: async () => { throw new Error("pr.test must not push chant/lifecycle"); } };
90
+ return { ...actual, pushLifecycleReport: async () => { throw new Error("pr.test must not push chant/lifecycle"); }, pushLifecycleRebasing: async () => { throw new Error("pr.test must not push chant/lifecycle"); } };
91
91
  });
92
92
 
93
93
  vi.mock("./run", () => ({
@@ -38,7 +38,7 @@ vi.mock("../../lifecycle/gate-change-set", () => ({
38
38
  }));
39
39
  vi.mock("../../lifecycle/git", async () => {
40
40
  const actual = await vi.importActual<typeof import("../../lifecycle/git")>("../../lifecycle/git");
41
- return { ...actual, pushLifecycleReport: async () => { throw new Error("pr-deploy-inputs.test must not push chant/lifecycle"); } };
41
+ return { ...actual, pushLifecycleReport: async () => { throw new Error("pr-deploy-inputs.test must not push chant/lifecycle"); }, pushLifecycleRebasing: async () => { throw new Error("pr-deploy-inputs.test must not push chant/lifecycle"); } };
42
42
  });
43
43
 
44
44
  vi.mock("./run", () => ({
@@ -53,7 +53,7 @@ vi.mock("../../lifecycle/gate-change-set", () => ({
53
53
  }));
54
54
  vi.mock("../../lifecycle/git", async () => {
55
55
  const actual = await vi.importActual<typeof import("../../lifecycle/git")>("../../lifecycle/git");
56
- return { ...actual, pushLifecycleReport: async () => { throw new Error("pr-endpoint.test must not push chant/lifecycle"); } };
56
+ return { ...actual, pushLifecycleReport: async () => { throw new Error("pr-endpoint.test must not push chant/lifecycle"); }, pushLifecycleRebasing: async () => { throw new Error("pr-endpoint.test must not push chant/lifecycle"); } };
57
57
  });
58
58
 
59
59
  vi.mock("./run", () => ({
@@ -44,7 +44,7 @@ vi.mock("../../lifecycle/gate-change-set", () => ({
44
44
  }));
45
45
  vi.mock("../../lifecycle/git", async () => {
46
46
  const actual = await vi.importActual<typeof import("../../lifecycle/git")>("../../lifecycle/git");
47
- return { ...actual, pushLifecycleReport: async () => ({}) };
47
+ return { ...actual, pushLifecycleReport: async () => ({}), pushLifecycleRebasing: async () => ({}) };
48
48
  });
49
49
  const applied: GreenApplyRecord[] = [];
50
50
  vi.mock("../../lifecycle/green-apply", async () => {
@@ -44,7 +44,7 @@ vi.mock("./fan-out", () => ({
44
44
  }));
45
45
  vi.mock("../../lifecycle/git", async () => {
46
46
  const actual = await vi.importActual<typeof import("../../lifecycle/git")>("../../lifecycle/git");
47
- return { ...actual, pushLifecycleReport: async () => { throw new Error("pr-plan-comment-targets.test must not push chant/lifecycle"); } };
47
+ return { ...actual, pushLifecycleReport: async () => { throw new Error("pr-plan-comment-targets.test must not push chant/lifecycle"); }, pushLifecycleRebasing: async () => { throw new Error("pr-plan-comment-targets.test must not push chant/lifecycle"); } };
48
48
  });
49
49
  vi.mock("./run", () => ({
50
50
  GATED_EXIT_CODE: 3,
@@ -45,7 +45,7 @@ vi.mock("./fan-out", () => ({
45
45
  }));
46
46
  vi.mock("../../lifecycle/git", async () => {
47
47
  const actual = await vi.importActual<typeof import("../../lifecycle/git")>("../../lifecycle/git");
48
- return { ...actual, pushLifecycleReport: async () => { throw new Error("pr-plan-flags.test must not push chant/lifecycle"); } };
48
+ return { ...actual, pushLifecycleReport: async () => { throw new Error("pr-plan-flags.test must not push chant/lifecycle"); }, pushLifecycleRebasing: async () => { throw new Error("pr-plan-flags.test must not push chant/lifecycle"); } };
49
49
  });
50
50
  vi.mock("./run", () => ({
51
51
  GATED_EXIT_CODE: 3,
@@ -44,7 +44,7 @@ vi.mock("./fan-out", () => ({
44
44
  }));
45
45
  vi.mock("../../lifecycle/git", async () => {
46
46
  const actual = await vi.importActual<typeof import("../../lifecycle/git")>("../../lifecycle/git");
47
- return { ...actual, pushLifecycleReport: async () => { throw new Error("pr-plan-targets.test must not push chant/lifecycle"); } };
47
+ return { ...actual, pushLifecycleReport: async () => { throw new Error("pr-plan-targets.test must not push chant/lifecycle"); }, pushLifecycleRebasing: async () => { throw new Error("pr-plan-targets.test must not push chant/lifecycle"); } };
48
48
  });
49
49
  vi.mock("./run", () => ({
50
50
  GATED_EXIT_CODE: 3,
@@ -44,14 +44,20 @@ vi.mock("../../lifecycle/gate-change-set", () => ({
44
44
  }));
45
45
  vi.mock("../../lifecycle/git", async () => {
46
46
  const actual = await vi.importActual<typeof import("../../lifecycle/git")>("../../lifecycle/git");
47
- return { ...actual, pushLifecycleReport: async () => { throw new Error("pr.test must not push chant/lifecycle"); } };
47
+ return { ...actual, pushLifecycleReport: async () => { throw new Error("pr.test must not push chant/lifecycle"); }, pushLifecycleRebasing: async () => pushRebasing() };
48
48
  });
49
+ // The record's push: never the real one. A test that writes the record sets what it answers.
50
+ let pushRebasing: () => Promise<{ pushed: boolean; pushWarning?: string }> = async () => {
51
+ throw new Error("pr.test must not push chant/lifecycle");
52
+ };
49
53
 
50
54
  // #4168: the record job writes the merge record on chant/lifecycle. Captured here, never written.
55
+ // `recordWrites` makes the write say it wrote, so the record job pushes.
51
56
  const written: Array<Record<string, unknown>> = [];
57
+ let recordWrites = false;
52
58
  vi.mock("../../lifecycle/merge-record", async () => {
53
59
  const actual = await vi.importActual<typeof import("../../lifecycle/merge-record")>("../../lifecycle/merge-record");
54
- return { ...actual, writeMergeRecord: async (r: Record<string, unknown>) => (written.push(r), { commit: null, written: false }) };
60
+ return { ...actual, writeMergeRecord: async (r: Record<string, unknown>) => (written.push(r), recordWrites ? { commit: "c".repeat(40), written: true } : { commit: null, written: false }) };
55
61
  });
56
62
 
57
63
  vi.mock("./run", () => ({
@@ -131,6 +137,10 @@ beforeEach(async () => {
131
137
  errors = [];
132
138
  applied = [];
133
139
  written.length = 0;
140
+ recordWrites = false;
141
+ pushRebasing = async () => {
142
+ throw new Error("pr.test must not push chant/lifecycle");
143
+ };
134
144
  failing.clear();
135
145
  refusal.clear();
136
146
  onRun = (r) => applied.push(r);
@@ -191,6 +201,28 @@ describe("pr-record (#4168)", () => {
191
201
  expect(written[0]).toMatchObject({ source: { kind: "direct-push" }, op: null, plan: "unapproved" });
192
202
  });
193
203
 
204
+ // #4551: the merge record goes out through the fetch-replay-retry push, and one that never reaches the remote fails the job.
205
+ test("a merge record pushed through the retrying push exits 0", async () => {
206
+ recordWrites = true;
207
+ let pushes = 0;
208
+ pushRebasing = async () => (pushes++, { pushed: true });
209
+ expect(await runComponentsPrRecord(ctx({ pr: 12 }))).toBe(0);
210
+ expect(pushes).toBe(1);
211
+ });
212
+
213
+ test("a merge record the remote never takes fails the job with LifecyclePushLostError's words, and the report is still written", async () => {
214
+ const { LifecyclePushLostError } = await vi.importActual<typeof import("../../lifecycle/git")>("../../lifecycle/git");
215
+ recordWrites = true;
216
+ pushRebasing = async () => {
217
+ throw new LifecyclePushLostError("origin", 3, "another writer pushed before each try");
218
+ };
219
+ expect(await runComponentsPrRecord(ctx({ pr: 12 }))).toBe(1);
220
+ expect(report("record")).toMatchObject({ status: "recorded", pr: 12 });
221
+ const said = errors.join("\n");
222
+ expect(said).toContain(`the merge record for ${HEAD} was written but not pushed`);
223
+ expect(said).toContain('chant/lifecycle was not pushed to "origin" after 3 tries');
224
+ });
225
+
194
226
  test("a member that fails to plan is recorded as plan-failed and exits 1", async () => {
195
227
  const plan = vi.spyOn(await import("../../components/pr-run"), "planPrSet");
196
228
  plan.mockImplementationOnce(async (input) => ({ ...(await (await vi.importActual<typeof import("../../components/pr-run")>("../../components/pr-run")).planPrSet(input)), failed: true }));
@@ -50,7 +50,7 @@ vi.mock("../../lifecycle/gate-change-set", () => ({
50
50
  }));
51
51
  vi.mock("../../lifecycle/git", async () => {
52
52
  const actual = await vi.importActual<typeof import("../../lifecycle/git")>("../../lifecycle/git");
53
- return { ...actual, pushLifecycleReport: async () => { throw new Error("pr-waves.test must not push chant/lifecycle"); } };
53
+ return { ...actual, pushLifecycleReport: async () => { throw new Error("pr-waves.test must not push chant/lifecycle"); }, pushLifecycleRebasing: async () => { throw new Error("pr-waves.test must not push chant/lifecycle"); } };
54
54
  });
55
55
 
56
56
  // The declaration at base sets no hooks, policy, security group or lock, and the change adds no migration (#4502).
@@ -45,7 +45,7 @@ vi.mock("../../lifecycle/gate-change-set", () => ({
45
45
  }));
46
46
  vi.mock("../../lifecycle/git", async () => {
47
47
  const actual = await vi.importActual<typeof import("../../lifecycle/git")>("../../lifecycle/git");
48
- return { ...actual, pushLifecycleReport: async () => { throw new Error("pr-waves.test must not push chant/lifecycle"); } };
48
+ return { ...actual, pushLifecycleReport: async () => { throw new Error("pr-waves.test must not push chant/lifecycle"); }, pushLifecycleRebasing: async () => { throw new Error("pr-waves.test must not push chant/lifecycle"); } };
49
49
  });
50
50
 
51
51
  vi.mock("./run", () => ({
@@ -78,7 +78,7 @@ vi.mock("../../lifecycle/gate-change-set", () => ({
78
78
  }));
79
79
  vi.mock("../../lifecycle/git", async () => {
80
80
  const actual = await vi.importActual<typeof import("../../lifecycle/git")>("../../lifecycle/git");
81
- return { ...actual, pushLifecycleReport: async () => { throw new Error("pr.test must not push chant/lifecycle"); } };
81
+ return { ...actual, pushLifecycleReport: async () => { throw new Error("pr.test must not push chant/lifecycle"); }, pushLifecycleRebasing: async () => { throw new Error("pr.test must not push chant/lifecycle"); } };
82
82
  });
83
83
 
84
84
  vi.mock("./run", () => ({
@@ -66,7 +66,7 @@
66
66
 
67
67
  import { spawnSync } from "node:child_process";
68
68
  import { CHANT_EXIT } from "../../exit-codes";
69
- import { anyResourceGrain, leaseRowsOf as leaseRowsOfLocks, lockTargetsOf, type LockGrain } from "../../lifecycle/lock-rows";
69
+ import { anyResourceGrain, leaseRowsOf as leaseRowsOfLocks, lockTargetsOf, queueRowsOfLocks, type LockGrain } from "../../lifecycle/lock-rows";
70
70
  import { existsSync, mkdirSync, readFileSync, realpathSync, writeFileSync } from "node:fs";
71
71
  import { dirname, join, relative, resolve, sep } from "node:path";
72
72
  import { loadChantConfig, resolveAutoReleaseDisabled, type ChantConfig } from "../../config";
@@ -617,18 +617,42 @@ async function leaseSetRows(p: Prepared, set: Pick<PrPlanSet, "locks">): Promise
617
617
  */
618
618
  export async function leaseRowsOf(p: Pick<Prepared, "gate">, set: Pick<PrPlanSet, "locks">, label = "this apply"): Promise<{ release(): Promise<boolean> } | { held: string } | { failed: string }> {
619
619
  const rows = leaseRowsOfLocks(set.locks);
620
- if (rows.length === 0) return { release: () => Promise.resolve(true) };
621
- const { leaseLockRows } = await import("../../lifecycle/resource-lock");
622
- let leased;
623
- try {
624
- leased = await leaseLockRows(p.gate, rows);
625
- } catch (err) {
626
- return { failed: `could not hold the rows ${label} changes in ${p.gate}, so nothing of it was applied: ${err instanceof Error ? err.message : String(err)}` };
620
+ // The ruling for ci-products (2026-10-28): the target and repo grains wait for their rows first, oldest commit first.
621
+ const queue = queueRowsOfLocks(set.locks);
622
+ if (rows.length === 0 && queue.length === 0) return { release: () => Promise.resolve(true) };
623
+ const { commitTimeOf, leaseLockRows, lockPollMs, lockWaitSeconds } = await import("../../lifecycle/resource-lock");
624
+ const held: Array<{ release(): Promise<boolean> }> = [];
625
+ const releaseAll = async () => {
626
+ let ok = true;
627
+ for (const l of held.reverse()) ok = (await l.release()) && ok;
628
+ return ok;
629
+ };
630
+ for (const [wanted, wait] of [[queue, true], [rows, false]] as const) {
631
+ if (wanted.length === 0) continue;
632
+ let leased;
633
+ try {
634
+ const commitAt = wait ? await commitTimeOf(process.env.GITHUB_SHA || process.env.CI_COMMIT_SHA || "HEAD") : undefined;
635
+ leased = await leaseLockRows(
636
+ p.gate,
637
+ wanted,
638
+ wait
639
+ ? { wait: { deadline: Date.now() + lockWaitSeconds(process.env) * 1000, pollMs: lockPollMs(process.env), log: (line) => console.error(formatInfo(`${label} ${line}`)), ...(commitAt ? { commitAt } : {}) } }
640
+ : {},
641
+ );
642
+ } catch (err) {
643
+ await releaseAll();
644
+ return { failed: `could not hold the rows ${label} changes in ${p.gate}, so nothing of it was applied: ${err instanceof Error ? err.message : String(err)}` };
645
+ }
646
+ if (!leased.ok) {
647
+ await releaseAll();
648
+ if (leased.timedOut) return { held: `LockWaitTimeoutError: ${leased.message}, so nothing of ${label} was applied.` };
649
+ return { held: `${leased.message}, so nothing of ${label} was applied. Apply again once that run ends; a run that is gone, or whose lease is older than CHANT_LOCK_STALE seconds, is taken over.` };
650
+ }
651
+ for (const h of leased.tookOver) console.error(formatInfo(`took over the rows of run ${h.run}, which is gone`));
652
+ console.error(formatInfo(`${label} holds ${leased.lease.keys.length} row${leased.lease.keys.length === 1 ? "" : "s"} of ${p.gate}${leased.waited ? ` after waiting ${leased.waitedSeconds ?? 0}s` : ""} while it applies`));
653
+ held.push(leased.lease);
627
654
  }
628
- if (!leased.ok) return { held: `${leased.message}, so nothing of ${label} was applied. Apply again once that run ends; a run that is gone, or whose lease is older than CHANT_LOCK_STALE seconds, is taken over.` };
629
- for (const h of leased.tookOver) console.error(formatInfo(`took over the rows of run ${h.run}, which is gone`));
630
- console.error(formatInfo(`${label} holds ${leased.lease.keys.length} row${leased.lease.keys.length === 1 ? "" : "s"} of ${p.gate} while it applies`));
631
- return leased.lease;
655
+ return { release: releaseAll };
632
656
  }
633
657
 
634
658
  /** `applyPrSet`'s `leaseRound` (#4594): a round after the first leases the rows its own plan locks. */
@@ -1333,8 +1357,8 @@ async function prApply(ctx: CommandContext, stage: StageEvents, beforeMerge?: Pr
1333
1357
  : applied.leaseFailed
1334
1358
  ? 1
1335
1359
  : failedRunExitCode(applied.run.results);
1336
- if (green && applied.status === "applied") await recordGreenApplied(p, green, set.doc.digest, approval, via);
1337
- const code = await stop(report, exit, applied.run.status === "gated" ? "gated" : undefined);
1360
+ const lost = green && applied.status === "applied" ? await recordGreenApplied(p, green, set.doc.digest, approval, via) : false;
1361
+ const code = await stop(report, lost && exit === 0 ? 1 : exit, applied.run.status === "gated" ? "gated" : undefined);
1338
1362
  if (applied.status === "applied" && !afterFailed) console.error(formatSuccess(`applied the plan ${report.digest} approved by ${(approval.approvedBy ?? []).join(", ")}`));
1339
1363
  // #4636: an update before merge that applied every member merges the pull request, never the other way round.
1340
1364
  if (code === 0 && beforeMerge && pr !== null && args.merge === "auto" && applied.status === "applied" && !afterFailed) return mergeAfterUpdate(ctx, p, pr);
@@ -1364,7 +1388,7 @@ async function mergeArgsProblem(args: CommandContext["args"]): Promise<string |
1364
1388
  */
1365
1389
  async function mergeAfterUpdate(ctx: CommandContext, p: Prepared, pr: number): Promise<number> {
1366
1390
  const { mergeAfterApply, mergeTokenEnv } = await import("../../pr-merge");
1367
- const { pushLifecycleReport } = await import("../../lifecycle/git");
1391
+ const { pushLifecycleRebasing, LifecyclePushLostError } = await import("../../lifecycle/git");
1368
1392
  const kind = p.forge?.kind ?? (ctx.args.forge as ForgeKind | undefined);
1369
1393
  if (!kind) return fail("--merge auto needs --forge <kind> to merge on");
1370
1394
  const env = mergeTokenEnv(ctx.args.mergeTokenEnv!);
@@ -1379,7 +1403,17 @@ async function mergeAfterUpdate(ctx: CommandContext, p: Prepared, pr: number): P
1379
1403
  console.error(formatWarning({ message: `the pull request was not merged: ${err instanceof Error ? err.message : String(err)}` }));
1380
1404
  return CHANT_EXIT.waiting;
1381
1405
  }
1382
- const pushed = await pushLifecycleReport();
1406
+ // A refused push fetches, replays the apply's records on the remote's tip and pushes again (#4551).
1407
+ let pushed: { pushed: boolean; pushWarning?: string };
1408
+ let lost = false;
1409
+ try {
1410
+ pushed = await pushLifecycleRebasing();
1411
+ } catch (err) {
1412
+ if (!(err instanceof LifecyclePushLostError)) throw err;
1413
+ console.error(formatError({ message: err.message }));
1414
+ pushed = { pushed: false, pushWarning: err.message };
1415
+ lost = true;
1416
+ }
1383
1417
  const merged = await mergeAfterApply({
1384
1418
  forge,
1385
1419
  pr,
@@ -1392,7 +1426,7 @@ async function mergeAfterUpdate(ctx: CommandContext, p: Prepared, pr: number): P
1392
1426
  return 0;
1393
1427
  }
1394
1428
  console.error(formatWarning({ message: `the pull request was not merged: ${merged.reason}${merged.posted ? "; the reason is posted on it" : ""}` }));
1395
- return CHANT_EXIT.waiting;
1429
+ return lost ? 1 : CHANT_EXIT.waiting;
1396
1430
  }
1397
1431
 
1398
1432
  /**
@@ -1601,7 +1635,10 @@ async function prRecord(ctx: CommandContext, stage: StageEvents): Promise<number
1601
1635
  });
1602
1636
 
1603
1637
  const { mergeSourceOf, writeMergeRecord, MERGE_RECORD_SCHEMA_ID, MERGE_RECORD_CONTRACT } = await import("../../lifecycle/merge-record");
1604
- const { pushLifecycleReport } = await import("../../lifecycle/git");
1638
+ const { pushLifecycleRebasing, LifecyclePushLostError } = await import("../../lifecycle/git");
1639
+ // Set when the merge record never reached the remote: the job fails rather than warns, since a record kept only
1640
+ // in this job's checkout is lost with it (#4551).
1641
+ let lost = false;
1605
1642
  // #4292: a member another branch applies has no merge on this one, so no record says it planned nothing here.
1606
1643
  if (!p.routedAway) {
1607
1644
  try {
@@ -1624,16 +1661,21 @@ async function prRecord(ctx: CommandContext, stage: StageEvents): Promise<number
1624
1661
  recordedAt: new Date().toISOString(),
1625
1662
  });
1626
1663
  if (written.written) {
1627
- const pushed = await pushLifecycleReport();
1664
+ const pushed = await pushLifecycleRebasing();
1628
1665
  if (pushed.pushWarning) console.error(formatWarning({ message: pushed.pushWarning }));
1629
1666
  }
1630
1667
  } catch (err) {
1631
- console.error(formatWarning({ message: `could not write the merge record for ${p.head}: ${err instanceof Error ? err.message : String(err)}` }));
1668
+ if (err instanceof LifecyclePushLostError) {
1669
+ console.error(formatError({ message: `the merge record for ${p.head} was written but not pushed: ${err.message}` }));
1670
+ lost = true;
1671
+ } else {
1672
+ console.error(formatWarning({ message: `could not write the merge record for ${p.head}: ${err instanceof Error ? err.message : String(err)}` }));
1673
+ }
1632
1674
  }
1633
1675
  }
1634
1676
 
1635
1677
  const stop = stopper(ctx, p, events, upload);
1636
- return stop(report, status === "plan-failed" ? 1 : 0);
1678
+ return stop(report, status === "plan-failed" || lost ? 1 : 0);
1637
1679
  }
1638
1680
 
1639
1681
  /** What a gate's description and messages call the change: the pull request, or the green commit (#4168 step 9). */
@@ -1730,10 +1772,15 @@ function reviewFor(args: CommandContext["args"], p: Prepared, pr: number | null,
1730
1772
  };
1731
1773
  }
1732
1774
 
1733
- /** Record the green commit as applied to the environment (#4168 step 9), and push `chant/lifecycle`. A failure warns. */
1734
- async function recordGreenApplied(p: Prepared, green: GreenTarget, digest: string, approval: PrApproval, via: "merges" | "gate"): Promise<void> {
1775
+ /**
1776
+ * Record the green commit as applied to the environment (#4168 step 9), and
1777
+ * push `chant/lifecycle`, fetching and replaying on a refused push. A record
1778
+ * that never reaches the remote is an error and returns true, so the stage
1779
+ * fails; any other failure warns.
1780
+ */
1781
+ async function recordGreenApplied(p: Prepared, green: GreenTarget, digest: string, approval: PrApproval, via: "merges" | "gate"): Promise<boolean> {
1735
1782
  const { writeGreenApply, GREEN_APPLY_CONTRACT } = await import("../../lifecycle/green-apply");
1736
- const { pushLifecycleReport } = await import("../../lifecycle/git");
1783
+ const { pushLifecycleRebasing, LifecyclePushLostError } = await import("../../lifecycle/git");
1737
1784
  try {
1738
1785
  await writeGreenApply({
1739
1786
  contract: GREEN_APPLY_CONTRACT,
@@ -1747,11 +1794,16 @@ async function recordGreenApplied(p: Prepared, green: GreenTarget, digest: strin
1747
1794
  merges: green.merges,
1748
1795
  appliedAt: new Date().toISOString(),
1749
1796
  });
1750
- const pushed = await pushLifecycleReport();
1797
+ const pushed = await pushLifecycleRebasing();
1751
1798
  if (pushed.pushWarning) console.error(formatWarning({ message: pushed.pushWarning }));
1752
1799
  } catch (err) {
1800
+ if (err instanceof LifecyclePushLostError) {
1801
+ console.error(formatError({ message: `the record of ${green.commit.slice(0, 12)} as applied to ${p.env} was written but not pushed: ${err.message}` }));
1802
+ return true;
1803
+ }
1753
1804
  console.error(formatWarning({ message: `could not record ${green.commit.slice(0, 12)} as applied to ${p.env}: ${err instanceof Error ? err.message : String(err)}` }));
1754
1805
  }
1806
+ return false;
1755
1807
  }
1756
1808
 
1757
1809
  /** How a stage stops: settle its events, write and publish the report, say how it ended, and return `code`. */
@@ -1903,12 +1955,14 @@ function emitReviewStop(events: RunEventStream | undefined, message: string): vo
1903
1955
 
1904
1956
  /**
1905
1957
  * Store `doc` under its digest with its entries mapped onto the member's
1906
- * graph (`storeGateChangeSet`), and push. A failure is a warning: the gate
1907
- * decides the same either way.
1958
+ * graph (`storeGateChangeSet`), and push, fetching and replaying on a refused
1959
+ * push. A failure to store is a warning: the gate decides the same either
1960
+ * way. A change set that never reaches the remote throws
1961
+ * `LifecyclePushLostError`, which stops the stage.
1908
1962
  */
1909
1963
  async function storeChangeSetForGate(ctx: CommandContext, p: Prepared, doc: PrPlanSet["doc"]): Promise<void> {
1910
1964
  const { storeGateChangeSet, gateGraphReader } = await import("../../lifecycle/gate-change-set");
1911
- const { pushLifecycleReport } = await import("../../lifecycle/git");
1965
+ const { pushLifecycleRebasing, LifecyclePushLostError } = await import("../../lifecycle/git");
1912
1966
  const graphArgs = [
1913
1967
  ...(ctx.args.param ?? []).flatMap((kv) => ["--param", kv]),
1914
1968
  ...(ctx.args.paramsFile ? ["--params-file", ctx.args.paramsFile] : []),
@@ -1918,8 +1972,9 @@ async function storeChangeSetForGate(ctx: CommandContext, p: Prepared, doc: PrPl
1918
1972
  if (stored.warning) console.error(formatWarning({ message: stored.warning }));
1919
1973
  // The push's own outcome is said by the gate's pending fact, or by the
1920
1974
  // release records the apply writes, which push the same branch.
1921
- if (stored.written) await pushLifecycleReport();
1975
+ if (stored.written) await pushLifecycleRebasing();
1922
1976
  } catch (err) {
1977
+ if (err instanceof LifecyclePushLostError) throw err;
1923
1978
  console.error(formatWarning({ message: `could not store the change set ${doc.digest}: ${err instanceof Error ? err.message : String(err)}` }));
1924
1979
  }
1925
1980
  }
@@ -2339,8 +2394,8 @@ async function prApplyWaves(
2339
2394
  }
2340
2395
 
2341
2396
  const done = p.plan.order.every((name) => completed.has(name));
2342
- if (green && done) await recordGreenApplied(p, green, approvedSet.doc.digest, approval, via);
2343
- return stop(report({ status: done ? "applied" : "wave-applied" }), 0);
2397
+ const lost = green && done ? await recordGreenApplied(p, green, approvedSet.doc.digest, approval, via) : false;
2398
+ return stop(report({ status: done ? "applied" : "wave-applied" }), lost ? 1 : 0);
2344
2399
  }
2345
2400
 
2346
2401
  // ── The component plan-wave and apply-wave steps (#4588) ─────────────────────
@@ -7,8 +7,10 @@ const appendReleaseRecordMock = vi.fn();
7
7
 
8
8
  vi.mock("../lifecycle/git", () => ({
9
9
  getHeadCommit: (...args: unknown[]) => getHeadCommitMock(...args),
10
- pushLifecycle: (...args: unknown[]) => pushLifecycleMock(...args),
10
+ // plywood#22 finding 9: the release record pushes with fetch, replay and retry.
11
+ pushLifecycleRebasing: (...args: unknown[]) => pushLifecycleMock(...args),
11
12
  StaleLifecycleBranchError: class StaleLifecycleBranchError extends Error {},
13
+ LifecyclePushLostError: class LifecyclePushLostError extends Error {},
12
14
  }));
13
15
 
14
16
  vi.mock("../lifecycle/release-ledger", async () => {
@@ -66,7 +68,7 @@ describe("extractRunDigest", () => {
66
68
  describe("maybeRecordAutoRelease", () => {
67
69
  beforeEach(() => {
68
70
  getHeadCommitMock.mockReset().mockResolvedValue("abc123headsha");
69
- pushLifecycleMock.mockReset().mockResolvedValue(true);
71
+ pushLifecycleMock.mockReset().mockResolvedValue({ pushed: true });
70
72
  appendReleaseRecordMock.mockReset();
71
73
  delete process.env.GITHUB_ACTOR;
72
74
  delete process.env.GITLAB_USER_LOGIN;
@@ -25,7 +25,7 @@
25
25
  * (`--git-sha` defaults to HEAD, `--run-id`/`--actor` fall back to common CI
26
26
  * env vars, timestamp is a real `new Date()` taken at record time).
27
27
  */
28
- import { getHeadCommit, pushLifecycle, StaleLifecycleBranchError } from "../lifecycle/git";
28
+ import { getHeadCommit, LifecyclePushLostError, pushLifecycleRebasing, StaleLifecycleBranchError } from "../lifecycle/git";
29
29
  import { appendReleaseRecord, InvalidReleaseRecordError, type ReleaseAdmission, type ReleaseDigestKind, type ReleaseRecord, type RunOrigin } from "../lifecycle/release-ledger";
30
30
  import { changeSetDigest } from "../change-set";
31
31
  import type { DriverComponent, DriverStepRecord } from "./driver";
@@ -106,7 +106,7 @@ export type AutoReleaseSkipReason =
106
106
  export type AutoReleaseResult =
107
107
  | { recorded: true; commit: string; record: ReleaseRecord }
108
108
  | { recorded: false; reason: AutoReleaseSkipReason; detail?: string }
109
- | { recorded: false; reason: "error"; error: string };
109
+ | { recorded: false; reason: "error"; error: string; lost?: true };
110
110
 
111
111
  /** Input describing one component's completed run. */
112
112
  export interface AutoReleaseRunInfo {
@@ -189,8 +189,10 @@ function resolveActor(override?: string): string | undefined {
189
189
  * requirement; an unattributed record defeats the ledger's purpose.
190
190
  *
191
191
  * Git-sha resolution failure and ledger-write failures
192
- * (`InvalidReleaseRecordError`, `StaleLifecycleBranchError`, or any other
193
- * error `appendReleaseRecord`/`pushLifecycle` throw) are reported as `{
192
+ * (`InvalidReleaseRecordError`, `StaleLifecycleBranchError`,
193
+ * `LifecyclePushLostError` when the push never landed after its replays, or
194
+ * any other error `appendReleaseRecord`/`pushLifecycleRebasing` throw) are
195
+ * reported as `{
194
196
  * recorded: false, reason: "error", error }` rather than propagated — an
195
197
  * auto-recorded ledger write is a best-effort observability side effect of a
196
198
  * successful deploy; it must never turn a successful `chant run --components`
@@ -250,9 +252,11 @@ export async function maybeRecordAutoRelease(
250
252
  },
251
253
  { cwd: options.cwd },
252
254
  );
253
- await pushLifecycle({ cwd: options.cwd });
255
+ // plywood#22 finding 9: another writer's push replays this record on its tip and pushes again, in place of a stale refusal.
256
+ await pushLifecycleRebasing({ cwd: options.cwd });
254
257
  return { recorded: true, commit, record };
255
258
  } catch (err) {
259
+ if (err instanceof LifecyclePushLostError) return { recorded: false, reason: "error", error: err.message, lost: true };
256
260
  if (err instanceof InvalidReleaseRecordError || err instanceof StaleLifecycleBranchError) {
257
261
  return { recorded: false, reason: "error", error: err.message };
258
262
  }
@@ -268,6 +268,16 @@ export interface Capability<In = unknown, Out = unknown> {
268
268
  * ../lifecycle/lock-rows.ts). Absent: the resource grain is refused.
269
269
  */
270
270
  lockRows?(input: In, plan: CapabilityPlan): LockRow[] | Promise<LockRow[]>;
271
+ /**
272
+ * Optional (ruling for ci-products 2026-10-28, "Ledger lock"): the row of
273
+ * the whole target an apply on the `target` grain waits for on the
274
+ * ledger, oldest commit first, up to the job's timeout, in place of
275
+ * failing on the engine's own lock. The pulumi lexicon answers
276
+ * `stack <project>/<stack>` for stock Pulumi, the terraform lexicon
277
+ * `root <root>` for Terraform, tofu and Terragrunt. `plan`, when given, is
278
+ * the member's plan. Absent or undefined: the apply takes no row.
279
+ */
280
+ targetLockRow?(input: In, plan?: CapabilityPlan): LockRow | undefined | Promise<LockRow | undefined>;
271
281
  /**
272
282
  * Optional: the outputs `run` exposed when it last ran, read without
273
283
  * changing anything (#3183). A pull request's plan reads them for each
@@ -1,5 +1,5 @@
1
1
  import { describe, test, expect } from "vitest";
2
- import { deployUnits } from "./deploy-units";
2
+ import { deployUnits, pulumiStackUnit } from "./deploy-units";
3
3
  import type { Phase } from "./component";
4
4
 
5
5
  const phase = (name: string, steps: Phase["steps"]): Phase => ({ phase: name, steps });
@@ -48,6 +48,23 @@ describe("deployUnits (#1495 piece 1)", () => {
48
48
  expect(deployUnits(deploy)).toEqual([{ unit: "web", lexicon: "aws" }]);
49
49
  });
50
50
 
51
+ test("a pulumi-up step's unit is its stack qualified by the project's directory (plywood#22)", () => {
52
+ const deploy = [
53
+ phase("up", [
54
+ { kind: "pulumi-up", dir: ".", stack: "dev", member: "shop" },
55
+ { kind: "pulumi-up", dir: "./infra/", stack: "dev", member: "infra" },
56
+ { kind: "pulumi-up", dir: "infra", stack: "dev", member: "infra" },
57
+ { kind: "pulumi-up", dir: "infra" },
58
+ ]),
59
+ ];
60
+ expect(deployUnits(deploy)).toEqual([
61
+ { unit: "dev", lexicon: "pulumi" },
62
+ { unit: "infra/dev", lexicon: "pulumi" },
63
+ ]);
64
+ // The pulumi lexicon's changedUnits names stacks with the same strings.
65
+ expect([pulumiStackUnit(".", "prod-us"), pulumiStackUnit("", "prod-us"), pulumiStackUnit("apps/web", "qa")]).toEqual(["prod-us", "prod-us", "apps/web/qa"]);
66
+ });
67
+
51
68
  test("an unlisted kind contributes no unit — the registry is the rule", () => {
52
69
  const deploy = [phase("Apply", [{ kind: "gcloud-deploy", stack: "x" }])];
53
70
  expect(deployUnits(deploy)).toEqual([]);