@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 96 lines 3.46 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 compute from "@distilled.cloud/gcp/compute_v1";
5 import * as Effect from "effect/Effect";
6 import { MinimumLogLevel } from "effect/References";
7 import * as Schedule from "effect/Schedule";
8
9 const { test } = Test.make({ providers: GCP.providers() });
10
11 const logLevel = Effect.provideService(MinimumLogLevel, process.env.DEBUG ? "Debug" : "Info");
12
13 const waitUntilGone = (project: string, name: string) =>
14 compute.getBackendBuckets({ project, backendBucket: name }).pipe(
15 Effect.as("found" as const),
16 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
17 Effect.repeat({
18 schedule: Schedule.spaced("1 second"),
19 until: (status) => status === "gone",
20 times: 10,
21 }),
22 );
23
24 test.provider(
25 "create, update, and delete a backend bucket",
26 (stack) =>
27 Effect.gen(function* () {
28 yield* stack.destroy();
29
30 const created = yield* stack.deploy(
31 Effect.gen(function* () {
32 const assets = yield* GCP.Storage.Bucket("Assets", {
33 location: "US-CENTRAL1",
34 forceDestroy: true,
35 });
36 return yield* GCP.Compute.BackendBucket("Cdn", {
37 bucketName: assets.bucketName,
38 description: "static assets",
39 });
40 }),
41 );
42
43 expect(created.name).toEqual(expect.any(String));
44 expect(created.bucketName).toEqual(expect.any(String));
45 expect(created.description).toEqual("static assets");
46 expect(created.enableCdn).toEqual(false);
47
48 const fetched = yield* compute.getBackendBuckets({
49 project: created.project,
50 backendBucket: created.name,
51 });
52 expect(fetched.name).toEqual(created.name);
53 expect(fetched.bucketName).toEqual(created.bucketName);
54 expect(fetched.description).toContain("alchemy-id=");
55 expect(fetched.description).toContain("static assets");
56
57 const updated = yield* stack.deploy(
58 Effect.gen(function* () {
59 const assets = yield* GCP.Storage.Bucket("Assets", {
60 bucketName: created.bucketName,
61 location: "US-CENTRAL1",
62 forceDestroy: true,
63 });
64 return yield* GCP.Compute.BackendBucket("Cdn", {
65 name: created.name,
66 bucketName: assets.bucketName,
67 description: "cdn origin",
68 enableCdn: true,
69 compressionMode: "AUTOMATIC",
70 customResponseHeaders: ["X-Frame-Options: DENY"],
71 });
72 }),
73 );
74
75 expect(updated.name).toEqual(created.name);
76 expect(updated.bucketName).toEqual(created.bucketName);
77 expect(updated.description).toEqual("cdn origin");
78 expect(updated.enableCdn).toEqual(true);
79 expect(updated.compressionMode).toEqual("AUTOMATIC");
80 expect(updated.customResponseHeaders).toContain("X-Frame-Options: DENY");
81
82 const refetched = yield* compute.getBackendBuckets({
83 project: updated.project,
84 backendBucket: updated.name,
85 });
86 expect(refetched.enableCdn).toEqual(true);
87 expect(refetched.description).toContain("cdn origin");
88 expect(refetched.customResponseHeaders).toContain("X-Frame-Options: DENY");
89
90 yield* stack.destroy();
91
92 const gone = yield* waitUntilGone(created.project, created.name);
93 expect(gone).toEqual("gone");
94 }).pipe(logLevel),
95 { tags: ["provider:gcp", "provider:gcp:compute", "live"], timeout: 120_000 },
96 );