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

main
ts 99 lines 3.87 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 dataplex from "@distilled.cloud/gcp/dataplex_v1";
5 import * as Output from "alchemy/Output";
6 import * as Effect from "effect/Effect";
7 import { MinimumLogLevel } from "effect/References";
8 import * as Schedule from "effect/Schedule";
9 import { withDataplexSlot } from "./quota.ts";
10
11 const { test } = Test.make({ providers: GCP.providers() });
12
13 const logLevel = Effect.provideService(MinimumLogLevel, process.env.DEBUG ? "Debug" : "Info");
14
15 const waitUntilGone = (name: string) =>
16 dataplex.getProjectsLocationsLakesZonesEntitiesPartitions({ name }).pipe(
17 Effect.as("found" as const),
18 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
19 Effect.repeat({
20 schedule: Schedule.spaced("2 seconds"),
21 until: (status) => status === "gone",
22 times: 10,
23 }),
24 );
25
26 // A lake (~2.5 min) plus a bucket asset (~1.5 min), then teardown of both,
27 // runs past 5 minutes.
28 test.provider.skipIf(!process.env.GCP_TEST_SLOW || !!process.env.FAST)(
29 "create and delete a lake entity partition",
30 (stack) =>
31 Effect.gen(function* () {
32 yield* stack.destroy();
33
34 const created = yield* stack.deploy(
35 Effect.gen(function* () {
36 const bucket = yield* GCP.Storage.Bucket("PartitionData", {
37 location: "US-CENTRAL1",
38 forceDestroy: true,
39 });
40 const lake = yield* GCP.Dataplex.Lake("Warehouse", {
41 location: "us-central1",
42 labels: { env: "test" },
43 });
44 const zone = yield* GCP.Dataplex.LakesZone("Landing", {
45 lake: lake.name,
46 type: "RAW",
47 locationType: "SINGLE_REGION",
48 discoverySpec: { enabled: false },
49 labels: { env: "test" },
50 });
51 const asset = yield* GCP.Dataplex.LakesAsset("RawBucket", {
52 zone: zone.name,
53 resourceSpec: {
54 type: "STORAGE_BUCKET",
55 name: Output.interpolate`projects/${bucket.projectNumber}/buckets/${bucket.bucketName}`,
56 },
57 discoverySpec: { enabled: false },
58 labels: { env: "test" },
59 });
60 const entity = yield* GCP.Dataplex.LakesEntity("Events", {
61 zone: zone.name,
62 asset: asset.assetId,
63 type: "TABLE",
64 system: "CLOUD_STORAGE",
65 dataPath: Output.interpolate`gs://${bucket.bucketName}/events`,
66 format: { format: "PARQUET" },
67 schema: {
68 userManaged: true,
69 fields: [{ name: "id", type: "STRING", mode: "REQUIRED" }],
70 partitionFields: [{ name: "dt", type: "STRING" }],
71 partitionStyle: "HIVE_COMPATIBLE",
72 },
73 });
74 const partition = yield* GCP.Dataplex.LakesEntitiesPartition("Day", {
75 entity: entity.name,
76 values: ["2024-01-01"],
77 location: Output.interpolate`gs://${bucket.bucketName}/events/dt=2024-01-01`,
78 });
79 return { bucket, lake, zone, asset, entity, partition };
80 }),
81 );
82
83 expect(created.partition.name).toContain("/partitions/");
84 expect(created.partition.values).toEqual(["2024-01-01"]);
85 expect(created.partition.entity).toEqual(created.entity.name);
86 expect(created.partition.location).toContain("dt=2024-01-01");
87
88 const fetched = yield* dataplex.getProjectsLocationsLakesZonesEntitiesPartitions({
89 name: created.partition.name,
90 });
91 expect(fetched.name).toEqual(created.partition.name);
92 expect(fetched.values).toEqual(["2024-01-01"]);
93
94 yield* stack.destroy();
95 const gone = yield* waitUntilGone(created.partition.name);
96 expect(gone).toEqual("gone");
97 }).pipe(logLevel, withDataplexSlot),
98 { tags: ["provider:gcp", "provider:gcp:dataplex", "live"], timeout: 900_000 },
99 );