@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
package/src/review-stack.test.ts
DELETED
|
@@ -1,254 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Review stacks (INTENTIUS/plywood#15): the three fixed argv, on `pr-<n>`
|
|
3
|
-
* names only, under pulumi and plunge. The runners are fakes, so no binary
|
|
4
|
-
* runs and no backend is written.
|
|
5
|
-
*/
|
|
6
|
-
import { chmodSync, mkdtempSync, readFileSync, writeFileSync } from "node:fs";
|
|
7
|
-
import { tmpdir } from "node:os";
|
|
8
|
-
import { join } from "node:path";
|
|
9
|
-
import { describe, expect, test } from "vitest";
|
|
10
|
-
import { tearDownPrEnvironment, type LivePrEnvironment } from "@intentius/chant/components/pr-environment";
|
|
11
|
-
import {
|
|
12
|
-
initReviewStack,
|
|
13
|
-
parseReviewStackLocation,
|
|
14
|
-
prNumberOf,
|
|
15
|
-
pulumiTemplateStack,
|
|
16
|
-
removeReviewStack,
|
|
17
|
-
reviewConfigSource,
|
|
18
|
-
reviewStackFor,
|
|
19
|
-
reviewStackLocation,
|
|
20
|
-
reviewStackTeardown,
|
|
21
|
-
REVIEW_STACK_TEARDOWN,
|
|
22
|
-
} from "./review-stack";
|
|
23
|
-
import { pulumiPlugin } from "./plugin";
|
|
24
|
-
import {
|
|
25
|
-
engineRunnerAt,
|
|
26
|
-
allowedReviewStack,
|
|
27
|
-
isReviewStackName,
|
|
28
|
-
reviewStackDestroyArgs,
|
|
29
|
-
reviewStackInitArgs,
|
|
30
|
-
reviewStackRmArgs,
|
|
31
|
-
runAllowedPlunge,
|
|
32
|
-
runAllowedPulumi,
|
|
33
|
-
runReviewStackPlunge,
|
|
34
|
-
runReviewStackPulumi,
|
|
35
|
-
type PulumiRunner,
|
|
36
|
-
} from "./run";
|
|
37
|
-
|
|
38
|
-
function fake(fail: Record<string, string> = {}) {
|
|
39
|
-
const calls: string[][] = [];
|
|
40
|
-
const run: PulumiRunner = async (args) => {
|
|
41
|
-
calls.push(args);
|
|
42
|
-
const key = args.slice(0, 2).join(" ");
|
|
43
|
-
if (fail[key]) throw Object.assign(new Error("exit 255"), { stderr: fail[key], code: 255 });
|
|
44
|
-
return { stdout: "" };
|
|
45
|
-
};
|
|
46
|
-
return { run, calls };
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
describe("review stack names", () => {
|
|
50
|
-
test("pr-<n>, with an optional suffix and an organization and project in front", () => {
|
|
51
|
-
for (const ok of ["pr-12", "pr-12-shop", "shop/pr-3", "acme/shop/pr-3"]) expect(isReviewStackName(ok), ok).toBe(true);
|
|
52
|
-
for (const no of ["prod", "pr-", "pr-x", "PR-12", "dev-pr-12", "a/b/c/pr-1", "pr-12/x", "-pr-1", ""]) expect(isReviewStackName(no), no).toBe(false);
|
|
53
|
-
});
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
describe("the review stack argv", () => {
|
|
57
|
-
test("the builders give the allowed forms", () => {
|
|
58
|
-
expect(allowedReviewStack(reviewStackInitArgs({ stack: "pr-12", copyConfigFrom: "dev" }))).toBe(true);
|
|
59
|
-
expect(allowedReviewStack(reviewStackInitArgs({ stack: "pr-12" }))).toBe(true);
|
|
60
|
-
expect(allowedReviewStack(reviewStackDestroyArgs({ stack: "pr-12" }))).toBe(true);
|
|
61
|
-
expect(allowedReviewStack(reviewStackRmArgs({ stack: "pr-12" }))).toBe(true);
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
test("refuses any other stack, flag or order", async () => {
|
|
65
|
-
const { run, calls } = fake();
|
|
66
|
-
for (const args of [
|
|
67
|
-
["destroy", "--yes", "--json", "--stack", "prod"],
|
|
68
|
-
["destroy", "--yes", "--json", "--stack", "pr-12", "--target", "urn:pulumi:x"],
|
|
69
|
-
["stack", "rm", "--yes", "--force", "--stack", "pr-12"],
|
|
70
|
-
["stack", "rm", "--yes", "--stack", "dev"],
|
|
71
|
-
["stack", "init", "prod", "--no-select"],
|
|
72
|
-
["stack", "init", "pr-1", "--no-select", "--copy-config-from", "pr-1"],
|
|
73
|
-
["stack", "init", "pr-1"],
|
|
74
|
-
["up", "--yes", "--json", "--stack", "pr-1"],
|
|
75
|
-
]) {
|
|
76
|
-
await expect(runReviewStackPulumi(run, args, "/tmp")).rejects.toThrow(/only review stacks/);
|
|
77
|
-
await expect(runReviewStackPlunge(run, args, "/tmp")).rejects.toThrow(/only review stacks/);
|
|
78
|
-
}
|
|
79
|
-
expect(calls).toEqual([]);
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
test("the read entry points still refuse all three", async () => {
|
|
83
|
-
const { run } = fake();
|
|
84
|
-
for (const args of [reviewStackInitArgs({ stack: "pr-1" }), reviewStackDestroyArgs({ stack: "pr-1" }), reviewStackRmArgs({ stack: "pr-1" })]) {
|
|
85
|
-
await expect(runAllowedPulumi(run, args, "/tmp")).rejects.toThrow();
|
|
86
|
-
await expect(runAllowedPlunge(run, args, "/tmp")).rejects.toThrow();
|
|
87
|
-
}
|
|
88
|
-
});
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
describe("initReviewStack and removeReviewStack", () => {
|
|
92
|
-
test("creates from the template's config, and an existing stack is found", async () => {
|
|
93
|
-
const a = fake();
|
|
94
|
-
expect(await initReviewStack({ dir: "/w", stack: "pr-7", template: "dev", run: a.run })).toEqual({ stack: "pr-7", status: "created" });
|
|
95
|
-
expect(a.calls).toEqual([["stack", "init", "pr-7", "--no-select", "--copy-config-from", "dev"]]);
|
|
96
|
-
const b = fake({ "stack init": "error: stack 'pr-7' already exists" });
|
|
97
|
-
expect(await initReviewStack({ dir: "/w", stack: "pr-7", template: "dev", run: b.run })).toEqual({ stack: "pr-7", status: "exists" });
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
test("destroys, then removes; a stack already gone is absent", async () => {
|
|
101
|
-
const a = fake();
|
|
102
|
-
expect(await removeReviewStack({ dir: "/w", stack: "pr-7", engine: "plunge", run: a.run })).toEqual({ stack: "pr-7", status: "removed" });
|
|
103
|
-
expect(a.calls).toEqual([
|
|
104
|
-
["destroy", "--yes", "--json", "--stack", "pr-7"],
|
|
105
|
-
["stack", "rm", "--yes", "--stack", "pr-7"],
|
|
106
|
-
]);
|
|
107
|
-
const b = fake({ "destroy --yes": "error: no stack named 'pr-7' found" });
|
|
108
|
-
expect(await removeReviewStack({ dir: "/w", stack: "pr-7", run: b.run })).toEqual({ stack: "pr-7", status: "absent" });
|
|
109
|
-
expect(b.calls).toHaveLength(1);
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
test("refuses a name that is not a review stack before running anything", async () => {
|
|
113
|
-
const a = fake();
|
|
114
|
-
await expect(removeReviewStack({ dir: "/w", stack: "prod", run: a.run })).rejects.toThrow(/not a review stack/);
|
|
115
|
-
await expect(initReviewStack({ dir: "/w", stack: "staging", template: "dev", run: a.run })).rejects.toThrow(/not a review stack/);
|
|
116
|
-
expect(a.calls).toEqual([]);
|
|
117
|
-
});
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
// ── #4609: the pull request environment ─────────────────────────────────────
|
|
121
|
-
|
|
122
|
-
describe("the review stack of a pull request's environment (#4609)", () => {
|
|
123
|
-
test("pr-<n> replaces the step's own stack name, keeping its organization and project", () => {
|
|
124
|
-
expect(prNumberOf("pr-12")).toBe(12);
|
|
125
|
-
for (const no of ["prod", "pr-0", "pr-x", "pr-12-a", undefined]) expect(prNumberOf(no), String(no)).toBeUndefined();
|
|
126
|
-
expect(reviewStackFor("dev", "pr-12")).toBe("pr-12");
|
|
127
|
-
expect(reviewStackFor("acme/shop/dev", "pr-12")).toBe("acme/shop/pr-12");
|
|
128
|
-
expect(reviewStackFor("dev", "pr-12", "web")).toBe("pr-12-web");
|
|
129
|
-
expect(reviewStackFor("dev", "prod")).toBeUndefined();
|
|
130
|
-
expect(() => reviewStackFor("dev", "pr-12", "Web_1")).toThrow(/reviewSuffix/);
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
test("a <project>/<stack> template names a Pulumi stack; a plain name or a review stack does not", () => {
|
|
134
|
-
expect(pulumiTemplateStack("shop/dev")).toEqual({ project: "shop", stack: "dev" });
|
|
135
|
-
expect(pulumiTemplateStack("acme/shop/dev")).toEqual({ org: "acme", project: "shop", stack: "dev" });
|
|
136
|
-
for (const no of ["staging", "a/b/c/d", "shop/pr-3", "shop/", "/dev", undefined]) expect(pulumiTemplateStack(no), String(no)).toBeUndefined();
|
|
137
|
-
expect(pulumiPlugin.prEnvTemplate!("shop/dev")).toBe("the Pulumi stack shop/dev");
|
|
138
|
-
expect(pulumiPlugin.prEnvTemplate!("staging")).toBeUndefined();
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
test("the config comes from the template's stack in its own project, else from the step's own stack", () => {
|
|
142
|
-
expect(reviewConfigSource({ stack: "dev", project: "shop" }, "shop/staging", "pr-12")).toBe("staging");
|
|
143
|
-
expect(reviewConfigSource({ stack: "acme/shop/dev", project: "shop" }, "shop/staging", "acme/shop/pr-12")).toBe("acme/shop/staging");
|
|
144
|
-
expect(reviewConfigSource({ stack: "dev", project: "shop" }, "acme/shop/staging", "pr-12")).toBe("acme/shop/staging");
|
|
145
|
-
// Another project's template, or a chant environment name: the step's own stack.
|
|
146
|
-
expect(reviewConfigSource({ stack: "dev", project: "api" }, "shop/staging", "pr-12")).toBe("dev");
|
|
147
|
-
expect(reviewConfigSource({ stack: "dev", project: "shop" }, "staging", "pr-12")).toBe("dev");
|
|
148
|
-
expect(reviewConfigSource({ stack: "pr-12", project: "shop" }, undefined, "pr-12")).toBeUndefined();
|
|
149
|
-
});
|
|
150
|
-
|
|
151
|
-
test("a location reads back as engine, directory and stack", () => {
|
|
152
|
-
expect(reviewStackLocation("plunge", "infra/site", "pr-12")).toBe("plunge:infra/site#pr-12");
|
|
153
|
-
expect(parseReviewStackLocation("plunge:infra/site#pr-12")).toEqual({ engine: "plunge", dir: "infra/site", stack: "pr-12" });
|
|
154
|
-
for (const no of ["infra/site#pr-12", "tofu:x#pr-1", "pulumi:x", "pulumi:#pr-1"]) expect(parseReviewStackLocation(no), no).toBeUndefined();
|
|
155
|
-
});
|
|
156
|
-
});
|
|
157
|
-
|
|
158
|
-
function live(over: Partial<LivePrEnvironment> = {}): LivePrEnvironment {
|
|
159
|
-
return {
|
|
160
|
-
pr: 12,
|
|
161
|
-
env: "pr-12",
|
|
162
|
-
template: "shop/dev",
|
|
163
|
-
marker: { stack: "shop", env: "pr-12" },
|
|
164
|
-
commit: "a".repeat(40),
|
|
165
|
-
components: ["site"],
|
|
166
|
-
applied: "2026-10-27T10:00:00.000Z",
|
|
167
|
-
expiresAt: "2026-10-30T10:00:00.000Z",
|
|
168
|
-
...over,
|
|
169
|
-
};
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
describe("the review stack teardown (#4609)", () => {
|
|
173
|
-
test("pr-env down destroys and removes each review stack the record names, through core's ownership check", async () => {
|
|
174
|
-
const pulumi = fake();
|
|
175
|
-
const plunge = fake();
|
|
176
|
-
const adapter = reviewStackTeardown({ cwd: "/work", run: pulumi.run, plunge: plunge.run });
|
|
177
|
-
const torn = await tearDownPrEnvironment({
|
|
178
|
-
pr: 12,
|
|
179
|
-
live: live({ components: ["site", "api"], locations: { site: "pulumi:infra/site#pr-12, pulumi:infra/edge#pr-12-edge", api: "plunge:api#acme/api/pr-12" } }),
|
|
180
|
-
adapters: [adapter],
|
|
181
|
-
});
|
|
182
|
-
if ("refusal" in torn) throw new Error(torn.refusal);
|
|
183
|
-
expect(torn.report.outcomes.map((o) => [o.lexicon, o.name, o.outcome])).toEqual(
|
|
184
|
-
expect.arrayContaining([
|
|
185
|
-
[REVIEW_STACK_TEARDOWN, "infra/site#pr-12", "deleted"],
|
|
186
|
-
[REVIEW_STACK_TEARDOWN, "infra/edge#pr-12-edge", "deleted"],
|
|
187
|
-
[REVIEW_STACK_TEARDOWN, "api#acme/api/pr-12", "deleted"],
|
|
188
|
-
]),
|
|
189
|
-
);
|
|
190
|
-
expect(torn.dropped).toBe(0);
|
|
191
|
-
// The teardown plan orders its entries by name (lifecycle/teardown.ts), so infra/edge comes first.
|
|
192
|
-
expect(pulumi.calls).toEqual([
|
|
193
|
-
["destroy", "--yes", "--json", "--stack", "pr-12-edge"],
|
|
194
|
-
["stack", "rm", "--yes", "--stack", "pr-12-edge"],
|
|
195
|
-
["destroy", "--yes", "--json", "--stack", "pr-12"],
|
|
196
|
-
["stack", "rm", "--yes", "--stack", "pr-12"],
|
|
197
|
-
]);
|
|
198
|
-
expect(plunge.calls).toEqual([
|
|
199
|
-
["destroy", "--yes", "--json", "--stack", "acme/api/pr-12"],
|
|
200
|
-
["stack", "rm", "--yes", "--stack", "acme/api/pr-12"],
|
|
201
|
-
]);
|
|
202
|
-
});
|
|
203
|
-
|
|
204
|
-
test("a stack of another name, another pull request or outside the project is a hole, and nothing runs for it", async () => {
|
|
205
|
-
const pulumi = fake();
|
|
206
|
-
const adapter = reviewStackTeardown({ cwd: "/work", run: pulumi.run });
|
|
207
|
-
const found = await adapter.owned({
|
|
208
|
-
environment: "pr-12",
|
|
209
|
-
marker: { stack: "shop", env: "pr-12" },
|
|
210
|
-
live: live({ locations: { a: "pulumi:infra#prod", b: "pulumi:infra#pr-13", c: "pulumi:../elsewhere#pr-12", d: "pulumi:/abs#pr-12", e: "not a location", f: "terraform-key-x" } }),
|
|
211
|
-
});
|
|
212
|
-
expect(found.candidates).toEqual([]);
|
|
213
|
-
expect(found.holes?.map((h) => h.name).sort()).toEqual(["a: pulumi:infra#prod", "b: pulumi:infra#pr-13", "c: pulumi:../elsewhere#pr-12", "d: pulumi:/abs#pr-12"]);
|
|
214
|
-
// A location another adapter wrote (no pulumi: or plunge: prefix) is not this teardown's.
|
|
215
|
-
expect(found.holes?.some((h) => h.name.startsWith("f:"))).toBe(false);
|
|
216
|
-
const torn = await tearDownPrEnvironment({ pr: 12, live: live({ locations: { a: "pulumi:infra#prod" } }), adapters: [reviewStackTeardown({ cwd: "/work", run: pulumi.run })] });
|
|
217
|
-
if ("refusal" in torn) throw new Error(torn.refusal);
|
|
218
|
-
expect(torn.report.plan.holes.length).toBe(1);
|
|
219
|
-
expect(pulumi.calls).toEqual([]);
|
|
220
|
-
});
|
|
221
|
-
|
|
222
|
-
test("a stack already gone counts as deleted, and a failed destroy as failed", async () => {
|
|
223
|
-
const gone = fake({ "destroy --yes": "error: no stack named 'pr-12' found" });
|
|
224
|
-
const adapter = reviewStackTeardown({ cwd: "/work", run: gone.run });
|
|
225
|
-
const found = await adapter.owned({ environment: "pr-12", marker: { stack: "shop", env: "pr-12" }, live: live({ locations: { site: "pulumi:infra#pr-12" } }) });
|
|
226
|
-
const done = await adapter.teardown({ environment: "pr-12", marker: { stack: "shop", env: "pr-12" }, live: live(), candidates: found.candidates });
|
|
227
|
-
expect(done.outcomes).toEqual([{ name: "infra#pr-12", outcome: "deleted", detail: "the stack was already gone" }]);
|
|
228
|
-
const broken = fake({ "destroy --yes": "error: the update failed" });
|
|
229
|
-
const a2 = reviewStackTeardown({ cwd: "/work", run: broken.run });
|
|
230
|
-
const f2 = await a2.owned({ environment: "pr-12", marker: { stack: "shop", env: "pr-12" }, live: live({ locations: { site: "pulumi:infra#pr-12" } }) });
|
|
231
|
-
const d2 = await a2.teardown({ environment: "pr-12", marker: { stack: "shop", env: "pr-12" }, live: live(), candidates: f2.candidates });
|
|
232
|
-
expect(d2.outcomes[0]).toMatchObject({ name: "infra#pr-12", outcome: "failed" });
|
|
233
|
-
});
|
|
234
|
-
|
|
235
|
-
test("against a fake pulumi binary, the teardown runs exactly destroy then stack rm in the program's directory", async () => {
|
|
236
|
-
const root = mkdtempSync(join(tmpdir(), "review-stack-bin-"));
|
|
237
|
-
const bin = join(root, "pulumi");
|
|
238
|
-
const log = join(root, "calls.log");
|
|
239
|
-
writeFileSync(bin, `#!/bin/sh\necho "$PWD|$*" >> "$FAKE_PULUMI_LOG"\nexit 0\n`);
|
|
240
|
-
chmodSync(bin, 0o755);
|
|
241
|
-
const adapter = reviewStackTeardown({ cwd: root, run: engineRunnerAt(bin), env: { FAKE_PULUMI_LOG: log, PULUMI_BACKEND_URL: `file://${root}`, PULUMI_SKIP_UPDATE_CHECK: "true" } });
|
|
242
|
-
const torn = await tearDownPrEnvironment({ pr: 12, live: live({ locations: { site: "pulumi:.#pr-12" } }), adapters: [adapter] });
|
|
243
|
-
if ("refusal" in torn) throw new Error(torn.refusal);
|
|
244
|
-
expect(torn.report.outcomes.map((o) => o.outcome)).toEqual(["deleted"]);
|
|
245
|
-
const lines = readFileSync(log, "utf-8").trim().split("\n");
|
|
246
|
-
expect(lines.map((l) => l.split("|")[1])).toEqual(["destroy --yes --json --stack pr-12", "stack rm --yes --stack pr-12"]);
|
|
247
|
-
});
|
|
248
|
-
|
|
249
|
-
test("the plugin gives core the teardown, under a name apart from the lexicon's", () => {
|
|
250
|
-
const adapter = pulumiPlugin.prEnvTeardown!({ cwd: "/work" });
|
|
251
|
-
expect(adapter?.name).toBe(REVIEW_STACK_TEARDOWN);
|
|
252
|
-
expect(adapter?.name).not.toBe(pulumiPlugin.name);
|
|
253
|
-
});
|
|
254
|
-
});
|
package/src/review-stack.ts
DELETED
|
@@ -1,266 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Review stacks (INTENTIUS/plywood#15): `pr-<n>` stacks made from a
|
|
3
|
-
* template stack's config and removed when their pull request closes or
|
|
4
|
-
* their TTL passes. These run the three fixed forms of
|
|
5
|
-
* `PULUMI_REVIEW_STACK_COMMANDS` (`./run.ts`), on review stack names only,
|
|
6
|
-
* so nothing here can touch any other stack.
|
|
7
|
-
*
|
|
8
|
-
* - {@link initReviewStack}: `stack init <pr-stack> --no-select
|
|
9
|
-
* --copy-config-from <template>`. A stack that already exists is not an
|
|
10
|
-
* error: the next preview and `up` update it.
|
|
11
|
-
* - {@link removeReviewStack}: `destroy --yes --json --stack <pr-stack>`,
|
|
12
|
-
* then `stack rm --yes --stack <pr-stack>`. A stack that is already gone
|
|
13
|
-
* is not an error, so a sweep that runs twice removes nothing twice.
|
|
14
|
-
*
|
|
15
|
-
* Who decides when they run is chant core's pull request environment
|
|
16
|
-
* (`ci.prEnvironment`, its records on the workspace ledger and its TTL
|
|
17
|
-
* sweep); these are the engine half only (#4609):
|
|
18
|
-
*
|
|
19
|
-
* - under `pr-<n>`, `pulumi-up` applies {@link reviewStackFor}'s stack,
|
|
20
|
-
* runs {@link initReviewStack} from {@link reviewConfigSource} before its
|
|
21
|
-
* first preview, and gives core the stack's location
|
|
22
|
-
* ({@link reviewStackLocation}) for the environment's record;
|
|
23
|
-
* - `pr-env down` and the sweep run {@link reviewStackTeardown} over the
|
|
24
|
-
* record's locations;
|
|
25
|
-
* - the plugin's `prEnvTemplate` takes a `<project>/<stack>` template
|
|
26
|
-
* ({@link pulumiTemplateStack}), so plywood's template needs no
|
|
27
|
-
* chant.config.ts environment of that name.
|
|
28
|
-
*/
|
|
29
|
-
import { isAbsolute, relative, resolve } from "node:path";
|
|
30
|
-
import {
|
|
31
|
-
defaultPlungeRunner,
|
|
32
|
-
defaultPulumiRunner,
|
|
33
|
-
isReviewStackName,
|
|
34
|
-
pulumiRunFailure,
|
|
35
|
-
reviewStackDestroyArgs,
|
|
36
|
-
reviewStackInitArgs,
|
|
37
|
-
reviewStackRmArgs,
|
|
38
|
-
runReviewStackPlunge,
|
|
39
|
-
runReviewStackPulumi,
|
|
40
|
-
type PulumiRunner,
|
|
41
|
-
} from "./run";
|
|
42
|
-
import type { PulumiMemberEngine } from "./member-engine";
|
|
43
|
-
import type { PrEnvTeardownAdapter } from "@intentius/chant/components/pr-environment";
|
|
44
|
-
import type { TeardownCandidate, TeardownHole, TeardownOutcome } from "@intentius/chant/lexicon";
|
|
45
|
-
|
|
46
|
-
export interface ReviewStackOptions {
|
|
47
|
-
/** The program's directory, where `Pulumi.yaml` is. */
|
|
48
|
-
dir: string;
|
|
49
|
-
/** The review stack, `pr-<n>` (or `pr-<n>-<suffix>`). */
|
|
50
|
-
stack: string;
|
|
51
|
-
engine?: PulumiMemberEngine;
|
|
52
|
-
/** Injected for tests; default the engine's binary. */
|
|
53
|
-
run?: PulumiRunner;
|
|
54
|
-
env?: Record<string, string>;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
export interface ReviewStackOutcome {
|
|
58
|
-
stack: string;
|
|
59
|
-
/** `created`, or `exists` when the stack was there already; `removed`, or `absent` when it was gone. */
|
|
60
|
-
status: "created" | "exists" | "removed" | "absent";
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
const ALREADY = /already exists/i;
|
|
64
|
-
const MISSING = /no stack named|not found|does not exist/i;
|
|
65
|
-
|
|
66
|
-
function runner(opts: ReviewStackOptions): (args: string[]) => Promise<{ stdout: string }> {
|
|
67
|
-
const plunge = opts.engine === "plunge";
|
|
68
|
-
const run = opts.run ?? (plunge ? defaultPlungeRunner : defaultPulumiRunner);
|
|
69
|
-
return (args) => (plunge ? runReviewStackPlunge : runReviewStackPulumi)(run, args, opts.dir, opts.env);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
function said(err: unknown): string {
|
|
73
|
-
const f = pulumiRunFailure(err);
|
|
74
|
-
return [f.stderr, f.stdout, f.message].filter(Boolean).join("\n");
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
function refuseName(stack: string): void {
|
|
78
|
-
if (!isReviewStackName(stack)) throw new Error(`"${stack}" is not a review stack name (pr-<n>); chant creates and removes review stacks only`);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/** Create the review stack from `template`'s config, or find it there already. */
|
|
82
|
-
export async function initReviewStack(opts: ReviewStackOptions & { template?: string }): Promise<ReviewStackOutcome> {
|
|
83
|
-
refuseName(opts.stack);
|
|
84
|
-
try {
|
|
85
|
-
await runner(opts)(reviewStackInitArgs({ stack: opts.stack, ...(opts.template ? { copyConfigFrom: opts.template } : {}) }));
|
|
86
|
-
return { stack: opts.stack, status: "created" };
|
|
87
|
-
} catch (err) {
|
|
88
|
-
if (ALREADY.test(said(err))) return { stack: opts.stack, status: "exists" };
|
|
89
|
-
throw err;
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
/** Destroy the review stack's resources and remove it, or find it gone already. */
|
|
94
|
-
export async function removeReviewStack(opts: ReviewStackOptions): Promise<ReviewStackOutcome> {
|
|
95
|
-
refuseName(opts.stack);
|
|
96
|
-
const run = runner(opts);
|
|
97
|
-
try {
|
|
98
|
-
await run(reviewStackDestroyArgs({ stack: opts.stack }));
|
|
99
|
-
} catch (err) {
|
|
100
|
-
if (MISSING.test(said(err))) return { stack: opts.stack, status: "absent" };
|
|
101
|
-
throw err;
|
|
102
|
-
}
|
|
103
|
-
await run(reviewStackRmArgs({ stack: opts.stack }));
|
|
104
|
-
return { stack: opts.stack, status: "removed" };
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
// ── the pull request environment (#4609) ────────────────────────────────────
|
|
108
|
-
|
|
109
|
-
/** A pull request's environment name, `pr-<n>`, as chant core names it. */
|
|
110
|
-
const PR_ENV = /^pr-([1-9][0-9]*)$/;
|
|
111
|
-
|
|
112
|
-
/** A review stack suffix: lowercase letters, digits and `-`, as {@link REVIEW_STACK_NAME} takes it. */
|
|
113
|
-
const SUFFIX = /^[a-z0-9][a-z0-9-]*$/;
|
|
114
|
-
|
|
115
|
-
/** A Pulumi organization, project or stack segment. */
|
|
116
|
-
const SEGMENT = /^[A-Za-z0-9][A-Za-z0-9._-]*$/;
|
|
117
|
-
|
|
118
|
-
/** The pull request number of `pr-<n>`, or undefined for any other environment. */
|
|
119
|
-
export function prNumberOf(env: string | undefined): number | undefined {
|
|
120
|
-
const m = typeof env === "string" ? PR_ENV.exec(env) : null;
|
|
121
|
-
return m ? Number(m[1]) : undefined;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
/**
|
|
125
|
-
* The review stack a `pulumi-up` step applies in pull request environment
|
|
126
|
-
* `env` (#4609): the step's stack with its last segment replaced by `env`
|
|
127
|
-
* (and `-<suffix>` when given), so `acme/shop/dev` in `pr-12` is
|
|
128
|
-
* `acme/shop/pr-12`. Undefined outside a pull request's environment.
|
|
129
|
-
*/
|
|
130
|
-
export function reviewStackFor(stack: string, env: string | undefined, suffix?: string): string | undefined {
|
|
131
|
-
if (prNumberOf(env) === undefined) return undefined;
|
|
132
|
-
if (suffix !== undefined && !SUFFIX.test(suffix)) throw new Error(`pulumi-up: reviewSuffix "${suffix}" is not lowercase letters, digits and "-"`);
|
|
133
|
-
const parts = stack.split("/");
|
|
134
|
-
const name = suffix ? `${env}-${suffix}` : env!;
|
|
135
|
-
const review = [...parts.slice(0, -1), name].join("/");
|
|
136
|
-
if (!isReviewStackName(review)) throw new Error(`pulumi-up: the review stack for "${stack}" in ${env} would be "${review}", which is not a review stack name`);
|
|
137
|
-
return review;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
/**
|
|
141
|
-
* Whether `template` (`ci.prEnvironment.template`) names a Pulumi stack:
|
|
142
|
-
* `<project>/<stack>`, as plywood's `review_stacks.template` is, or
|
|
143
|
-
* `<org>/<project>/<stack>`. The parts, or undefined for any other form,
|
|
144
|
-
* which is then a chant.config.ts environment as before.
|
|
145
|
-
*/
|
|
146
|
-
export function pulumiTemplateStack(template: string | undefined): { org?: string; project: string; stack: string } | undefined {
|
|
147
|
-
if (typeof template !== "string") return undefined;
|
|
148
|
-
const parts = template.split("/");
|
|
149
|
-
if (parts.length < 2 || parts.length > 3 || !parts.every((p) => SEGMENT.test(p))) return undefined;
|
|
150
|
-
if (isReviewStackName(template)) return undefined;
|
|
151
|
-
return parts.length === 3 ? { org: parts[0]!, project: parts[1]!, stack: parts[2]! } : { project: parts[0]!, stack: parts[1]! };
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
/**
|
|
155
|
-
* The stack a review stack copies its config from (`--copy-config-from`):
|
|
156
|
-
* the template's stack when the template names a stack of this project
|
|
157
|
-
* (`project`, `Pulumi.yaml`'s name), else the step's own stack, which is the
|
|
158
|
-
* stack the template environment applies. Never the review stack itself.
|
|
159
|
-
*/
|
|
160
|
-
export function reviewConfigSource(step: { stack: string; project?: string }, template: string | undefined, review: string): string | undefined {
|
|
161
|
-
const named = pulumiTemplateStack(template);
|
|
162
|
-
let from = step.stack;
|
|
163
|
-
if (named && step.project !== undefined && named.project === step.project) {
|
|
164
|
-
// A two-part template is project/stack, which Pulumi would read as org/stack: keep the step's own prefix.
|
|
165
|
-
from = named.org ? template! : [...step.stack.split("/").slice(0, -1), named.stack].join("/");
|
|
166
|
-
}
|
|
167
|
-
return from === review ? undefined : from;
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
/** A review stack's location on the environment's record: `<engine>:<dir>#<stack>`, `dir` relative to the project root. */
|
|
171
|
-
export function reviewStackLocation(engine: PulumiMemberEngine, dir: string, stack: string): string {
|
|
172
|
-
return `${engine}:${dir.split("\\").join("/") || "."}#${stack}`;
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
/** A location {@link reviewStackLocation} wrote, read back, or undefined when it does not read. */
|
|
176
|
-
export function parseReviewStackLocation(location: string): { engine: PulumiMemberEngine; dir: string; stack: string } | undefined {
|
|
177
|
-
const m = /^(pulumi|plunge):([^#]+)#([^#\s]+)$/.exec(location.trim());
|
|
178
|
-
return m ? { engine: m[1] as PulumiMemberEngine, dir: m[2]!, stack: m[3]! } : undefined;
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
/** The name `pr-env down` attributes review stack outcomes to; distinct from the lexicon's own, as core requires. */
|
|
182
|
-
export const REVIEW_STACK_TEARDOWN = "pulumi-review-stacks";
|
|
183
|
-
|
|
184
|
-
/** The candidate type of a review stack in a teardown. */
|
|
185
|
-
export const REVIEW_STACK_TYPE = "pulumi:pulumi:Stack";
|
|
186
|
-
|
|
187
|
-
/** The adapter's options: the project root, and runners for tests. */
|
|
188
|
-
export interface ReviewStackTeardownOptions {
|
|
189
|
-
cwd: string;
|
|
190
|
-
run?: PulumiRunner;
|
|
191
|
-
plunge?: PulumiRunner;
|
|
192
|
-
env?: Record<string, string>;
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
/** Core's `PrEnvTeardownAdapter` (a type only, so the lexicon bundles without core's pull request modules). */
|
|
196
|
-
export type ReviewStackTeardown = PrEnvTeardownAdapter;
|
|
197
|
-
|
|
198
|
-
/**
|
|
199
|
-
* The review stacks a pull request's environment holds, as its record's
|
|
200
|
-
* `locations` say, and their removal (#4609): `pr-env down` and the TTL
|
|
201
|
-
* sweep run it through core's teardown, after core's ownership check.
|
|
202
|
-
*
|
|
203
|
-
* The locations came from the up job, which ran the change's code, so each
|
|
204
|
-
* is checked as data first: it must read as `<engine>:<dir>#<stack>`, its
|
|
205
|
-
* `dir` must stay inside the project root, and its stack must be a review
|
|
206
|
-
* stack of this pull request (`pr-<n>` or `pr-<n>-<suffix>` for the record's
|
|
207
|
-
* `n`). Anything else is a hole, so nothing outside is removed and the
|
|
208
|
-
* environment stays live for a person to read. A review stack's marker is its
|
|
209
|
-
* name, which only `pr-<n>`'s environment gives it, so the candidate carries
|
|
210
|
-
* the environment's marker. Removal is {@link removeReviewStack}: destroy,
|
|
211
|
-
* then `stack rm` without `--force`.
|
|
212
|
-
*/
|
|
213
|
-
export function reviewStackTeardown(opts: ReviewStackTeardownOptions): ReviewStackTeardown {
|
|
214
|
-
const root = resolve(opts.cwd);
|
|
215
|
-
const read = (pr: number, location: string): { engine: PulumiMemberEngine; dir: string; stack: string } | string => {
|
|
216
|
-
const at = parseReviewStackLocation(location);
|
|
217
|
-
if (!at) return `the location "${location}" does not read as <engine>:<dir>#<stack>`;
|
|
218
|
-
const abs = resolve(root, at.dir);
|
|
219
|
-
const rel = relative(root, abs);
|
|
220
|
-
if (isAbsolute(at.dir) || rel.startsWith("..") || isAbsolute(rel)) return `the location "${location}" names a directory outside the project`;
|
|
221
|
-
const last = at.stack.split("/").pop()!;
|
|
222
|
-
if (!isReviewStackName(at.stack) || !(last === `pr-${pr}` || last.startsWith(`pr-${pr}-`))) return `the location "${location}" names a stack that is not a review stack of pull request ${pr}`;
|
|
223
|
-
return { ...at, dir: abs };
|
|
224
|
-
};
|
|
225
|
-
const byName = new Map<string, { engine: PulumiMemberEngine; dir: string; stack: string }>();
|
|
226
|
-
return {
|
|
227
|
-
name: REVIEW_STACK_TEARDOWN,
|
|
228
|
-
async owned(input) {
|
|
229
|
-
const candidates: TeardownCandidate[] = [];
|
|
230
|
-
const holes: TeardownHole[] = [];
|
|
231
|
-
for (const [component, joined] of Object.entries(input.live.locations ?? {})) {
|
|
232
|
-
for (const location of joined.split(",").map((l) => l.trim()).filter(Boolean)) {
|
|
233
|
-
if (!location.startsWith("pulumi:") && !location.startsWith("plunge:")) continue;
|
|
234
|
-
const at = read(input.live.pr, location);
|
|
235
|
-
if (typeof at === "string") {
|
|
236
|
-
holes.push({ name: `${component}: ${location}`, reason: "read-failed", type: REVIEW_STACK_TYPE, detail: at });
|
|
237
|
-
continue;
|
|
238
|
-
}
|
|
239
|
-
const name = `${relative(root, at.dir).split("\\").join("/") || "."}#${at.stack}`;
|
|
240
|
-
if (byName.has(name)) continue;
|
|
241
|
-
byName.set(name, at);
|
|
242
|
-
candidates.push({ name, type: REVIEW_STACK_TYPE, physicalId: at.stack, marker: { stack: input.marker.stack, env: input.environment } });
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
return { candidates, ...(holes.length > 0 ? { holes } : {}) };
|
|
246
|
-
},
|
|
247
|
-
async teardown(input) {
|
|
248
|
-
const outcomes: TeardownOutcome[] = [];
|
|
249
|
-
for (const c of input.candidates) {
|
|
250
|
-
const at = byName.get(c.name);
|
|
251
|
-
if (!at) {
|
|
252
|
-
outcomes.push({ name: c.name, outcome: "failed", detail: "not a review stack this teardown enumerated" });
|
|
253
|
-
continue;
|
|
254
|
-
}
|
|
255
|
-
try {
|
|
256
|
-
const run = at.engine === "plunge" ? opts.plunge : opts.run;
|
|
257
|
-
const done = await removeReviewStack({ dir: at.dir, stack: at.stack, engine: at.engine, ...(run ? { run } : {}), ...(opts.env ? { env: opts.env } : {}) });
|
|
258
|
-
outcomes.push({ name: c.name, outcome: "deleted", ...(done.status === "absent" ? { detail: "the stack was already gone" } : {}) });
|
|
259
|
-
} catch (err) {
|
|
260
|
-
outcomes.push({ name: c.name, outcome: "failed", detail: said(err) || String(err) });
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
return { outcomes };
|
|
264
|
-
},
|
|
265
|
-
};
|
|
266
|
-
}
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* `--refresh` and `--target-dependents` through the pulumi lexicon's
|
|
3
|
-
* allowlists (#4627): both in the preview and in stock `pulumi up`, in the
|
|
4
|
-
* tail's order, `--target-dependents` only after a `--target`, and no
|
|
5
|
-
* `--refresh` on plunge's `up --plan`, which applies a saved plan whose
|
|
6
|
-
* preview refreshed. Written for the ci-products post-merge pass.
|
|
7
|
-
*/
|
|
8
|
-
import { describe, expect, test } from "vitest";
|
|
9
|
-
import { plungeUpArgs, pulumiUpArgs, pulumiUpPreviewArgs, runAllowedPlunge, runAllowedPulumi, runApplyPlunge, runApplyPulumi, type PulumiRunner } from "./run";
|
|
10
|
-
import { createPulumiUpCapability } from "./pulumi-up";
|
|
11
|
-
|
|
12
|
-
function fake(): { run: PulumiRunner; calls: string[][] } {
|
|
13
|
-
const calls: string[][] = [];
|
|
14
|
-
return { run: async (args) => (calls.push(args), { stdout: "" }), calls };
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
describe("--refresh and --target-dependents (#4627)", () => {
|
|
18
|
-
test("the preview carries them in the tail's order", async () => {
|
|
19
|
-
const args = pulumiUpPreviewArgs({ stack: "dev", refresh: true, targets: ["urn:a"], targetDependents: true });
|
|
20
|
-
expect(args).toEqual(["preview", "--json", "--show-sames", "--stack", "dev", "--refresh", "--target", "urn:a", "--target-dependents"]);
|
|
21
|
-
const { run, calls } = fake();
|
|
22
|
-
await runAllowedPulumi(run, args, "/tmp");
|
|
23
|
-
await runAllowedPlunge(run, args, "/tmp");
|
|
24
|
-
expect(calls).toHaveLength(2);
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
test("--target-dependents is dropped without a target", () => {
|
|
28
|
-
expect(pulumiUpPreviewArgs({ stack: "dev", targetDependents: true })).not.toContain("--target-dependents");
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
test("stock up takes both; plunge up --plan takes --target-dependents and no --refresh", async () => {
|
|
32
|
-
const { run, calls } = fake();
|
|
33
|
-
await runApplyPulumi(run, pulumiUpArgs({ stack: "dev", refresh: true, targets: ["urn:a"], targetDependents: true }), "/tmp");
|
|
34
|
-
await runApplyPlunge(run, plungeUpArgs({ plan: "/tmp/p.json", stack: "dev", targets: ["urn:a"], targetDependents: true }), "/tmp");
|
|
35
|
-
expect(calls).toEqual([
|
|
36
|
-
["up", "--yes", "--json", "--stack", "dev", "--refresh", "--target", "urn:a", "--target-dependents"],
|
|
37
|
-
["up", "--plan", "/tmp/p.json", "--yes", "--json", "--stack", "dev", "--target", "urn:a", "--target-dependents"],
|
|
38
|
-
]);
|
|
39
|
-
await expect(runApplyPlunge(run, ["up", "--plan", "/tmp/p.json", "--yes", "--json", "--stack", "dev", "--refresh"], "/tmp")).rejects.toThrow(/applies a plunge stack only as/);
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
test("out of order, or --target-dependents with no target, is refused", async () => {
|
|
43
|
-
const { run, calls } = fake();
|
|
44
|
-
for (const tail of [["--target-dependents"], ["--target", "urn:a", "--refresh"], ["--target-dependents", "--target", "urn:a"], ["--refresh", "--refresh"]]) {
|
|
45
|
-
await expect(runApplyPulumi(run, ["up", "--yes", "--json", "--stack", "dev", ...tail], "/tmp"), tail.join(" ")).rejects.toThrow(/applies a Pulumi stack only as/);
|
|
46
|
-
}
|
|
47
|
-
expect(calls).toEqual([]);
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
test("the capability says it takes both", () => {
|
|
51
|
-
expect(createPulumiUpCapability().planFlags).toEqual({ refresh: "accept", targetDependents: "accept" });
|
|
52
|
-
});
|
|
53
|
-
});
|