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

main
ts 95 lines 3.46 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 dataplex from "@distilled.cloud/gcp/dataplex_v1";
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 // Data domains are allowlisted: the testing project gets Forbidden
16 // "Permission 'dataplex.dataDomains.get' denied". Set
17 // GCP_TEST_DATAPLEX_DATA_DOMAIN=1 on an allowlisted project.
18 const runLifecycle = process.env.GCP_TEST_DATAPLEX_DATA_DOMAIN === "1";
19
20 const waitUntilGone = (name: string) =>
21 dataplex.getProjectsLocationsDataDomainsBindings({ name }).pipe(
22 Effect.as("found" as const),
23 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
24 Effect.repeat({
25 schedule: Schedule.spaced("1 second"),
26 until: (status) => status === "gone",
27 times: 10,
28 }),
29 );
30
31 test.provider(
32 "getProjectsLocationsDataDomainsBindings on a missing binding fails with a typed tag",
33 (stack) =>
34 Effect.gen(function* () {
35 const { project } = yield* GcpEnvironment.current;
36 yield* stack.destroy();
37
38 const error = yield* Effect.flip(
39 dataplex.getProjectsLocationsDataDomainsBindings({
40 name: `projects/${project}/locations/us-central1/dataDomains/alchemy-missing/bindings/alchemy-missing`,
41 }),
42 );
43 expect(error._tag).toEqual(runLifecycle ? "NotFound" : "Forbidden");
44
45 yield* stack.destroy();
46 }).pipe(logLevel, withDataplexSlot),
47 { tags: ["provider:gcp", "provider:gcp:dataplex", "live"], timeout: 900_000 },
48 );
49
50 test.provider.skipIf(!runLifecycle)(
51 "create and delete a data domain binding",
52 (stack) =>
53 Effect.gen(function* () {
54 const { project } = yield* GcpEnvironment.current;
55 yield* stack.destroy();
56
57 const created = yield* stack.deploy(
58 Effect.gen(function* () {
59 const domain = yield* GCP.Dataplex.DataDomain("Finance", {
60 location: "us-central1",
61 displayName: "Finance",
62 labels: { env: "test" },
63 contacts: {
64 identities: [
65 {
66 contactName: "steward",
67 contactRole: "steward",
68 contactId: "steward@example.com",
69 },
70 ],
71 },
72 });
73 return yield* GCP.Dataplex.DataDomainsBinding("Project", {
74 parent: domain.name,
75 resource: `//cloudresourcemanager.googleapis.com/projects/${project}`,
76 });
77 }),
78 );
79
80 expect(created.name).toContain("/bindings/");
81 expect(created.dataDomainBindingId).toEqual(expect.any(String));
82 expect(created.resource).toContain(`projects/${project}`);
83
84 const fetched = yield* dataplex.getProjectsLocationsDataDomainsBindings({
85 name: created.name,
86 });
87 expect(fetched.name).toEqual(created.name);
88 expect(fetched.resource).toEqual(created.resource);
89
90 yield* stack.destroy();
91 const gone = yield* waitUntilGone(created.name);
92 expect(gone).toEqual("gone");
93 }).pipe(logLevel, withDataplexSlot),
94 { tags: ["provider:gcp", "provider:gcp:dataplex", "live"], timeout: 900_000 },
95 );