@intentius/chant-lexicon-pulumi 0.124.98 → 0.124.99
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/adopt.d.ts +0 -1
- package/dist/capability-plugin.d.ts +0 -1
- package/dist/change-set.d.ts +0 -1
- package/dist/changed-units.d.ts +0 -1
- package/dist/check-step.d.ts +0 -1
- package/dist/ci-setup.d.ts +0 -1
- package/dist/codegen/docs-cli.d.ts +0 -1
- package/dist/codegen/docs.d.ts +0 -1
- package/dist/codegen/package.d.ts +0 -1
- package/dist/composites/pulumi-adopt-op.d.ts +0 -1
- package/dist/composites/pulumi-watch-op.d.ts +0 -1
- package/dist/config.d.ts +0 -1
- package/dist/describe-resources.d.ts +0 -1
- package/dist/drift-read.d.ts +0 -1
- package/dist/drift-record.d.ts +0 -1
- package/dist/engine-events.d.ts +0 -1
- package/dist/engine-graph.d.ts +0 -1
- package/dist/exit-codes.d.ts +0 -1
- package/dist/index.d.ts +0 -1
- package/dist/init-templates.d.ts +0 -1
- package/dist/integrity.json +2 -2
- package/dist/lint/audit-catalog.d.ts +0 -1
- package/dist/lint/post-synth/index.d.ts +0 -1
- package/dist/lint/post-synth/member-read-helpers.d.ts +0 -1
- package/dist/lint/post-synth/pul001.d.ts +0 -1
- package/dist/lint/post-synth/pul002.d.ts +0 -1
- package/dist/lint/post-synth/pul003.d.ts +0 -1
- package/dist/lint/post-synth/pul004.d.ts +0 -1
- package/dist/lint/post-synth/pul005.d.ts +0 -1
- package/dist/lint/post-synth/pul006.d.ts +0 -1
- package/dist/lint/post-synth/pul007.d.ts +0 -1
- package/dist/lint/post-synth/pul008.d.ts +0 -1
- package/dist/lint/post-synth/pul009.d.ts +0 -1
- package/dist/lint/post-synth/pul010.d.ts +0 -1
- package/dist/lint/post-synth/pul011.d.ts +0 -1
- package/dist/lint/post-synth/pul012.d.ts +0 -1
- package/dist/lint/post-synth/pul013.d.ts +0 -1
- package/dist/lint/post-synth/pul014.d.ts +0 -1
- package/dist/lint/post-synth/pul015.d.ts +0 -1
- package/dist/lint/rules/index.d.ts +0 -1
- package/dist/lint/rules/member-dir-absolute.d.ts +0 -1
- package/dist/lock-rows.d.ts +0 -1
- package/dist/lsp/completions.d.ts +0 -1
- package/dist/lsp/documents.d.ts +0 -1
- package/dist/lsp/hover.d.ts +0 -1
- package/dist/lsp/keys.d.ts +0 -1
- package/dist/lsp/object-path.d.ts +0 -1
- package/dist/lsp/yaml-cursor.d.ts +0 -1
- package/dist/manifest.json +1 -1
- package/dist/member-engine.d.ts +0 -1
- package/dist/member-outputs.d.ts +0 -1
- package/dist/op/activities/index.d.ts +0 -1
- package/dist/op/activities/pulumi-adopt.d.ts +0 -1
- package/dist/op/activities/pulumi.d.ts +0 -1
- package/dist/op/activity-contracts.d.ts +0 -1
- package/dist/op/builders.d.ts +0 -1
- package/dist/package-cli.d.ts +0 -1
- package/dist/plan-shape.d.ts +0 -1
- package/dist/planned-output-changes.d.ts +0 -1
- package/dist/plugin.d.ts +0 -1
- package/dist/plunge-timings.d.ts +0 -1
- package/dist/preview-tips.d.ts +0 -1
- package/dist/pulumi-up.d.ts +0 -1
- package/dist/release-copy.d.ts +0 -1
- package/dist/review-stack.d.ts +0 -1
- package/dist/run.d.ts +0 -1
- package/dist/serializer.d.ts +0 -1
- package/dist/stack-export-snapshot.d.ts +0 -1
- package/dist/stack-ops.d.ts +0 -1
- package/dist/stack-outputs.d.ts +0 -1
- package/dist/stack-references.d.ts +0 -1
- package/dist/trace-facts.d.ts +0 -1
- package/dist/values.d.ts +0 -1
- package/dist/workspace-member.d.ts +0 -1
- package/package.json +3 -4
- package/dist/adopt.d.ts.map +0 -1
- package/dist/capability-plugin.d.ts.map +0 -1
- package/dist/change-set.d.ts.map +0 -1
- package/dist/changed-units.d.ts.map +0 -1
- package/dist/check-step.d.ts.map +0 -1
- package/dist/ci-setup.d.ts.map +0 -1
- package/dist/codegen/docs-cli.d.ts.map +0 -1
- package/dist/codegen/docs.d.ts.map +0 -1
- package/dist/codegen/package.d.ts.map +0 -1
- package/dist/composites/pulumi-adopt-op.d.ts.map +0 -1
- package/dist/composites/pulumi-watch-op.d.ts.map +0 -1
- package/dist/config.d.ts.map +0 -1
- package/dist/describe-resources.d.ts.map +0 -1
- package/dist/drift-read.d.ts.map +0 -1
- package/dist/drift-record.d.ts.map +0 -1
- package/dist/engine-events.d.ts.map +0 -1
- package/dist/engine-graph.d.ts.map +0 -1
- package/dist/exit-codes.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/init-templates.d.ts.map +0 -1
- package/dist/lint/audit-catalog.d.ts.map +0 -1
- package/dist/lint/post-synth/index.d.ts.map +0 -1
- package/dist/lint/post-synth/member-read-helpers.d.ts.map +0 -1
- package/dist/lint/post-synth/pul001.d.ts.map +0 -1
- package/dist/lint/post-synth/pul002.d.ts.map +0 -1
- package/dist/lint/post-synth/pul003.d.ts.map +0 -1
- package/dist/lint/post-synth/pul004.d.ts.map +0 -1
- package/dist/lint/post-synth/pul005.d.ts.map +0 -1
- package/dist/lint/post-synth/pul006.d.ts.map +0 -1
- package/dist/lint/post-synth/pul007.d.ts.map +0 -1
- package/dist/lint/post-synth/pul008.d.ts.map +0 -1
- package/dist/lint/post-synth/pul009.d.ts.map +0 -1
- package/dist/lint/post-synth/pul010.d.ts.map +0 -1
- package/dist/lint/post-synth/pul011.d.ts.map +0 -1
- package/dist/lint/post-synth/pul012.d.ts.map +0 -1
- package/dist/lint/post-synth/pul013.d.ts.map +0 -1
- package/dist/lint/post-synth/pul014.d.ts.map +0 -1
- package/dist/lint/post-synth/pul015.d.ts.map +0 -1
- package/dist/lint/rules/index.d.ts.map +0 -1
- package/dist/lint/rules/member-dir-absolute.d.ts.map +0 -1
- package/dist/lock-rows.d.ts.map +0 -1
- package/dist/lsp/completions.d.ts.map +0 -1
- package/dist/lsp/documents.d.ts.map +0 -1
- package/dist/lsp/hover.d.ts.map +0 -1
- package/dist/lsp/keys.d.ts.map +0 -1
- package/dist/lsp/object-path.d.ts.map +0 -1
- package/dist/lsp/yaml-cursor.d.ts.map +0 -1
- package/dist/member-engine.d.ts.map +0 -1
- package/dist/member-outputs.d.ts.map +0 -1
- package/dist/op/activities/index.d.ts.map +0 -1
- package/dist/op/activities/pulumi-adopt.d.ts.map +0 -1
- package/dist/op/activities/pulumi.d.ts.map +0 -1
- package/dist/op/activity-contracts.d.ts.map +0 -1
- package/dist/op/builders.d.ts.map +0 -1
- package/dist/package-cli.d.ts.map +0 -1
- package/dist/plan-shape.d.ts.map +0 -1
- package/dist/planned-output-changes.d.ts.map +0 -1
- package/dist/plugin.d.ts.map +0 -1
- package/dist/plunge-timings.d.ts.map +0 -1
- package/dist/preview-tips.d.ts.map +0 -1
- package/dist/pulumi-up.d.ts.map +0 -1
- package/dist/release-copy.d.ts.map +0 -1
- package/dist/review-stack.d.ts.map +0 -1
- package/dist/run.d.ts.map +0 -1
- package/dist/serializer.d.ts.map +0 -1
- package/dist/stack-export-snapshot.d.ts.map +0 -1
- package/dist/stack-ops.d.ts.map +0 -1
- package/dist/stack-outputs.d.ts.map +0 -1
- package/dist/stack-references.d.ts.map +0 -1
- package/dist/trace-facts.d.ts.map +0 -1
- package/dist/values.d.ts.map +0 -1
- package/dist/workspace-member.d.ts.map +0 -1
- package/src/adopt.ts +0 -202
- package/src/capability-plugin.ts +0 -34
- package/src/change-set.test.ts +0 -245
- package/src/change-set.ts +0 -508
- package/src/changed-units.test.ts +0 -87
- package/src/changed-units.ts +0 -96
- package/src/check-step.test.ts +0 -191
- package/src/check-step.ts +0 -316
- package/src/ci-setup.test.ts +0 -234
- package/src/ci-setup.ts +0 -224
- package/src/codegen/docs-cli.ts +0 -4
- package/src/codegen/docs.ts +0 -58
- package/src/codegen/package.ts +0 -63
- package/src/composites/pulumi-adopt-op.test.ts +0 -258
- package/src/composites/pulumi-adopt-op.ts +0 -193
- package/src/composites/pulumi-watch-op.test.ts +0 -42
- package/src/composites/pulumi-watch-op.ts +0 -85
- package/src/config.ts +0 -43
- package/src/describe-resources.test.ts +0 -112
- package/src/describe-resources.ts +0 -118
- package/src/drift-read.test.ts +0 -178
- package/src/drift-read.ts +0 -94
- package/src/drift-record.test.ts +0 -197
- package/src/drift-record.ts +0 -326
- package/src/engine-events.test.ts +0 -160
- package/src/engine-events.ts +0 -395
- package/src/engine-graph.test.ts +0 -141
- package/src/engine-graph.ts +0 -149
- package/src/exit-codes.test.ts +0 -21
- package/src/exit-codes.ts +0 -71
- package/src/index.ts +0 -139
- package/src/init-templates.ts +0 -85
- package/src/lint/audit-catalog.test.ts +0 -33
- package/src/lint/audit-catalog.ts +0 -174
- package/src/lint/post-synth/index.ts +0 -35
- package/src/lint/post-synth/member-read-helpers.ts +0 -122
- package/src/lint/post-synth/post-synth.test.ts +0 -245
- package/src/lint/post-synth/pul001.ts +0 -38
- package/src/lint/post-synth/pul002.ts +0 -38
- package/src/lint/post-synth/pul003.ts +0 -43
- package/src/lint/post-synth/pul004.ts +0 -32
- package/src/lint/post-synth/pul005.ts +0 -31
- package/src/lint/post-synth/pul006.ts +0 -31
- package/src/lint/post-synth/pul007.ts +0 -35
- package/src/lint/post-synth/pul008.ts +0 -35
- package/src/lint/post-synth/pul009.ts +0 -32
- package/src/lint/post-synth/pul010.ts +0 -42
- package/src/lint/post-synth/pul011.ts +0 -38
- package/src/lint/post-synth/pul012.ts +0 -35
- package/src/lint/post-synth/pul013.ts +0 -35
- package/src/lint/post-synth/pul014.ts +0 -32
- package/src/lint/post-synth/pul015.ts +0 -39
- package/src/lint/rules/index.ts +0 -7
- package/src/lint/rules/member-dir-absolute.test.ts +0 -37
- package/src/lint/rules/member-dir-absolute.ts +0 -83
- package/src/lock-rows.test.ts +0 -60
- package/src/lock-rows.ts +0 -56
- package/src/lsp/completions.test.ts +0 -69
- package/src/lsp/completions.ts +0 -119
- package/src/lsp/documents.ts +0 -48
- package/src/lsp/hover.test.ts +0 -56
- package/src/lsp/hover.ts +0 -83
- package/src/lsp/keys.ts +0 -169
- package/src/lsp/object-path.ts +0 -71
- package/src/lsp/yaml-cursor.ts +0 -85
- package/src/member-engine.test.ts +0 -112
- package/src/member-engine.ts +0 -97
- package/src/member-outputs.test.ts +0 -339
- package/src/member-outputs.ts +0 -157
- package/src/op/activities/index.ts +0 -36
- package/src/op/activities/pulumi-adopt.ts +0 -345
- package/src/op/activities/pulumi.ts +0 -136
- package/src/op/activity-contracts.ts +0 -129
- package/src/op/builders.ts +0 -67
- package/src/package-cli.ts +0 -14
- package/src/plan-shape.test.ts +0 -91
- package/src/plan-shape.ts +0 -105
- package/src/planned-output-changes.test.ts +0 -85
- package/src/planned-output-changes.ts +0 -141
- package/src/plugin.test.ts +0 -96
- package/src/plugin.ts +0 -272
- package/src/plunge-timings.test.ts +0 -241
- package/src/plunge-timings.ts +0 -115
- package/src/plunge-up-failed.test.ts +0 -54
- package/src/pr-note.test.ts +0 -87
- package/src/preview-generated.test.ts +0 -124
- package/src/preview-tips.test.ts +0 -134
- package/src/preview-tips.ts +0 -128
- package/src/pulumi-up.test.ts +0 -581
- package/src/pulumi-up.ts +0 -1102
- package/src/pulumi-urn-node.test.ts +0 -94
- package/src/release-copy.test.ts +0 -162
- package/src/release-copy.ts +0 -223
- package/src/review-stack.test.ts +0 -254
- package/src/review-stack.ts +0 -266
- package/src/run-plan-flags.test.ts +0 -53
- package/src/run.test.ts +0 -540
- package/src/run.ts +0 -1129
- package/src/serializer.test.ts +0 -9
- package/src/serializer.ts +0 -15
- package/src/skills/chant-pulumi-plunge.md +0 -51
- package/src/skills/chant-pulumi-stack-export.md +0 -54
- package/src/skills/chant-pulumi.md +0 -83
- package/src/stack-export-snapshot.test.ts +0 -192
- package/src/stack-export-snapshot.ts +0 -312
- package/src/stack-ops.fake-binary.test.ts +0 -323
- package/src/stack-ops.test.ts +0 -511
- package/src/stack-ops.ts +0 -1082
- package/src/stack-outputs.ts +0 -66
- package/src/stack-references.test.ts +0 -96
- package/src/stack-references.ts +0 -110
- package/src/testdata/plunge-drift/README.md +0 -10
- package/src/testdata/plunge-drift/assets-drifted.ndjson +0 -3
- package/src/testdata/plunge-drift/component-unsupported.ndjson +0 -3
- package/src/testdata/plunge-drift/role-in-sync.ndjson +0 -3
- package/src/testdata/plunge-drift/settled-empty.ndjson +0 -2
- package/src/testdata/plunge-graph/Pulumi.yaml +0 -4
- package/src/testdata/plunge-graph/README.md +0 -12
- package/src/testdata/plunge-graph/engine-graph.json +0 -158
- package/src/testdata/plunge-graph/stack-export.json +0 -49
- package/src/testdata/plunge-member/Pulumi.yaml +0 -4
- package/src/testdata/plunge-member/README.md +0 -3
- package/src/testdata/plunge-member/stack-export.json +0 -480
- package/src/testdata/plunge-outputs/Pulumi.yaml +0 -9
- package/src/testdata/plunge-outputs/README.md +0 -7
- package/src/testdata/plunge-outputs/stack-export.json +0 -2003
- package/src/testdata/plunge-outputs/stack-output.json +0 -19
- package/src/testdata/pulumi-member/Pulumi.yaml +0 -2
- package/src/testdata/pulumi-member/README.md +0 -50
- package/src/testdata/pulumi-member/recording/Pulumi.dev.yaml +0 -19
- package/src/testdata/pulumi-member/recording/Pulumi.yaml +0 -7
- package/src/testdata/pulumi-member/recording/index.js +0 -47
- package/src/testdata/pulumi-member/recording/package-lock.json +0 -2707
- package/src/testdata/pulumi-member/recording/package.json +0 -9
- package/src/testdata/pulumi-member/stack-export.json +0 -746
- package/src/testdata/pulumi-outputs/Pulumi.yaml +0 -7
- package/src/testdata/pulumi-outputs/README.md +0 -9
- package/src/testdata/pulumi-outputs/preview-replaced.json +0 -2894
- package/src/testdata/pulumi-outputs/preview-settled.json +0 -2894
- package/src/testdata/pulumi-outputs/stack-export.json +0 -1919
- package/src/testdata/pulumi-outputs/stack-output.json +0 -19
- package/src/testdata/pulumi-preview/Pulumi.yaml +0 -7
- package/src/testdata/pulumi-preview/README.md +0 -9
- package/src/testdata/pulumi-preview/preview-create.json +0 -992
- package/src/testdata/pulumi-preview/preview.json +0 -2894
- package/src/testdata/pulumi-preview/stack-export.json +0 -1919
- package/src/testdata/pulumi-refresh/Pulumi.yaml +0 -7
- package/src/testdata/pulumi-refresh/README.md +0 -14
- package/src/testdata/pulumi-refresh/all.json +0 -3742
- package/src/testdata/pulumi-refresh/bucket-edited.json +0 -468
- package/src/testdata/pulumi-refresh/policy-deleted.json +0 -95
- package/src/testdata/pulumi-refresh/queue-edited.json +0 -250
- package/src/testdata/pulumi-refresh/role-same.json +0 -242
- package/src/testdata/pulumi-refresh/secret-edited.json +0 -247
- package/src/testdata/pulumi-refresh/stack-export.json +0 -1907
- package/src/testdata/pulumi-stream/README.md +0 -16
- package/src/testdata/pulumi-stream/preview-stream.ndjson +0 -42
- package/src/testdata/pulumi-stream/up-failed-plunge.ndjson +0 -5
- package/src/testdata/pulumi-unexported/Pulumi.yaml +0 -2
- package/src/testdata/pulumi-urn-node/Pulumi.yaml +0 -7
- package/src/testdata/pulumi-urn-node/README.md +0 -9
- package/src/testdata/pulumi-urn-node/preview.json +0 -2894
- package/src/testdata/pulumi-urn-node/stack-export.json +0 -1919
- package/src/trace-facts.test.ts +0 -38
- package/src/trace-facts.ts +0 -83
- package/src/values.ts +0 -147
- package/src/workspace-kinds.test.ts +0 -47
- package/src/workspace-member.test.ts +0 -127
- package/src/workspace-member.ts +0 -304
|
@@ -1,312 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The stack export as the member's snapshot (#4546).
|
|
3
|
-
*
|
|
4
|
-
* After a successful `up`, the `pulumi-up` capability (`./pulumi-up.ts`)
|
|
5
|
-
* runs `pulumi stack export --stack <s>` (`plunge stack export` on plunge),
|
|
6
|
-
* strips its secrets, and writes it through chant's index store (#4519,
|
|
7
|
-
* `@intentius/chant/lifecycle/snapshot-store`), whose default is
|
|
8
|
-
* `refs/chant/snapshots`. Ruling B on INTENTIUS/plywood#1 put it there:
|
|
9
|
-
* never `chant/lifecycle`, and never the working tree. The graph read
|
|
10
|
-
* (`./workspace-member.ts`) and the member's reads in `./run.ts` take that
|
|
11
|
-
* snapshot, and fall back to a checked-in `stack-export.json` when the store
|
|
12
|
-
* has none, so a member nobody applies through chant reads as before.
|
|
13
|
-
*
|
|
14
|
-
* ## Where it sits in the store
|
|
15
|
-
*
|
|
16
|
-
* One snapshot per environment and stack, at
|
|
17
|
-
* `<env>/<stack>__pulumi-export.json` under the member's ledger prefix
|
|
18
|
-
* (`_members/<member>/` in a workspace, found from the stack's directory).
|
|
19
|
-
* The key is its own, so `chant lifecycle snapshot` of the pulumi lexicon
|
|
20
|
-
* (`<stack>__pulumi`) never overwrites it. The document is a
|
|
21
|
-
* `LifecycleSnapshot` (lexicon `pulumi`, the resources by node key, the
|
|
22
|
-
* stack's outputs under `stackExports`) with the stripped export under
|
|
23
|
-
* `pulumiExport`, so every reader of the snapshot family can list it.
|
|
24
|
-
*
|
|
25
|
-
* ## Secrets
|
|
26
|
-
*
|
|
27
|
-
* The export holds each secret as ciphertext, and `deployment.secrets_providers.state`
|
|
28
|
-
* holds what decrypts it (a passphrase salt, an encrypted data key). Before
|
|
29
|
-
* the store sees it, every secret envelope becomes `"[secret]"`, the string
|
|
30
|
-
* the preview and `stack output` print for one, and the provider's `state`
|
|
31
|
-
* is dropped. A `plaintext` envelope (an export someone took with
|
|
32
|
-
* `--show-secrets`) is blinded the same way, though chant never asks for one.
|
|
33
|
-
*
|
|
34
|
-
* ## Failing
|
|
35
|
-
*
|
|
36
|
-
* The snapshot is derived and safe to lose (snapshot-store.ts's rule), so a
|
|
37
|
-
* failed export or write never fails the apply. The capability's output
|
|
38
|
-
* says what happened (`exportSnapshot`), and the next apply writes it again.
|
|
39
|
-
*/
|
|
40
|
-
import { execFile } from "node:child_process";
|
|
41
|
-
import { promisify } from "node:util";
|
|
42
|
-
import type { SnapshotStore, StorePublish } from "@intentius/chant/lifecycle/snapshot-store";
|
|
43
|
-
import { isPulumiNodeless, pulumiNodeKey } from "@intentius/chant/pulumi-urn";
|
|
44
|
-
import { pulumiExportResources } from "./change-set";
|
|
45
|
-
import { pulumiExportedOutputValues } from "./member-outputs";
|
|
46
|
-
import type { PulumiMemberEngine } from "./member-engine";
|
|
47
|
-
import {
|
|
48
|
-
defaultPlungeRunner,
|
|
49
|
-
defaultPulumiRunner,
|
|
50
|
-
pulumiRunFailure,
|
|
51
|
-
readMemberExport,
|
|
52
|
-
runAllowedPlunge,
|
|
53
|
-
runAllowedPulumi,
|
|
54
|
-
type PulumiRunner,
|
|
55
|
-
} from "./run";
|
|
56
|
-
import { isObject, PULUMI_BLINDED_SECRET, PULUMI_SECRET_SIG, PULUMI_SIG_KEY } from "./values";
|
|
57
|
-
import { PULUMI_EXPORT_FILE } from "./workspace-member";
|
|
58
|
-
|
|
59
|
-
const execFileAsync = promisify(execFile);
|
|
60
|
-
|
|
61
|
-
/** The store key's suffix: `<stack>__pulumi-export`, beside the lexicon snapshot's `<stack>__pulumi`. */
|
|
62
|
-
export const PULUMI_EXPORT_SNAPSHOT_SUFFIX = "pulumi-export";
|
|
63
|
-
|
|
64
|
-
/** The snapshot key for a stack's export. */
|
|
65
|
-
export function pulumiExportSnapshotKey(stack: string): string {
|
|
66
|
-
return `${stack}__${PULUMI_EXPORT_SNAPSHOT_SUFFIX}`;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/** The argv chant runs for the export, after `pulumi` or `plunge`: no `--file`, no `--show-secrets`, no `--version`. */
|
|
70
|
-
export function pulumiStackExportArgs(opts: { stack: string }): string[] {
|
|
71
|
-
return ["stack", "export", "--stack", opts.stack];
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* The export with every secret blinded and the secrets provider's state
|
|
76
|
-
* dropped. Returns a new value; the input is not changed.
|
|
77
|
-
*/
|
|
78
|
-
export function stripPulumiExportSecrets(doc: unknown): unknown {
|
|
79
|
-
const walk = (v: unknown): unknown => {
|
|
80
|
-
if (Array.isArray(v)) return v.map(walk);
|
|
81
|
-
if (!isObject(v)) return v;
|
|
82
|
-
if (v[PULUMI_SIG_KEY] === PULUMI_SECRET_SIG) return PULUMI_BLINDED_SECRET;
|
|
83
|
-
const out: Record<string, unknown> = {};
|
|
84
|
-
for (const [k, x] of Object.entries(v)) out[k] = walk(x);
|
|
85
|
-
return out;
|
|
86
|
-
};
|
|
87
|
-
const stripped = walk(doc);
|
|
88
|
-
const deployment = isObject(stripped) ? stripped.deployment : undefined;
|
|
89
|
-
if (isObject(deployment) && isObject(deployment.secrets_providers)) {
|
|
90
|
-
const { state: _state, ...rest } = deployment.secrets_providers;
|
|
91
|
-
deployment.secrets_providers = rest;
|
|
92
|
-
}
|
|
93
|
-
return stripped;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
/** The snapshot document the store holds. A `LifecycleSnapshot` with the export beside it. */
|
|
97
|
-
export interface PulumiExportSnapshot {
|
|
98
|
-
lexicon: "pulumi";
|
|
99
|
-
environment: string;
|
|
100
|
-
stack: string;
|
|
101
|
-
commit: string;
|
|
102
|
-
timestamp: string;
|
|
103
|
-
resources: Record<string, { type: string; physicalId?: string; status: string }>;
|
|
104
|
-
stackExports?: Record<string, Record<string, unknown>>;
|
|
105
|
-
/** The stripped `pulumi stack export`. */
|
|
106
|
-
pulumiExport: unknown;
|
|
107
|
-
/** The engine that took it. */
|
|
108
|
-
engine: PulumiMemberEngine;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
/** The snapshot for a stripped export. `resources` are keyed by the URN tail the graph uses, providers and the stack left out. */
|
|
112
|
-
export function pulumiExportSnapshot(opts: {
|
|
113
|
-
exported: unknown;
|
|
114
|
-
environment: string;
|
|
115
|
-
stack: string;
|
|
116
|
-
engine: PulumiMemberEngine;
|
|
117
|
-
commit?: string;
|
|
118
|
-
timestamp: string;
|
|
119
|
-
}): PulumiExportSnapshot {
|
|
120
|
-
const resources: PulumiExportSnapshot["resources"] = {};
|
|
121
|
-
for (const r of pulumiExportResources(opts.exported)) {
|
|
122
|
-
if (isPulumiNodeless(r.type)) continue;
|
|
123
|
-
const key = pulumiNodeKey(r.urn);
|
|
124
|
-
if (key === null) continue;
|
|
125
|
-
resources[key] = { type: r.type, ...(typeof r.id === "string" && r.id !== "" ? { physicalId: r.id } : {}), status: "deployed" };
|
|
126
|
-
}
|
|
127
|
-
const outputs = pulumiExportedOutputValues(opts.exported);
|
|
128
|
-
return {
|
|
129
|
-
lexicon: "pulumi",
|
|
130
|
-
environment: opts.environment,
|
|
131
|
-
stack: opts.stack,
|
|
132
|
-
commit: opts.commit ?? "",
|
|
133
|
-
timestamp: opts.timestamp,
|
|
134
|
-
resources,
|
|
135
|
-
...(Object.keys(outputs).length > 0 ? { stackExports: { [opts.stack]: outputs } } : {}),
|
|
136
|
-
pulumiExport: opts.exported,
|
|
137
|
-
engine: opts.engine,
|
|
138
|
-
};
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
/** What writing the export did, for the apply's output. */
|
|
142
|
-
export interface PulumiExportWrite {
|
|
143
|
-
written: boolean;
|
|
144
|
-
/** The store, for messages: `refs/chant/snapshots`, a directory, an s3 URL. */
|
|
145
|
-
where?: string;
|
|
146
|
-
/** `<env>/<stack>__pulumi-export`. */
|
|
147
|
-
key?: string;
|
|
148
|
-
/** The commit or object version the write made. */
|
|
149
|
-
version?: string;
|
|
150
|
-
publish?: StorePublish;
|
|
151
|
-
/** Why nothing was written. */
|
|
152
|
-
reason?: string;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
export interface WritePulumiExportOptions {
|
|
156
|
-
/** The stack's directory. The store and the member's ledger prefix are found from it. */
|
|
157
|
-
dir: string;
|
|
158
|
-
stack: string;
|
|
159
|
-
/** The deploy environment (`DeployContext.env`). */
|
|
160
|
-
environment: string;
|
|
161
|
-
engine: PulumiMemberEngine;
|
|
162
|
-
run?: PulumiRunner;
|
|
163
|
-
plunge?: PulumiRunner;
|
|
164
|
-
/** The store. Default: the project's (`resolveSnapshotStore` from `dir`). `null` writes nothing. */
|
|
165
|
-
store?: SnapshotStore | null;
|
|
166
|
-
/** The time stamped on the snapshot. Default: now. */
|
|
167
|
-
now?: () => Date;
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
async function headCommit(dir: string): Promise<string> {
|
|
171
|
-
try {
|
|
172
|
-
const { stdout } = await execFileAsync("git", ["rev-parse", "HEAD"], { cwd: dir });
|
|
173
|
-
return stdout.trim();
|
|
174
|
-
} catch {
|
|
175
|
-
return "";
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
/** The project's store from `dir`, or null when this chant has no index store or it cannot be built. */
|
|
180
|
-
async function projectStore(dir: string): Promise<SnapshotStore | null> {
|
|
181
|
-
try {
|
|
182
|
-
const mod = (await import("@intentius/chant/lifecycle/snapshot-store")) as { resolveSnapshotStore?: (o: { cwd: string }) => Promise<SnapshotStore> };
|
|
183
|
-
return typeof mod.resolveSnapshotStore === "function" ? await mod.resolveSnapshotStore({ cwd: dir }) : null;
|
|
184
|
-
} catch {
|
|
185
|
-
return null;
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
/**
|
|
190
|
-
* Export the stack, strip its secrets and write it to the store. Never
|
|
191
|
-
* throws: a failure is `written: false` with the reason. With no store, or
|
|
192
|
-
* one that keeps nothing (`none`, the read-only `orphan-branch`), nothing
|
|
193
|
-
* runs.
|
|
194
|
-
*/
|
|
195
|
-
export async function writePulumiExportSnapshot(opts: WritePulumiExportOptions): Promise<PulumiExportWrite> {
|
|
196
|
-
const store = opts.store === undefined ? await projectStore(opts.dir) : opts.store;
|
|
197
|
-
if (store === null) return { written: false, reason: "no index store to write to (#4519), so the export was not taken" };
|
|
198
|
-
if (!store.writable) return { written: false, where: store.where, reason: `the ${store.kind} store keeps no snapshot, so the export was not taken` };
|
|
199
|
-
const args = pulumiStackExportArgs({ stack: opts.stack });
|
|
200
|
-
let stdout: string;
|
|
201
|
-
try {
|
|
202
|
-
({ stdout } =
|
|
203
|
-
opts.engine === "plunge"
|
|
204
|
-
? await runAllowedPlunge(opts.plunge ?? defaultPlungeRunner, args, opts.dir)
|
|
205
|
-
: await runAllowedPulumi(opts.run ?? defaultPulumiRunner, args, opts.dir));
|
|
206
|
-
} catch (err) {
|
|
207
|
-
const f = pulumiRunFailure(err);
|
|
208
|
-
const why = f.missingBinary ? `the ${opts.engine} binary was not found on PATH` : (f.stderr?.trim() || f.message).split("\n").slice(-3).join("\n");
|
|
209
|
-
return { written: false, reason: `${opts.engine} ${args.join(" ")} failed: ${why}` };
|
|
210
|
-
}
|
|
211
|
-
let exported: unknown;
|
|
212
|
-
try {
|
|
213
|
-
exported = JSON.parse(stdout) as unknown;
|
|
214
|
-
} catch {
|
|
215
|
-
return { written: false, reason: `${opts.engine} ${args.join(" ")} printed no JSON` };
|
|
216
|
-
}
|
|
217
|
-
const key = pulumiExportSnapshotKey(opts.stack);
|
|
218
|
-
const snapshot = pulumiExportSnapshot({
|
|
219
|
-
exported: stripPulumiExportSecrets(exported),
|
|
220
|
-
environment: opts.environment,
|
|
221
|
-
stack: opts.stack,
|
|
222
|
-
engine: opts.engine,
|
|
223
|
-
commit: await headCommit(opts.dir),
|
|
224
|
-
timestamp: (opts.now ?? (() => new Date()))().toISOString(),
|
|
225
|
-
});
|
|
226
|
-
const at = { cwd: opts.dir };
|
|
227
|
-
try {
|
|
228
|
-
const result = await store.write(opts.environment, key, `${JSON.stringify(snapshot, null, 2)}\n`, at);
|
|
229
|
-
if (!result.written) return { written: false, where: store.where, key: `${opts.environment}/${key}`, reason: result.reason ?? "the store kept nothing" };
|
|
230
|
-
const publish = await store.publish(at);
|
|
231
|
-
return { written: true, where: store.where, key: `${opts.environment}/${key}`, ...(result.version ? { version: result.version } : {}), publish };
|
|
232
|
-
} catch (err) {
|
|
233
|
-
return { written: false, where: store.where, key: `${opts.environment}/${key}`, reason: err instanceof Error ? err.message : String(err) };
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
/** An export the store holds for a member. */
|
|
238
|
-
export interface StoredPulumiExport {
|
|
239
|
-
/** The stripped export. */
|
|
240
|
-
doc: unknown;
|
|
241
|
-
environment: string;
|
|
242
|
-
stack: string;
|
|
243
|
-
/** `<env>/<stack>__pulumi-export`. */
|
|
244
|
-
key: string;
|
|
245
|
-
where: string;
|
|
246
|
-
timestamp: string;
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
export interface ReadStoredPulumiExportOptions {
|
|
250
|
-
/** The member's directory. The store and the member's ledger prefix are found from it. */
|
|
251
|
-
dir: string;
|
|
252
|
-
/** The member's stack, when known. Without it, the store's export is read only when it holds one stack's. */
|
|
253
|
-
stack?: string;
|
|
254
|
-
/** Read this environment only. Default: the newest export of any environment. */
|
|
255
|
-
environment?: string;
|
|
256
|
-
/** The store. Default: the project's. `null` reads nothing. */
|
|
257
|
-
store?: SnapshotStore | null;
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
/**
|
|
261
|
-
* The newest export the store holds for the member, or undefined when it
|
|
262
|
-
* holds none, holds several stacks' and no stack was named, or cannot be
|
|
263
|
-
* read. Never throws.
|
|
264
|
-
*/
|
|
265
|
-
export async function readStoredPulumiExport(opts: ReadStoredPulumiExportOptions): Promise<StoredPulumiExport | undefined> {
|
|
266
|
-
const store = opts.store === undefined ? await projectStore(opts.dir) : opts.store;
|
|
267
|
-
if (store === null) return undefined;
|
|
268
|
-
const at = { cwd: opts.dir };
|
|
269
|
-
const suffix = `__${PULUMI_EXPORT_SNAPSHOT_SUFFIX}`;
|
|
270
|
-
try {
|
|
271
|
-
const environments = opts.environment ? [opts.environment] : await store.environments(at);
|
|
272
|
-
const found: StoredPulumiExport[] = [];
|
|
273
|
-
for (const environment of environments) {
|
|
274
|
-
const keys = (await store.keys(environment, at)).filter((k) => (opts.stack ? k === pulumiExportSnapshotKey(opts.stack) : k.endsWith(suffix)));
|
|
275
|
-
for (const key of keys) {
|
|
276
|
-
const text = await store.readLatest(environment, key, at);
|
|
277
|
-
if (text === null) continue;
|
|
278
|
-
let snap: Partial<PulumiExportSnapshot>;
|
|
279
|
-
try {
|
|
280
|
-
snap = JSON.parse(text) as Partial<PulumiExportSnapshot>;
|
|
281
|
-
} catch {
|
|
282
|
-
continue;
|
|
283
|
-
}
|
|
284
|
-
if (snap.pulumiExport === undefined) continue;
|
|
285
|
-
const stack = typeof snap.stack === "string" ? snap.stack : key.slice(0, -suffix.length);
|
|
286
|
-
found.push({ doc: snap.pulumiExport, environment, stack, key: `${environment}/${key}`, where: store.where, timestamp: typeof snap.timestamp === "string" ? snap.timestamp : "" });
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
if (found.length === 0) return undefined;
|
|
290
|
-
if (!opts.stack && new Set(found.map((f) => f.stack)).size > 1) return undefined;
|
|
291
|
-
return found.sort((a, b) => (a.timestamp < b.timestamp ? 1 : a.timestamp > b.timestamp ? -1 : 0))[0];
|
|
292
|
-
} catch {
|
|
293
|
-
return undefined;
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
/** Where a member's export came from. */
|
|
298
|
-
export type MemberExportSource = { from: "store"; stored: StoredPulumiExport } | { from: "file"; file: string };
|
|
299
|
-
|
|
300
|
-
/**
|
|
301
|
-
* The member's export: the store's, else the checked-in
|
|
302
|
-
* {@link PULUMI_EXPORT_FILE}. Undefined when neither reads.
|
|
303
|
-
*/
|
|
304
|
-
export async function readMemberExportStored(
|
|
305
|
-
dir: string,
|
|
306
|
-
opts: { stack?: string; environment?: string; store?: SnapshotStore | null } = {},
|
|
307
|
-
): Promise<{ doc: unknown; source: MemberExportSource } | undefined> {
|
|
308
|
-
const stored = await readStoredPulumiExport({ dir, ...opts });
|
|
309
|
-
if (stored) return { doc: stored.doc, source: { from: "store", stored } };
|
|
310
|
-
const doc = readMemberExport(dir);
|
|
311
|
-
return doc === undefined ? undefined : { doc, source: { from: "file", file: PULUMI_EXPORT_FILE } };
|
|
312
|
-
}
|
|
@@ -1,323 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The gated stack operations on core's adapters (#4808), against a fake
|
|
3
|
-
* `pulumi` binary over a local file backend: the export of one version, the
|
|
4
|
-
* live-run check before a cancel, and the check that nothing moved between a
|
|
5
|
-
* move's plan and its write. The fake is a node script written per test that
|
|
6
|
-
* keeps its stacks, history and locks under a temp directory laid out as a
|
|
7
|
-
* file backend (`.pulumi/stacks`, `.pulumi/history`, `.pulumi/locks`); with
|
|
8
|
-
* `cloud` it numbers its updates and exports any of them by `--version`, as
|
|
9
|
-
* Pulumi Cloud does. The ledger is in memory, digesting with chant's own
|
|
10
|
-
* `gatedRequestDigest`.
|
|
11
|
-
*/
|
|
12
|
-
import { chmodSync, existsSync, mkdirSync, mkdtempSync, readdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
13
|
-
import { tmpdir } from "node:os";
|
|
14
|
-
import { join } from "node:path";
|
|
15
|
-
import { describe, expect, test } from "vitest";
|
|
16
|
-
import { gatedRequestDigest, type GatedRequest } from "@intentius/chant/lifecycle/gated-request-digest";
|
|
17
|
-
import type { LiveRun } from "@intentius/chant/state-unlock";
|
|
18
|
-
import { engineRunnerAt, type PulumiRunner } from "./run";
|
|
19
|
-
import { gatedStackCancel, gatedStackExport, gatedStackMove, PulumiStackOpRefused, type GatedRequestApi, type PulumiStackOpCommon } from "./stack-ops";
|
|
20
|
-
|
|
21
|
-
function ledger() {
|
|
22
|
-
const pending: { digest: string; request: GatedRequest }[] = [];
|
|
23
|
-
const approvals = new Map<string, string>();
|
|
24
|
-
const spent = new Set<string>();
|
|
25
|
-
const finished: { digest: string; result: string; detail?: Record<string, unknown> }[] = [];
|
|
26
|
-
const api: GatedRequestApi = {
|
|
27
|
-
async readGatedRequests(op) {
|
|
28
|
-
return pending.map((p) => ({ op, gate: p.request.subject, digest: p.digest, request: p.request, pending: {} as never, approvals: [], ...(spent.has(p.digest) ? { applied: {} as never } : {}) }));
|
|
29
|
-
},
|
|
30
|
-
async requestGate(input) {
|
|
31
|
-
const digest = gatedRequestDigest(input.op, input.request);
|
|
32
|
-
if (spent.has(digest)) return { status: "spent", digest, request: input.request };
|
|
33
|
-
if (!pending.some((p) => p.digest === digest)) pending.push({ digest, request: input.request });
|
|
34
|
-
const by = approvals.get(digest);
|
|
35
|
-
const command = `chant approve ${input.op} ${input.request.subject} --plan ${digest}`;
|
|
36
|
-
if (!by) return { status: "waiting", digest, request: input.request, command };
|
|
37
|
-
if (by === input.request.by) return { status: "refused", digest, request: input.request, by, reason: "the requester's own approval does not count", command };
|
|
38
|
-
return { status: "approved", digest, request: input.request, approval: { version: 1, op: input.op, gate: input.request.subject, resolvedBy: by, timestamp: "2026-11-09T12:00:00Z" } as never };
|
|
39
|
-
},
|
|
40
|
-
async spendGatedRequest(input) {
|
|
41
|
-
spent.add(input.digest);
|
|
42
|
-
return { version: 1, kind: "applied", op: input.op, gate: input.gate, planDigest: input.digest, approvedAt: input.approval.timestamp, approvedBy: input.approval.resolvedBy, timestamp: "2026-11-09T12:01:00Z" };
|
|
43
|
-
},
|
|
44
|
-
async finishGatedRequest(input) {
|
|
45
|
-
finished.push({ digest: input.digest, result: input.result, ...(input.detail ? { detail: input.detail } : {}) });
|
|
46
|
-
return { record: {} as never, pushed: true };
|
|
47
|
-
},
|
|
48
|
-
};
|
|
49
|
-
return { api, pending, approve: (digest: string, by: string) => approvals.set(digest, by), finished, spent };
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
const FAKE = String.raw`
|
|
53
|
-
const fs = require("fs"), path = require("path");
|
|
54
|
-
const root = __ROOT__;
|
|
55
|
-
const cloud = __CLOUD__;
|
|
56
|
-
const a = process.argv.slice(2);
|
|
57
|
-
fs.appendFileSync(path.join(root, "calls.log"), JSON.stringify(a) + "\n");
|
|
58
|
-
const stackOf = () => a[a.indexOf("--stack") + 1];
|
|
59
|
-
const state = (s) => path.join(root, ".pulumi", "stacks", "shop", s + ".json");
|
|
60
|
-
const hist = (s) => path.join(root, ".pulumi", "history", "shop", s);
|
|
61
|
-
const versions = (s) => (fs.existsSync(hist(s)) ? fs.readdirSync(hist(s)).map((f) => Number(f.split(".")[0])).sort((x, y) => x - y) : []);
|
|
62
|
-
const locks = (s) => path.join(root, ".pulumi", "locks", "organization", "shop", s);
|
|
63
|
-
const fail = (m) => { process.stderr.write("error: " + m + "\n"); process.exit(255); };
|
|
64
|
-
const out = (t) => { process.stdout.write(t); process.exit(0); };
|
|
65
|
-
if (a[0] === "stack" && a[1] === "export") {
|
|
66
|
-
const s = stackOf();
|
|
67
|
-
const vi = a.indexOf("--version");
|
|
68
|
-
if (vi >= 0) {
|
|
69
|
-
if (!cloud) fail("the current backend (fake) does not provide the ability to export previous deployments");
|
|
70
|
-
const f = path.join(hist(s), a[vi + 1] + ".json");
|
|
71
|
-
if (!fs.existsSync(f)) fail("no version " + a[vi + 1]);
|
|
72
|
-
out(fs.readFileSync(f, "utf8"));
|
|
73
|
-
}
|
|
74
|
-
if (!fs.existsSync(state(s))) fail("no stack named " + s);
|
|
75
|
-
out(fs.readFileSync(state(s), "utf8"));
|
|
76
|
-
}
|
|
77
|
-
if (a[0] === "stack" && a[1] === "history") {
|
|
78
|
-
const v = versions(stackOf());
|
|
79
|
-
out(JSON.stringify([{ version: cloud && v.length ? v[v.length - 1] : 0, kind: "update", result: "succeeded" }]));
|
|
80
|
-
}
|
|
81
|
-
if (a[0] === "cancel") {
|
|
82
|
-
const d = locks(stackOf());
|
|
83
|
-
if (!fs.existsSync(d) || fs.readdirSync(d).length === 0) fail("no update is in progress");
|
|
84
|
-
// Released locks move aside to released/, so the fake deletes nothing.
|
|
85
|
-
const gone = path.join(root, "released");
|
|
86
|
-
fs.mkdirSync(gone, { recursive: true });
|
|
87
|
-
for (const f of fs.readdirSync(d)) fs.renameSync(path.join(d, f), path.join(gone, f));
|
|
88
|
-
out("The currently running update for '" + stackOf() + "' has been canceled!\n");
|
|
89
|
-
}
|
|
90
|
-
if (a[0] === "preview") {
|
|
91
|
-
const f = path.join(root, "preview", stackOf() + ".json");
|
|
92
|
-
out(fs.existsSync(f) ? fs.readFileSync(f, "utf8") : JSON.stringify({ steps: [], changeSummary: {} }));
|
|
93
|
-
}
|
|
94
|
-
if (a[0] === "state" && a[1] === "move") {
|
|
95
|
-
const src = a[3], dst = a[5], urns = a.slice(7);
|
|
96
|
-
const from = JSON.parse(fs.readFileSync(state(src), "utf8"));
|
|
97
|
-
const to = JSON.parse(fs.readFileSync(state(dst), "utf8"));
|
|
98
|
-
const moving = from.deployment.resources.filter((r) => urns.includes(r.urn));
|
|
99
|
-
from.deployment.resources = from.deployment.resources.filter((r) => !urns.includes(r.urn));
|
|
100
|
-
to.deployment.resources.push(...moving.map((r) => ({ ...r, urn: r.urn.replace("urn:pulumi:" + src + "::", "urn:pulumi:" + dst + "::") })));
|
|
101
|
-
fs.writeFileSync(state(src), JSON.stringify(from));
|
|
102
|
-
fs.writeFileSync(state(dst), JSON.stringify(to));
|
|
103
|
-
for (const s of [src, dst]) fs.writeFileSync(path.join(root, "preview", s + ".json"), JSON.stringify({ steps: [], changeSummary: {} }));
|
|
104
|
-
out("");
|
|
105
|
-
}
|
|
106
|
-
fail("the fake pulumi does not know " + a.join(" "));
|
|
107
|
-
`;
|
|
108
|
-
|
|
109
|
-
const exportDoc = (resources: { urn: string; type: string }[], time = "2026-11-09T10:00:00Z") => JSON.stringify({ version: 3, deployment: { manifest: { time }, resources: resources.map((r) => ({ ...r, custom: true })) } });
|
|
110
|
-
|
|
111
|
-
/** A file backend, a stack directory naming it, and a fake `pulumi` over it. */
|
|
112
|
-
function backend(opts: { cloud?: boolean } = {}) {
|
|
113
|
-
const root = mkdtempSync(join(tmpdir(), "stack-ops-backend-"));
|
|
114
|
-
mkdirSync(join(root, ".pulumi", "stacks", "shop"), { recursive: true });
|
|
115
|
-
mkdirSync(join(root, "preview"));
|
|
116
|
-
writeFileSync(join(root, "calls.log"), "");
|
|
117
|
-
const bin = join(root, "pulumi");
|
|
118
|
-
writeFileSync(bin, `#!/usr/bin/env node\n${FAKE.replace("__ROOT__", JSON.stringify(root)).replace("__CLOUD__", String(opts.cloud === true))}`);
|
|
119
|
-
chmodSync(bin, 0o755);
|
|
120
|
-
const dir = mkdtempSync(join(tmpdir(), "stack-ops-dir-"));
|
|
121
|
-
writeFileSync(join(dir, "Pulumi.yaml"), `name: shop\nruntime: nodejs\nbackend:\n url: file://${root}\n`);
|
|
122
|
-
return {
|
|
123
|
-
root,
|
|
124
|
-
dir,
|
|
125
|
-
run: engineRunnerAt(bin),
|
|
126
|
-
setState: (stack: string, text: string) => writeFileSync(join(root, ".pulumi", "stacks", "shop", `${stack}.json`), text),
|
|
127
|
-
setVersion: (stack: string, n: number, text: string) => {
|
|
128
|
-
mkdirSync(join(root, ".pulumi", "history", "shop", stack), { recursive: true });
|
|
129
|
-
writeFileSync(join(root, ".pulumi", "history", "shop", stack, `${n}.json`), text);
|
|
130
|
-
},
|
|
131
|
-
setPreview: (stack: string, steps: unknown[]) => writeFileSync(join(root, "preview", `${stack}.json`), JSON.stringify({ steps, changeSummary: {} })),
|
|
132
|
-
lock: (stack: string, id: string, timestamp: string) => {
|
|
133
|
-
const d = join(root, ".pulumi", "locks", "organization", "shop", stack);
|
|
134
|
-
mkdirSync(d, { recursive: true });
|
|
135
|
-
writeFileSync(join(d, `${id}.json`), JSON.stringify({ pid: 4242, username: "ci", hostname: "runner-7", timestamp }));
|
|
136
|
-
},
|
|
137
|
-
locks: (stack: string) => {
|
|
138
|
-
const d = join(root, ".pulumi", "locks", "organization", "shop", stack);
|
|
139
|
-
return existsSync(d) ? readdirSync(d) : [];
|
|
140
|
-
},
|
|
141
|
-
calls: (): string[][] =>
|
|
142
|
-
readFileSync(join(root, "calls.log"), "utf-8")
|
|
143
|
-
.split("\n")
|
|
144
|
-
.filter(Boolean)
|
|
145
|
-
.map((l) => JSON.parse(l) as string[]),
|
|
146
|
-
};
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
const outside = (): string => mkdtempSync(join(tmpdir(), "stack-ops-out-"));
|
|
150
|
-
const bucket = (stack: string, name: string) => ({ urn: `urn:pulumi:${stack}::shop::aws:s3/bucketV2:BucketV2::${name}`, type: "aws:s3/bucketV2:BucketV2" });
|
|
151
|
-
|
|
152
|
-
describe("export by version (#4808)", () => {
|
|
153
|
-
test("on a backend that numbers its updates, the request binds the version asked for, and the approved call exports that version", async () => {
|
|
154
|
-
const b = backend({ cloud: true });
|
|
155
|
-
const v = [1, 2, 3].map((n) => exportDoc([bucket("dev", `b${n}`)], `2026-11-0${n}T00:00:00Z`));
|
|
156
|
-
v.forEach((text, i) => b.setVersion("dev", i + 1, text));
|
|
157
|
-
b.setState("dev", v[2]!);
|
|
158
|
-
const l = ledger();
|
|
159
|
-
const out = join(outside(), "dev.v2.json");
|
|
160
|
-
const opts = { by: "alice", rules: { mode: "ledger" as const }, gated: l.api, env: {}, run: b.run, dir: b.dir, stack: "dev", engine: "pulumi" as const, out, version: "2" };
|
|
161
|
-
|
|
162
|
-
const first = await gatedStackExport(opts);
|
|
163
|
-
expect(first.status).toBe("waiting");
|
|
164
|
-
expect(first.request).toMatchObject({ kind: "stack-export", subject: "dev", fields: { version_id: "2" } });
|
|
165
|
-
expect(b.calls().some((c) => c.includes("--version"))).toBe(false);
|
|
166
|
-
expect(existsSync(out)).toBe(false);
|
|
167
|
-
|
|
168
|
-
l.approve(first.digest, "bob");
|
|
169
|
-
const done = await gatedStackExport(opts);
|
|
170
|
-
expect(done).toMatchObject({ status: "done", digest: first.digest, result: { file: out, version: "2", resources: 1 } });
|
|
171
|
-
expect(readFileSync(out, "utf-8")).toBe(v[1]);
|
|
172
|
-
expect(b.calls()).toContainEqual(["stack", "export", "--stack", "dev", "--version", "2"]);
|
|
173
|
-
expect(l.finished[0]).toMatchObject({ result: "applied", detail: { version_id: "2", approved_by: "bob" } });
|
|
174
|
-
|
|
175
|
-
// A version the stack never had is refused before anything is asked.
|
|
176
|
-
await expect(gatedStackExport({ ...opts, version: "9", out: join(outside(), "x.json") })).rejects.toThrow(/has no version 9/);
|
|
177
|
-
expect(l.pending).toHaveLength(1);
|
|
178
|
-
});
|
|
179
|
-
|
|
180
|
-
test("on a file backend the version is the export's digest, so a stack that changed after the approval asks again before writing", async () => {
|
|
181
|
-
const b = backend();
|
|
182
|
-
b.setState("dev", exportDoc([bucket("dev", "a")]));
|
|
183
|
-
const l = ledger();
|
|
184
|
-
const out = join(outside(), "dev.json");
|
|
185
|
-
const opts = { by: "alice", rules: { mode: "ledger" as const }, gated: l.api, env: {}, run: b.run, dir: b.dir, stack: "dev", engine: "pulumi" as const, out };
|
|
186
|
-
|
|
187
|
-
const first = await gatedStackExport(opts);
|
|
188
|
-
expect(first.status).toBe("waiting");
|
|
189
|
-
expect(first.request.fields.version_id).toMatch(/^sha256:[0-9a-f]{64}$/);
|
|
190
|
-
l.approve(first.digest, "bob");
|
|
191
|
-
|
|
192
|
-
// An update lands between the approval and the export: the approval was for the state before it.
|
|
193
|
-
const newer = exportDoc([bucket("dev", "a"), bucket("dev", "b")], "2026-11-09T11:00:00Z");
|
|
194
|
-
b.setState("dev", newer);
|
|
195
|
-
const again = await gatedStackExport(opts);
|
|
196
|
-
expect(again.status).toBe("waiting");
|
|
197
|
-
expect(again.digest).not.toBe(first.digest);
|
|
198
|
-
expect(existsSync(out)).toBe(false);
|
|
199
|
-
expect(l.spent.size).toBe(0);
|
|
200
|
-
|
|
201
|
-
l.approve(again.digest, "bob");
|
|
202
|
-
expect(await gatedStackExport(opts)).toMatchObject({ status: "done", result: { resources: 2 } });
|
|
203
|
-
expect(readFileSync(out, "utf-8")).toBe(newer);
|
|
204
|
-
|
|
205
|
-
// A numbered version on a backend that keeps none is refused before anything is asked.
|
|
206
|
-
await expect(gatedStackExport({ ...opts, version: "2", out: join(outside(), "y.json") })).rejects.toThrow(/has no version 2/);
|
|
207
|
-
});
|
|
208
|
-
});
|
|
209
|
-
|
|
210
|
-
describe("cancel checks the live runs (#4808)", () => {
|
|
211
|
-
const lockedAt = "2026-11-09T10:00:00Z";
|
|
212
|
-
const run = (started: string): LiveRun => ({ id: "77", status: "in_progress", started, url: "https://forge.example/acme/shop/actions/runs/77" });
|
|
213
|
-
|
|
214
|
-
test("a run that began before the lock was taken refuses the release, and nothing is asked", async () => {
|
|
215
|
-
const b = backend();
|
|
216
|
-
b.lock("dev", "lock-1", lockedAt);
|
|
217
|
-
const l = ledger();
|
|
218
|
-
const call = gatedStackCancel({ by: "alice", rules: { mode: "ledger" }, gated: l.api, env: {}, run: b.run, dir: b.dir, stack: "dev", engine: "pulumi", lockId: "lock-1", liveRuns: async () => [run("2026-11-09T09:58:00Z")] });
|
|
219
|
-
await expect(call).rejects.toBeInstanceOf(PulumiStackOpRefused);
|
|
220
|
-
await expect(call).rejects.toMatchObject({ code: "live-run" });
|
|
221
|
-
await expect(call).rejects.toThrow(/run 77 \(in_progress/);
|
|
222
|
-
expect(l.pending).toEqual([]);
|
|
223
|
-
expect(b.locks("dev")).toEqual(["lock-1.json"]);
|
|
224
|
-
});
|
|
225
|
-
|
|
226
|
-
test("with no live run it waits, and once approved runs pulumi cancel and checks the lock file is gone", async () => {
|
|
227
|
-
const b = backend();
|
|
228
|
-
b.lock("dev", "lock-1", lockedAt);
|
|
229
|
-
const l = ledger();
|
|
230
|
-
const opts = { by: "alice", rules: { mode: "ledger" as const }, gated: l.api, env: {}, run: b.run, dir: b.dir, stack: "dev", engine: "pulumi" as const, lockId: "lock-1", liveRuns: async () => [run("2026-11-09T11:00:00Z")] };
|
|
231
|
-
const asked = await gatedStackCancel(opts);
|
|
232
|
-
expect(asked.status).toBe("waiting");
|
|
233
|
-
expect(asked.request).toMatchObject({ kind: "stack-cancel", subject: "dev", fields: { id: "lock-1" } });
|
|
234
|
-
l.approve(asked.digest, "bob");
|
|
235
|
-
const done = await gatedStackCancel(opts);
|
|
236
|
-
expect(done).toMatchObject({ status: "done", result: { lockChecked: true, liveRuns: 1 } });
|
|
237
|
-
expect(b.calls()).toContainEqual(["cancel", "--yes", "--stack", "dev"]);
|
|
238
|
-
expect(b.locks("dev")).toEqual([]);
|
|
239
|
-
expect(l.finished[0]).toMatchObject({ result: "applied", detail: { lock_id: "lock-1", locked_by: "ci@runner-7", locked_at: lockedAt, approved_by: "bob" } });
|
|
240
|
-
});
|
|
241
|
-
|
|
242
|
-
test("a run that comes back after the approval holds the release, and the approval stays unspent", async () => {
|
|
243
|
-
const b = backend();
|
|
244
|
-
b.lock("dev", "lock-1", lockedAt);
|
|
245
|
-
const l = ledger();
|
|
246
|
-
let reads = 0;
|
|
247
|
-
const liveRuns = async () => (++reads >= 3 ? [run("2026-11-09T09:59:00Z")] : []);
|
|
248
|
-
const opts = { by: "alice", rules: { mode: "ledger" as const }, gated: l.api, env: {}, run: b.run, dir: b.dir, stack: "dev", engine: "pulumi" as const, lockId: "lock-1", liveRuns };
|
|
249
|
-
l.approve((await gatedStackCancel(opts)).digest, "bob");
|
|
250
|
-
await expect(gatedStackCancel(opts)).rejects.toMatchObject({ code: "held" });
|
|
251
|
-
expect(l.spent.size).toBe(0);
|
|
252
|
-
expect(b.calls().some((c) => c[0] === "cancel")).toBe(false);
|
|
253
|
-
expect(b.locks("dev")).toEqual(["lock-1.json"]);
|
|
254
|
-
});
|
|
255
|
-
|
|
256
|
-
test("with no runs reader and no forge in the environment, the release is refused: nothing says the holder is gone", async () => {
|
|
257
|
-
const b = backend();
|
|
258
|
-
b.lock("dev", "lock-1", lockedAt);
|
|
259
|
-
const l = ledger();
|
|
260
|
-
await expect(gatedStackCancel({ by: "alice", rules: { mode: "ledger" }, gated: l.api, env: {}, run: b.run, dir: b.dir, stack: "dev", engine: "pulumi", lockId: "lock-1" })).rejects.toThrow(/runs could not be read/);
|
|
261
|
-
expect(l.pending).toEqual([]);
|
|
262
|
-
});
|
|
263
|
-
});
|
|
264
|
-
|
|
265
|
-
describe("move checks nothing moved since its plan (#4808)", () => {
|
|
266
|
-
const logs = (stack: string) => bucket(stack, "logs");
|
|
267
|
-
const step = (op: string, urn: string) => ({ op, urn, type: "aws:s3/bucketV2:BucketV2", provider: "", ...(op === "create" ? { newState: { type: "aws:s3/bucketV2:BucketV2", inputs: {} } } : { oldState: { type: "aws:s3/bucketV2:BucketV2", inputs: {} } }) });
|
|
268
|
-
/** Two stacks on one file backend, net holding the bucket and app's program declaring it. */
|
|
269
|
-
function twoStacks() {
|
|
270
|
-
const b = backend();
|
|
271
|
-
b.setState("net", exportDoc([logs("net"), bucket("net", "keep")]));
|
|
272
|
-
b.setState("app", exportDoc([]));
|
|
273
|
-
b.setPreview("net", [step("delete", logs("net").urn)]);
|
|
274
|
-
b.setPreview("app", [step("create", logs("app").urn)]);
|
|
275
|
-
const appDir = mkdtempSync(join(tmpdir(), "stack-ops-dir-"));
|
|
276
|
-
writeFileSync(join(appDir, "Pulumi.yaml"), readFileSync(join(b.dir, "Pulumi.yaml"), "utf-8"));
|
|
277
|
-
return { b, appDir };
|
|
278
|
-
}
|
|
279
|
-
const common = (l: ReturnType<typeof ledger>, run: PulumiRunner, b: ReturnType<typeof backend>, appDir: string): PulumiStackOpCommon & Parameters<typeof gatedStackMove>[0] => ({
|
|
280
|
-
by: "alice",
|
|
281
|
-
rules: { mode: "ledger" },
|
|
282
|
-
gated: l.api,
|
|
283
|
-
env: {},
|
|
284
|
-
run,
|
|
285
|
-
engine: "pulumi",
|
|
286
|
-
source: { member: "shop/net", dir: b.dir, stack: "net" },
|
|
287
|
-
dest: { member: "shop/app", dir: appDir, stack: "app" },
|
|
288
|
-
urns: [logs("net").urn],
|
|
289
|
-
});
|
|
290
|
-
|
|
291
|
-
test("plans both stacks, waits, moves with pulumi state move, and both preview clean after", async () => {
|
|
292
|
-
const { b, appDir } = twoStacks();
|
|
293
|
-
const l = ledger();
|
|
294
|
-
const opts = common(l, b.run, b, appDir);
|
|
295
|
-
const asked = await gatedStackMove(opts);
|
|
296
|
-
expect(asked.status).toBe("waiting");
|
|
297
|
-
expect(asked.request).toMatchObject({ kind: "stack-move", subject: "move:net:app", fields: { urns: logs("net").urn, proof: expect.stringMatching(/^sha256:/) } });
|
|
298
|
-
expect(b.calls().some((c) => c[0] === "state")).toBe(false);
|
|
299
|
-
l.approve(asked.digest, "bob");
|
|
300
|
-
const done = await gatedStackMove(opts);
|
|
301
|
-
expect(done).toMatchObject({ status: "done", result: { engine: "pulumi", moved: [logs("net").urn] } });
|
|
302
|
-
expect(b.calls().filter((c) => c[0] === "state")).toEqual([["state", "move", "--source", "net", "--dest", "app", "--yes", logs("net").urn]]);
|
|
303
|
-
expect(l.finished[0]).toMatchObject({ result: "applied", detail: { afterNoChange: true, result: "applied", "shop/net.before_digest": expect.stringMatching(/^sha256:/) } });
|
|
304
|
-
});
|
|
305
|
-
|
|
306
|
-
test("a state that changes between the plan and the write refuses the move under the locks, and nothing moves", async () => {
|
|
307
|
-
const { b, appDir } = twoStacks();
|
|
308
|
-
const l = ledger();
|
|
309
|
-
const asked = await gatedStackMove(common(l, b.run, b, appDir));
|
|
310
|
-
l.approve(asked.digest, "bob");
|
|
311
|
-
// The approved call exports both stacks for its plan; an update lands on net before the move reads them again under the locks.
|
|
312
|
-
let exports = 0;
|
|
313
|
-
const racing: PulumiRunner = async (args, o) => {
|
|
314
|
-
if (args[0] === "stack" && args[1] === "export" && ++exports === 3) b.setState("net", exportDoc([logs("net"), bucket("net", "keep"), bucket("net", "new")]));
|
|
315
|
-
return b.run(args, o);
|
|
316
|
-
};
|
|
317
|
-
const moved = await gatedStackMove(common(l, racing, b, appDir));
|
|
318
|
-
expect(moved).toMatchObject({ status: "failed", check: "moved", error: expect.stringMatching(/shop\/net.*changed since the plan/) });
|
|
319
|
-
expect(b.calls().some((c) => c[0] === "state")).toBe(false);
|
|
320
|
-
expect(l.spent.size).toBe(1);
|
|
321
|
-
expect(l.finished[0]).toMatchObject({ result: "failed", detail: { result: "refused", moved: "shop/net" } });
|
|
322
|
-
});
|
|
323
|
-
});
|