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

main
ts 72 lines 2.72 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.getProjectsLocationsBucketsLinks({ name }).pipe(
16 Effect.map((link) =>
17 link.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("2 seconds"),
22 until: (status) => status === "gone",
23 times: 10,
24 }),
25 );
26
27 test.provider.skipIf(!!process.env.FAST)(
28 "create and delete a logging bucket link",
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 const bucket = yield* GCP.Logging.LogBucket("AppLogs", {
38 analyticsEnabled: true,
39 description: "analytics parent",
40 });
41 const link = yield* GCP.Logging.BucketsLink("Analytics", {
42 bucket: bucket.name,
43 description: "bigquery analytics",
44 });
45 return { bucket, link };
46 }),
47 );
48
49 expect(created.link.linkId).toEqual(expect.any(String));
50 expect(created.link.linkId).toMatch(/^[a-z][a-z0-9_]*$/);
51 expect(created.link.bucket).toEqual(created.bucket.name);
52 expect(created.link.project).toEqual(project);
53 expect(created.link.location).toEqual("global");
54 expect(created.link.name).toEqual(`${created.bucket.name}/links/${created.link.linkId}`);
55 expect(created.link.description).toEqual("bigquery analytics");
56 expect(created.link.lifecycleState).toEqual("ACTIVE");
57
58 const fetched = yield* logging.getProjectsLocationsBucketsLinks({
59 name: created.link.name,
60 });
61 expect(fetched.name).toEqual(created.link.name);
62 expect(fetched.lifecycleState).toEqual("ACTIVE");
63 expect(fetched.description).toContain("alchemy-id=");
64 expect(fetched.description).toContain("bigquery analytics");
65
66 yield* stack.destroy();
67
68 const gone = yield* waitUntilGone(created.link.name);
69 expect(gone).toEqual("gone");
70 }).pipe(logLevel),
71 { tags: ["provider:gcp", "provider:gcp:logging", "live"], timeout: 180_000 },
72 );