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

main
ts 93 lines 3.5 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.getProjectsLocationsGlossariesTerms({ 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 a glossary term",
27 (stack) =>
28 Effect.gen(function* () {
29 yield* stack.destroy();
30
31 const created = yield* stack.deploy(
32 Effect.gen(function* () {
33 const glossary = yield* GCP.Dataplex.Glossary("BusinessTerms", {
34 location: "us-central1",
35 displayName: "terms parent",
36 labels: { env: "test" },
37 });
38 const term = yield* GCP.Dataplex.GlossariesTerm("Customer", {
39 glossary: glossary.name,
40 displayName: "Customer",
41 description: "a paying account",
42 labels: { env: "test" },
43 });
44 return { glossary, term };
45 }),
46 );
47
48 expect(created.term.name).toContain("/terms/");
49 expect(created.term.termId).toEqual(expect.any(String));
50 expect(created.term.glossary).toEqual(created.glossary.name);
51 expect(created.term.displayName).toEqual("Customer");
52 expect(created.term.description).toEqual("a paying account");
53 expect(created.term.labels).toMatchObject({ env: "test" });
54
55 const fetched = yield* dataplex.getProjectsLocationsGlossariesTerms({
56 name: created.term.name,
57 });
58 expect(fetched.name).toEqual(created.term.name);
59 expect(fetched.labels?.env).toEqual("test");
60 expect(Object.keys(fetched.labels ?? {}).some((key) => key.startsWith("alchemy-"))).toEqual(
61 true,
62 );
63
64 const updated = yield* stack.deploy(
65 Effect.gen(function* () {
66 const glossary = yield* GCP.Dataplex.Glossary("BusinessTerms", {
67 glossaryId: created.glossary.glossaryId,
68 location: "us-central1",
69 displayName: "terms parent",
70 labels: { env: "test" },
71 });
72 const term = yield* GCP.Dataplex.GlossariesTerm("Customer", {
73 glossary: glossary.name,
74 termId: created.term.termId,
75 displayName: "Customer account",
76 description: "updated term",
77 labels: { env: "prod", team: "data" },
78 });
79 return { glossary, term };
80 }),
81 );
82
83 expect(updated.term.name).toEqual(created.term.name);
84 expect(updated.term.displayName).toEqual("Customer account");
85 expect(updated.term.description).toEqual("updated term");
86 expect(updated.term.labels).toMatchObject({ env: "prod", team: "data" });
87
88 yield* stack.destroy();
89 const gone = yield* waitUntilGone(created.term.name);
90 expect(gone).toEqual("gone");
91 }).pipe(logLevel, withDataplexSlot),
92 { tags: ["provider:gcp", "provider:gcp:dataplex", "live"], timeout: 900_000 },
93 );