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

main
ts 112 lines 4.14 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 Effect from "effect/Effect";
6 import { MinimumLogLevel } from "effect/References";
7 import * as Schedule from "effect/Schedule";
8 import { withDataplexSlot } from "./quota.ts";
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 dataplex.getProjectsLocationsEntryGroupsEntries({ name }).pipe(
16 Effect.as("found" as const),
17 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
18 Effect.repeat({
19 schedule: Schedule.spaced("1 second"),
20 until: (status) => status === "gone",
21 times: 10,
22 }),
23 );
24
25 test.provider.skipIf(!!process.env.FAST)(
26 "create, update, and delete an entry",
27 (stack) =>
28 Effect.gen(function* () {
29 yield* stack.destroy();
30
31 const created = yield* stack.deploy(
32 Effect.gen(function* () {
33 const type = yield* GCP.Dataplex.EntryType("Kind", {
34 location: "us-central1",
35 displayName: "kind",
36 });
37 const group = yield* GCP.Dataplex.EntryGroup("Catalog", {
38 location: "us-central1",
39 displayName: "catalog",
40 labels: { env: "test" },
41 });
42 const entry = yield* GCP.Dataplex.EntryGroupsEntry("Orders", {
43 entryGroup: group.name,
44 entryType: type.name,
45 fullyQualifiedName: "custom:orders",
46 entrySource: {
47 system: "custom",
48 platform: "alchemy",
49 displayName: "orders a",
50 },
51 labels: { env: "test" },
52 });
53 return { type, group, entry };
54 }),
55 );
56
57 expect(created.entry.name).toContain("/entries/");
58 expect(created.entry.entryGroup).toEqual(created.group.name);
59 expect(created.entry.entryType).toContain(created.type.entryTypeId);
60 expect(created.entry.fullyQualifiedName).toEqual("custom:orders");
61 expect(created.entry.labels).toMatchObject({ env: "test" });
62
63 const fetched = yield* dataplex.getProjectsLocationsEntryGroupsEntries({
64 name: created.entry.name,
65 view: "ALL",
66 });
67 expect(fetched.name).toEqual(created.entry.name);
68 expect(fetched.entryType).toContain(created.type.entryTypeId);
69 expect(fetched.entrySource?.labels?.env).toEqual("test");
70 expect(
71 Object.keys(fetched.entrySource?.labels ?? {}).some((key) => key.startsWith("alchemy-")),
72 ).toEqual(true);
73
74 const updated = yield* stack.deploy(
75 Effect.gen(function* () {
76 const type = yield* GCP.Dataplex.EntryType("Kind", {
77 entryTypeId: created.type.entryTypeId,
78 location: "us-central1",
79 displayName: "kind",
80 });
81 const group = yield* GCP.Dataplex.EntryGroup("Catalog", {
82 entryGroupId: created.group.entryGroupId,
83 location: "us-central1",
84 displayName: "catalog",
85 labels: { env: "test" },
86 });
87 const entry = yield* GCP.Dataplex.EntryGroupsEntry("Orders", {
88 entryGroup: group.name,
89 entryId: created.entry.entryId,
90 entryType: type.name,
91 fullyQualifiedName: "custom:orders.v2",
92 entrySource: {
93 system: "custom",
94 platform: "alchemy",
95 displayName: "orders b",
96 },
97 labels: { env: "prod", team: "data" },
98 });
99 return { type, group, entry };
100 }),
101 );
102
103 expect(updated.entry.name).toEqual(created.entry.name);
104 expect(updated.entry.fullyQualifiedName).toEqual("custom:orders.v2");
105 expect(updated.entry.labels).toMatchObject({ env: "prod", team: "data" });
106
107 yield* stack.destroy();
108 const gone = yield* waitUntilGone(created.entry.name);
109 expect(gone).toEqual("gone");
110 }).pipe(logLevel, withDataplexSlot),
111 { tags: ["provider:gcp", "provider:gcp:dataplex", "live"], timeout: 900_000 },
112 );