@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 103 lines 3.59 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 logging from "@distilled.cloud/gcp/logging_v2";
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 const waitUntilGone = (name: string) =>
15 logging.getLocationsBuckets({ name }).pipe(
16 Effect.map((bucket) =>
17 bucket.lifecycleState === "DELETE_REQUESTED" ? ("gone" as const) : ("found" as const),
18 ),
19 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
20 Effect.repeat({
21 schedule: Schedule.spaced("1 second"),
22 until: (status) => status === "gone",
23 times: 10,
24 }),
25 );
26
27 test.provider(
28 "create, update, replace, and delete a locations logging bucket",
29 (stack) =>
30 Effect.gen(function* () {
31 const { project } = yield* GcpEnvironment.current;
32
33 yield* stack.destroy();
34
35 const created = yield* stack.deploy(
36 Effect.gen(function* () {
37 return yield* GCP.Logging.LocationsBucket("AppLogs", {
38 description: "application logs",
39 retentionDays: 31,
40 });
41 }),
42 );
43
44 expect(created.bucketId).toEqual(expect.any(String));
45 expect(created.location).toEqual("global");
46 expect(created.parent).toEqual(`projects/${project}`);
47 expect(created.name).toEqual(
48 `projects/${project}/locations/global/buckets/${created.bucketId}`,
49 );
50 expect(created.description).toEqual("application logs");
51 expect(created.retentionDays).toEqual(31);
52 expect(created.lifecycleState).toEqual("ACTIVE");
53
54 const fetched = yield* logging.getLocationsBuckets({
55 name: created.name,
56 });
57 expect(fetched.name).toEqual(created.name);
58 expect(fetched.retentionDays).toEqual(31);
59 expect(fetched.description).toContain("alchemy-id=");
60 expect(fetched.description).toContain("application logs");
61
62 const updated = yield* stack.deploy(
63 Effect.gen(function* () {
64 return yield* GCP.Logging.LocationsBucket("AppLogs", {
65 bucketId: created.bucketId,
66 location: created.location,
67 description: "retained application logs",
68 retentionDays: 60,
69 });
70 }),
71 );
72
73 expect(updated.name).toEqual(created.name);
74 expect(updated.description).toEqual("retained application logs");
75 expect(updated.retentionDays).toEqual(60);
76
77 const last = created.bucketId.at(-1) ?? "a";
78 const nextBucketId = `${created.bucketId.slice(0, -1)}${last === "z" ? "0" : "z"}`;
79
80 const replaced = yield* stack.deploy(
81 Effect.gen(function* () {
82 return yield* GCP.Logging.LocationsBucket("AppLogs", {
83 bucketId: nextBucketId,
84 location: "global",
85 description: "replaced bucket",
86 retentionDays: 31,
87 });
88 }),
89 );
90
91 expect(replaced.bucketId).not.toEqual(created.bucketId);
92 expect(replaced.description).toEqual("replaced bucket");
93
94 const previousGone = yield* waitUntilGone(created.name);
95 expect(previousGone).toEqual("gone");
96
97 yield* stack.destroy();
98
99 const gone = yield* waitUntilGone(replaced.name);
100 expect(gone).toEqual("gone");
101 }).pipe(logLevel),
102 { tags: ["provider:gcp", "provider:gcp:logging", "live"], timeout: 90_000 },
103 );