The best way to control Claude Code, Codex and more from any computer or phone

main
ts 116 lines 4.31 KB
Raw
1 import * as GCP from "@alchemy.run/gcp";
2 import { expect } from "@alchemy.run/test";
3 import * as Test from "@alchemy.run/test/Alchemy";
4 import * as securityposture from "@distilled.cloud/gcp/securityposture_v1";
5 import * as Effect from "effect/Effect";
6 import {
7 logLevel,
8 organization,
9 runLifecycle,
10 waitUntilDeploymentGone,
11 waitUntilPostureGone,
12 } from "./common.ts";
13
14 const { test } = Test.make({ providers: GCP.providers() });
15
16 test.provider.skipIf(!runLifecycle)(
17 "getOrganizationsLocationsPostureDeployments on a missing deployment fails with a typed tag",
18 (stack) =>
19 Effect.gen(function* () {
20 yield* stack.destroy();
21
22 const error = yield* Effect.flip(
23 securityposture.getOrganizationsLocationsPostureDeployments({
24 name: `${organization}/locations/global/postureDeployments/alchemy-missing`,
25 }),
26 );
27 expect(error._tag).toEqual("NotFound");
28
29 yield* stack.destroy();
30 }).pipe(logLevel),
31 {
32 tags: ["provider:gcp", "provider:gcp:securityposture", "live"],
33 timeout: 90_000,
34 },
35 );
36
37 test.provider.skipIf(!runLifecycle)(
38 "create, update, and delete a posture deployment",
39 (stack) =>
40 Effect.gen(function* () {
41 yield* stack.destroy();
42
43 const created = yield* stack.deploy(
44 Effect.gen(function* () {
45 const posture = yield* GCP.SecurityPosture.Posture("Baseline", {
46 organization,
47 state: "ACTIVE",
48 description: "deployable baseline",
49 annotations: { env: "test" },
50 });
51 const deployment = yield* GCP.SecurityPosture.PostureDeployment("Staging", {
52 organization,
53 postureId: posture.name,
54 postureRevisionId: posture.revisionId.as<string>(),
55 description: "staging deployment",
56 annotations: { env: "test" },
57 });
58 return { posture, deployment };
59 }),
60 );
61
62 expect(created.posture.state).toEqual("ACTIVE");
63 expect(created.posture.revisionId).toEqual(expect.any(String));
64 expect(created.deployment.postureDeploymentId).toEqual(expect.any(String));
65 expect(created.deployment.organization).toEqual(organization);
66 expect(created.deployment.name).toEqual(
67 `${organization}/locations/global/postureDeployments/${created.deployment.postureDeploymentId}`,
68 );
69 expect(created.deployment.postureId).toEqual(created.posture.name);
70 expect(created.deployment.postureRevisionId).toEqual(created.posture.revisionId);
71 expect(created.deployment.description).toEqual("staging deployment");
72 expect(created.deployment.annotations).toMatchObject({ env: "test" });
73
74 const fetched = yield* securityposture.getOrganizationsLocationsPostureDeployments({
75 name: created.deployment.name,
76 });
77 expect(fetched.name).toEqual(created.deployment.name);
78 expect(fetched.annotations?.["alchemy-id"]).toEqual(expect.any(String));
79
80 const updated = yield* stack.deploy(
81 Effect.gen(function* () {
82 const posture = yield* GCP.SecurityPosture.Posture("Baseline", {
83 organization,
84 postureId: created.posture.postureId,
85 state: "ACTIVE",
86 description: "deployable baseline v2",
87 annotations: { env: "prod" },
88 });
89 const deployment = yield* GCP.SecurityPosture.PostureDeployment("Staging", {
90 organization,
91 postureDeploymentId: created.deployment.postureDeploymentId,
92 postureId: posture.name,
93 postureRevisionId: posture.revisionId.as<string>(),
94 description: "staging deployment v2",
95 annotations: { env: "prod" },
96 });
97 return { posture, deployment };
98 }),
99 );
100
101 expect(updated.deployment.name).toEqual(created.deployment.name);
102 expect(updated.deployment.postureId).toEqual(updated.posture.name);
103 expect(updated.posture.description).toEqual("deployable baseline v2");
104
105 yield* stack.destroy();
106
107 const deploymentGone = yield* waitUntilDeploymentGone(created.deployment.name);
108 expect(deploymentGone).toEqual("gone");
109 const postureGone = yield* waitUntilPostureGone(created.posture.name);
110 expect(postureGone).toEqual("gone");
111 }).pipe(logLevel),
112 {
113 tags: ["provider:gcp", "provider:gcp:securityposture", "live"],
114 timeout: 120_000,
115 },
116 );