@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 87 lines 3.15 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.getFoldersLocationsBucketsLinks({ 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(
28 "getFoldersLocationsBucketsLinks on a missing link fails with NotFound",
29 (stack) =>
30 Effect.gen(function* () {
31 const { project } = yield* GcpEnvironment.current;
32
33 yield* stack.destroy();
34
35 const error = yield* Effect.flip(
36 logging.getFoldersLocationsBucketsLinks({
37 name: `projects/${project}/locations/global/buckets/_Default/links/alchemy-does-not-exist`,
38 }),
39 );
40 expect(error._tag).toBe("NotFound");
41
42 yield* stack.destroy();
43 }).pipe(logLevel),
44 { tags: ["provider:gcp", "provider:gcp:logging", "live"], timeout: 90_000 },
45 );
46
47 test.provider.skipIf(!!process.env.FAST)(
48 "create and delete a folder logging bucket link",
49 (stack) =>
50 Effect.gen(function* () {
51 yield* stack.destroy();
52
53 const created = yield* stack.deploy(
54 Effect.gen(function* () {
55 const bucket = yield* GCP.Logging.LogBucket("FolderLinkBucket", {
56 analyticsEnabled: true,
57 description: "analytics parent",
58 });
59 const link = yield* GCP.Logging.FolderBucketsLink("FolderLink", {
60 bucketName: bucket.name,
61 description: "bigquery analytics",
62 });
63 return { bucket, link };
64 }),
65 );
66
67 expect(created.link.linkId).toEqual(expect.any(String));
68 expect(created.link.linkId).toMatch(/^[a-z][a-z0-9_]*$/);
69 expect(created.link.bucketName).toEqual(created.bucket.name);
70 expect(created.link.name).toEqual(`${created.bucket.name}/links/${created.link.linkId}`);
71 expect(created.link.description).toEqual("bigquery analytics");
72 expect(["ACTIVE", "CREATING"]).toContain(created.link.lifecycleState);
73
74 const fetched = yield* logging.getFoldersLocationsBucketsLinks({
75 name: created.link.name,
76 });
77 expect(fetched.name).toEqual(created.link.name);
78 expect(fetched.description).toContain("alchemy-id=");
79 expect(fetched.description).toContain("bigquery analytics");
80
81 yield* stack.destroy();
82
83 const gone = yield* waitUntilGone(created.link.name);
84 expect(gone).toEqual("gone");
85 }).pipe(logLevel),
86 { tags: ["provider:gcp", "provider:gcp:logging", "live"], timeout: 180_000 },
87 );