@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 122 lines 4.24 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 redis from "@distilled.cloud/gcp/redis_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 // Memorystore instance create + update + delete runs well past 5 minutes.
15 const runLifecycle = !!process.env.GCP_TEST_SLOW && !process.env.FAST;
16
17 const waitUntilGone = (name: string) =>
18 redis.getProjectsLocationsInstances({ name }).pipe(
19 Effect.as("found" as const),
20 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
21 Effect.repeat({
22 schedule: Schedule.spaced("2 seconds"),
23 until: (status) => status === "gone",
24 times: 10,
25 }),
26 );
27
28 test.provider(
29 "getProjectsLocationsInstances on a missing instance fails with NotFound",
30 (stack) =>
31 Effect.gen(function* () {
32 const { project } = yield* GcpEnvironment.current;
33
34 yield* stack.destroy();
35
36 const error = yield* Effect.flip(
37 redis.getProjectsLocationsInstances({
38 name: `projects/${project}/locations/us-central1/instances/alchemy-redis-missing`,
39 }),
40 );
41 expect(error._tag).toBe("NotFound");
42
43 const page = yield* redis.listProjectsLocationsInstances({
44 parent: `projects/${project}/locations/-`,
45 pageSize: 10,
46 });
47 expect(
48 (page.instances ?? []).map((instance) => instance.name?.split("/").pop()),
49 ).not.toContain("alchemy-redis-missing");
50
51 yield* stack.destroy();
52 }).pipe(logLevel),
53 { tags: ["provider:gcp", "provider:gcp:redis", "live"], timeout: 90_000 },
54 );
55
56 test.provider.skipIf(!runLifecycle)(
57 "create, update, and delete a redis instance",
58 (stack) =>
59 Effect.gen(function* () {
60 yield* stack.destroy();
61
62 const created = yield* stack.deploy(
63 Effect.gen(function* () {
64 return yield* GCP.Redis.Instance("Cache", {
65 location: "us-central1",
66 tier: "BASIC",
67 memorySizeGb: 1,
68 displayName: "alchemy-test-cache",
69 labels: { env: "test" },
70 });
71 }),
72 );
73
74 expect(created.name).toContain("/instances/");
75 expect(created.instanceId).toEqual(expect.any(String));
76 expect(created.location).toEqual("us-central1");
77 expect(created.tier).toEqual("BASIC");
78 expect(created.memorySizeGb).toEqual(1);
79 expect(created.displayName).toEqual("alchemy-test-cache");
80 expect(created.labels).toMatchObject({ env: "test" });
81 expect(created.state).toEqual("READY");
82
83 const fetched = yield* redis.getProjectsLocationsInstances({
84 name: created.name,
85 });
86 expect(fetched.name).toEqual(created.name);
87 expect(fetched.tier).toEqual("BASIC");
88 expect(fetched.memorySizeGb).toEqual(1);
89 expect(fetched.labels?.env).toEqual("test");
90 expect(fetched.displayName).toEqual("alchemy-test-cache");
91
92 const updated = yield* stack.deploy(
93 Effect.gen(function* () {
94 return yield* GCP.Redis.Instance("Cache", {
95 instanceId: created.instanceId,
96 location: "us-central1",
97 tier: "BASIC",
98 memorySizeGb: 1,
99 displayName: "alchemy-prod-cache",
100 labels: { env: "prod", role: "cache" },
101 });
102 }),
103 );
104
105 expect(updated.name).toEqual(created.name);
106 expect(updated.displayName).toEqual("alchemy-prod-cache");
107 expect(updated.labels).toMatchObject({ env: "prod", role: "cache" });
108
109 const refetched = yield* redis.getProjectsLocationsInstances({
110 name: created.name,
111 });
112 expect(refetched.displayName).toEqual("alchemy-prod-cache");
113 expect(refetched.labels?.env).toEqual("prod");
114 expect(refetched.labels?.role).toEqual("cache");
115
116 yield* stack.destroy();
117
118 const gone = yield* waitUntilGone(created.name);
119 expect(gone).toEqual("gone");
120 }).pipe(logLevel),
121 { tags: ["provider:gcp", "provider:gcp:redis", "live"], timeout: 1_800_000 },
122 );