@intentius/chant-lexicon-pulumi 0.124.87 → 0.124.89

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/stack-ops.js CHANGED
@@ -91,7 +91,7 @@ import { isAbsolute, join, resolve } from "node:path";
91
91
  import { chantGatedLedger, gatedOp } from "@intentius/chant/lifecycle/gated-op";
92
92
  import { exportStateVersion, StateExportError } from "@intentius/chant/state-export";
93
93
  import { runStateMigration } from "@intentius/chant/state-migration";
94
- import { describeRun, forgeLiveRuns, releaseStateLock } from "@intentius/chant/state-unlock";
94
+ import { describeRun, forgeLiveRunsOf, releaseStateLock } from "@intentius/chant/state-unlock";
95
95
  import { parsePulumiUrn, pulumiNodeKey } from "@intentius/chant/pulumi-urn";
96
96
  import { pulumiStackBackend } from "./adopt.js";
97
97
  import { pulumiExportResources, pulumiPreviewDigest, pulumiSteps, PULUMI_UNCHANGED_OPS } from "./change-set.js";
@@ -100,6 +100,25 @@ import { defaultPlungeRunner, defaultPulumiRunner, plungeMoveArgs, previewPulumi
100
100
  import { isObject } from "./values.js";
101
101
  /** The op the requests are recorded under, unless the caller names its own. */
102
102
  export const PULUMI_STACK_OPS_OP = "pulumi-stack-ops";
103
+ /** The approve line `common` asks for (#4911), as core's adapters take `words.approveCommand`; undefined for core's own. */
104
+ export function stackOpApproveCommand(common) {
105
+ const given = common.approveCommand;
106
+ if (given === undefined)
107
+ return undefined;
108
+ if (typeof given === "function")
109
+ return given;
110
+ const op = common.op ?? PULUMI_STACK_OPS_OP;
111
+ const sign = common.rules.mode === "sealed" ? "--sign" : "";
112
+ return (gate, digest) => given
113
+ .replace(/\{(op|gate|digest|sign)\}/g, (_, k) => ({ op, gate, digest, sign })[k])
114
+ .replace(/\s+/g, " ")
115
+ .trim();
116
+ }
117
+ /** The words core's walks take: the op, the kind, and the product's approve line when it gives one. */
118
+ function wordsOf(common, kind) {
119
+ const approveCommand = stackOpApproveCommand(common);
120
+ return { op: common.op ?? PULUMI_STACK_OPS_OP, kind, ...(approveCommand ? { approveCommand } : {}) };
121
+ }
103
122
  /** An operation core's checks refused before it acted: `code` says which, `runs` names the live runs. */
104
123
  export class PulumiStackOpRefused extends Error {
105
124
  constructor(code, message, extra = {}) {
@@ -258,7 +277,7 @@ export async function gatedStackExport(opts) {
258
277
  source,
259
278
  out,
260
279
  ...(opts.version ? { version: opts.version } : {}),
261
- words: { op: opts.op ?? PULUMI_STACK_OPS_OP, kind: "stack-export" },
280
+ words: wordsOf(opts, "stack-export"),
262
281
  env,
263
282
  ...gatedSettings(opts),
264
283
  });
@@ -360,13 +379,31 @@ export async function pulumiStackLockIds(opts) {
360
379
  return { checked: false, ...(at.backend ? { backend: at.backend } : {}), ids: [] };
361
380
  return { checked: true, ...(at.backend ? { backend: at.backend } : {}), ids: diyStackLockIds(at.root, at.project, opts.stack) };
362
381
  }
363
- /** The runs of the forge `forge` names over `env`, as core reads them (#4808). */
364
- function forgeRuns(env, forge) {
365
- return async () => {
366
- const { forgeTargetWith } = await import("@intentius/chant/forge-flags");
367
- const t = forgeTargetWith(env, forge ?? {});
368
- return forgeLiveRuns({ kind: t.kind, apiBase: t.apiBase, repo: t.repo, token: t.token, ...(t.tokenHeader ? { tokenHeader: t.tokenHeader } : {}) });
369
- };
382
+ /**
383
+ * The lock id a cancel asks to release (#4911): `given` when the caller
384
+ * names one, else the one lock {@link pulumiStackLockIds} finds on the
385
+ * stack's `file://` backend. No lock, two locks, a backend chant cannot
386
+ * list, or a read that failed answers a `refusal` with chant's message; a
387
+ * product words it from the code, the `backend` and the `ids`.
388
+ */
389
+ export async function pulumiStackLockToCancel(given, stack) {
390
+ if (given)
391
+ return { lockId: given, read: false };
392
+ let locks;
393
+ try {
394
+ locks = await pulumiStackLockIds(stack);
395
+ }
396
+ catch (e) {
397
+ return { refusal: "read-failed", message: `a cancel names the lock it releases, and reading stack ${stack.stack}'s lock failed: ${e.message}` };
398
+ }
399
+ const backend = locks.backend ? { backend: locks.backend } : {};
400
+ if (!locks.checked)
401
+ return { refusal: "not-listed", ...backend, message: `a cancel names the lock it releases here: chant reads a stack's lock from a file:// backend only, and stack ${stack.stack}'s backend is ${locks.backend ?? "none chant can find"}` };
402
+ if (locks.ids.length === 0)
403
+ return { refusal: "no-lock", ...backend, ids: [], message: `stack ${stack.stack} holds no lock now, so there is nothing to cancel` };
404
+ if (locks.ids.length > 1)
405
+ return { refusal: "many-locks", ...backend, ids: locks.ids, message: `stack ${stack.stack} holds ${locks.ids.length} locks (${locks.ids.join(", ")}); name the one to release` };
406
+ return { lockId: locks.ids[0], read: true };
370
407
  }
371
408
  /**
372
409
  * Release a stuck lock after an approval of its lock id, while no run that
@@ -425,8 +462,9 @@ export async function gatedStackCancel(opts) {
425
462
  subject: opts.stack,
426
463
  by: opts.by,
427
464
  lock,
428
- liveRuns: opts.liveRuns ?? forgeRuns(env, opts.forge),
429
- words: { op: opts.op ?? PULUMI_STACK_OPS_OP, kind: "stack-cancel" },
465
+ // #4911, #4920: core's reader of the forge's runs, the origin remote naming the forge on a laptop.
466
+ liveRuns: opts.liveRuns ?? forgeLiveRunsOf(env, opts.forge ?? {}, { cwd: dir }),
467
+ words: wordsOf(opts, "stack-cancel"),
430
468
  ...(opts.commit ? { commit: opts.commit } : {}),
431
469
  ...gatedSettings(opts),
432
470
  });
@@ -450,6 +488,19 @@ export async function gatedStackCancel(opts) {
450
488
  return { status: "done", digest: r.digest, request, approvedBy: r.approvedBy, recorded: r.recorded, result: { lockChecked: checked, liveRuns: r.liveRuns } };
451
489
  }
452
490
  }
491
+ /**
492
+ * The destination as `pulumi state move --dest` takes it (#4911): the bare
493
+ * stack in the source's project, else `<org>/<project>/<stack>`. A DIY
494
+ * backend's organization is always `organization`; on Pulumi Cloud (no
495
+ * backend, or an http(s) one) it is `org` when given. A stack already
496
+ * qualified is kept.
497
+ */
498
+ export function pulumiMoveDestStack(source, dest, opts = {}) {
499
+ if (dest.stack.includes("/") || dest.project === source.project)
500
+ return dest.stack;
501
+ const cloud = !dest.backend || /^https?:\/\//.test(dest.backend);
502
+ return `${(cloud ? opts.org : undefined) ?? "organization"}/${dest.project}/${dest.stack}`;
503
+ }
453
504
  /** The entries of a preview that change anything. */
454
505
  function changing(part) {
455
506
  return part.entries.filter((e) => e.mayAppear === true || ["create", "update", "replace", "delete", "forget"].includes(e.action)).map((e) => ({ address: e.address, type: e.type, action: e.mayAppear ? "may-appear" : e.action }));
@@ -530,9 +581,14 @@ export async function gatedStackMove(opts) {
530
581
  throw new Error(`${opts.source.member} runs on ${engine} and ${opts.dest.member} on ${destEngine}; a move needs both stacks on one engine`);
531
582
  const urns = [...new Set(opts.urns)].sort();
532
583
  const runners = { ...(opts.run ? { run: opts.run } : {}), ...(opts.plunge ? { plunge: opts.plunge } : {}), engine };
584
+ // #4911: with both projects, the destination's --dest name is the lexicon's to decide.
585
+ const destBackend = opts.source.project && opts.dest.project ? pulumiStackBackend(destDir, { env })?.url : undefined;
586
+ const destStack = opts.source.project && opts.dest.project
587
+ ? pulumiMoveDestStack({ project: opts.source.project }, { project: opts.dest.project, stack: opts.dest.stack, ...(destBackend ? { backend: destBackend } : {}) }, opts.org ? { org: opts.org } : {})
588
+ : opts.dest.stack;
533
589
  const sides = [
534
590
  { ...opts.source, dir: sourceDir },
535
- { ...opts.dest, dir: destDir },
591
+ { ...opts.dest, stack: destStack, dir: destDir },
536
592
  ];
537
593
  const side = (member) => sides.find((s) => s.member === member);
538
594
  const previews = async () => {
@@ -549,7 +605,7 @@ export async function gatedStackMove(opts) {
549
605
  if (left.length > 0)
550
606
  throw new Error(`refusing to move: the previews change more than the moved resources, so the stacks would not preview no change after it: ${left.join("; ")}`);
551
607
  if (engine === "plunge") {
552
- const args = plungeMoveArgs({ source: opts.source.stack, dest: opts.dest.stack, urns });
608
+ const args = plungeMoveArgs({ source: opts.source.stack, dest: destStack, urns });
553
609
  let view;
554
610
  try {
555
611
  view = moveView((await runAllowedPlunge(opts.plunge ?? defaultPlungeRunner, args, sourceDir)).stdout);
@@ -565,7 +621,7 @@ export async function gatedStackMove(opts) {
565
621
  }
566
622
  }
567
623
  const digestOf = async (member) => sha256(await exportNow({ ...side(member), ...runners }));
568
- const move = { source: opts.source.stack, dest: opts.dest.stack, urns };
624
+ const move = { source: opts.source.stack, dest: destStack, urns };
569
625
  const proof = { changes: [], summary: `the previews change only the ${urns.length} moved resource(s)` };
570
626
  const roots = [];
571
627
  for (const s of sides) {
@@ -618,17 +674,17 @@ export async function gatedStackMove(opts) {
618
674
  return { changes, summary: changes.length === 0 ? "no change" : `${changes.length} change(s)` };
619
675
  },
620
676
  };
621
- const subject = `move:${opts.source.stack}:${opts.dest.stack}`;
622
- const fields = { source: opts.source.stack, dest: opts.dest.stack, engine, urns: urns.join(",") };
677
+ const subject = `move:${opts.source.stack}:${destStack}`;
678
+ const fields = { source: opts.source.stack, dest: destStack, engine, urns: urns.join(",") };
623
679
  const r = await runStateMigration({
624
680
  name: subject,
625
681
  by: opts.by,
626
682
  roots,
627
683
  engine: migration,
628
- words: { op: opts.op ?? PULUMI_STACK_OPS_OP, kind: "stack-move" },
684
+ words: wordsOf(opts, "stack-move"),
629
685
  fields,
630
686
  detail: (res) => ({ urns: urns.length, engine, afterNoChange: res.status === "applied" }),
631
- description: `move of ${urns.length} resource(s) from ${opts.source.stack} to ${opts.dest.stack}`,
687
+ description: `move of ${urns.length} resource(s) from ${opts.source.stack} to ${destStack}`,
632
688
  ...(opts.runId ? { runId: opts.runId } : {}),
633
689
  ...(opts.commit ? { commit: opts.commit } : {}),
634
690
  ...gatedSettings(opts),
@@ -785,11 +841,13 @@ export async function gatedStackAction(opts) {
785
841
  return { output: { result: { urn: opts.urn, engine, preview: digest, exit, tail }, error }, detail: { result: "failed", exit, tail: tail.slice(-400), urn: opts.urn, error: error.slice(0, 400) }, failed: true };
786
842
  }
787
843
  }));
844
+ const approve = stackOpApproveCommand(opts);
845
+ const command = (fallback) => (approve ? approve(subject, r.digest) : fallback);
788
846
  switch (r.status) {
789
847
  case "waiting":
790
- return { status: "waiting", digest: r.digest, request: r.request, command: r.command };
848
+ return { status: "waiting", digest: r.digest, request: r.request, command: command(r.command) };
791
849
  case "refused":
792
- return { status: "refused", digest: r.digest, request: r.request, by: r.by, reason: r.reason, command: r.command };
850
+ return { status: "refused", digest: r.digest, request: r.request, by: r.by, reason: r.reason, command: command(r.command) };
793
851
  case "spent":
794
852
  return { status: "spent", digest: r.digest, request: r.request };
795
853
  case "held":
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@intentius/chant-lexicon-pulumi",
3
- "version": "0.124.87",
3
+ "version": "0.124.89",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "src/",
@@ -54,7 +54,7 @@
54
54
  "access": "public"
55
55
  },
56
56
  "peerDependencies": {
57
- "@intentius/chant": "^0.124.87",
57
+ "@intentius/chant": "^0.124.89",
58
58
  "zod": "^4.3.6"
59
59
  },
60
60
  "description": "pulumi lexicon for chant: a Pulumi program as a workspace member, its preview in the change set and its refresh as drift records",
@@ -12,6 +12,7 @@ import { tmpdir } from "node:os";
12
12
  import { join } from "node:path";
13
13
  import { describe, expect, test } from "vitest";
14
14
  import { CI_SETUP_UNLINKED_FLOOR } from "@intentius/chant/lexicon";
15
+ import { CI_TOOL_DOCKER_ARCH, CI_TOOL_JOB_ARCH, CI_TOOL_SHA256, ciToolFetchScript } from "@intentius/chant/ci-image";
15
16
  import {
16
17
  ciEngineDir,
17
18
  ciFetchScript,
@@ -56,7 +57,7 @@ describe("recordedSums", () => {
56
57
  test("an unrecorded release has none, and the caller's sums replace the table", () => {
57
58
  expect(recordedSums("pulumi", "3.300.0")).toEqual({});
58
59
  expect(recordedSums("pulumi", "3.300.0", { x64: "a".repeat(64) })).toEqual({ x64: "a".repeat(64) });
59
- expect(() => recordedSums("pulumi", "3.300.0", { x64: "nope" })).toThrow(/64 hex/);
60
+ expect(() => recordedSums("pulumi", "3.300.0", { x64: "nope" })).toThrow(/64 lower-case hex/);
60
61
  });
61
62
  });
62
63
 
@@ -71,8 +72,8 @@ describe("pulumiInstallLine", () => {
71
72
 
72
73
  test("checks the checksums file, then the recorded sum per architecture, then the archive", () => {
73
74
  expect(line).toContain(`/pulumi-${PULUMI_CI_VERSION}-checksums.txt"`);
74
- expect(line).toContain(`x64) want=${PINNED_SHA256["pulumi-v3.272.0-linux-x64.tar.gz"]} ;;`);
75
- expect(line).toContain(`arm64) want=${PINNED_SHA256["pulumi-v3.272.0-linux-arm64.tar.gz"]} ;;`);
75
+ expect(line).toContain(`(amd64) want=${PINNED_SHA256["pulumi-v3.272.0-linux-x64.tar.gz"]} ;;`);
76
+ expect(line).toContain(`(arm64) want=${PINNED_SHA256["pulumi-v3.272.0-linux-arm64.tar.gz"]} ;;`);
76
77
  expect(line).toContain("sha256sum -c -");
77
78
  expect(line.indexOf("want=")).toBeLessThan(line.indexOf("sha256sum -c"));
78
79
  });
@@ -85,15 +86,15 @@ describe("pulumiInstallLine", () => {
85
86
  test("another version, unrecorded, checks only the checksums file", () => {
86
87
  const other = pulumiInstallLine("3.300.0");
87
88
  expect(other).toContain("/opt/chant/pulumi-3.300.0");
88
- expect(other).toContain("want= &&");
89
- expect(other).not.toContain("x64) want=");
89
+ expect(other).toContain('case "$a" in (*) want= ;; esac');
90
+ expect(other).not.toContain("(amd64) want=");
90
91
  });
91
92
 
92
93
  test("a product's root and sums", () => {
93
94
  const own = pulumiInstallLine("3.272.0", { root: "/opt/plywood", sha256: { x64: "b".repeat(64) } });
94
95
  expect(own).toContain('"/opt/plywood/pulumi-3.272.0/pulumi"');
95
- expect(own).toContain(`x64) want=${"b".repeat(64)} ;;`);
96
- expect(own).not.toContain("arm64) want=");
96
+ expect(own).toContain(`(amd64) want=${"b".repeat(64)} ;;`);
97
+ expect(own).not.toContain("(arm64) want=");
97
98
  expect(() => pulumiInstallLine("3.272.0", { root: "relative/dir" })).toThrow(/absolute/);
98
99
  });
99
100
  });
@@ -103,7 +104,7 @@ describe("plungeInstallLine", () => {
103
104
  const line = plungeInstallLine();
104
105
  expect(line.startsWith(`{ [ -x "${CI_ENGINE_ROOT}/plunge-${PLUNGE_CI_VERSION}/plunge" ] || (set -e;`)).toBe(true);
105
106
  expect(line).toContain(`plunge-v${PLUNGE_CI_VERSION}-checksums.txt`);
106
- expect(line).toContain(`x64) want=${PINNED_SHA256["plunge-v0.1.0-linux-x64.tar.gz"]} ;;`);
107
+ expect(line).toContain(`(amd64) want=${PINNED_SHA256["plunge-v0.1.0-linux-x64.tar.gz"]} ;;`);
107
108
  expect(line).toContain("--strip-components=1");
108
109
  expect(line).toContain(`ln -sf "${ciEngineDir("plunge", PLUNGE_CI_VERSION)}/plunge" /usr/local/bin/plunge`);
109
110
  expect(line).not.toContain("plunge version");
@@ -165,16 +166,18 @@ describe("an unlinked install line (#4814)", () => {
165
166
  describe("ciFetchScript (#4814)", () => {
166
167
  test("takes the target directory, an arch expression and a checksums URL word", () => {
167
168
  const s = ciFetchScript("pulumi", "3.272.0", { dir: "/out/opt/plywood/pulumi-3.272.0", arch: CI_DOCKER_ARCH, checksumsUrl: '"$CHECKSUMS_URL"' });
168
- expect(s.startsWith(`a=${CI_DOCKER_ARCH} && `)).toBe(true);
169
+ // #4908: ci-image's script, which reads the Docker build's architecture as amd64 or arm64.
170
+ expect(s.startsWith(`a=${CI_TOOL_DOCKER_ARCH} && `)).toBe(true);
169
171
  expect(CI_DOCKER_ARCH).toBe(`"$(case "$TARGETARCH" in (arm64) echo arm64 ;; (*) echo x64 ;; esac)"`);
170
172
  expect(s).toContain('curl -fsSLo "$t/sums" "$CHECKSUMS_URL"');
171
173
  expect(s).toContain('tar -xzf "$t/$f" -C "/out/opt/plywood/pulumi-3.272.0" --strip-components=1');
172
- expect(s).toContain(`x64) want=${PINNED_SHA256["pulumi-v3.272.0-linux-x64.tar.gz"]} ;;`);
174
+ expect(s).toContain(`(amd64) want=${PINNED_SHA256["pulumi-v3.272.0-linux-x64.tar.gz"]} ;;`);
173
175
  });
174
176
 
175
177
  test("defaults to the job's architecture and the release's own checksums file", () => {
176
178
  const s = ciFetchScript("plunge", "0.1.0", { dir: "/opt/chant/plunge-0.1.0" });
177
- expect(s.startsWith(`a=${CI_JOB_ARCH} && `)).toBe(true);
179
+ expect(s.startsWith(`a=${CI_TOOL_JOB_ARCH} && `)).toBe(true);
180
+ expect(CI_JOB_ARCH).toBe(`"$(uname -m | sed 's/x86_64/x64/;s/aarch64/arm64/')"`);
178
181
  expect(s).toContain('curl -fsSLo "$t/sums" "https://github.com/INTENTIUS/plunge/releases/download/plunge-v0.1.0/plunge-v0.1.0-checksums.txt"');
179
182
  expect(() => ciFetchScript("plunge", "0.1.0", { dir: "relative" })).toThrow(/absolute/);
180
183
  });
@@ -212,6 +215,18 @@ describe("ciFetchScript (#4814)", () => {
212
215
  },
213
216
  );
214
217
 
218
+ test("is ci-image's fetch script, and the pins are ci-image's (#4908)", () => {
219
+ const sums = { x64: "e".repeat(64), arm64: "f".repeat(64) };
220
+ expect(ciFetchScript("pulumi", "3.272.0", { dir: "/out/p", arch: CI_DOCKER_ARCH, sha256: sums, checksumsUrl: '"$U"' })).toBe(
221
+ ciToolFetchScript("pulumi", "3.272.0", { dir: "/out/p", arch: CI_TOOL_DOCKER_ARCH, sha256: { amd64: sums.x64, arm64: sums.arm64 }, checksumsUrl: '"$U"' }),
222
+ );
223
+ expect(ciFetchScript("plunge", "0.2.0", { dir: "/out/g" })).toBe(ciToolFetchScript("plunge", "0.2.0", { dir: "/out/g" }));
224
+ expect(PINNED_SHA256["pulumi-v3.272.0-linux-x64.tar.gz"]).toBe(CI_TOOL_SHA256["pulumi-3.272.0-linux-amd64"]);
225
+ expect(PINNED_SHA256["plunge-v0.2.0-linux-arm64.tar.gz"]).toBe(CI_TOOL_SHA256["plunge-0.2.0-linux-arm64"]);
226
+ // plywood's pinnedSums, which turned ci-image's sums into these words, is this call.
227
+ expect(recordedSums("plunge", "0.2.0")).toEqual({ x64: CI_TOOL_SHA256["plunge-0.2.0-linux-amd64"], arm64: CI_TOOL_SHA256["plunge-0.2.0-linux-arm64"] });
228
+ });
229
+
215
230
  test("the floor names the next release", () => {
216
231
  expect(PULUMI_CI_SETUP_FLOOR).toBe(CI_SETUP_UNLINKED_FLOOR);
217
232
  expect(CI_SETUP_UNLINKED_FLOOR).toBe("0.124.78");
package/src/ci-setup.ts CHANGED
@@ -32,8 +32,15 @@
32
32
  * download and check alone, for an image build's `RUN` with the arch from
33
33
  * `$TARGETARCH` ({@link CI_DOCKER_ARCH}) and the checksums URL from a build
34
34
  * argument, so a tampered checksums file can be shown to fail the build.
35
+ *
36
+ * Since #4908 the download, the check and the recorded sums are
37
+ * `@intentius/chant/ci-image`'s, the one copy every engine install uses:
38
+ * {@link ciFetchScript} is `ciToolFetchScript` and {@link PINNED_SHA256} is
39
+ * read from `CI_TOOL_SHA256`. This module keeps the Pulumi words (the x64
40
+ * and arm64 archive names, the sums by them) and the install lines.
35
41
  */
36
42
  import { CI_SETUP_UNLINKED_FLOOR } from "@intentius/chant/lexicon";
43
+ import { CI_TOOL_DOCKER_ARCH, CI_TOOL_JOB_ARCH, CI_TOOL_SHA256, ciToolFetchScript, ciToolRelease, ciToolSha256, type CiToolArch } from "@intentius/chant/ci-image";
37
44
  import { pulumiMemberEngine } from "./member-engine";
38
45
 
39
46
  /** The first chant with `link: false` and {@link ciFetchScript} (#4814). It is core's floor, so it freezes with chant's release. */
@@ -54,32 +61,7 @@ export const CI_ENGINE_ROOT = "/opt/chant";
54
61
  export type CiArch = "x64" | "arm64";
55
62
  export const CI_ARCHES: readonly CiArch[] = ["x64", "arm64"];
56
63
 
57
- /**
58
- * The sha256 of each recorded Linux archive, copied from its release's
59
- * checksums file (the same sums plywood#12 records). A checksums file that
60
- * lists another sum for one of these fails the install. Add a release's
61
- * two lines when moving a default version.
62
- */
63
- export const PINNED_SHA256: Readonly<Record<string, string>> = {
64
- "pulumi-v3.272.0-linux-x64.tar.gz": "58d545f2b98761051922008ebd381ecef95484d7f7a5ff7faa15d7a780ea84f6",
65
- "pulumi-v3.272.0-linux-arm64.tar.gz": "4f0741901b8982c4326b702dabf483c63d2cf77c88ac42dd752b72541284a534",
66
- "plunge-v0.1.0-linux-x64.tar.gz": "22b89da39ab7dc11268c7b625fec3d99c0793c9c47bf8d031fa94e6967ee8187",
67
- "plunge-v0.1.0-linux-arm64.tar.gz": "6855611b8cf8381d73f5ddf0b5c0a0d83bdc2a5bd8c50d415e52bb05a4574f83",
68
- };
69
-
70
- /** What a caller may set on an install line. */
71
- export interface CiInstallOptions {
72
- /** Where the versioned directories live. Default {@link CI_ENGINE_ROOT}. */
73
- root?: string;
74
- /** Recorded sums by architecture, in place of {@link PINNED_SHA256}'s for this release. */
75
- sha256?: Partial<Record<CiArch, string>>;
76
- /**
77
- * Link the binary into /usr/local/bin (default true). `false` (#4814)
78
- * leaves PATH alone and skips only on the versioned directory, for a pin
79
- * a step runs by its path.
80
- */
81
- link?: boolean;
82
- }
64
+ const TOOL_ARCH: Record<CiArch, CiToolArch> = { x64: "amd64", arm64: "arm64" };
83
65
 
84
66
  /** One release's download: the base URL, the archive per architecture, and its checksums file. */
85
67
  export interface CiRelease {
@@ -89,42 +71,65 @@ export interface CiRelease {
89
71
  }
90
72
 
91
73
  const VERSION = /^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/;
92
- const SHA256 = /^[0-9a-f]{64}$/;
93
74
  const ROOT = /^\/[A-Za-z0-9._/-]*$/;
94
75
 
95
- /** The release of `engine` at `version`. A version is a plain semver, so it is safe on a shell line. */
76
+ /** The release of `engine` at `version`, as ci-image names it (#4908). A version is a plain semver, so it is safe on a shell line. */
96
77
  export function ciRelease(engine: CiEngine, version: string): CiRelease {
97
78
  if (!VERSION.test(version)) throw new Error(`${engine} version ${JSON.stringify(version)} is not a release version such as 3.272.0`);
98
- if (engine === "pulumi") {
99
- return {
100
- base: `https://github.com/pulumi/pulumi/releases/download/v${version}`,
101
- archive: (arch) => `pulumi-v${version}-linux-${arch}.tar.gz`,
102
- checksums: `pulumi-${version}-checksums.txt`,
103
- };
104
- }
79
+ const r = ciToolRelease(engine, version, "amd64");
105
80
  return {
106
- base: `https://github.com/INTENTIUS/plunge/releases/download/plunge-v${version}`,
107
- archive: (arch) => `plunge-v${version}-linux-${arch}.tar.gz`,
108
- checksums: `plunge-v${version}-checksums.txt`,
81
+ base: r.url.slice(0, r.url.lastIndexOf("/")),
82
+ archive: (arch) => ciToolRelease(engine, version, TOOL_ARCH[arch]).asset,
83
+ checksums: r.checksums!,
109
84
  };
110
85
  }
111
86
 
87
+ /**
88
+ * The sha256 of each recorded Linux archive, by its file name: ci-image's
89
+ * `CI_TOOL_SHA256` for Pulumi and plunge (#4908), where a release's two
90
+ * lines are added when a default version moves.
91
+ */
92
+ export const PINNED_SHA256: Readonly<Record<string, string>> = Object.fromEntries(
93
+ Object.entries(CI_TOOL_SHA256).flatMap(([key, sum]) => {
94
+ const m = /^(pulumi|plunge)-(.+)-linux-(amd64|arm64)$/.exec(key);
95
+ return m ? [[ciRelease(m[1] as CiEngine, m[2]!).archive(m[3] === "amd64" ? "x64" : "arm64"), sum]] : [];
96
+ }),
97
+ );
98
+
99
+ /** What a caller may set on an install line. */
100
+ export interface CiInstallOptions {
101
+ /** Where the versioned directories live. Default {@link CI_ENGINE_ROOT}. */
102
+ root?: string;
103
+ /** Recorded sums by architecture, in place of {@link PINNED_SHA256}'s for this release. */
104
+ sha256?: Partial<Record<CiArch, string>>;
105
+ /**
106
+ * Link the binary into /usr/local/bin (default true). `false` (#4814)
107
+ * leaves PATH alone and skips only on the versioned directory, for a pin
108
+ * a step runs by its path.
109
+ */
110
+ link?: boolean;
111
+ }
112
+
112
113
  /** Where one release of one engine lives after its line runs. */
113
114
  export function ciEngineDir(engine: CiEngine, version: string, root = CI_ENGINE_ROOT): string {
114
115
  if (!ROOT.test(root)) throw new Error(`an engine root is an absolute path of letters, digits and ._/-, not ${JSON.stringify(root)}`);
115
116
  return `${root.replace(/\/+$/, "")}/${engine}-${version}`;
116
117
  }
117
118
 
119
+ /** The caller's sums by ci-image's architecture names. */
120
+ function toolSums(given: Partial<Record<CiArch, string>> | undefined): Partial<Record<CiToolArch, string>> | undefined {
121
+ if (!given) return undefined;
122
+ const out: Partial<Record<CiToolArch, string>> = {};
123
+ for (const arch of CI_ARCHES) if (given[arch] !== undefined) out[TOOL_ARCH[arch]] = given[arch];
124
+ return out;
125
+ }
126
+
118
127
  /** The recorded sums for `version`, by architecture: the caller's, else {@link PINNED_SHA256}'s. */
119
128
  export function recordedSums(engine: CiEngine, version: string, given?: Partial<Record<CiArch, string>>): Partial<Record<CiArch, string>> {
120
- const r = ciRelease(engine, version);
129
+ ciRelease(engine, version);
130
+ const sums = ciToolSha256(engine, version, toolSums(given));
121
131
  const out: Partial<Record<CiArch, string>> = {};
122
- for (const arch of CI_ARCHES) {
123
- const sum = given ? given[arch] : PINNED_SHA256[r.archive(arch)];
124
- if (sum === undefined) continue;
125
- if (!SHA256.test(sum)) throw new Error(`the recorded sha256 for ${r.archive(arch)} is not 64 hex digits`);
126
- out[arch] = sum;
127
- }
132
+ for (const arch of CI_ARCHES) if (sums[TOOL_ARCH[arch]] !== undefined) out[arch] = sums[TOOL_ARCH[arch]];
128
133
  return out;
129
134
  }
130
135
 
@@ -138,6 +143,17 @@ export const CI_JOB_ARCH = `"$(uname -m | sed 's/x86_64/x64/;s/aarch64/arm64/')"
138
143
  */
139
144
  export const CI_DOCKER_ARCH = `"$(case "$TARGETARCH" in (arm64) echo arm64 ;; (*) echo x64 ;; esac)"`;
140
145
 
146
+ /**
147
+ * `arch`, an expression giving x64 or arm64, as ci-image's amd64 or arm64.
148
+ * The two expressions here are ci-image's own; another is mapped in the
149
+ * shell.
150
+ */
151
+ function toolArch(arch: string | undefined): string {
152
+ if (arch === undefined || arch === CI_JOB_ARCH) return CI_TOOL_JOB_ARCH;
153
+ if (arch === CI_DOCKER_ARCH) return CI_TOOL_DOCKER_ARCH;
154
+ return `"$(case ${arch} in (x64) echo amd64 ;; (*) echo ${arch} ;; esac)"`;
155
+ }
156
+
141
157
  /** Where {@link ciFetchScript} puts a release and what it checks it against. */
142
158
  export interface CiFetchOptions {
143
159
  /** The directory the archive unpacks into, an absolute path: `/out/opt/plywood/pulumi-3.272.0` in an image's fetch stage. */
@@ -153,42 +169,27 @@ export interface CiFetchOptions {
153
169
  /**
154
170
  * Shell that downloads one release into `dir` and checks it against the
155
171
  * release's checksums file and, when recorded, the sum per architecture
156
- * (#4814). Run it under `set -e`. Both archives unpack a top directory named
157
- * after the engine, which `--strip-components=1` drops. `arch` and
158
- * `checksumsUrl` go onto the line as they are, so they are the caller's
159
- * shell, never a value from outside.
172
+ * (#4814): ci-image's `ciToolFetchScript` (#4908). Run it under `set -e`.
173
+ * Both archives unpack a top directory named after the engine, which
174
+ * `--strip-components=1` drops. `arch` and `checksumsUrl` go onto the line
175
+ * as they are, so they are the caller's shell, never a value from outside.
160
176
  */
161
177
  export function ciFetchScript(engine: CiEngine, version: string, options: CiFetchOptions): string {
162
178
  if (!ROOT.test(options.dir)) throw new Error(`a fetch directory is an absolute path of letters, digits and ._/-, not ${JSON.stringify(options.dir)}`);
163
- return fetchScript(engine, version, options.dir, recordedSums(engine, version, options.sha256), options.arch ?? CI_JOB_ARCH, options.checksumsUrl);
164
- }
165
-
166
- function fetchScript(engine: CiEngine, version: string, dir: string, sums: Partial<Record<CiArch, string>>, arch: string, checksumsUrl?: string): string {
167
- const r = ciRelease(engine, version);
168
- const recorded = CI_ARCHES.filter((a) => sums[a]);
169
- const pinCase = recorded.length > 0 ? `case "$a" in ${recorded.map((a) => `${a}) want=${sums[a]} ;;`).join(" ")} *) want= ;; esac` : "want=";
170
- const file = r.archive("x64").replace("-x64.", "-$a.");
171
- return [
172
- `a=${arch}`,
173
- `f="${file}"`,
174
- `t="$(mktemp -d)"`,
175
- `curl -fsSLo "$t/$f" "${r.base}/$f"`,
176
- `curl -fsSLo "$t/sums" ${checksumsUrl ?? `"${r.base}/${r.checksums}"`}`,
177
- // The archive's line, with any ./ or * before the name taken off.
178
- `line="$(sed -n "s#^\\([0-9a-f]\\{64\\}\\) *[*.]*/*$f\\$#\\1#p" "$t/sums")"`,
179
- `{ [ -n "$line" ] || { echo "${engine} ${version}: $f is not in ${r.checksums}" >&2; exit 1; }; }`,
180
- pinCase,
181
- `{ [ -z "$want" ] || [ "$line" = "$want" ] || { echo "${engine} ${version}: ${r.checksums} lists $line for $f; chant records $want" >&2; exit 1; }; }`,
182
- `echo "$line $t/$f" | sha256sum -c - >/dev/null`,
183
- `mkdir -p "${dir}"`,
184
- `tar -xzf "$t/$f" -C "${dir}" --strip-components=1`,
185
- ].join(" && ");
179
+ ciRelease(engine, version);
180
+ const sha256 = toolSums(options.sha256);
181
+ return ciToolFetchScript(engine, version, {
182
+ dir: options.dir,
183
+ arch: toolArch(options.arch),
184
+ ...(sha256 ? { sha256 } : {}),
185
+ ...(options.checksumsUrl !== undefined ? { checksumsUrl: options.checksumsUrl } : {}),
186
+ });
186
187
  }
187
188
 
188
189
  /** The line for one engine: skip when present, else fetch and check, then link into /usr/local/bin unless `link` is false. */
189
190
  function installLine(engine: CiEngine, version: string, options: CiInstallOptions, present?: string): string {
190
191
  const dir = ciEngineDir(engine, version, options.root);
191
- const install = `(set -e; ${fetchScript(engine, version, dir, recordedSums(engine, version, options.sha256), CI_JOB_ARCH)})`;
192
+ const install = `(set -e; ${ciFetchScript(engine, version, { dir, ...(options.sha256 ? { sha256: options.sha256 } : {}) })})`;
192
193
  // Unlinked: the versioned directory alone says whether this release is there.
193
194
  if (options.link === false) return `[ -x "${dir}/${engine}" ] || ${install}`;
194
195
  const link = `ln -sf "${dir}/${engine}" /usr/local/bin/${engine}`;
package/src/index.ts CHANGED
@@ -111,7 +111,7 @@ export { readPulumiDrift, type PulumiDriftRunners } from "./drift-read";
111
111
  export { pulumiAuditCatalog } from "./lint/audit-catalog";
112
112
  // The Preview/Drift watch composite and its step builders (#4494).
113
113
  export { PulumiWatchOp, type PulumiWatchOpConfig, type PulumiWatchOpResources } from "./composites/pulumi-watch-op";
114
- export { gatedStackExport, gatedStackCancel, gatedStackMove, gatedStackAction, checkStackActionUrn, stackActionScope, stackActionSubject, PulumiStackActionRefused, PULUMI_ACTION_TYPE_PREFIX, type PulumiStackActionOptions, type PulumiStackActionResult, type PulumiStackActionRefusal, moveLeftovers, diyStackLockIds, diyStackLock, pulumiStackLockIds, pulumiStackVersionSource, PulumiStackOpRefused, type PulumiStackOpRefusal, type PulumiStackOpCheck, type PulumiStackExportResult, type PulumiStackCancelResult, type PulumiStackMoveResult, type PulumiStackLocks, PULUMI_STACK_OPS_OP, type PulumiStackOpOutcome, type PulumiStackOpCommon, type PulumiStackOpKind } from "./stack-ops";
114
+ export { gatedStackExport, gatedStackCancel, gatedStackMove, gatedStackAction, checkStackActionUrn, stackActionScope, stackActionSubject, PulumiStackActionRefused, PULUMI_ACTION_TYPE_PREFIX, type PulumiStackActionOptions, type PulumiStackActionResult, type PulumiStackActionRefusal, moveLeftovers, pulumiMoveDestStack, pulumiStackLockToCancel, stackOpApproveCommand, type PulumiLockToCancel, type PulumiLockToCancelRefusal, diyStackLockIds, diyStackLock, pulumiStackLockIds, pulumiStackVersionSource, PulumiStackOpRefused, type PulumiStackOpRefusal, type PulumiStackOpCheck, type PulumiStackExportResult, type PulumiStackCancelResult, type PulumiStackMoveResult, type PulumiStackLocks, PULUMI_STACK_OPS_OP, type PulumiStackOpOutcome, type PulumiStackOpCommon, type PulumiStackOpKind } from "./stack-ops";
115
115
  // Review stacks (INTENTIUS/plywood#15): pr-<n> stacks only.
116
116
  export {
117
117
  initReviewStack,
@@ -19,7 +19,10 @@ import {
19
19
  gatedStackAction,
20
20
  gatedStackMove,
21
21
  moveLeftovers,
22
+ pulumiMoveDestStack,
23
+ pulumiStackLockToCancel,
22
24
  PulumiStackActionRefused,
25
+ stackOpApproveCommand,
23
26
  stackActionScope,
24
27
  pulumiStackLockIds,
25
28
  PULUMI_STACK_OPS_OP,
@@ -418,3 +421,91 @@ describe("the version reads (#4808)", () => {
418
421
  expect(pulumi.calls).toHaveLength(2);
419
422
  });
420
423
  });
424
+
425
+ // #4911: what plywood built beside the lexicon's verbs.
426
+ describe("the product's approve line, lock, destination and requester (#4911)", () => {
427
+ test("a template the product words its approve line in, filled with the op, the gate, the digest and --sign when sealed", () => {
428
+ const line = stackOpApproveCommand({ approveCommand: "plywood approve {gate} --op {op} --plan {digest} {sign}", rules: { mode: "ledger" } })!;
429
+ expect(line("dev", "sha256:ab")).toBe(`plywood approve dev --op ${PULUMI_STACK_OPS_OP} --plan sha256:ab`);
430
+ const sealed = stackOpApproveCommand({ approveCommand: "plywood approve {gate} --op {op} --plan {digest} {sign}", rules: { mode: "sealed" }, op: "mine" })!;
431
+ expect(sealed("dev", "d")).toBe("plywood approve dev --op mine --plan d --sign");
432
+ expect(stackOpApproveCommand({ rules: { mode: "ledger" } })).toBeUndefined();
433
+ });
434
+
435
+ test("a waiting cancel and a waiting move print the product's line", async () => {
436
+ const root = outside();
437
+ const locks = join(root, ".pulumi", "locks", "organization", "shop", "dev");
438
+ mkdirSync(locks, { recursive: true });
439
+ writeFileSync(join(locks, "lock-1.json"), "{}");
440
+ const l = ledger();
441
+ const approveCommand = (gate: string, digest: string) => `plywood approve ${gate} --plan ${digest}`;
442
+ const asked = await gatedStackCancel({ by: "alice", rules: { mode: "ledger" }, gated: l.api, env: {}, dir: stackDir(`file://${root}`), stack: "dev", engine: "pulumi", lockId: "lock-1", liveRuns: async () => [], approveCommand });
443
+ expect(asked).toMatchObject({ status: "waiting", command: `plywood approve dev --plan ${asked.digest}` });
444
+ });
445
+
446
+ test("the lock to cancel: the one given, the one held, or a refusal the product words", async () => {
447
+ const root = outside();
448
+ const locks = join(root, ".pulumi", "locks", "organization", "shop", "dev");
449
+ mkdirSync(locks, { recursive: true });
450
+ const dir = stackDir(`file://${root}`);
451
+ expect(await pulumiStackLockToCancel("given", { dir, stack: "dev", env: {} })).toEqual({ lockId: "given", read: false });
452
+ expect(await pulumiStackLockToCancel(undefined, { dir, stack: "dev", env: {} })).toMatchObject({ refusal: "no-lock", ids: [] });
453
+ writeFileSync(join(locks, "lock-1.json"), "{}");
454
+ expect(await pulumiStackLockToCancel(undefined, { dir, stack: "dev", env: {} })).toEqual({ lockId: "lock-1", read: true });
455
+ writeFileSync(join(locks, "lock-2.json"), "{}");
456
+ expect(await pulumiStackLockToCancel(undefined, { dir, stack: "dev", env: {} })).toMatchObject({ refusal: "many-locks", ids: ["lock-1", "lock-2"] });
457
+ expect(await pulumiStackLockToCancel(undefined, { dir: stackDir("s3://bucket"), stack: "dev", env: {} })).toMatchObject({ refusal: "not-listed", backend: "s3://bucket" });
458
+ });
459
+
460
+ test("--dest: the bare stack in one project, else qualified, the org on Pulumi Cloud only", () => {
461
+ expect(pulumiMoveDestStack({ project: "shop" }, { project: "shop", stack: "app" })).toBe("app");
462
+ expect(pulumiMoveDestStack({ project: "net" }, { project: "shop", stack: "app" }, { org: "acme" })).toBe("acme/shop/app");
463
+ expect(pulumiMoveDestStack({ project: "net" }, { project: "shop", stack: "app", backend: "https://api.pulumi.com" }, { org: "acme" })).toBe("acme/shop/app");
464
+ expect(pulumiMoveDestStack({ project: "net" }, { project: "shop", stack: "app", backend: "file:///state" }, { org: "acme" })).toBe("organization/shop/app");
465
+ expect(pulumiMoveDestStack({ project: "net" }, { project: "shop", stack: "app" })).toBe("organization/shop/app");
466
+ expect(pulumiMoveDestStack({ project: "net" }, { project: "shop", stack: "o/shop/app" })).toBe("o/shop/app");
467
+ });
468
+
469
+ test("a move given both projects names the destination itself", async () => {
470
+ const l = ledger();
471
+ const pulumi = runner((args) => {
472
+ const stack = args[args.indexOf("--stack") + 1];
473
+ return stack === "net" ? previewDoc([step("delete", src("logs"))]) : previewDoc([step("create", dst("logs"))]);
474
+ });
475
+ const asked = await gatedStackMove({
476
+ by: "alice",
477
+ rules: { mode: "ledger" },
478
+ gated: l.api,
479
+ env: {},
480
+ run: pulumi.run,
481
+ engine: "pulumi",
482
+ source: { member: "infra/net", dir: stackDir(`file://${outside()}`), stack: "net", project: "infra" },
483
+ dest: { member: "shop/app", dir: stackDir(`file://${outside()}`), stack: "app", project: "shop" },
484
+ urns: [src("logs")],
485
+ org: "acme",
486
+ approveCommand: "plywood approve {gate} --op {op} --plan {digest} {sign}",
487
+ });
488
+ expect(asked).toMatchObject({ status: "waiting", request: { subject: "move:net:organization/shop/app", fields: { dest: "organization/shop/app" } } });
489
+ if (asked.status === "waiting") expect(asked.command).toBe(`plywood approve move:net:organization/shop/app --op ${PULUMI_STACK_OPS_OP} --plan ${asked.digest}`);
490
+ });
491
+ });
492
+
493
+ // #4920: a laptop cancel names the forge and the repository from the stack checkout's origin remote.
494
+ describe("cancel on a laptop (#4920)", () => {
495
+ test("with no CI variables and no repository given, the origin remote names the repository; only the token is missing", async () => {
496
+ const { execFileSync } = await import("node:child_process");
497
+ const root = outside();
498
+ const locks = join(root, ".pulumi", "locks", "organization", "shop", "dev");
499
+ mkdirSync(locks, { recursive: true });
500
+ writeFileSync(join(locks, "lock-1.json"), "{}");
501
+ const dir = stackDir(`file://${root}`);
502
+ const base = { by: "alice", rules: { mode: "ledger" as const }, env: {}, dir, stack: "dev", engine: "pulumi" as const, lockId: "lock-1", forge: { kind: "github" as const } };
503
+ const before = await gatedStackCancel({ ...base, gated: ledger().api }).then(() => "", (e: Error) => e.message);
504
+ expect(before).toMatch(/GITHUB_REPOSITORY/);
505
+ execFileSync("git", ["-C", dir, "init", "-q"]);
506
+ execFileSync("git", ["-C", dir, "remote", "add", "origin", "git@github.com:acme/infra.git"]);
507
+ const after = await gatedStackCancel({ ...base, gated: ledger().api }).then(() => "", (e: Error) => e.message);
508
+ expect(after).toMatch(/a token/);
509
+ expect(after).not.toMatch(/GITHUB_REPOSITORY/);
510
+ });
511
+ });