@devries-cameron20 / t3code Mirror · read-only
Fork 0

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

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 06:00 UTC

main
ts 116 lines 4.04 KB
Raw
1 import * as GCP from "@alchemy.run/gcp";
2 import { GcpEnvironment } from "@alchemy.run/gcp/Environment";
3 import { expect } from "@alchemy.run/test";
4 import * as Test from "@alchemy.run/test/Alchemy";
5 import * as config from "@distilled.cloud/gcp/config_v1";
6 import * as Effect from "effect/Effect";
7 import { MinimumLogLevel } from "effect/References";
8 import * as Schedule from "effect/Schedule";
9
10 const { test } = Test.make({ providers: GCP.providers() });
11
12 const logLevel = Effect.provideService(MinimumLogLevel, process.env.DEBUG ? "Debug" : "Info");
13
14 // A preview runs Terraform through Cloud Build as a service account that
15 // needs Infra Manager roles. Set GCP_TEST_CONFIG=1 on a project prepared for
16 // it to run the full lifecycle.
17 const entitled = process.env.GCP_TEST_CONFIG === "1";
18 const runLifecycle = entitled && !process.env.FAST;
19
20 const waitUntilGone = (name: string) =>
21 config.getProjectsLocationsPreviews({ name }).pipe(
22 Effect.as("found" as const),
23 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
24 Effect.repeat({
25 schedule: Schedule.spaced("2 seconds"),
26 until: (status) => status === "gone",
27 times: 10,
28 }),
29 );
30
31 test.provider(
32 "getProjectsLocationsPreviews on a missing preview fails with a typed tag",
33 (stack) =>
34 Effect.gen(function* () {
35 const { project } = yield* GcpEnvironment.current;
36 yield* stack.destroy();
37
38 const error = yield* Effect.flip(
39 config.getProjectsLocationsPreviews({
40 name: `projects/${project}/locations/us-central1/previews/alchemy-missing-preview`,
41 }),
42 );
43 expect(error._tag).toEqual("NotFound");
44
45 yield* stack.destroy();
46 }).pipe(logLevel),
47 { tags: ["provider:gcp", "provider:gcp:config", "live"], timeout: 90_000 },
48 );
49
50 test.provider(
51 "create preview without a blueprint is rejected with BadRequest",
52 (stack) =>
53 Effect.gen(function* () {
54 const { project } = yield* GcpEnvironment.current;
55 const serviceAccount = `projects/${project}/serviceAccounts/alchemy-testing@${project}.iam.gserviceaccount.com`;
56 yield* stack.destroy();
57
58 const error = yield* Effect.flip(
59 stack.deploy(
60 Effect.gen(function* () {
61 return yield* GCP.Config.Preview("Plan", {
62 serviceAccount,
63 });
64 }),
65 ),
66 );
67 // "invalid preview: missing required terraform blueprint specification"
68 expect(error._tag).toEqual("BadRequest");
69
70 yield* stack.destroy();
71 }).pipe(logLevel),
72 { tags: ["provider:gcp", "provider:gcp:config", "live"], timeout: 90_000 },
73 );
74
75 test.provider.skipIf(!runLifecycle)(
76 "create and delete a preview",
77 (stack) =>
78 Effect.gen(function* () {
79 const { project } = yield* GcpEnvironment.current;
80 const serviceAccount = `projects/${project}/serviceAccounts/alchemy-testing@${project}.iam.gserviceaccount.com`;
81 yield* stack.destroy();
82
83 const created = yield* stack.deploy(
84 Effect.gen(function* () {
85 return yield* GCP.Config.Preview("Plan", {
86 serviceAccount,
87 terraformBlueprint: {
88 gitSource: {
89 repo: "https://github.com/terraform-google-modules/terraform-docs-samples.git",
90 directory: "storage/quickstart",
91 },
92 },
93 labels: { env: "test" },
94 });
95 }),
96 );
97
98 expect(created.name).toContain("/previews/");
99 expect(created.previewId).toEqual(expect.any(String));
100 expect(created.location).toEqual("us-central1");
101 expect(created.serviceAccount).toEqual(serviceAccount);
102 expect(created.labels).toMatchObject({ env: "test" });
103
104 const fetched = yield* config.getProjectsLocationsPreviews({
105 name: created.name,
106 });
107 expect(fetched.name).toEqual(created.name);
108 expect(fetched.labels?.env).toEqual("test");
109
110 yield* stack.destroy();
111
112 const gone = yield* waitUntilGone(created.name);
113 expect(gone).toEqual("gone");
114 }).pipe(logLevel),
115 { tags: ["provider:gcp", "provider:gcp:config", "live"], timeout: 120_000 },
116 );